From: tjhunt Date: Wed, 6 May 2009 09:02:48 +0000 (+0000) Subject: moodle_page: MDL-12212 kill legacy page_allows_editing implementations X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=cfcfb9f3d09c13ad6af0d61fa6a4f01d61e08c94;p=moodle.git moodle_page: MDL-12212 kill legacy page_allows_editing implementations --- diff --git a/admin/pagelib.php b/admin/pagelib.php index 4514bba90d..62c76cd767 100644 --- a/admin/pagelib.php +++ b/admin/pagelib.php @@ -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. * diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index e4471ffdb7..a92a63dcc6 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -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); diff --git a/blog/blogpage.php b/blog/blogpage.php index c4ba4a4ba5..dde6e70d5b 100644 --- a/blog/blogpage.php +++ b/blog/blogpage.php @@ -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; diff --git a/blog/header.php b/blog/header.php index 05d5d56f43..bf663f1a46 100755 --- a/blog/header.php +++ b/blog/header.php @@ -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; diff --git a/course/view.php b/course/view.php index 332fb5f7ee..d68aff4508 100644 --- a/course/view.php +++ b/course/view.php @@ -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) { diff --git a/index.php b/index.php index c4c5a263c4..277c102947 100644 --- a/index.php +++ b/index.php @@ -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); diff --git a/lib/pagelib.php b/lib/pagelib.php index a0b185d401..b65e314ef7 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -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 = ''; - if (!empty($CFG->showblocksonmodpages)) { - $buttons .= ''; - } - $buttons .= '
'.update_module_button($this->modulerecord->id, $this->course->id, get_string('modulename', $this->activityname)).'
frametarget.' method="get" action="view.php">
'. - ''. - ''. - '
'; - } else { - $buttons = ' '; + $buttons = ''; + if ($this->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { + $buttons .= ''; } + $buttons .= '
'.update_module_button($this->modulerecord->id, $this->course->id, get_string('modulename', $this->activityname)).'
frametarget.' method="get" action="view.php">
'. + ''. + ''. + '
'; if (empty($morenavlinks)) { $morenavlinks = array(); diff --git a/my/index.php b/my/index.php index 76774b8546..61d8c38c79 100644 --- a/my/index.php +++ b/my/index.php @@ -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); diff --git a/my/pagelib.php b/my/pagelib.php index a7a718bca7..d70811758b 100644 --- a/my/pagelib.php +++ b/my/pagelib.php @@ -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; diff --git a/tag/index.php b/tag/index.php index d97fb54a2b..0de525965b 100644 --- a/tag/index.php +++ b/tag/index.php @@ -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; diff --git a/tag/pagelib.php b/tag/pagelib.php index 44de6ad0bd..d89b0259c1 100644 --- a/tag/pagelib.php +++ b/tag/pagelib.php @@ -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() {