]> git.mjollnir.org Git - moodle.git/commitdiff
moodle_page: MDL-12212 kill $CFG->pagepath (use $PAGE->set_pagetype)
authortjhunt <tjhunt>
Wed, 6 May 2009 08:38:55 +0000 (08:38 +0000)
committertjhunt <tjhunt>
Wed, 6 May 2009 08:38:55 +0000 (08:38 +0000)
deprecate $PAGE->get_format_name (use $PAGE->pagetype)
deprecate page_id_and_class (use $PAGE->pagetype)

19 files changed:
admin/auth_config.php
admin/mnet/enr_course_enrol.php
admin/mnet/enr_courses.php
admin/mnet/enr_hosts.php
admin/stickyblocks.php
blog/blogpage.php
course/mod.php
course/modedit.php
lib/blocklib.php
lib/pagelib.php
lib/weblib.php
login/index.php
mod/data/field.php
mod/hotpot/view.php
mod/lesson/action/addbranchtable.php
mod/lesson/action/addpage.php
my/pagelib.php
question/question.php
tag/pagelib.php

index 0ceca51e79db743086858bbfcdf8ca4e27903d44..542a56463ba6e503f28ce20b0915c6a418b2757f 100644 (file)
@@ -8,7 +8,7 @@ require_once $CFG->libdir.'/adminlib.php';
 
 $auth = required_param('auth', PARAM_SAFEDIR);
 
-$CFG->pagepath = 'auth/' . $auth;
+$PAGE->set_pagetype('auth-' . $auth);
 
 admin_externalpage_setup('authsetting'.$auth);
 
index 52dbae7442df5d3ea85430c0f1c7fde15e9fefab..7cfb03e8123ba20447c37ab4216640cfc9fc5c48 100644 (file)
@@ -11,7 +11,7 @@
     }
 
     admin_externalpage_setup('mnetenrol');
-    $CFG->pagepath = 'admin/mnet';
+    $PAGE->set_pagetype('admin-mnet');
 
     require_once("$CFG->dirroot/enrol/enrol.class.php");   /// Open the factory class
     $enrolment = enrolment_factory::factory('mnet');
index cd16a7dd0af073b98885cddb602cb35fded8888d..0d9fd8d0b2aab05c5078a77ad5922a33408916ce 100644 (file)
@@ -11,7 +11,7 @@
 
 
     admin_externalpage_setup('mnetenrol');
-    $CFG->pagepath = 'admin/mnet';
+    $PAGE->set_pagetype('admin-mnet');
 
     require_once("$CFG->dirroot/enrol/enrol.class.php");   /// Open the factory class
     $enrolment = enrolment_factory::factory('mnet');
index 23f47d0c817da6c9ba124b51371c7bd4410975bf..3a7cdfb81b068a6c08595d6dfddac6b85dd3f9fb 100644 (file)
@@ -6,8 +6,7 @@
     require_once($CFG->libdir.'/adminlib.php');
 
     admin_externalpage_setup('mnetenrol');
-    $CFG->pagepath = 'admin/mnet';
-
+    $PAGE->set_pagetype('admin-mnet');
 
     require_once("$CFG->dirroot/enrol/enrol.class.php");   /// Open the factory class
 
index c2aefae6e9a1cf8e9cf9c793ab7c5648a56632d8..8b9eaf07aed711c0922153874137a41c49f7fdd6 100644 (file)
@@ -40,7 +40,7 @@
         define('ADMIN_STICKYBLOCKS',$pt);
 
         $PAGE = page_create_object($pt, SITEID);
