Skip to content

Commit

Permalink
moodle_page: MDL-12212 completely remove the old tag and admin page c…
Browse files Browse the repository at this point in the history
…lasses
  • Loading branch information
tjhunt committed May 6, 2009
1 parent 5ed7053 commit f8b80db
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 165 deletions.
67 changes: 0 additions & 67 deletions admin/pagelib.php

This file was deleted.

65 changes: 38 additions & 27 deletions admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@
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;
}
Expand All @@ -40,33 +41,25 @@

if (empty($adminroot->errors)) {
switch ($return) {
case 'site': redirect("$CFG->wwwroot/");
case 'site': redirect("$CFG->wwwroot/");
case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
}
} else {
$errormsg = get_string('errorwithsettings', 'admin');
$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 !== '') {
Expand All @@ -80,11 +73,11 @@

echo '<form action="settings.php" method="post" id="adminsettings">';
echo '<div class="settingsform clearfix">';
echo '<input type="hidden" name="section" value="'.$PAGE->section.'" />';
$PAGE->url->hidden_params_out();
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="return" value="'.$return.'" />';

echo $page->output_html();
echo $settingspage->output_html();

echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';

Expand All @@ -94,12 +87,30 @@
} 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 '<table id="layout-table"><tr>';
$lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
Expand Down Expand Up @@ -128,12 +139,12 @@

echo '<form action="settings.php" method="post" id="adminsettings">';
echo '<div class="settingsform clearfix">';
echo '<input type="hidden" name="section" value="'.$PAGE->section.'" />';
$PAGE->url->hidden_params_out();
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="return" value="'.$return.'" />';
print_heading($page->visiblename);
print_heading($settingspage->visiblename);

echo $page->output_html();
echo $settingspage->output_html();

echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';

Expand Down
4 changes: 3 additions & 1 deletion blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ function _add_edit_controls($options) {
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()));

Expand Down
55 changes: 35 additions & 20 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)));

Expand Down Expand Up @@ -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 '<table id="layout-table" summary=""><tr>';

$lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 18 additions & 3 deletions lib/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,18 @@ function get_id() {
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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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];
Expand Down
5 changes: 2 additions & 3 deletions lib/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
Expand Down
Loading

0 comments on commit f8b80db

Please sign in to comment.