]> git.mjollnir.org Git - moodle.git/commitdiff
moodle_page: MDL-12212 Kill legacy url_... and blocks_... methods
authortjhunt <tjhunt>
Wed, 6 May 2009 08:55:53 +0000 (08:55 +0000)
committertjhunt <tjhunt>
Wed, 6 May 2009 08:55:53 +0000 (08:55 +0000)
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

28 files changed:
admin/pagelib.php
admin/search.php
admin/settings.php
blocks/moodleblock.class.php
blocks/rss_client/block_rss_client.php
blocks/rss_client/config_instance.html
blocks/rss_client/config_instance_tabs.php
blog/blogpage.php
blog/header.php
course/view.php
index.php
lib/adminlib.php
lib/blocklib.php
lib/pagelib.php
lib/simpletest/testpagelib_moodlepage.php
lib/weblib.php
mod/chat/view.php
mod/data/view.php
mod/lesson/action/continue.php
mod/lesson/pagelib.php
mod/lesson/view.php
mod/quiz/view.php
mod/resource/lib.php
mod/survey/view.php
my/index.php
my/pagelib.php
tag/index.php
tag/pagelib.php

index 2a7ad1cae2073e29074982b8f1b9344114a6b8c5..374b1aa959e81353c465575b0652fc653c995405 100644 (file)
@@ -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 = '&nbsp;';
+            $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, '');
     }
 }
 
index 2d13ba56baf9f66df85373e2d5f7356a3dc37ca5..a1de51bedb053e1b586f3256d6e4926a1e7c4ccf 100644 (file)
@@ -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()) {
index ae1aefde5942e1b2ab786ebdceff9f5f8bf8afd4..4be54055109be5bf5490708d6a35fb8819e3f4f2 100644 (file)
@@ -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 '<table id="layout-table"><tr>';
     $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
index c6bb802c4348822af2d066d6384d48b9391d8537..e4471ffdb7c72e6c996a97aa6f81b12848c04e8f 100644 (file)
@@ -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 .= '<a class="icon roles" title="'. $this->str->assignroles .'" href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">' .
index 4fc064ca564e434c4fda56309f3ba9ebb5031cbb..dcceaf4f17b9b99b9feb32e72e4ef9a425069b60 100644 (file)
             //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',
             } 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',
index 9abb4d3bbc17ab232e4e9b5e36d9b428e1f03dd7..83f6d76ef35fc926c9f49b8be1c573d0fa9e37f7 100644 (file)
@@ -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 '&nbsp;<a href="'.$addrsspage.'">'. get_string('editnewsfeeds', 'block_rss_client') .'</a><br />';
index 24a6447753bcfa024f46ef6153f40a71928cd7df..e8541e0d0b5273832208cbbb3d7f88787f4e84b8 100644 (file)
@@ -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'));
 
index aa00ba2323d404d47d6cc3c2f5be7dd19cbc8723..2f3e952dd5049b2567c7b9832ce3514001b7eb90 100644 (file)
@@ -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 .= '<input type="hidden" name="'.$key.'" value="'.s($val).'" />';
             }
 
-            $editformstring = '<form '.$CFG->frametarget.' method="get" action="'.$this->url_get_path().'"><div>'
+            $editformstring = '<form '.$CFG->frametarget.' method="get" action="'.$this->url->out(false).'"><div>'
                              .$paramstring.'<input type="submit" value="'.$editingString.'" /></div></form>';
         }
 
index e6474bffb548c5008254ccb0abcb0b345228aa55..05d5d56f43f676b676a92ddf3303e2474104bda8 100755 (executable)
@@ -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;
index da352c3bdcc6b186ad0990e550d5ce947be28eeb..332fb5f7ee1fa78107c3ccda48c55839fe3640db 100644 (file)
@@ -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) {
index a0f35487b68fdc75fe1c154ef28f1f9cea75df47..c4c5a263c47c2732da079cb6d54a1f571b69c2f7 100644 (file)
--- a/index.php
+++ b/index.php
     }
 
     $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]),
