Skip to content

Commit

Permalink
moodle_page: MDL-12212 kill legacy page_allows_editing implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhunt committed May 6, 2009
1 parent 934524d commit cfcfb9f
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 92 deletions.
10 changes: 0 additions & 10 deletions admin/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@
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.
*
Expand Down
3 changes: 2 additions & 1 deletion blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ function _add_edit_controls($options) {
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);
Expand Down
8 changes: 0 additions & 8 deletions blog/blogpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ function init_full() {
$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;
Expand Down
1 change: 1 addition & 0 deletions blog/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
$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;
Expand Down
1 change: 1 addition & 0 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
67 changes: 8 additions & 59 deletions lib/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public function get_docspath() {
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.
Expand Down Expand Up @@ -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'
);
}

Expand Down Expand Up @@ -860,46 +860,6 @@ function init_full() {
$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.
Expand Down Expand Up @@ -1018,13 +978,6 @@ function init_full() {
$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;

Expand All @@ -1036,18 +989,14 @@ function print_header($title, $morenavlinks = NULL, $bodytags = '', $meta = '')
$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();
Expand Down
1 change: 1 addition & 0 deletions my/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 0 additions & 9 deletions my/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@

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;
Expand Down
1 change: 1 addition & 0 deletions tag/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//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;

Expand Down
5 changes: 0 additions & 5 deletions tag/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit cfcfb9f

Please sign in to comment.