moodle_page: MDL-12212 kill legacy page_allows_editing implementations
This commit is contained in:
@@ -21,16 +21,6 @@ page_map_class(PAGE_ADMIN, 'page_admin');
|
||||
class page_admin extends page_base {
|
||||
var $extrabutton = '';
|
||||
|
||||
function _legacy_blocks_get_default() {
|
||||
return 'admin_tree,admin_bookmarks';
|
||||
}
|
||||
|
||||
// seems reasonable that the only people that can edit blocks on the admin pages
|
||||
// are the admins... but maybe we want a role for this?
|
||||
function user_allowed_editing() {
|
||||
return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to pass extra HTML that is added after the turn blocks editing on/off button.
|
||||
*
|
||||
|
||||
@@ -457,7 +457,8 @@ class block_base {
|
||||
if (empty($this->instance->pageid)) {
|
||||
$this->instance->pageid = 0;
|
||||
}
|
||||
if (!empty($PAGE->type) and ($this->instance->pagetype == $PAGE->type) and $this->instance->pageid == $PAGE->id) {
|
||||
|
||||
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);
|
||||
|
||||
@@ -48,14 +48,6 @@ class page_blog extends page_base {
|
||||
$this->full_init_done = true;
|
||||
}
|
||||
|
||||
// For this test page, only admins are going to be allowed editing (for simplicity).
|
||||
function user_allowed_editing() {
|
||||
if (isloggedin() && !isguest()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//over-ride parent method's print_header because blog already passes more than just the title along
|
||||
function print_header($pageTitle='', $pageHeading='', $pageNavigation='', $pageFocus='', $pageMeta='') {
|
||||
global $CFG, $USER;
|
||||
|
||||
@@ -64,6 +64,7 @@ if (!empty($tagid)) {
|
||||
$array['tagid'] = $tagid;
|
||||
}
|
||||
$PAGE->set_url('blog/index.php', $array);
|
||||
$PAGE->set_blocks_editing_capability('moodle/blog:create');
|
||||
$PAGE->init_full(); //init the BlogInfo object and the courserecord object
|
||||
|
||||
$editing = false;
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
|
||||
$PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
|
||||
$PAGE->set_url('course/view.php', array('id' => $course->id));
|
||||
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
|
||||
$pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH);
|
||||
|
||||
if ($reset_user_allowed_editing) {
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
|
||||
$PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
|
||||
$PAGE->set_pagetype('site-index');
|
||||
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
|
||||
$PAGE->set_url('');
|
||||
$PAGE->set_docs_path('');
|
||||
$pageblocks = blocks_setup($PAGE);
|
||||
|
||||
+8
-59
@@ -188,6 +188,7 @@ class moodle_page {
|
||||
public function get_url() {
|
||||
if (is_null($this->_url)) {
|
||||
debugging('This page did no call $PAGE->set_url(...). Realying on a guess.', DEBUG_DEVELOPER);
|
||||
global $ME;
|
||||
return new moodle_url($ME);
|
||||
}
|
||||
return new moodle_url($this->_url); // Return a clone for safety.
|
||||
@@ -745,7 +746,6 @@ function page_map_class($type, $classname = NULL) {
|
||||
if ($mappings === NULL) {
|
||||
$mappings = array(
|
||||
PAGE_COURSE_VIEW => 'page_course',
|
||||
'site-index' => 'page_course'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -860,46 +860,6 @@ class page_course extends page_base {
|
||||
$this->full_init_done = true;
|
||||
}
|
||||
|
||||
// USER-RELATED THINGS
|
||||
|
||||
// Can user edit the course page or "sticky page"?
|
||||
// This is also about editting of blocks BUT mainly activities in course page layout, see
|
||||
// update_course_icon() has very similar checks - it must use the same capabilities
|
||||
//
|
||||
// this is a _very_ expensive check - so cache it during execution
|
||||
//
|
||||
function user_allowed_editing() {
|
||||
$this->init_full();
|
||||
|
||||
if (isset($this->_user_allowed_editing)) {
|
||||
return $this->_user_allowed_editing;
|
||||
}
|
||||
|
||||
if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM))
|
||||
&& defined('ADMIN_STICKYBLOCKS')) {
|
||||
$this->_user_allowed_editing = true;
|
||||
return true;
|
||||
}
|
||||
if (has_capability('moodle/course:manageactivities', $this->context)) {
|
||||
$this->_user_allowed_editing = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Exhaustive (and expensive!) checks to see if the user
|
||||
// has editing abilities to a specific module/block/group...
|
||||
// This code would benefit from the ability to check specifically
|
||||
// for overrides.
|
||||
foreach ($this->childcontexts as $cc) {
|
||||
if (($cc->contextlevel == CONTEXT_MODULE &&
|
||||
has_capability('moodle/course:manageactivities', $cc)) ||
|
||||
($cc->contextlevel == CONTEXT_BLOCK &&
|
||||
has_capability('moodle/site:manageblocks', $cc))) {
|
||||
$this->_user_allowed_editing = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HTML OUTPUT SECTION
|
||||
|
||||
// This function prints out the common part of the page's header.
|
||||
@@ -1018,13 +978,6 @@ class page_generic_activity extends page_base {
|
||||
$this->full_init_done = true;
|
||||
}
|
||||
|
||||
function user_allowed_editing() {
|
||||
$this->init_full();
|
||||
// Yu: I think this is wrong, should be checking manageactivities instead
|
||||
//return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_COURSE, $this->modulerecord->course));
|
||||
return has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $this->modulerecord->id));
|
||||
}
|
||||
|
||||
function print_header($title, $morenavlinks = NULL, $bodytags = '', $meta = '') {
|
||||
global $USER, $CFG;
|
||||
|
||||
@@ -1036,18 +989,14 @@ class page_generic_activity extends page_base {
|
||||
$title = str_replace($search, $replace, $title);
|
||||
}
|
||||
|
||||
if (empty($morenavlinks) && $this->user_allowed_editing()) {
|
||||
$buttons = '<table><tr><td>'.update_module_button($this->modulerecord->id, $this->course->id, get_string('modulename', $this->activityname)).'</td>';
|
||||
if (!empty($CFG->showblocksonmodpages)) {
|
||||
$buttons .= '<td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
|
||||
'<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
|
||||
'<input type="hidden" name="edit" value="'.($this->user_is_editing()?'off':'on').'" />'.
|
||||
'<input type="submit" value="'.get_string($this->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td>';
|
||||
}
|
||||
$buttons .= '</tr></table>';
|
||||
} else {
|
||||
$buttons = ' ';
|
||||
$buttons = '<table><tr><td>'.update_module_button($this->modulerecord->id, $this->course->id, get_string('modulename', $this->activityname)).'</td>';
|
||||
if ($this->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
|
||||
$buttons .= '<td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
|
||||
'<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
|
||||
'<input type="hidden" name="edit" value="'.($this->user_is_editing()?'off':'on').'" />'.
|
||||
'<input type="submit" value="'.get_string($this->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td>';
|
||||
}
|
||||
$buttons .= '</tr></table>';
|
||||
|
||||
if (empty($morenavlinks)) {
|
||||
$morenavlinks = array();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
$PAGE = page_create_instance($USER->id);
|
||||
$PAGE->set_url('my/index.php');
|
||||
$PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
|
||||
|
||||
$pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH);
|
||||
|
||||
|
||||
@@ -4,15 +4,6 @@ require_once($CFG->libdir.'/pagelib.php');
|
||||
|
||||
class page_my_moodle extends page_base {
|
||||
|
||||
function user_allowed_editing() {
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function print_header($title) {
|
||||
|
||||
global $USER, $CFG;
|
||||
|
||||
@@ -35,6 +35,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));
|
||||
$PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
|
||||
$pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH);
|
||||
$PAGE->tag_object = $tag;
|
||||
|
||||
|
||||
@@ -10,11 +10,6 @@ class page_tag extends page_base {
|
||||
|
||||
var $tag_object = NULL;
|
||||
|
||||
function user_allowed_editing() {
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
return has_capability('moodle/tag:editblocks', $systemcontext);
|
||||
}
|
||||
|
||||
//----------- printing funtions -----------
|
||||
|
||||
function print_header() {
|
||||
|
||||
Reference in New Issue
Block a user