]> git.mjollnir.org Git - moodle.git/commitdiff
moodle_page: MDL-12212 kill legacy page_allows_editing implementations
authortjhunt <tjhunt>
Wed, 6 May 2009 09:02:48 +0000 (09:02 +0000)
committertjhunt <tjhunt>
Wed, 6 May 2009 09:02:48 +0000 (09:02 +0000)
admin/pagelib.php
blocks/moodleblock.class.php
blog/blogpage.php
blog/header.php
course/view.php
index.php
lib/pagelib.php
my/index.php
my/pagelib.php
tag/index.php
tag/pagelib.php

index 4514bba90d0f6def98a73a7553f7421184c891fc..62c76cd7674272c9645219b23f77a429208a6777 100644 (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.
      *
index e4471ffdb7c72e6c996a97aa6f81b12848c04e8f..a92a63dcc61d01aa63e9b87c0a2b73ca41c65efa 100644 (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);
index c4ba4a4ba530c781c179e717949354907d092a40..dde6e70d5b1446855fe8e76ea98cce2806d27c7c 100644 (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;
index 05d5d56f43f676b676a92ddf3303e2474104bda8..bf663f1a46640cba7960f931eef75b47dd0a99fb 100755 (executable)
@@ -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;
index 332fb5f7ee1fa78107c3ccda48c55839fe3640db..d68aff45080fca06b9f5f9f935aec37e855a04b0 100644 (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) {
index c4c5a263c47c2732da079cb6d54a1f571b69c2f7..277c102947cbd3411ca7f316e95c853255c7fff5 100644 (file)
--- 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);
index a0b185d401a8cdc3b54733bf003a1e334203ccb7..b65e314ef7e403ee380d60d1503553affb3fc4ea 100644 (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();
index 76774b8546aca083a821bba8d112f2b8d230e36a..61d8c38c79ef5bff4387271b6212d3293408996c 100644 (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);
 
index a7a718bca72e71ac15b7f1f4e240f89ccb6458bf..d70811758b949d3c72b33b2677d178983ff75c9b 100644 (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;
index d97fb54a2b9e5c0e4f5f1587f11a289746e10fcc..0de525965b13f789f0fffecba0c8f92acbb390ca 100644 (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;
 
index 44de6ad0bdd7da916aba19a3d3dee09681eb0322..d89b0259c1ea911f8a84b4808c7c2265d5e9551a 100644 (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() {