index 8b3523fbe438b614e8a242903fc3d0db41730ac8..418f48e15f0c1f6cbd6b1f02b6120946db40d50d 100644 (file)
@@ -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 '<table id="layout-table" summary=""><tr>';
 
         $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
index 51bc2306acc05d71812a9afb962ded2f8ee9af48..2f864206da722255fcc8dbad37c543fcefa71934 100644 (file)
@@ -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 '<div class="block-config" id="'.$block->name.'">';   /// Make CSS easier
 
                 print_heading($strheading);
-                echo '<form method="post" name="block-config" action="'. $page->url_get_path() .'">';
+                echo '<form method="post" name="block-config" action="'. $page->url->out(false) .'">';
                 echo '<p>';
                 foreach($hiddendata as $name => $val) {
                     echo '<input type="hidden" name="'. $name .'" value="'. $val .'" />';
@@ -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.'&amp;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
index dcf6a9cd87a8d7a42c6f1c3ae17ec8938cfaaf8b..e23e5241cbb2d3e17aeff8fe414eac7aee9dc92b 100644 (file)
@@ -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 <strong>url_get_path()</strong>', 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? '?' : '&amp;';
-            $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;
 
index 2f4d1f85d33ef9901b974048a292c5fae3c9a43d..7e2e3001dcf86d8073ce7d0559f84b1ca87cdc91 100644 (file)
@@ -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) {
index a2ec5509fb1075b770494245eae2e4b077a42c6f..3bc59d1cbfe10a83641a020cfea856d54d4e76b7 100644 (file)
@@ -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 {
index f94cf15d07cff3d1871b3c24127b5c425129ff99..49f265dbccd474f3c35f5a1a1fbec7007ba21062 100644 (file)
@@ -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);
 
index ed15395bc9baece01509d3a0d36ff090d20948d7..112a91c36a35aa59026a8f12563525a794463398 100755 (executable)
 
 
 // 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);
 
index d9ae2a88c20380fe2225c029328da5958347dfc3..68fab67235e31e575c1b5e0e81acf5aaf3ee2279 100644 (file)
     }
 
     $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);
 
index 388ee61cadd69f1042e512b412e563aa7791d815..b1975b6cd11b1778c3f85c020be44bb8cc0d557b 100644 (file)
@@ -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
      *
index 848de15e2b1889560ff7515edd5f3be12f394bc9..8565fc905dc1044a5fc394477ecd9830351abc78 100644 (file)
         // 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
         }
 
         $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);
 
             }
             $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);
index bbdc88453e51f2840d24f37b0401d85478e74014..f0223bcd3a3d7b65e20b2a190bf44cb42d901baa 100644 (file)
@@ -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);
 
index f892283e15a7c644a951953d5636404362d902b4..a8ec4a9000be6556509dc11e32e6acab25020882 100644 (file)
@@ -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);
 
index 84c38d10a30081927c56c0abf4f6ad5c285bfc5e..5ad0be6d0dda86428a8b8978ef3a9546a9f87b95 100644 (file)
@@ -14,7 +14,6 @@
     }
 
     require_login($course->id, false, $cm);
-    
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
     require_capability('mod/survey:participate', $context);
index 0d6c8ee3d3df2007c07228fb110dc2e3cc402f52..76774b8546aca083a821bba8d112f2b8d230e36a 100644 (file)
@@ -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);
 
index d7db4831333b0e7b2c86c34411424a196227aec7..1c43a18280dfdc10b659319bb572f38ddf03bfc3 100644 (file)
@@ -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.
 
index 04dbc2652b505ac42ab07cef8fde64f58c539cb5..d97fb54a2b9e5c0e4f5f1587f11a289746e10fcc 100644 (file)
@@ -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;
 
index 9eb8ea9e3f54ac4048855691e5d296d20a365076..658dc00074a47430209eb2dda984cc6378716d50 100644 (file)
@@ -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() {