Skip to content

Commit

Permalink
moodle_page: MDL-12212 reimplement user_is_editing, deprecate isediting
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhunt committed May 6, 2009
1 parent d7f688d commit 830dd6e
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 140 deletions.
6 changes: 0 additions & 6 deletions admin/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ function user_allowed_editing() {
return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM));
}

// has to be fixed. i know there's a "proper" way to do this
function user_is_editing() {
global $USER;
return $USER->adminediting;
}

/**
* Use this to pass extra HTML that is added after the turn blocks editing on/off button.
*
Expand Down
12 changes: 2 additions & 10 deletions admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,8 @@
$PAGE->set_pagetype('admin-setting-' . $section);
$PAGE->init_extra($section);

if (!isset($USER->adminediting)) {
$USER->adminediting = false;
}

if ($PAGE->user_allowed_editing()) {
if ($adminediting == 1) {
$USER->adminediting = true;
} elseif ($adminediting == 0) {
$USER->adminediting = false;
}
if ($PAGE->user_allowed_editing() && $adminediting != -1) {
$USER->editing = $adminediting;
}


Expand Down
4 changes: 2 additions & 2 deletions blocks/admin/block_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function init() {

function get_content() {

global $CFG, $USER, $SITE, $COURSE, $DB;
global $CFG, $USER, $SITE, $COURSE, $DB, $PAGE;

if ($this->content !== NULL) {
return $this->content;
Expand Down Expand Up @@ -57,7 +57,7 @@ function get_content() {

if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/edit.gif" class="icon" alt="" />';
if (isediting($this->instance->pageid)) {
if ($PAGE->user_is_editing()) {
$this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=off&amp;sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
} else {
$this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=on&amp;sesskey='.sesskey().'">'.get_string('turneditingon').'</a>';
Expand Down
4 changes: 2 additions & 2 deletions blocks/course_summary/block_course_summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function specialization() {
}

function get_content() {
global $CFG, $COURSE;
global $CFG, $COURSE, $PAGE;

if($this->content !== NULL) {
return $this->content;
Expand All @@ -28,7 +28,7 @@ function get_content() {
$options = new object();
$options->noclean = true; // Don't clean Javascripts etc
$this->content->text = format_text($COURSE->summary, FORMAT_HTML, $options);
if (isediting($COURSE->id)) { // ?? courseid param not there??
if ($PAGE->user_is_editing()) {
if($COURSE->id == SITEID) {
$editpage = $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=frontpagesettings';
} else {
Expand Down
6 changes: 3 additions & 3 deletions blocks/site_main_menu/block_site_main_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function applicable_formats() {
}

function get_content() {
global $USER, $CFG, $COURSE, $DB;
global $USER, $CFG, $COURSE, $DB, $PAGE;

if ($this->content !== NULL) {
return $this->content;
Expand All @@ -35,8 +35,8 @@ function get_content() {
require_once($CFG->dirroot.'/course/lib.php');

$context = get_context_instance(CONTEXT_COURSE, $course->id);
$isediting = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context);
$modinfo =& get_fast_modinfo($course);
$isediting = $PAGE->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$modinfo = get_fast_modinfo($course);

/// extra fast view mode
if (!$isediting) {
Expand Down
4 changes: 2 additions & 2 deletions blocks/social_activities/block_social_activities.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function applicable_formats() {
}

function get_content() {
global $USER, $CFG, $COURSE, $DB;
global $USER, $CFG, $COURSE, $DB, $PAGE;

if ($this->content !== NULL) {
return $this->content;
Expand All @@ -35,7 +35,7 @@ function get_content() {
require_once($CFG->dirroot.'/course/lib.php');

$context = get_context_instance(CONTEXT_COURSE, $course->id);
$isediting = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context);
$isediting = $PAGE->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$modinfo = get_fast_modinfo($course);

/// extra fast view mode
Expand Down
18 changes: 3 additions & 15 deletions blog/blogpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ function user_allowed_editing() {
return false;
}

// Also, admins are considered to have "always on" editing (I wanted to avoid duplicating
// the code that turns editing on/off here; you can roll your own or copy course/view.php).
function user_is_editing() {
global $SESSION;

if (isloggedin() && !isguest()) {
$this->editing = !empty($SESSION->blog_editing_enabled);
return $this->editing;
}
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 $USER;
Expand All @@ -82,18 +70,18 @@ function print_header($pageTitle='', $pageHeading='', $pageNavigation='', $pageF

/////////// Blog page specific functions
function get_extra_header_string() {
global $SESSION, $CFG, $USER;
global $CFG, $USER;

$editformstring = '';
if ($this->user_allowed_editing()) {
if (!empty($SESSION->blog_editing_enabled)) {
if ($this->user_is_editing()) {
$editingString = get_string('turneditingoff');
} else {
$editingString = get_string('turneditingon');
}

$params = $this->url->params();
$params['edit'] = empty($SESSION->blog_editing_enabled) ? 1 : 0;
$params['edit'] = $this->user_is_editing() ? 0 : 1;
$paramstring = '';
foreach ($params as $key=>$val) {
$paramstring .= '<input type="hidden" name="'.$key.'" value="'.s($val).'" />';
Expand Down
3 changes: 1 addition & 2 deletions blog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@

$sitecontext = get_context_instance(CONTEXT_SYSTEM);


// change block edit staus if not guest and logged in
if (isloggedin() and !isguest() and $edit != -1) {
$SESSION->blog_editing_enabled = $edit;
$USER->editing = $edit;
}

if (empty($filtertype)) {
Expand Down
11 changes: 0 additions & 11 deletions blog/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ function blog_check_and_install_blocks() {
}


/**
* Adaptation of isediting in moodlelib.php for blog module
* @return bool
*/
function blog_isediting() {
global $SESSION;

return !empty($SESSION->blog_editing_enabled);
}


/**
* This function is in lib and not in BlogInfo because entries being searched
* might be found in any number of blogs rather than just one.
Expand Down
4 changes: 2 additions & 2 deletions course/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

if (update_category_button($category->id)) {
if ($categoryedit !== -1) {
$USER->categoryediting = $categoryedit;
$USER->editing = $categoryedit;
}
$editingon = !empty($USER->categoryediting);
$editingon = $PAGE->user_is_editing();
$navbaritem = update_category_button($category->id); // Must call this again after updating the state.
} else {
$navbaritem = print_course_search('', true, 'navbar');
Expand Down
12 changes: 6 additions & 6 deletions course/format/topics/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
$section = 0;
$thissection = $sections[$section];

if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {

// Note, no need for a 'left side' cell or DIV.
// Note, 'right side' is BEFORE content.
Expand All @@ -141,7 +141,7 @@
$summaryformatoptions->noclean = true;
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);

if (isediting($course->id) && has_capability('moodle/course:update', $coursecontext)) {
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
echo '<a title="'.$streditsummary.'" '.
' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
' class="icon edit" alt="'.$streditsummary.'" /></a>';
Expand All @@ -150,7 +150,7 @@

print_section($course, $thissection, $mods, $modnamesused);

if (isediting($course->id)) {
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, $section, $modnames);
}

Expand Down Expand Up @@ -227,7 +227,7 @@
'<img src="'.$CFG->pixpath.'/i/one.gif" class="icon" alt="'.$strshowonlytopic.'" /></a><br />';
}

if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {

if ($course->marker == $section) { // Show the "light globe" on/off
echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.'<img src="'.$CFG->pixpath.'/i/marked.gif" alt="'.$strmarkedthistopic.'" /></a><br />';
Expand Down Expand Up @@ -266,15 +266,15 @@
echo '&nbsp;';
}

if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
'<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
}
echo '</div>';

print_section($course, $thissection, $mods, $modnamesused);

if (isediting($course->id)) {
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, $section, $modnames);
}
}
Expand Down
12 changes: 6 additions & 6 deletions course/format/weeks/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
$section = 0;
$thissection = $sections[$section];

if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {

// Note, 'right side' is BEFORE content.
echo '<li id="section-0" class="section main" >';
Expand All @@ -131,7 +131,7 @@
$summaryformatoptions->noclean = true;
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);

if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo '<p><a title="'.$streditsummary.'" '.
' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
' class="icon edit" alt="'.$streditsummary.'" /></a></p>';
Expand All @@ -140,7 +140,7 @@

print_section($course, $thissection, $mods, $modnamesused);

if (isediting($course->id)) {
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, $section, $modnames);
}

Expand Down Expand Up @@ -223,7 +223,7 @@
'<img src="'.$CFG->pixpath.'/i/one.gif" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
}

if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
if ($thissection->visible) { // Show the hide/show eye
echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekhide.'">'.
'<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
Expand Down Expand Up @@ -256,15 +256,15 @@
$summaryformatoptions->noclean = true;
echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);

if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
'<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
}
echo '</div>';

print_section($course, $thissection, $mods, $modnamesused);

if (isediting($course->id)) {
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, $section, $modnames);
}
}
Expand Down
4 changes: 2 additions & 2 deletions course/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

if (update_category_button()) {
if ($categoryedit !== -1) {
$USER->categoryediting = $categoryedit;
$USER->editing = $categoryedit;
}
$adminediting = !empty($USER->categoryediting);
$adminediting = $PAGE->user_is_editing();
} else {
$adminediting = false;
}
Expand Down
8 changes: 4 additions & 4 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
* Prints a section full of activity modules
*/
function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false) {
global $CFG, $USER, $DB;
global $CFG, $USER, $DB, $PAGE;

static $initialised;

Expand All @@ -1385,7 +1385,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
if (!isset($initialised)) {
$groupbuttons = ($course->groupmode or (!$course->groupmodeforce));
$groupbuttonslink = (!$course->groupmodeforce);
$isediting = isediting($course->id);
$isediting = $PAGE->user_is_editing();
$ismoving = $isediting && ismoving($course->id);
if ($ismoving) {
$strmovehere = get_string("movehere");
Expand Down Expand Up @@ -2181,7 +2181,7 @@ function print_course_request_buttons($systemcontext) {
* to see it.
*/
function update_category_button($categoryid = 0) {
global $CFG, $USER;
global $CFG, $PAGE;

// Check permissions.
$context = get_category_or_system_context($categoryid);
Expand All @@ -2190,7 +2190,7 @@ function update_category_button($categoryid = 0) {
}

// Work out the appropriate action.
if (!empty($USER->categoryediting)) {
if ($PAGE->user_is_editing()) {
$label = get_string('turneditingoff');
$edit = 'off';
} else {
Expand Down
4 changes: 2 additions & 2 deletions course/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

if (update_category_button()) {
if ($edit !== -1) {
$USER->categoryediting = $edit;
$USER->editing = $edit;
}
$adminediting = !empty($USER->categoryediting);
$adminediting = $PAGE->user_is_editing();
} else {
$adminediting = false;
}
Expand Down
13 changes: 2 additions & 11 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3931,17 +3931,8 @@ function admin_externalpage_setup($section, $extrabutton = '',
}

$adminediting = optional_param('adminedit', -1, PARAM_BOOL);

if (!isset($USER->adminediting)) {
$USER->adminediting = false;
}

if ($PAGE->user_allowed_editing()) {
if ($adminediting == 1) {
$USER->adminediting = true;
} elseif ($adminediting == 0) {
$USER->adminediting = false;
}
if ($PAGE->user_allowed_editing() && $adminediting != -1) {
$USER->editing = $adminediting;
}
}

Expand Down
Loading

0 comments on commit 830dd6e

Please sign in to comment.