From f8b80dbd957c0f891361ba015576fd65cc254887 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 6 May 2009 09:11:07 +0000 Subject: [PATCH] moodle_page: MDL-12212 completely remove the old tag and admin page classes --- admin/pagelib.php | 67 ------------------------------------ admin/settings.php | 65 +++++++++++++++++++--------------- blocks/moodleblock.class.php | 4 ++- lib/adminlib.php | 55 ++++++++++++++++++----------- lib/pagelib.php | 21 +++++++++-- lib/upgradelib.php | 5 ++- tag/index.php | 20 +++++++---- tag/pagelib.php | 38 -------------------- 8 files changed, 110 insertions(+), 165 deletions(-) delete mode 100644 admin/pagelib.php delete mode 100644 tag/pagelib.php diff --git a/admin/pagelib.php b/admin/pagelib.php deleted file mode 100644 index 62c76cd767..0000000000 --- a/admin/pagelib.php +++ /dev/null @@ -1,67 +0,0 @@ -libdir.'/pagelib.php'); - -define('PAGE_ADMIN', 'admin'); - -// Bounds for block widths -// more flexible for theme designers taken from theme config.php -$lmin = (empty($THEME->block_l_min_width)) ? 0 : $THEME->block_l_min_width; -$lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width; -$rmin = (empty($THEME->block_r_min_width)) ? 0 : $THEME->block_r_min_width; -$rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width; - -define('BLOCK_L_MIN_WIDTH', $lmin); -define('BLOCK_L_MAX_WIDTH', $lmax); -define('BLOCK_R_MIN_WIDTH', $rmin); -define('BLOCK_R_MAX_WIDTH', $rmax); - -page_map_class(PAGE_ADMIN, 'page_admin'); - -class page_admin extends page_base { - var $extrabutton = ''; - - /** - * Use this to pass extra HTML that is added after the turn blocks editing on/off button. - * - * @param string $extrabutton HTML code. - */ - function set_extra_button($extrabutton) { - $this->extrabutton = $extrabutton; - } - - function print_header($focus='') { - global $USER, $CFG, $SITE; - - $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->user_allowed_editing()) { - $options = $this->url->params(); - if ($this->user_is_editing()) { - $caption = get_string('blockseditoff'); - $options['adminedit'] = 'off'; - } else { - $caption = get_string('blocksediton'); - $options['adminedit'] = 'on'; - } - $buttons = print_single_button($this->url->out(false), $options, $caption, 'get', '', true); - } - $buttons .= $this->extrabutton; - - $navlinks = array(); - foreach ($visiblepathtosection as $element) { - $navlinks[] = array('name' => $element, 'link' => null, 'type' => 'misc'); - } - $navigation = build_navigation($navlinks); - - print_header("$SITE->shortname: " . implode(": ",$visiblepathtosection), $SITE->fullname, $navigation, $focus, '', true, $buttons, ''); - } -} - -?> diff --git a/admin/settings.php b/admin/settings.php index 1e9d4a7e23..da6ca837c3 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -5,24 +5,25 @@ require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/blocklib.php'); require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php'); -$section = required_param('section', PARAM_SAFEDIR); -$return = optional_param('return','', PARAM_ALPHA); +$section = required_param('section', PARAM_SAFEDIR); +$return = optional_param('return','', PARAM_ALPHA); $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)); +$PAGE->set_pagetype('admin-setting-' . $section); $adminroot = admin_get_root(); // need all settings -$page = $adminroot->locate($section); +$settingspage = $adminroot->locate($section, true); -if (empty($page) or !($page instanceof admin_settingpage)) { +if (empty($settingspage) or !($settingspage instanceof admin_settingpage)) { print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/"); die; } -if (!($page->check_access())) { +if (!($settingspage->check_access())) { print_error('accessdenied', 'admin'); die; } @@ -40,7 +41,7 @@ if ($data = data_submitted() and confirm_sesskey()) { if (empty($adminroot->errors)) { switch ($return) { - case 'site': redirect("$CFG->wwwroot/"); + case 'site': redirect("$CFG->wwwroot/"); case 'admin': redirect("$CFG->wwwroot/$CFG->admin/"); } } else { @@ -48,25 +49,17 @@ if ($data = data_submitted() and confirm_sesskey()) { $firsterror = reset($adminroot->errors); $focus = $firsterror->id; } - $adminroot =& admin_get_root(true); //reload tree - $page =& $adminroot->locate($section); + $adminroot = admin_get_root(true); //reload tree + $settingspage = $adminroot->locate($section); } -/// very hacky page setup -page_map_class(PAGE_ADMIN, 'page_admin'); -$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number -$PAGE->set_pagetype('admin-setting-' . $section); -$PAGE->init_extra($section); - if ($PAGE->user_allowed_editing() && $adminediting != -1) { $USER->editing = $adminediting; } - /// print header stuff ------------------------------------------------------------ - if (empty($SITE->fullname)) { - print_header($page->visiblename, $page->visiblename, '', $focus); + print_header($settingspage->visiblename, $settingspage->visiblename, '', $focus); print_simple_box(get_string('configintrosite', 'admin'), 'center', '50%'); if ($errormsg !== '') { @@ -80,11 +73,11 @@ if (empty($SITE->fullname)) { echo '
'; echo '
'; - echo ''; + $PAGE->url->hidden_params_out(); echo ''; echo ''; - echo $page->output_html(); + echo $settingspage->output_html(); echo '
'; @@ -94,12 +87,30 @@ if (empty($SITE->fullname)) { } else { $pageblocks = blocks_setup($PAGE); - $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]), - BLOCK_R_MAX_WIDTH); + $preferred_width_left = blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]); + $preferred_width_right = blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]); + + // The search page currently doesn't handle block editing + if ($PAGE->user_allowed_editing()) { + $options = $PAGE->url->params(); + if ($PAGE->user_is_editing()) { + $caption = get_string('blockseditoff'); + $options['adminedit'] = 'off'; + } else { + $caption = get_string('blocksediton'); + $options['adminedit'] = 'on'; + } + $buttons = print_single_button($PAGE->url->out(false), $options, $caption, 'get', '', true); + } + + $visiblepathtosection = array_reverse($settingspage->visiblepath); + $navlinks = array(); + foreach ($visiblepathtosection as $element) { + $navlinks[] = array('name' => $element, 'link' => null, 'type' => 'misc'); + } + $navigation = build_navigation($navlinks); - $PAGE->print_header($focus); + print_header("$SITE->shortname: " . implode(": ",$visiblepathtosection), $SITE->fullname, $navigation, $focus, '', true, $buttons, ''); echo ''; $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable; @@ -128,12 +139,12 @@ if (empty($SITE->fullname)) { echo ''; echo '
'; - echo ''; + $PAGE->url->hidden_params_out(); echo ''; echo ''; - print_heading($page->visiblename); + print_heading($settingspage->visiblename); - echo $page->output_html(); + echo $settingspage->output_html(); echo '
'; diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index a92a63dcc6..cecf71fdc0 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -461,7 +461,9 @@ class block_base { if (($this->instance->pagetype == $PAGE->pagetype) and $this->instance->pageid == $PAGE->id) { $page = $PAGE; } else { - $page = page_create_object($this->instance->pagetype, $this->instance->pageid); + $page = new moodle_page(); + $page->set_pagetype($this->instance->pagetype); + $page->pageid = $this->instance->pageid; } $script = $page->url->out(array('instanceid' => $this->instance->id, 'sesskey' => sesskey())); diff --git a/lib/adminlib.php b/lib/adminlib.php index d086ce5c38..504df0e6ea 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3896,7 +3896,6 @@ function admin_externalpage_setup($section, $extrabutton = '', global $CFG, $PAGE, $USER; require_once($CFG->libdir.'/blocklib.php'); - require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php'); if ($site = get_site()) { require_login(); @@ -3905,18 +3904,15 @@ function admin_externalpage_setup($section, $extrabutton = '', die; } - 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->set_extra_button($extrabutton); TODO - $adminroot = admin_get_root(false, false); // settings not required for external pages $extpage = $adminroot->locate($section); + $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); + // $PAGE->set_extra_button($extrabutton); TODO + if (!$actualurl) { $actualurl = $extpage->url; } - $PAGE->set_pagetype(null); $PAGE->set_url(str_replace($CFG->wwwroot . '/', '', $actualurl), array_merge($extraurlparams, array('section' => $section))); @@ -3954,14 +3950,37 @@ function admin_externalpage_print_header($focus='') { if (!empty($SITE->fullname) and !empty($SITE->shortname)) { $pageblocks = blocks_setup($PAGE); - $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]), - BLOCK_R_MAX_WIDTH); + $preferred_width_left = blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]); + $preferred_width_right = blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]); + + $adminroot = admin_get_root(false, false); //settings not required - only pages + + // fetch the path parameter + $section = $PAGE->url->param('section'); + $current = $adminroot->locate($section, true); + $visiblepathtosection = array_reverse($current->visiblepath); + + // The search page currently doesn't handle block editing + if ($PAGE->user_allowed_editing()) { + $options = $PAGE->url->params(); + if ($PAGE->user_is_editing()) { + $caption = get_string('blockseditoff'); + $options['adminedit'] = 'off'; + } else { + $caption = get_string('blocksediton'); + $options['adminedit'] = 'on'; + } + $buttons = print_single_button($PAGE->url->out(false), $options, $caption, 'get', '', true); + } + + $navlinks = array(); + foreach ($visiblepathtosection as $element) { + $navlinks[] = array('name' => $element, 'link' => null, 'type' => 'misc'); + } + $navigation = build_navigation($navlinks); + + print_header("$SITE->shortname: " . implode(": ",$visiblepathtosection), $SITE->fullname, $navigation, $focus, '', true, $buttons, ''); - $PAGE->print_header($focus); echo '
'; $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable; @@ -4015,12 +4034,8 @@ function admin_externalpage_print_footer() { if (!empty($SITE->fullname)) { $pageblocks = blocks_setup($PAGE); - $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]), - BLOCK_R_MAX_WIDTH); + $preferred_width_left = blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]); + $preferred_width_right = blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]); $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable; foreach ($lt as $column) { diff --git a/lib/pagelib.php b/lib/pagelib.php index e623fed27c..0fdb40dd5e 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -835,6 +835,18 @@ class moodle_page { return 0; } + /** + * @deprecated since Moodle 2.0 + * @return the 'page id'. This concept no longer exists. + */ + function get_pageid() { + debugging('Call to deprecated method moodle_page::get_pageid(). It should not be necessary any more.', DEBUG_DEVELOPER); + if (!is_null($this->_legacypageobject)) { + return $this->_legacypageobject->get_id(); + } + return 0; + } + /** * @deprecated since Moodle 2.0 - user $PAGE->cm instead. * @return $this->cm; @@ -891,6 +903,9 @@ function page_create_object($type, $id = NULL) { $data->pageid = $id; $classname = page_map_class($type); + if (!$classname) { + return $PAGE; + } $legacypage = new $classname; $legacypage->init_quick($data); @@ -938,10 +953,10 @@ function page_map_class($type, $classname = NULL) { if (!isset($mappings[$type])) { debugging('Page class mapping requested for unknown type: '.$type); - } - - if (empty($classname) && !class_exists($mappings[$type])) { + return null; + } else if (empty($classname) && !class_exists($mappings[$type])) { debugging('Page class mapping for id "'.$type.'" exists but class "'.$mappings[$type].'" is not defined'); + return null; } return $mappings[$type]; diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 47df59acfb..25e25b76eb 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -566,7 +566,6 @@ function upgrade_plugins_blocks($startcallback, $endcallback) { // Finally, if we are in the first_install of BLOCKS setup frontpage and admin page blocks if ($first_install) { - require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php'); //Iterate over each course - there should be only site course here now if ($courses = $DB->get_records('course')) { foreach ($courses as $course) { @@ -575,8 +574,8 @@ function upgrade_plugins_blocks($startcallback, $endcallback) { } } - page_map_class(PAGE_ADMIN, 'page_admin'); - $page = page_create_object(PAGE_ADMIN, 0); // there must be some id number + $page = new moodle_page(); + $page->set_pagetype('admin'); blocks_repopulate_page($page); } } diff --git a/tag/index.php b/tag/index.php index ed30755679..a29ca6719b 100644 --- a/tag/index.php +++ b/tag/index.php @@ -3,7 +3,6 @@ require_once('../config.php'); require_once('lib.php'); require_once('locallib.php'); -require_once('pagelib.php'); require_once($CFG->dirroot.'/lib/weblib.php'); require_once($CFG->dirroot.'/blog/lib.php'); @@ -31,20 +30,29 @@ if (empty($tag)) { redirect($CFG->wwwroot.'/tag/search.php'); } - -//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)); +$PAGE->set_subpage($tag->id); $PAGE->set_blocks_editing_capability('moodle/tag:editblocks'); $pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH); -$PAGE->tag_object = $tag; if (($edit != -1) and $PAGE->user_allowed_editing()) { $USER->editing = $edit; } +$tagname = tag_display_name($tag); + +$navlinks = array(); +$navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => ''); +$navlinks[] = array('name' => $tagname, 'link' => '', 'type' => ''); -$PAGE->print_header(); +$navigation = build_navigation($navlinks); +$title = get_string('tag', 'tag') .' - '. $tagname; + +$button = ''; +if ($PAGE->user_allowed_editing() ) { + $button = update_tag_button($tag->id); +} +print_header_simple($title, '', $navigation, '', '', '', $button); // Manage all tags links $systemcontext = get_context_instance(CONTEXT_SYSTEM); diff --git a/tag/pagelib.php b/tag/pagelib.php deleted file mode 100644 index 4dcef9c6fa..0000000000 --- a/tag/pagelib.php +++ /dev/null @@ -1,38 +0,0 @@ -libdir.'/pagelib.php'); -require_once('lib.php'); - -define('PAGE_TAG_INDEX', 'tag-index'); -define('TAG_FORMAT', 'tag'); - -class page_tag extends page_base { - - var $tag_object = NULL; - - //----------- printing funtions ----------- - - function print_header() { - - global $USER, $CFG; - - $tagname = tag_display_name($this->tag_object); - - $navlinks = array(); - $navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => ''); - $navlinks[] = array('name' => $tagname, 'link' => '', 'type' => ''); - - $navigation = build_navigation($navlinks); - $title = get_string('tag', 'tag') .' - '. $tagname; - - $button = ''; - if( $this->user_allowed_editing() ) { - $button = update_tag_button($this->id); - } - print_header_simple($title, '', $navigation, '', '', '', $button); - } -} - -page_map_class(PAGE_TAG_INDEX, 'page_tag'); - -?> -- 2.39.5