From: tjhunt Date: Wed, 6 May 2009 08:55:53 +0000 (+0000) Subject: moodle_page: MDL-12212 Kill legacy url_... and blocks_... methods X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ad52c04f4c7e3294d1d8bcabbac74f6ad940df20;p=moodle.git moodle_page: MDL-12212 Kill legacy url_... and blocks_... methods Start calling $PAGE->set_url in all the places it will be necessary Start of a stub implementation of $PAGE->blocks to stop other things breaking Remove some of the special case methods in admin_page --- diff --git a/admin/pagelib.php b/admin/pagelib.php index 2a7ad1cae2..374b1aa959 100644 --- a/admin/pagelib.php +++ b/admin/pagelib.php @@ -19,35 +19,9 @@ define('BLOCK_R_MAX_WIDTH', $rmax); page_map_class(PAGE_ADMIN, 'page_admin'); class page_admin extends page_base { - - var $section = ''; - var $visiblepathtosection; - var $extraurlparams = array(); var $extrabutton = ''; - var $url = ''; - - // hack alert! - // this function works around the inability to store the section name - // in default block, maybe we should "improve" the blocks a bit? - function init_extra($section) { - global $CFG; - - if($this->full_init_done) { - return; - } - $adminroot = admin_get_root(false, false); //settings not required - only pages - - // fetch the path parameter - $this->section = $section; - $current = $adminroot->locate($section, true); - $this->visiblepathtosection = array_reverse($current->visiblepath); - - // all done - $this->full_init_done = true; - } - - function blocks_get_default() { + function _legacy_blocks_get_default() { return 'admin_tree,admin_bookmarks'; } @@ -63,22 +37,6 @@ class page_admin extends page_base { return $USER->adminediting; } - function url_get_path() { - global $CFG; - if (!empty($this->url)) { - return $this->url; - } - - $adminroot = admin_get_root(false, false); //settings not required - only pages - - $root = $adminroot->locate($this->section); - if ($root instanceof admin_externalpage) { - return $root->url; - } else { - return ($CFG->wwwroot . '/' . $CFG->admin . '/settings.php'); - } - } - /** * Use this to pass extra HTML that is added after the turn blocks editing on/off button. * @@ -88,31 +46,19 @@ class page_admin extends page_base { $this->extrabutton = $extrabutton; } - /** - * Use this to pass extra URL parameters that, for example, the blocks editing controls need to reload the current page accurately. - * - * @param array $extraurlparams paramname => value array. - */ - function set_extra_url_params($extraurlparams, $actualurl = '') { - $this->extraurlparams = $extraurlparams; - if (!empty($actualurl)) { - $this->url = $actualurl; - } - } - - function url_get_parameters() { // only handles parameters relevant to the admin pagetype - return array_merge($this->extraurlparams, array('section' => $this->section)); - } - - function print_header($section = '', $focus='') { + function print_header($focus='') { global $USER, $CFG, $SITE; - $this->init_full($section); // we're trusting that init_full() has already been called by now; it should have. - // if not, print_header() has to be called with a $section parameter + $adminroot = admin_get_root(false, false); //settings not required - only pages + + // fetch the path parameter + $section = $this->url->param('section'); + $current = $adminroot->locate($section, true); + $visiblepathtosection = array_reverse($current->visiblepath); // The search page currently doesn't handle block editing - if ($this->section != 'search' and $this->user_allowed_editing()) { - $options = $this->url_get_parameters(); + if ($this->user_allowed_editing()) { + $options = $this->url->params(); if ($this->user_is_editing()) { $caption = get_string('blockseditoff'); $options['adminedit'] = 'off'; @@ -120,19 +66,17 @@ class page_admin extends page_base { $caption = get_string('blocksediton'); $options['adminedit'] = 'on'; } - $buttons = print_single_button($this->url_get_path(), $options, $caption, 'get', '', true); - } else { - $buttons = ' '; + $buttons = print_single_button($this->url->out(false), $options, $caption, 'get', '', true); } $buttons .= $this->extrabutton; $navlinks = array(); - foreach ($this->visiblepathtosection as $element) { + foreach ($visiblepathtosection as $element) { $navlinks[] = array('name' => $element, 'link' => null, 'type' => 'misc'); } $navigation = build_navigation($navlinks); - print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection), $SITE->fullname, $navigation, $focus, '', true, $buttons, ''); + print_header("$SITE->shortname: " . implode(": ",$visiblepathtosection), $SITE->fullname, $navigation, $focus, '', true, $buttons, ''); } } diff --git a/admin/search.php b/admin/search.php index 2d13ba56ba..a1de51bedb 100644 --- a/admin/search.php +++ b/admin/search.php @@ -7,13 +7,14 @@ require_once($CFG->libdir.'/adminlib.php'); $query = trim(optional_param('query', '', PARAM_NOTAGS)); // Search string +$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); $adminroot = admin_get_root(); // need all settings here $adminroot->search = $query; // So we can reference it in search boxes later in this invocation $statusmsg = ''; $errormsg = ''; $focus = ''; -admin_externalpage_setup('search'); // now hidden page +admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page // now we'll deal with the case that the admin has submitted the form with changed settings if ($data = data_submitted() and confirm_sesskey()) { diff --git a/admin/settings.php b/admin/settings.php index ae1aefde59..4be5405510 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -12,6 +12,7 @@ $adminediting = optional_param('adminedit', -1, PARAM_BOOL); /// no guest autologin require_login(0, false); $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_url($CFG->admin . '/settings.php', array('section' => $section)); $adminroot = admin_get_root(); // need all settings $page = $adminroot->locate($section); @@ -106,7 +107,7 @@ if (empty($SITE->fullname)) { $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH); - $PAGE->print_header('', $focus); + $PAGE->print_header($focus); echo ''; $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable; diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index c6bb802c43..e4471ffdb7 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -462,7 +462,7 @@ class block_base { } else { $page = page_create_object($this->instance->pagetype, $this->instance->pageid); } - $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => sesskey())); + $script = $page->url->out(array('instanceid' => $this->instance->id, 'sesskey' => sesskey())); if (empty($this->instance->pinned)) { $movebuttons .= '' . diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php index 4fc064ca56..dcceaf4f17 100644 --- a/blocks/rss_client/block_rss_client.php +++ b/blocks/rss_client/block_rss_client.php @@ -109,7 +109,7 @@ //if ($page->user_allowed_editing()) { // for SUBMITTERS_ALL_ACCOUNT_HOLDERS we're going to run into trouble later if we show it and then they don't have write access to the page. if (isset($this->config)) { // This instance is configured - show Add/Edit feeds link. - $script = $page->url_get_full( + $script = $page->url->out( array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', @@ -121,7 +121,7 @@ } else { // This instance has not been configured yet - show configure link? if (has_capability('block/rss_client:manageanyfeeds', $context)) { - $script = $page->url_get_full( + $script = $page->url->out( array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', diff --git a/blocks/rss_client/config_instance.html b/blocks/rss_client/config_instance.html index 9abb4d3bbc..83f6d76ef3 100644 --- a/blocks/rss_client/config_instance.html +++ b/blocks/rss_client/config_instance.html @@ -103,9 +103,9 @@ print_box_start(); if (has_capability('block/rss_client:createprivatefeeds', $context) || has_capability('block/rss_client:createsharedfeeds', $context)) { - $addrsspage = $page->url_get_full(array('instanceid' => $this->instance->id, + $addrsspage = $page->url->out(array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), - 'blockaction' => 'config', + 'blockaction' => 'config', 'currentaction' => 'managefeeds', 'id' => $id)); print ' '. get_string('editnewsfeeds', 'block_rss_client') .'
'; diff --git a/blocks/rss_client/config_instance_tabs.php b/blocks/rss_client/config_instance_tabs.php index 24a6447753..e8541e0d0b 100644 --- a/blocks/rss_client/config_instance_tabs.php +++ b/blocks/rss_client/config_instance_tabs.php @@ -13,12 +13,12 @@ if (empty($this->instance->pinned)) { } if (has_capability('moodle/site:manageblocks', $context)) { - $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', 'currentaction' => 'configblock', 'id' => $id, 'section' => 'rss')); + $script = $page->url->out(array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', 'currentaction' => 'configblock', 'id' => $id, 'section' => 'rss')); $row[] = new tabobject('configblock', $script, get_string('configblock', 'block_rss_client')); } -$script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', 'currentaction' => 'managefeeds', 'id' => $id, 'section' => 'rss')); +$script = $page->url->out(array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', 'currentaction' => 'managefeeds', 'id' => $id, 'section' => 'rss')); $row[] = new tabobject('managefeeds', $script, get_string('managefeeds', 'block_rss_client')); diff --git a/blog/blogpage.php b/blog/blogpage.php index aa00ba2323..2f3e952dd5 100644 --- a/blog/blogpage.php +++ b/blog/blogpage.php @@ -80,36 +80,6 @@ class page_blog extends page_base { print_header($pageTitle, $pageHeading, $pageNavigation, $pageFocus, $pageMeta, true, $extraheader ); } - // This should point to the script that displays us - function url_get_path() { - global $CFG; - - return $CFG->wwwroot .'/blog/index.php'; - } - - function url_get_parameters() { - - $array = array(); - if (!$this->full_init_done) { - $array['userid'] = $this->id; - return $array; - } - - if (!empty($this->course->id)) { - $array['courseid'] = $this->course->id; - } - if (!empty($this->filtertype)) { - $array['filtertype'] = $this->filtertype; - } - if (!empty($this->filterselect)) { - $array['filterselect'] = $this->filterselect; - } - if (!empty($this->tagid)) { - $array['tagid'] = $this->tagid; - } - return $array; - } - /////////// Blog page specific functions function get_extra_header_string() { global $SESSION, $CFG, $USER; @@ -122,14 +92,14 @@ class page_blog extends page_base { $editingString = get_string('turneditingon'); } - $params = $this->url_get_parameters(); + $params = $this->url->params(); $params['edit'] = empty($SESSION->blog_editing_enabled) ? 1 : 0; $paramstring = ''; foreach ($params as $key=>$val) { $paramstring .= ''; } - $editformstring = 'frametarget.' method="get" action="'.$this->url_get_path().'">
' + $editformstring = 'frametarget.' method="get" action="'.$this->url->out(false).'">
' .$paramstring.'
'; } diff --git a/blog/header.php b/blog/header.php index e6474bffb5..05d5d56f43 100755 --- a/blog/header.php +++ b/blog/header.php @@ -50,7 +50,20 @@ $PAGE->set_course($course); $PAGE->filtertype = $filtertype; $PAGE->filterselect = $filterselect; $PAGE->tagid = $tagid; - +$array = array(); +if (!empty($course->id)) { + $array['courseid'] = $course->id; +} +if (!empty($filtertype)) { + $array['filtertype'] = $filtertype; +} +if (!empty($filterselect)) { + $array['filterselect'] = $filterselect; +} +if (!empty($tagid)) { + $array['tagid'] = $tagid; +} +$PAGE->set_url('blog/index.php', $array); $PAGE->init_full(); //init the BlogInfo object and the courserecord object $editing = false; diff --git a/course/view.php b/course/view.php index da352c3bdc..332fb5f7ee 100644 --- a/course/view.php +++ b/course/view.php @@ -19,8 +19,6 @@ $marker = optional_param('marker',-1 , PARAM_INT); $switchrole = optional_param('switchrole',-1, PARAM_INT); - - if (empty($id) && empty($name) && empty($idnumber)) { print_error('unspecifycourseid', 'error'); } @@ -94,6 +92,7 @@ } $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id); + $PAGE->set_url('course/view.php', array('id' => $course->id)); $pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH); if ($reset_user_allowed_editing) { diff --git a/index.php b/index.php index a0f35487b6..c4c5a263c4 100644 --- a/index.php +++ b/index.php @@ -88,9 +88,11 @@ } $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID); + $PAGE->set_pagetype('site-index'); + $PAGE->set_url(''); $PAGE->set_docs_path(''); $pageblocks = blocks_setup($PAGE); - $editing = $PAGE->user_is_editing(); + $editing = $PAGE->user_is_editing(); $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH); $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), diff --git a/lib/adminlib.php b/lib/adminlib.php index 8b3523fbe4..418f48e15f 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3891,7 +3891,8 @@ class admin_setting_manageportfolio extends admin_setting { * @param string $actualurl if the actual page being viewed is not the normal one for this * page (e.g. admin/roles/allowassin.php, instead of admin/roles/manage.php, you can pass the alternate URL here. */ -function admin_externalpage_setup($section, $extrabutton='', $extraurlparams=array(), $actualurl='') { +function admin_externalpage_setup($section, $extrabutton = '', + $extraurlparams = array(), $actualurl = '') { global $CFG, $PAGE, $USER; require_once($CFG->libdir.'/blocklib.php'); @@ -3907,13 +3908,17 @@ function admin_externalpage_setup($section, $extrabutton='', $extraurlparams=arr page_map_class(PAGE_ADMIN, 'page_admin'); $PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); - $PAGE->init_extra($section); // hack alert! $PAGE->set_extra_button($extrabutton); - $PAGE->set_extra_url_params($extraurlparams, $actualurl); $adminroot = admin_get_root(false, false); // settings not required for external pages $extpage = $adminroot->locate($section); + if (!$actualurl) { + $actualurl = $extpage->url; + } + $PAGE->set_url(str_replace($CFG->wwwroot . '/', '', $actualurl), + array_merge($extraurlparams, array('section' => $section))); + if (empty($extpage) or !($extpage instanceof admin_externalpage)) { print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/"); die; @@ -3964,7 +3969,7 @@ function admin_externalpage_print_header($focus='') { blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH); - $PAGE->print_header('', $focus); + $PAGE->print_header($focus); echo '
'; $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable; diff --git a/lib/blocklib.php b/lib/blocklib.php index 51bc2306ac..2f864206da 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -330,7 +330,7 @@ function blocks_print_group(&$page, &$pageblocks, $position) { $managecourseblocks = has_capability('moodle/site:manageblocks', $coursecontext); $editmymoodle = $page->pagetype == PAGE_MY_MOODLE && has_capability('moodle/my:manageblocks', $coursecontext); - if ($page->blocks_default_position() == $position && + if ($page->blocks->get_default_position() == $position && $page->user_is_editing() && ($managecourseblocks || $editmymoodle || $myownblogpage || defined('ADMIN_STICKYBLOCKS'))) { @@ -473,7 +473,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, ); // To this data, add anything the page itself needs to display - $hiddendata = array_merge($hiddendata, $page->url_get_parameters()); + $hiddendata = $page->url->params($hiddendata); if ($data = data_submitted()) { $remove = array_keys($hiddendata); @@ -493,7 +493,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, echo '
'; /// Make CSS easier print_heading($strheading); - echo '
'; + echo ''; echo '

'; foreach($hiddendata as $name => $val) { echo ''; @@ -640,7 +640,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, break; } - $newpos = $page->blocks_default_position(); + $newpos = $page->blocks->get_default_position(); if (!empty($pinned)) { $sql = "SELECT 1, MAX(weight) + 1 AS nextfree FROM {block_pinned} @@ -682,7 +682,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, if ($redirect) { // In order to prevent accidental duplicate actions, redirect to a page with a clean url - redirect($page->url_get_full()); + redirect($page->url->out()); } } @@ -843,7 +843,7 @@ function blocks_get_pinned($page) { $blocks = $DB->get_records_select('block_pinned', $select, $params, 'position, weight'); - $positions = $page->blocks_get_positions(); + $positions = $page->blocks->get_positions(); $arr = array(); foreach($positions as $key => $position) { @@ -905,7 +905,7 @@ function blocks_get_by_page($page) { $blocks = $DB->get_records_select('block_instance', "pageid = ? AND ? LIKE (" . $DB->sql_concat('pagetype', "'%'") . ")", array($page->get_id(), $page->pagetype), 'position, weight'); - $positions = $page->blocks_get_positions(); + $positions = $page->blocks->get_positions(); $arr = array(); foreach($positions as $key => $position) { $arr[$position] = array(); @@ -946,7 +946,7 @@ function blocks_print_adminblock(&$page, &$pageblocks) { } asort($menu); - $target = $page->url_get_full(array('sesskey' => sesskey(), 'blockaction' => 'add')); + $target = $page->url->out(array('sesskey' => sesskey(), 'blockaction' => 'add')); $content = popup_form($target.'&blockid=', $menu, 'add_block', '', $stradd .'...', '', '', true); print_side_block($strblocks, $content, NULL, NULL, NULL, array('class' => 'block_adminblock')); } @@ -994,7 +994,7 @@ function blocks_repopulate_page($page) { $blocknames = $page->blocks_get_default(); } - $positions = $page->blocks_get_positions(); + $positions = $page->blocks->get_positions(); $posblocks = explode(':', $blocknames); // Now one array holds the names of the positions, and the other one holds the blocks diff --git a/lib/pagelib.php b/lib/pagelib.php index dcf6a9cd87..e23e5241cb 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -77,6 +77,8 @@ class moodle_page { protected $_url = null; + protected $_blocks = null; + /// Getter methods ============================================================= /// Due to the __get magic below, you normally do not call these as $PAGE->get_x /// methods, but instead use the $PAGE->x syntax. @@ -184,7 +186,17 @@ class moodle_page { debugging('This page did no call $PAGE->set_url(...). Realying on a guess.', DEBUG_DEVELOPER); return new moodle_url($ME); } - return $this->_url; + return new moodle_url($this->_url); // Return a clone for safety. + } + + /** + * @return blocks_manager the blocks manager object for this page. + */ + public function get_blocks() { + if (is_null($this->_blocks)) { + $this->_blocks = new blocks_manager(); + } + return $this->_blocks; } /** @@ -362,7 +374,7 @@ class moodle_page { * If legacy code has set $CFG->pagepath that will be used instead, and a * developer warning issued. */ - protected function initialise_default_pagetype($script = '') { + protected function initialise_default_pagetype($script = null) { global $CFG, $SCRIPT; if (isset($CFG->pagepath)) { @@ -372,7 +384,7 @@ class moodle_page { unset($CFG->pagepath); } - if (empty($script)) { + if (is_null($script)) { $script = ltrim($SCRIPT, '/'); $len = strlen($CFG->admin); if (substr($script, 0, $len) == $CFG->admin) { @@ -541,21 +553,21 @@ class moodle_page { } /** - * @deprecated since Moodle 2.0 + * @deprecated since Moodle 2.0 - use $PAGE->blocks->get_positions() instead * @return string the places on this page where blocks can go. */ function blocks_get_positions() { debugging('Call to deprecated method moodle_page::blocks_get_positions. Use $PAGE->blocks->get_positions() instead.'); - return $PAGE->blocks->get_positions(); + return $this->blocks->get_positions(); } /** - * @deprecated since Moodle 2.0 + * @deprecated since Moodle 2.0 - use $PAGE->blocks->get_default_position() instead * @return string the default place for blocks on this page. */ function blocks_default_position() { debugging('Call to deprecated method moodle_page::blocks_default_position. Use $PAGE->blocks->get_default_position() instead.'); - return $PAGE->blocks->get_default_position(); + return $this->blocks->get_default_position(); } /** @@ -571,6 +583,44 @@ class moodle_page { function blocks_move_position(&$instance, $move) { debugging('Call to deprecated method moodle_page::blocks_move_position. This method has no function any more.'); } + + /** + * @deprecated since Moodle 2.0 - use $this->url->params() instead. + * @return array URL parameters for this page. + */ + function url_get_parameters() { + debugging('Call to deprecated method moodle_page::url_get_parameters. Use $this->url->params() instead.'); + return $this->url->params(); + } + + /** + * @deprecated since Moodle 2.0 - use $this->url->params() instead. + * @return string URL for this page without parameters. + */ + function url_get_path() { + debugging('Call to deprecated method moodle_page::url_get_path. Use $this->url->out(false) instead.'); + return $this->url->out(false); + } + + /** + * @deprecated since Moodle 2.0 - use $this->url->out() instead. + * @return string full URL for this page. + */ + function url_get_full($extraparams = array()) { + debugging('Call to deprecated method moodle_page::url_get_full. Use $this->url->out() instead.'); + return $this->url->out($extraparams); + } +} + +/** Stub implementation of the blocks_manager, to stop things from breaking too badly. */ +class blocks_manager { + public function get_positions() { + return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT); + } + + public function get_default_position() { + return BLOCK_POS_RIGHT; + } } /** @@ -605,11 +655,15 @@ function page_create_object($type, $id = NULL) { $data->pageid = $id; $classname = page_map_class($type); - $object = new $classname; - $object->init_quick($data); + $legacypage = new $classname; + $legacypage->init_quick($data); + // $PAGE->set_pagetype($type); + // $PAGE->set_url(str_replace($CFG->wwwroot . '/', '', $legacypage->url_get_full_())); + // return $PAGE; + $course = $PAGE->course; if ($course->id != $SITE->id) { - $object->set_course($course); + $legacypage->set_course($course); } else { try { $category = $PAGE->category; @@ -618,13 +672,12 @@ function page_create_object($type, $id = NULL) { $category = false; } if ($category) { - $object->set_category_by_id($category->id); + $legacypage->set_category_by_id($category->id); } else { - $object->set_course($SITE); + $legacypage->set_course($SITE); } } - //$object->set_pagetype($type); - return $object; + return $legacypage; } /** @@ -709,45 +762,6 @@ class page_base extends moodle_page { // SELF-REPORTING SECTION - // Derived classes HAVE to define their "home url" - function url_get_path() { - trigger_error('Page class does not implement method url_get_path()', E_USER_WARNING); - return NULL; - } - - // It's not always required to pass any arguments to the home url, so this doesn't trigger any errors (sensible default) - function url_get_parameters() { - return array(); - } - - // This should actually NEVER be overridden unless you have GOOD reason. Works fine as it is. - function url_get_full($extraparams = array()) { - $path = $this->url_get_path(); - if(empty($path)) { - return NULL; - } - - $params = $this->url_get_parameters(); - if (!empty($params)) { - $params = array_merge($params, $extraparams); - } else { - $params = $extraparams; - } - - if(empty($params)) { - return $path; - } - - $first = true; - - foreach($params as $var => $value) { - $path .= $first? '?' : '&'; - $path .= $var .'='. urlencode($value); - $first = false; - } - - return $path; - } // Simple stuff, do not override this. function get_id() { @@ -904,37 +918,9 @@ class page_course extends page_base { // SELF-REPORTING SECTION - // This should return a fully qualified path to the URL which is responsible for displaying us. - function url_get_path() { - global $CFG; - if (defined('ADMIN_STICKYBLOCKS')) { - return $CFG->wwwroot.'/'.$CFG->admin.'/stickyblocks.php'; - } - if($this->id == SITEID) { - return $CFG->wwwroot .'/index.php'; - } - else { - return $CFG->wwwroot .'/course/view.php'; - } - } - - // This should return an associative array of any GET/POST parameters that are needed by the URL - // which displays us to make it work. If none are needed, return an empty array. - function url_get_parameters() { - if (defined('ADMIN_STICKYBLOCKS')) { - return array('pt' => ADMIN_STICKYBLOCKS); - } - if($this->id == SITEID) { - return array(); - } - else { - return array('id' => $this->id); - } - } - // When we are creating a new page, use the data at your disposal to provide a textual representation of the // blocks that are going to get added to this new page. Delimit block names with commas (,) and use double - // colons (:) to delimit between block positions in the page. See blocks_get_positions() for additional info. + // colons (:) to delimit between block positions in the page. function _legacy_blocks_get_default() { global $CFG; @@ -1020,24 +1006,6 @@ class page_generic_activity extends page_base { return isediting($this->modulerecord->course); } - function url_get_path() { - global $CFG; - return $CFG->wwwroot .'/mod/'.$this->activityname.'/view.php'; - } - - function url_get_parameters() { - $this->init_full(); - return array('id' => $this->modulerecord->id); - } - - function blocks_get_positions() { - return array(BLOCK_POS_LEFT); - } - - function blocks_default_position() { - return BLOCK_POS_LEFT; - } - function print_header($title, $morenavlinks = NULL, $bodytags = '', $meta = '') { global $USER, $CFG; diff --git a/lib/simpletest/testpagelib_moodlepage.php b/lib/simpletest/testpagelib_moodlepage.php index 2f4d1f85d3..7e2e3001dc 100644 --- a/lib/simpletest/testpagelib_moodlepage.php +++ b/lib/simpletest/testpagelib_moodlepage.php @@ -38,7 +38,7 @@ if (!defined('MOODLE_INTERNAL')) { require_once($CFG->libdir . '/pagelib.php'); class testable_moodle_page extends moodle_page { - public function initialise_default_pagetype($script = '') { + public function initialise_default_pagetype($script = null) { parent::initialise_default_pagetype($script); } public function url_to_class_name($url) { diff --git a/lib/weblib.php b/lib/weblib.php index a2ec5509fb..3bc59d1cbf 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -259,7 +259,7 @@ class moodle_url { $this->port = $url->port; $this->user = $url->user; $this->pass = $url->pass; - $this->path = $url->pass; + $this->path = $url->path; $this->fragment = $url->fragment; $this->params = $url->params; } else { diff --git a/mod/chat/view.php b/mod/chat/view.php index f94cf15d07..49f265dbcc 100644 --- a/mod/chat/view.php +++ b/mod/chat/view.php @@ -63,7 +63,8 @@ // Initialize $PAGE, compute blocks - $PAGE = page_create_instance($chat->id); + $PAGE = page_create_instance($chat->id); + $PAGE->set_url('mod/chat/view.php', array('id' => $cm->id)); $pageblocks = blocks_setup($PAGE); $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210); diff --git a/mod/data/view.php b/mod/data/view.php index ed15395bc9..112a91c36a 100755 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -256,7 +256,8 @@ // Initialize $PAGE, compute blocks - $PAGE = page_create_instance($data->id); + $PAGE = page_create_instance($data->id); + $PAGE->set_url('mod/data/view.php', array('id' => $cm->id)); $pageblocks = blocks_setup($PAGE); $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210); diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index d9ae2a88c2..68fab67235 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -791,6 +791,7 @@ } $PAGE = page_create_object('mod-lesson-view', $lesson->id); + $PAGE->set_url('mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id)); $PAGE->set_lessonpageid($page->id); $pageblocks = blocks_setup($PAGE); diff --git a/mod/lesson/pagelib.php b/mod/lesson/pagelib.php index 388ee61cad..b1975b6cd1 100644 --- a/mod/lesson/pagelib.php +++ b/mod/lesson/pagelib.php @@ -140,16 +140,6 @@ class page_lesson extends page_generic_activity { lesson_print_messages(); } - /** - * Needed to add the ID of the current lesson page - * - * @return array - **/ - function url_get_parameters() { - $this->init_full(); - return array('id' => $this->modulerecord->id, 'pageid' => $this->lessonpageid);; - } - /** * Set the current lesson page ID * diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 848de15e2b..8565fc905d 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -465,9 +465,7 @@ // update the clock if (!has_capability('mod/lesson:manage', $context)) { $timer->lessontime = time(); - if (!$DB->update_record('lesson_timer', $timer)) { - print_error('cannotupdatetimer', 'lesson'); - } + $DB->update_record('lesson_timer', $timer); } /// This is the warning msg for teachers to inform them that cluster and unseen does not work while logged in as a teacher @@ -503,6 +501,7 @@ } $PAGE = page_create_instance($lesson->id); + $PAGE->set_url('mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id)); $PAGE->set_lessonpageid($page->id); $pageblocks = blocks_setup($PAGE); @@ -838,9 +837,7 @@ } $timer->lessontime = time(); - if (!$DB->update_record("lesson_timer", $timer)) { - print_error('cannotupdatetimer', 'lesson'); - } + $DB->update_record("lesson_timer", $timer); } add_to_log($course->id, "lesson", "end", "view.php?id=$cm->id", "$lesson->id", $cm->id); diff --git a/mod/quiz/view.php b/mod/quiz/view.php index bbdc88453e..f0223bcd3a 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -57,7 +57,8 @@ add_to_log($course->id, "quiz", "view", "view.php?id=$cm->id", $quiz->id, $cm->id); /// Initialize $PAGE, compute blocks - $PAGE = page_create_instance($quiz->id); + $PAGE = page_create_instance($quiz->id); + $PAGE->set_url('mod/quiz/view.php', array('id' => $cm->id)); $pageblocks = blocks_setup($PAGE); $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210); diff --git a/mod/resource/lib.php b/mod/resource/lib.php index f892283e15..a8ec4a9000 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -89,6 +89,7 @@ class resource_base { require_once($CFG->dirroot.'/course/lib.php'); //required by some blocks $PAGE = page_create_object(PAGE_COURSE_VIEW, $this->course->id); + $PAGE->set_url('mod/resource/view.php', array('id' => $this->cm->id)); $this->PAGE = $PAGE; $pageblocks = blocks_setup($PAGE); diff --git a/mod/survey/view.php b/mod/survey/view.php index 84c38d10a3..5ad0be6d0d 100644 --- a/mod/survey/view.php +++ b/mod/survey/view.php @@ -14,7 +14,6 @@ } require_login($course->id, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('mod/survey:participate', $context); diff --git a/my/index.php b/my/index.php index 0d6c8ee3d3..76774b8546 100644 --- a/my/index.php +++ b/my/index.php @@ -6,7 +6,7 @@ require_once($CFG->libdir.'/blocklib.php'); require_once($CFG->dirroot.'/course/lib.php'); require_once('pagelib.php'); - + require_login(); $mymoodlestr = get_string('mymoodle','my'); @@ -24,6 +24,7 @@ $blockaction = optional_param('blockaction', '', PARAM_ALPHA); $PAGE = page_create_instance($USER->id); + $PAGE->set_url('my/index.php'); $pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH); diff --git a/my/pagelib.php b/my/pagelib.php index d7db483133..1c43a18280 100644 --- a/my/pagelib.php +++ b/my/pagelib.php @@ -54,26 +54,8 @@ class page_my_moodle extends page_base { print_header($title, $header,$navigation,'','',true, $button, $loggedinas.$langmenu); } - - function url_get_path() { - global $CFG; - if ($PAGE->pagetype == PAGE_MY_MOODLE) { - return $CFG->wwwroot.'/my/index.php'; - } elseif (defined('ADMIN_STICKYBLOCKS')){ - return $CFG->wwwroot.'/'.$CFG->admin.'/stickyblocks.php'; - } - } - - function url_get_parameters() { - if (defined('ADMIN_STICKYBLOCKS')) { - return array('pt' => ADMIN_STICKYBLOCKS); - } else { - return array(); - } - } } - define('PAGE_MY_MOODLE', 'my-index'); define('MY_MOODLE_FORMAT', 'my'); //doing this so we don't run into problems with applicable formats. diff --git a/tag/index.php b/tag/index.php index 04dbc2652b..d97fb54a2b 100644 --- a/tag/index.php +++ b/tag/index.php @@ -34,6 +34,7 @@ if (empty($tag)) { //create a new page_tag object, defined in pagelib.php $PAGE = page_create_object(PAGE_TAG_INDEX, $tag->id); +$PAGE->set_url('tag/index.php', array('id' => $tag->id)); $pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH); $PAGE->tag_object = $tag; diff --git a/tag/pagelib.php b/tag/pagelib.php index 9eb8ea9e3f..658dc00074 100644 --- a/tag/pagelib.php +++ b/tag/pagelib.php @@ -21,19 +21,6 @@ class page_tag extends page_base { return (!empty($USER->editing)); } - - function url_get_path() { - global $CFG; - return $CFG->wwwroot.'/tag/index.php'; - - } - - function url_get_parameters() { - $param = array(); - $param['id'] = $this->id; - return $param; - } - //----------- printing funtions ----------- function print_header() {