Skip to content

Commit

Permalink
moodle_page: MDL-12212 Kill legacy url_... and blocks_... methods
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tjhunt committed May 6, 2009
1 parent 4873f5f commit ad52c04
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 281 deletions.
82 changes: 13 additions & 69 deletions admin/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,9 @@
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';
}

Expand All @@ -63,22 +37,6 @@ function user_is_editing() {
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.
*
Expand All @@ -88,51 +46,37 @@ function set_extra_button($extrabutton) {
$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';
} else {
$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, '');
}
}

Expand Down
3 changes: 2 additions & 1 deletion admin/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

$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()) {
Expand Down
3 changes: 2 additions & 1 deletion admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/// 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);
Expand Down Expand Up @@ -106,7 +107,7 @@
$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;
Expand Down
2 changes: 1 addition & 1 deletion blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ function _add_edit_controls($options) {
} 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.'">' .
Expand Down
4 changes: 2 additions & 2 deletions blocks/rss_client/block_rss_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function get_content() {
//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',
Expand All @@ -121,7 +121,7 @@ function get_content() {
} 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',
Expand Down
4 changes: 2 additions & 2 deletions blocks/rss_client/config_instance.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
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 />';
Expand Down
4 changes: 2 additions & 2 deletions blocks/rss_client/config_instance_tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
}

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'));

Expand Down
34 changes: 2 additions & 32 deletions blog/blogpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,6 @@ function print_header($pageTitle='', $pageHeading='', $pageNavigation='', $pageF
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;
Expand All @@ -122,14 +92,14 @@ function get_extra_header_string() {
$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>';
}

Expand Down
15 changes: 14 additions & 1 deletion blog/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@
$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;
Expand Down
3 changes: 1 addition & 2 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
13 changes: 9 additions & 4 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3891,7 +3891,8 @@ public function output_html($data, $query='') {
* @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');
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit ad52c04

Please sign in to comment.