moodle_page: MDL-12212 kill legacy page_allows_editing implementations

This commit is contained in:
tjhunt
2009-05-06 09:02:48 +00:00
parent 934524d70b
commit cfcfb9f3d0
11 changed files with 15 additions and 92 deletions
-10
View File
@@ -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.
*
+2 -1
View File
@@ -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);
-8
View File
@@ -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;
+1
View File
@@ -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;
+1
View File
@@ -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) {
+1
View File
@@ -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
View File
@@ -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 = '&nbsp;';
$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();
+1
View File
@@ -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);
-9
View File
@@ -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;
+1
View File
@@ -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;
-5
View File
@@ -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() {