From 850d2db82af5570d252d1e68e79bc8b0e877c733 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 19 Jul 2012 11:30:05 +0800 Subject: [PATCH] MDL-25012 - blogs: introduce a specific 'enabled' config setting Rather than overloading the $CFG->bloglevel setting which had a confusing UI in the appearance subsystem. In order to achieve this we modify take the defaults from the existing bloglevel setting and set that for $CFG->enableblogs. Note that in order to prevent a bad default settings from being set we also set $CFG->bloglevel to a valid 'enabled' setting. --- admin/settings/appearance.php | 3 +-- admin/settings/subsystems.php | 6 +----- blocks/blog_menu/block_blog_menu.php | 2 +- blocks/blog_recent/block_blog_recent.php | 2 +- blog/edit.php | 2 +- blog/index.php | 2 +- blog/lib.php | 7 +++---- blog/locallib.php | 2 +- blog/preferences.php | 2 +- lang/en/admin.php | 2 ++ lang/en/blog.php | 1 - lib/cronlib.php | 4 ++-- lib/db/upgrade.php | 20 ++++++++++++++++++++ lib/filelib.php | 2 +- lib/navigationlib.php | 6 +++--- version.php | 2 +- 16 files changed, 40 insertions(+), 25 deletions(-) diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 9995af3804887..212554b0950d8 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -75,8 +75,7 @@ $temp->add(new admin_setting_configcheckbox('useblogassociations', new lang_string('useblogassociations', 'blog'), new lang_string('configuseblogassociations','blog'), 1)); $temp->add(new admin_setting_bloglevel('bloglevel', new lang_string('bloglevel', 'admin'), new lang_string('configbloglevel', 'admin'), 4, array(BLOG_GLOBAL_LEVEL => new lang_string('worldblogs','blog'), BLOG_SITE_LEVEL => new lang_string('siteblogs','blog'), - BLOG_USER_LEVEL => new lang_string('personalblogs','blog'), - 0 => new lang_string('disableblogs','blog')))); + BLOG_USER_LEVEL => new lang_string('personalblogs','blog')))); $temp->add(new admin_setting_configcheckbox('useexternalblogs', new lang_string('useexternalblogs', 'blog'), new lang_string('configuseexternalblogs','blog'), 1)); $temp->add(new admin_setting_configselect('externalblogcrontime', new lang_string('externalblogcrontime', 'blog'), new lang_string('configexternalblogcrontime', 'blog'), 86400, array(43200 => new lang_string('numhours', '', 12), diff --git a/admin/settings/subsystems.php b/admin/settings/subsystems.php index 0e629b805c04e..0d3db2ed1d231 100644 --- a/admin/settings/subsystems.php +++ b/admin/settings/subsystems.php @@ -26,11 +26,7 @@ $optionalsubsystems->add(new admin_setting_configcheckbox('enablerssfeeds', new lang_string('enablerssfeeds', 'admin'), new lang_string('configenablerssfeeds', 'admin'), 0)); - $optionalsubsystems->add(new admin_setting_bloglevel('bloglevel', new lang_string('bloglevel', 'admin'), - new lang_string('configbloglevel', 'admin'), 4, array(5 => new lang_string('worldblogs','blog'), - 4 => new lang_string('siteblogs','blog'), - 1 => new lang_string('personalblogs','blog'), - 0 => new lang_string('disableblogs','blog')))); + $optionalsubsystems->add(new admin_setting_configcheckbox('enableblogs', new lang_string('enableblogs', 'admin'), new lang_string('configenableblogs', 'admin'), 1)); $options = array('off'=>new lang_string('off', 'mnet'), 'strict'=>new lang_string('on', 'mnet')); $optionalsubsystems->add(new admin_setting_configselect('mnet_dispatcher_mode', new lang_string('net', 'mnet'), new lang_string('configmnet', 'mnet'), 'off', $options)); diff --git a/blocks/blog_menu/block_blog_menu.php b/blocks/blog_menu/block_blog_menu.php index c85576a0f26a0..bdbe4573830d3 100644 --- a/blocks/blog_menu/block_blog_menu.php +++ b/blocks/blog_menu/block_blog_menu.php @@ -58,7 +58,7 @@ function get_content() { return $this->content; } - if (empty($CFG->bloglevel)) { + if (empty($CFG->enableblogs)) { $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { diff --git a/blocks/blog_recent/block_blog_recent.php b/blocks/blog_recent/block_blog_recent.php index fe6c970c8fec0..1bee81e6c964f 100644 --- a/blocks/blog_recent/block_blog_recent.php +++ b/blocks/blog_recent/block_blog_recent.php @@ -52,7 +52,7 @@ function get_content() { } // verify blog is enabled - if (empty($CFG->bloglevel)) { + if (empty($CFG->enableblogs)) { $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { diff --git a/blog/edit.php b/blog/edit.php index 3ed91554cdb31..d39ec414c13b1 100644 --- a/blog/edit.php +++ b/blog/edit.php @@ -69,7 +69,7 @@ $id = required_param('entryid', PARAM_INT); } -if (empty($CFG->bloglevel)) { +if (empty($CFG->enableblogs)) { print_error('blogdisable', 'blog'); } diff --git a/blog/index.php b/blog/index.php index feb320e9cbdb2..94bc527cfcbb7 100644 --- a/blog/index.php +++ b/blog/index.php @@ -34,7 +34,7 @@ } $PAGE->set_url('/blog/index.php', $url_params); -if (empty($CFG->bloglevel)) { +if (empty($CFG->enableblogs)) { print_error('blogdisable', 'blog'); } diff --git a/blog/lib.php b/blog/lib.php index 764fc64a060a4..280102965b052 100644 --- a/blog/lib.php +++ b/blog/lib.php @@ -64,7 +64,7 @@ function blog_user_can_edit_entry($blogentry) { function blog_user_can_view_user_entry($targetuserid, $blogentry=null) { global $CFG, $USER, $DB; - if (empty($CFG->bloglevel)) { + if (empty($CFG->enableblogs)) { return false; // blog system disabled } @@ -349,8 +349,7 @@ function blog_get_context_url($context=null) { */ function blog_is_enabled_for_user() { global $CFG; - //return (!empty($CFG->bloglevel) && $CFG->bloglevel <= BLOG_GLOBAL_LEVEL && isloggedin() && !isguestuser()); - return (!empty($CFG->bloglevel) && (isloggedin() || ($CFG->bloglevel == BLOG_GLOBAL_LEVEL))); + return (!empty($CFG->enableblogs) && (isloggedin() || ($CFG->bloglevel == BLOG_GLOBAL_LEVEL))); } /** @@ -406,7 +405,7 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) { } // If blog level is global then display a link to view all site entries - if (!empty($CFG->bloglevel) && $CFG->bloglevel >= BLOG_GLOBAL_LEVEL && has_capability('moodle/blog:view', context_system::instance())) { + if (!empty($CFG->enableblogs) && $CFG->bloglevel >= BLOG_GLOBAL_LEVEL && has_capability('moodle/blog:view', context_system::instance())) { $options[CONTEXT_SYSTEM] = array('viewsite' => array( 'string' => get_string('viewsiteentries', 'blog'), 'link' => new moodle_url('/blog/index.php') diff --git a/blog/locallib.php b/blog/locallib.php index 813b6c6a7d885..0356e24abaaf6 100644 --- a/blog/locallib.php +++ b/blog/locallib.php @@ -602,7 +602,7 @@ public function can_user_view($targetuserid) { global $CFG, $USER, $DB; $sitecontext = context_system::instance(); - if (empty($CFG->bloglevel) || !has_capability('moodle/blog:view', $sitecontext)) { + if (empty($CFG->enableblogs) || !has_capability('moodle/blog:view', $sitecontext)) { return false; // blog system disabled or user has no blog view capability } diff --git a/blog/preferences.php b/blog/preferences.php index 3ab869b2eaa4b..9bbc3fcf6c050 100644 --- a/blog/preferences.php +++ b/blog/preferences.php @@ -64,7 +64,7 @@ $context = context_course::instance($courseid); } -if (empty($CFG->bloglevel)) { +if (empty($CFG->enableblogs)) { print_error('blogdisable', 'blog'); } diff --git a/lang/en/admin.php b/lang/en/admin.php index 9c143985d96b8..63d3bf4e96e96 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -180,6 +180,7 @@ $string['configdeleteincompleteusers'] = 'After this period, old not fully setup accounts are deleted.'; $string['configdeleteunconfirmed'] = 'If you are using email authentication, this is the period within which a response will be accepted from users. After this period, old unconfirmed accounts are deleted.'; $string['configdenyemailaddresses'] = 'To deny email addresses from particular domains list them here in the same way. All other domains will be accepted. To deny subdomains add the domain with a preceding \'.\'. eg hotmail.com yahoo.co.uk .live.com'; +$string['configenableblogs'] = 'This switch provides all site users with their own blog.'; $string['configenabledevicedetection'] = 'Enables detection of mobiles, smartphones, tablets or default devices (desktop PCs, laptops, etc) for the application of themes and other features.'; $string['configdisableuserimages'] = 'Disable the ability for users to change user profile images.'; $string['configdisplayloginfailures'] = 'This will display information to selected users about previous failed logins.'; @@ -464,6 +465,7 @@ $string['emoticonsreset'] = 'Reset emoticons setting to default values'; $string['emptysettingvalue'] = 'Empty'; $string['enableajax'] = 'Enable AJAX'; +$string['enableblogs'] = 'Enable blogs'; $string['enablecalendarexport'] = 'Enable calendar export'; $string['enablecomments'] = 'Enable comments'; $string['enablecourserequests'] = 'Enable course requests'; diff --git a/lang/en/blog.php b/lang/en/blog.php index 197931e0c1542..546753e80eaf6 100644 --- a/lang/en/blog.php +++ b/lang/en/blog.php @@ -74,7 +74,6 @@ $string['deleteotagswarn'] = 'Are you sure you want to remove these tags from all blog posts and remove it from the system?'; $string['description'] = 'Description'; $string['description_help'] = 'Enter a sentence or two summarising the contents of your external blog. (If no description is supplied, the description recorded in your external blog will be used).'; -$string['disableblogs'] = 'Disable blog system completely'; $string['donothaveblog'] = 'You do not have your own blog, sorry.'; $string['editentry'] = 'Edit a blog entry'; $string['editexternalblog'] = 'Edit this external blog'; diff --git a/lib/cronlib.php b/lib/cronlib.php index 8535689effe58..7ec99e5c0f07c 100644 --- a/lib/cronlib.php +++ b/lib/cronlib.php @@ -352,7 +352,7 @@ function cron_run() { // Run external blog cron if needed - if ($CFG->useexternalblogs) { + if (!empty($CFG->enableblogs) && $CFG->useexternalblogs) { require_once($CFG->dirroot . '/blog/lib.php'); mtrace("Fetching external blog entries...", ''); $sql = "timefetched < ? OR timefetched = 0"; @@ -364,7 +364,7 @@ function cron_run() { mtrace('done.'); } // Run blog associations cleanup - if ($CFG->useblogassociations) { + if (!empty($CFG->enableblogs) && $CFG->useblogassociations) { require_once($CFG->dirroot . '/blog/lib.php'); // delete entries whose contextids no longer exists mtrace("Deleting blog associations linked to non-existent contexts...", ''); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 726428213b3ad..6079ed35da476 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1081,5 +1081,25 @@ function xmldb_main_upgrade($oldversion) { // Main savepoint reached upgrade_main_savepoint(true, 2012072600.01); } + + if ($oldversion < 2012080600.00) { + // Move the ability to disable blogs to its own setting MDL-25012. + + if (isset($CFG->bloglevel)) { + // Only change settings if existing setting was set. + if (empty($CFG->bloglevel)) { + set_config('enableblogs', 0); + // Now set the bloglevel to a valid setting as the disabled setting has been removed. + // This prevents confusing results when users enable the blog system in future. + set_config('bloglevel', BLOG_USER_LEVEL); + } else { + set_config('enableblogs', 1); + } + } + + // Main savepoint reached + upgrade_main_savepoint(true, 2012080600.00); + } + return true; } diff --git a/lib/filelib.php b/lib/filelib.php index 32df4bceee7f6..366b1593037fa 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -3451,7 +3451,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) { send_file_not_found(); } - if (empty($CFG->bloglevel)) { + if (empty($CFG->enableblogs)) { print_error('siteblogdisable', 'blog'); } diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 0317445fd87af..43dfe9eefb403 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -2296,7 +2296,7 @@ protected function load_for_user($user=null, $forceforcontext=false) { } // Add blog nodes - if (!empty($CFG->bloglevel)) { + if (!empty($CFG->enableblogs)) { if (!$this->cache->cached('userblogoptions'.$user->id)) { require_once($CFG->dirroot.'/blog/lib.php'); // Get all options for the user @@ -2658,7 +2658,7 @@ public function add_front_page_course_essentials(navigation_node $coursenode, st $filterselect = 0; // Blogs - if (!empty($CFG->bloglevel) + if (!empty($CFG->enableblogs) and ($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser()))) and has_capability('moodle/blog:view', context_system::instance())) { $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect)); @@ -4196,7 +4196,7 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr } // Blogs - if ($currentuser && !empty($CFG->bloglevel)) { + if ($currentuser && !empty($CFG->enableblogs)) { $blog = $usersetting->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER, null, 'blogs'); $blog->add(get_string('preferences', 'blog'), new moodle_url('/blog/preferences.php'), navigation_node::TYPE_SETTING); if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', context_system::instance())) { diff --git a/version.php b/version.php index 6f790c025fb2f..cc69f894e03c4 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012080200.01; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012080600.00; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes