Permalink
Browse files

Merge branch 'wip-MDL-27122-MOODLE_20_STABLE' of git://github.com/mar…

…inaglancy/moodle into MOODLE_20_STABLE
  • Loading branch information...
2 parents 7d5f928 + 914cbfa commit 43b2bb6cd9f0893d15f0cbde32eb495fac92f6b7 @samhemelryk samhemelryk committed Aug 2, 2011
Showing with 58 additions and 10 deletions.
  1. +48 −2 admin/blocks.php
  2. +0 −5 config-dist.php
  3. +3 −0 lang/en/admin.php
  4. +7 −3 lib/blocklib.php
View
@@ -12,6 +12,8 @@
$hide = optional_param('hide', 0, PARAM_INT);
$show = optional_param('show', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
+ $unprotect = optional_param('unprotect', 0, PARAM_INT);
+ $protect = optional_param('protect', 0, PARAM_INT);
/// Print headings
@@ -24,6 +26,9 @@
$strcourses = get_string('blockinstances', 'admin');
$strname = get_string('name');
$strshowblockcourse = get_string('showblockcourse');
+ $strprotecthdr = get_string('blockprotect', 'admin'). $OUTPUT->help_icon('blockprotect','admin');
+ $strprotect = get_string('blockprotect', 'admin');
+ $strunprotect = get_string('blockunprotect', 'admin');
/// If data submitted, then process and store.
@@ -43,6 +48,36 @@
admin_get_root(true, false); // settings not required - only pages
}
+ if (!isset($CFG->undeletableblocktypes) || (!is_array($CFG->undeletableblocktypes) && !is_string($CFG->undeletableblocktypes))) {
+ $undeletableblocktypes = array('navigation', 'settings');
+ } else if (is_string($CFG->undeletableblocktypes)) {
+ $undeletableblocktypes = explode(',', $CFG->undeletableblocktypes);
+ } else {
+ $undeletableblocktypes = $CFG->undeletableblocktypes;
+ }
+
+ if (!empty($protect) && confirm_sesskey()) {
+ if (!$block = $DB->get_record('block', array('id'=>$protect))) {
+ print_error('blockdoesnotexist', 'error');
+ }
+ if (!in_array($block->name, $undeletableblocktypes)) {
+ $undeletableblocktypes[] = $block->name;
+ set_config('undeletableblocktypes', implode(',', $undeletableblocktypes));
+ }
+ admin_get_root(true, false); // settings not required - only pages
+ }
+
+ if (!empty($unprotect) && confirm_sesskey()) {
+ if (!$block = $DB->get_record('block', array('id'=>$unprotect))) {
+ print_error('blockdoesnotexist', 'error');
+ }
+ if (in_array($block->name, $undeletableblocktypes)) {
+ $undeletableblocktypes = array_diff($undeletableblocktypes, array($block->name));
+ set_config('undeletableblocktypes', implode(',', $undeletableblocktypes));
+ }
+ admin_get_root(true, false); // settings not required - only pages
+ }
+
if (!empty($delete) && confirm_sesskey()) {
echo $OUTPUT->header();
echo $OUTPUT->heading($strmanageblocks);
@@ -114,8 +149,8 @@
$table = new flexible_table('admin-blocks-compatible');
- $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'delete', 'settings'));
- $table->define_headers(array($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strdelete, $strsettings));
+ $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'undeletable', 'delete', 'settings'));
+ $table->define_headers(array($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strprotecthdr, $strdelete, $strsettings));
$table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php');
$table->set_attribute('class', 'compatibleblockstable blockstable generaltable');
$table->setup();
@@ -191,12 +226,23 @@
$version = "$block->version ($plugin->version)";
}
+ if (!$blockobject) {
+ // ignore
+ $undeletable = '';
+ } else if (in_array($blockname, $undeletableblocktypes)) {
+ $undeletable = '<a href="blocks.php?unprotect='.$blockid.'&amp;sesskey='.sesskey().'" title="'.$strunprotect.'">'.
+ '<img src="'.$OUTPUT->pix_url('t/unlock') . '" class="icon" alt="'.$strunprotect.'" /></a>';
+ } else {
+ $undeletable = '<a href="blocks.php?protect='.$blockid.'&amp;sesskey='.sesskey().'" title="'.$strprotect.'">'.
+ '<img src="'.$OUTPUT->pix_url('t/unlock_gray') . '" class="icon" alt="'.$strprotect.'" /></a>';
+ }
$table->add_data(array(
'<span'.$class.'>'.$strblockname.'</span>',
$blocklist,
'<span'.$class.'>'.$version.'</span>',
$visible,
+ $undeletable,
$delete,
$settings
));
View
@@ -208,11 +208,6 @@
// These blocks are used when no other default setting is found.
// $CFG->defaultblocks = 'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';
//
-// The blocks in this list will be protected from deletion, and this is primarily
-// used to protect the navigation and settings blocks which can be very hard to
-// get back if accidentally delete.
-// $CFG->undeletableblocktypes = 'navigation,settings';
-//
// You can specify a different class to be created for the $PAGE global, and to
// compute which blocks appear on each page. However, I cannot think of any good
// reason why you would need to change that. It just felt wrong to hard-code the
View
@@ -71,6 +71,9 @@
$string['blockediplist'] = 'Blocked IP List';
$string['blockinstances'] = 'Instances';
$string['blockmultiple'] = 'Multiple';
+$string['blockprotect'] = 'Protect from delete';
+$string['blockprotect_help'] = 'The blocks instances will be protected from deletion from the site-wide context, and this is primarily used to protect the navigation and settings blocks which can be very hard to get back if accidentally delete.';
+$string['blockunprotect'] = 'Unprotect';
$string['blocksettings'] = 'Manage blocks';
$string['bloglevel'] = 'Blog visibility';
$string['bloglevelupgrade'] = 'Blog visibility upgrade';
View
@@ -972,9 +972,11 @@ public function edit_controls($block) {
global $CFG;
if (!isset($CFG->undeletableblocktypes) || (!is_array($CFG->undeletableblocktypes) && !is_string($CFG->undeletableblocktypes))) {
- $CFG->undeletableblocktypes = array('navigation','settings');
+ $undeletableblocktypes = array('navigation','settings');
} else if (is_string($CFG->undeletableblocktypes)) {
- $CFG->undeletableblocktypes = explode(',', $CFG->undeletableblocktypes);
+ $undeletableblocktypes = explode(',', $CFG->undeletableblocktypes);
+ } else {
+ $undeletableblocktypes = $CFG->undeletableblocktypes;
}
$controls = array();
@@ -1012,7 +1014,9 @@ public function edit_controls($block) {
}
if ($this->page->user_can_edit_blocks() && $block->user_can_edit() && $block->user_can_addto($this->page)) {
- if (!in_array($block->instance->blockname, $CFG->undeletableblocktypes)) {
+ if (!in_array($block->instance->blockname, $undeletableblocktypes)
+ || !in_array($block->instance->pagetypepattern, array('*', 'site-index'))
+ || $block->instance->parentcontextid != SITEID) {
// Delete icon.
$controls[] = array('url' => $actionurl . '&bui_deleteid=' . $block->instance->id,
'icon' => 't/delete', 'caption' => get_string('delete'));

0 comments on commit 43b2bb6

Please sign in to comment.