-        $blocks = blocks_setup($PAGE,BLOCKS_PINNED_TRUE);
+        $blocks = blocks_setup($PAGE, BLOCKS_PINNED_TRUE);
         $blocks_preferred_width = bounded_number(180, blocks_preferred_width($blocks[BLOCK_POS_LEFT]), 210);
 
         $navlinks = array(array('name' => get_string('administration'),
index 43839a9dfeb655736aba641f94ec66e3607ba28d..67c0111308048fae6e7d7c915c2883bd5de3fcbd 100644 (file)
@@ -17,15 +17,6 @@ class page_blog extends page_base {
     var $filterselect = NULL;
     var $tagid = NULL;
 
-    // we have no format type, use 'blog'
-    //I think it's a bug, but if this is left the default NULL value then pages can
-    //fail to load completely
-    function get_format_name() {
-        global $CFG;
-        require_once($CFG->dirroot .'/blog/lib.php');
-        return PAGE_BLOG_VIEW;
-    }
-
     // Do any validation of the officially recognized bits of the data and forward to parent.
     // Do NOT load up "expensive" resouces (e.g. SQL data) here!
     function init_quick($data) {
index a01b065eaf550cb2581a8d1872eb10bc11d638d3..054e5b30a7ca3a8873171f06582e1a773ba7b5ba 100644 (file)
@@ -63,7 +63,7 @@
             $strdeletecheck = get_string('deletecheck', '', $fullmodulename);
             $strdeletecheckfull = get_string('deletecheckfull', '', "$fullmodulename '$cm->name'");
 
-            $CFG->pagepath = 'mod/'.$cm->modname.'/delete';
+            $PAGE->set_pagetype('mod-' . $cm->modname . '-delete');
 
             print_header_simple($strdeletecheck, '', build_navigation(array(array('name'=>$strdeletecheck, 'link'=>'', 'type'=>'misc'))));
 
index 0c8c6adc8129465cb08405da1309654fd38dcdcd..a68de8b6ae442f0f7030e73e8424efb80a71da8f 100644 (file)
             $pageheading = get_string('addinganew', 'moodle', $fullmodulename);
         }
 
-        $CFG->pagepath = 'mod/'.$module->name;
+        $pagepath = 'mod-' . $module->name . '-';
         if (!empty($type)) {
-            $CFG->pagepath .= '/'.$type;
+            $pagepath .= $type;
         } else {
-            $CFG->pagepath .= '/mod';
+            $pagepath .= 'mod';
         }
+        $PAGE->set_pagetype($pagepath);
 
         $navlinksinstancename = '';
 
index 9f7273155f1e37950ca9c6119a3f38ca6cd291ce..5323c72e19b87be78dd18bc02964a38d7d71a4aa 100644 (file)
@@ -94,7 +94,7 @@ function blocks_get_missing(&$page, &$pageblocks) {
 
     $missingblocks = array();
     $allblocks = blocks_get_record();
-    $pageformat = $page->get_format_name();
+    $pageformat = $page->pagetype;
 
     if(!empty($allblocks)) {
         foreach($allblocks as $block) {
@@ -117,7 +117,7 @@ function blocks_remove_inappropriate($page) {
         return;
     }
 
-    if(($pageformat = $page->get_format_name()) == NULL) {
+    if(($pageformat = $page->pagetype) == NULL) {
         return;
     }
 
@@ -325,10 +325,10 @@ function blocks_print_group(&$page, &$pageblocks, $position) {
     include_once($CFG->dirroot.'/my/pagelib.php');
 
     $coursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
-    $myownblogpage = (isset($page->filtertype) && isset($page->filterselect) && $page->type=='blog-view' && $page->filtertype=='user' && $page->filterselect == $USER->id);
+    $myownblogpage = (isset($page->filtertype) && isset($page->filterselect) && $page->pagetype=='blog-view' && $page->filtertype=='user' && $page->filterselect == $USER->id);
 
     $managecourseblocks = has_capability('moodle/site:manageblocks', $coursecontext);
-    $editmymoodle = $page->type == PAGE_MY_MOODLE && has_capability('moodle/my:manageblocks', $coursecontext);
+    $editmymoodle = $page->pagetype == PAGE_MY_MOODLE && has_capability('moodle/my:manageblocks', $coursecontext);
 
     if ($page->blocks_default_position() == $position &&
         $page->user_is_editing() &&
index 99ea6139c5054deb352ebdb87496106b6f1c59ee..5eb552b0c4198e0ad76342911bdd76a06141105c 100644 (file)
@@ -56,6 +56,8 @@ class moodle_page {
 
     protected $_pagetype = null;
 
+    protected $_legacyclass = null;
+
     /**
      * @return integer one of the STATE_... constants. You should not normally need
      * to use this in your code. It is indended for internal use by this class
@@ -102,8 +104,8 @@ class moodle_page {
      * @return string e.g. 'my-index' or 'mod-quiz-attempt'. Same as the id attribute on <body>.
      */
     public function get_pagetype() {
-        if (is_null($this->_pagetype)) {
-            throw new coding_exception('$PAGE->pagetype accessed before it was known.');
+        if (is_null($this->_pagetype) || isset($CFG->pagepath)) {
+            $this->initialise_default_pagetype();
         }
         return $this->_pagetype;
     }
@@ -193,7 +195,46 @@ class moodle_page {
         }
     }
 
+    /**
+     * Sets ->pagetype from the script name. For example, if the script that was
+     * run is mod/quiz/view.php, ->pagetype will be set to 'mod-quiz-view'.
+     * @param string $script the path to the script that should be used to
+     * initialise ->pagetype. If not passed the $SCRIPT global will be used.
+     * If legacy code has set $CFG->pagepath that will be used instead, and a
+     * developer warning issued.
+     */
+    protected function initialise_default_pagetype($script = '') {
+        global $CFG, $SCRIPT;
+
+        if (isset($CFG->pagepath)) {
+            debugging('Some code appears to have set $CFG->pagepath. That was a horrible deprecated thing. ' .
+                    'Don\'t do it! Try calling $PAGE->set_pagetype() instead.');
+            $script = $CFG->pagepath;
+            unset($CFG->pagepath);
+        }
+
+        if (empty($script)) {
+            $script = ltrim($SCRIPT, '/');
+            $len = strlen($CFG->admin);
+            if (substr($script, 0, $len) == $CFG->admin) {
+                $script = 'admin' . substr($script, $len);
+            }
+        }
+
+        $path = str_replace('.php', '', $script);
+        if (substr($path, -1) == '/') {
+            $path .= 'index';
+        }
+
+        if (empty($path) || $path == 'index') {
+            $this->_pagetype = 'site-index';
+        } else {
+            $this->_pagetype = str_replace('/', '-', $path);
+        }
+    }
+
 /// Deperecated fields and methods for backwards compatibility =================
+
     /**
      * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead.
      * @return string page type.
@@ -202,6 +243,15 @@ class moodle_page {
         debugging('Call to deprecated method moodle_page::get_type. Please use $PAGE->pagetype instead.');
         return $this->get_pagetype();
     }
+
+    /**
+     * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead.
+     * @return string this is what page_id_and_class used to return via the $getclass parameter.
+     */
+    function get_format_name() {
+        return $this->get_pagetype();
+    }
+
     /**
      * @deprecated since Moodle 2.0 - use $PAGE->course instead.
      * @return object course.
@@ -210,6 +260,25 @@ class moodle_page {
         debugging('Call to deprecated method moodle_page::get_courserecord. Please use $PAGE->course instead.');
         return $this->get_course();
     }
+
+    /**
+     * @deprecated since Moodle 2.0
+     * @return string this is what page_id_and_class used to return via the $getclass parameter.
+     */
+    public function get_legacyclass() {
+        if (is_null($this->_legacyclass)) {
+            $pagetype = $this->pagetype;
+            if ($pagetype == 'site-index') {
+                $this->_legacyclass = 'course';
+            } else if (substr($pagetype, 0, 6) == 'admin-') {
+                $this->_legacyclass = 'admin';
+            } else {
+                $this->_legacyclass = substr($pagetype, 0, strrpos($pagetype, '-'));
+            }
+        }
+        debugging('Call to deprecated method moodle_page::get_legacyclass.');
+        return $this->_legacyclass;
+    }
 }
 
 /**
@@ -220,17 +289,16 @@ class moodle_page {
  */
 function page_import_types($path) {
     global $CFG;
-
     debugging('Call to deprecated function page_import_types.', DEBUG_DEVELOPER);
 }
 
 /**
- * Factory function page_create_object(). Called with a numeric ID for a page, it autodetects
- * the page type, constructs the correct object and returns it.
+ * @deprecated since Moodle 2.0
+ * @param integer $instance legacy page instance id.
+ * @return the global $PAGE object.
  */
 function page_create_instance($instance) {
-    page_id_and_class($id, $class);
-    return page_create_object($id, $instance);
+    return page_create_object($PAGE->pagetype, $instance);
 }
 
 /**
@@ -309,32 +377,8 @@ class page_base extends moodle_page {
      */
     var $full_init_done = false;
 
-    /**
-     * The class attribute that Moodle has to assign to the BODY tag for this page.
-     * @var string $body_class
-     */
-    var $body_class     = NULL;
-
-    /**
-     * The id attribute that Moodle has to assign to the BODY tag for this page.
-     * @var string $body_id
-     */
-    var $body_id        = NULL;
-
 /// Class Functions
 
-    // CONSTRUCTION
-
-    // A whole battery of functions to allow standardized-name constructors in all versions of PHP.
-    // The constructor is actually called construct()
-    function __construct() {
-        $this->construct();
-    }
-
-    function construct() {
-        page_id_and_class($this->body_id, $this->body_class);
-    }
-
     // USER-RELATED THINGS
 
     // By default, no user is editing anything and none CAN edit anything. Developers
@@ -430,11 +474,6 @@ class page_base extends moodle_page {
         return $this->id;
     }
 
-    // "Sensible default" case here. Take it from the body id.
-    function get_format_name() {
-        return $this->body_id;
-    }
-
     // Initialize the data members of the parent class
     function init_quick($data) {
         $this->type = $data->pagetype;
@@ -503,7 +542,6 @@ class page_course extends page_base {
     // this is a _very_ expensive check - so cache it during execution
     //
     function user_allowed_editing() {
-
         $this->init_full();
 
         if (isset($this->_user_allowed_editing)) {
@@ -511,7 +549,7 @@ class page_course extends page_base {
         }
 
         if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM))
-            && defined('ADMIN_STICKYBLOCKS')) {
+                && defined('ADMIN_STICKYBLOCKS')) {
             $this->_user_allowed_editing = true;
             return true;
         }
@@ -586,21 +624,6 @@ class page_course extends page_base {
 
     // SELF-REPORTING SECTION
 
-    // This is like the "category" of a page of this "type". For example, if the type is PAGE_COURSE_VIEW
-    // the format_name is the actual name of the course format. If the type were PAGE_ACTIVITY_VIEW, then
-    // the format_name might be that activity's name etc.
-    function get_format_name() {
-        $this->init_full();
-        if (defined('ADMIN_STICKYBLOCKS')) {
-            return PAGE_COURSE_VIEW;
-        }
-        if($this->id == SITEID) {
-            return parent::get_format_name();
-        }
-        // This needs to reflect the path hierarchy under Moodle root.
-        return 'course-view-'.$this->course->format;
-    }
-
     // This should return a fully qualified path to the URL which is responsible for displaying us.
     function url_get_path() {
         global $CFG;
index 284db8b4bcdd2dd3ec5a4eb2254c8c6f0d20b777..cac8859079919c6bd00da88dc22cbb75e115395f 100644 (file)
@@ -2327,7 +2327,8 @@ function print_header ($title='', $heading='', $navigation='', $focus='',
 
     // Create class and id for this page
 
-    page_id_and_class($pageid, $pageclass);
+    $pageid = $PAGE->pagetype;
+    $pageclass = $PAGE->legacyclass;
 
     $pageclass .= ' course-'.$COURSE->id;
 
@@ -6493,39 +6494,16 @@ function print_side_block_end($attributes = array(), $title='') {
 
 }
 
-
+/**
+ * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the .
+ * @param string $getid used to return $PAGE->pagetype.
+ * @param string $getclass used to return $PAGE->legacyclass.
+ */
 function page_id_and_class(&$getid, &$getclass) {
-    // Create class and id for this page
-    global $CFG, $SCRIPT;
-
-    static $class = NULL;
-    static $id    = NULL;
-
-    if (empty($CFG->pagepath)) {
-        $CFG->pagepath = ltrim($SCRIPT, '/');
-    }
-
-    if (empty($class) || empty($id)) {
-        $path = str_replace('.php', '', $CFG->pagepath);
-        if (substr($path, -1) == '/') {
-            $path .= 'index';
-        }
-        if (empty($path) || $path == 'index') {
-            $id    = 'site-index';
-            $class = 'course';
-        } else if (substr($path, 0, 5) == 'admin') {
-            $id    = str_replace('/', '-', $path);
-            $class = 'admin';
-        } else {
-            $id    = str_replace('/', '-', $path);
-            $class = explode('-', $id);
-            array_pop($class);
-            $class = implode('-', $class);
-        }
-    }
-
-    $getid    = $id;
-    $getclass = $class;
+    global $PAGE;
+    debugging('Call to deprecated function page_id_and_class. Please use $PAGE->pagetype instead.', DEBUG_DEVELOPER);
+    $getid = $PAGE->pagetype;
+    $getclass = $PAGE->legacyclass;
 }
 
 /**
index b4c1b81d51548892d3a7765889eb1538d77a8dc3..da4d18762056cfe17796f54a76c1f671679090aa 100644 (file)
@@ -12,6 +12,9 @@
     $loginguest  = optional_param('loginguest', 0, PARAM_BOOL); // determines whether visitors are logged in as guest automatically
     $testcookies = optional_param('testcookies', 0, PARAM_BOOL); // request cookie test
 
+    $context = get_context_instance(CONTEXT_SYSTEM);
+    $PAGE->set_context($context);
+
     //initialize variables
     $errormsg = '';
     $errorcode = 0;
             }
 
         /// Go to my-moodle page instead of homepage if mymoodleredirect enabled
-            if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) and !empty($CFG->mymoodleredirect) and !isguest()) {
+            if (!has_capability('moodle/site:config', $context) and !empty($CFG->mymoodleredirect) and !isguest()) {
                 if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
                     $urltogo = $CFG->wwwroot.'/my/';
                 }
index 7ba49e9bd747ab4e857ff7de14a53e67b089179f..3f64edf8f747b4d5dfb6069df56de34ab9770726 100755 (executable)
     }
     asort($menufield);    //sort in alphabetical order
 
-
+    $PAGE->set_pagetype('mod-data-field-' . $newtype);
     if (($mode == 'new') && (!empty($newtype)) && confirm_sesskey()) {          ///  Adding a new field
-        $CFG->pagepath='mod/data/field/'.$newtype;
-        data_print_header($course,$cm,$data,'fields');
+        data_print_header($course, $cm, $data,'fields');
 
         $field = data_get_field_new($newtype, $data);
         $field->display_edit_field();
 
     } else if ($mode == 'display' && confirm_sesskey()) { /// Display/edit existing field
-        $CFG->pagepath='mod/data/field/'.$newtype;
-        data_print_header($course,$cm,$data,'fields');
+        data_print_header($course, $cm, $data,'fields');
 
         $field = data_get_field_from_id($fid, $data);
         $field->display_edit_field();
 
     } else {                                              /// Display the main listing of all fields
-
-        $CFG->pagepath='mod/data/field/'.$newtype;
-        data_print_header($course,$cm,$data,'fields');
-
+        data_print_header($course, $cm, $data,'fields');
 
         if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) {
             notify(get_string('nofieldindatabase','data'));  // nothing in database
index 49033d6818d0a14f89a03ea0c2894b5e546a6533..909a2aefd635122e864e3020792dced8463cc5a4 100644 (file)
     // insert hot-potatoes.js
     $hp->insert_script(HOTPOT_JS);
     // get Moodle pageid and pageclass
-    $pageid = '';
-    $pageclass = '';
-    if (function_exists('page_id_and_class')) {
-        page_id_and_class($pageid, $pageclass);
-    }
+    $pageid = $PAGE->pagetype;
+
     // extract first <head> tag
     $head = '';
     $pattern = '|<head([^>]*)>(.*?)</head>|is';
index ae518e9172fe8b3781aae5eaabd81b7c37ff61a7..b7e7309a7997d27a92d7306b0a95f1ac664732db 100644 (file)
@@ -7,8 +7,6 @@
  * @package lesson
  **/
 
-    $CFG->pagepath = 'mod/lesson/addbranchtable';
-    
     // first get the preceeding page
     $pageid = required_param('pageid', PARAM_INT);
     
index 10229e1f3ec0f2c6a5aee5d730e2662a79b930cf..3093d460c174558bbe0fbcbf942d62059e0f29b2 100644 (file)
@@ -6,8 +6,6 @@
  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  * @package lesson
  **/
-    $CFG->pagepath = 'mod/lesson/addpage';
-    
     // first get the preceeding page
     $pageid = required_param('pageid', PARAM_INT);
     $qtype = optional_param('qtype', LESSON_MULTICHOICE, PARAM_INT);
index ce7cdd4d94bb20e3479c30a1492ca7748272d8ae..d6e2b9f76fc94246e88515fa8cc684c313b77025 100644 (file)
@@ -5,8 +5,7 @@ require_once($CFG->libdir.'/pagelib.php');
 class page_my_moodle extends page_base {
 
     function user_allowed_editing() {
-        page_id_and_class($id,$class);
-        if ($id == PAGE_MY_MOODLE) {
+        if ($PAGE->pagetype == PAGE_MY_MOODLE) {
             return true;
         } else if (has_capability('moodle/my:manageblocks', get_context_instance(CONTEXT_SYSTEM)) && defined('ADMIN_STICKYBLOCKS')) {
             return true;
@@ -58,8 +57,7 @@ class page_my_moodle extends page_base {
     
     function url_get_path() {
         global $CFG;
-        page_id_and_class($id,$class);
-        if ($id == PAGE_MY_MOODLE) {
+        if ($PAGE->pagetype == PAGE_MY_MOODLE) {
             return $CFG->wwwroot.'/my/index.php';
         } elseif (defined('ADMIN_STICKYBLOCKS')){
             return $CFG->wwwroot.'/'.$CFG->admin.'/stickyblocks.php';
@@ -90,10 +88,6 @@ class page_my_moodle extends page_base {
         }
         return $instance->position;
     }
-
-    function get_format_name() {
-        return MY_MOODLE_FORMAT;
-    }
 }
 
 
index 2e0b2ca313f2ec5bf830b3774cae34f853c41114..9148d1a952c8664898d4dc438f3cef25f36e5e6f 100644 (file)
@@ -115,7 +115,7 @@ if ($id) {
 if (!isset($QTYPES[$question->qtype])) {
     print_error('unknownquestiontype', 'question', $returnurl, $question->qtype);
 }
-$CFG->pagepath = 'question/type/' . $question->qtype;
+$PAGE->set_pagetype('question-type-' . $question->qtype);
 
 // Create the question editing form.
 if ($wizardnow!=='' && !$movecontext){
index c1611d2b95aa8e309a9d19efdc7d85e1e92ac84a..27a1306df89e339125b46d665fd4f62bd46d974b 100644 (file)
@@ -51,12 +51,8 @@ class page_tag extends page_base {
         return $instance->position;
     }
 
-    function get_format_name() {
-        return TAG_FORMAT;
-    }
-    
     //-----------  printing funtions -----------
-    
+
     function print_header() {
 
         global $USER, $CFG;