Skip to content

Commit

Permalink
MDL-25012 - blogs: introduce a specific 'enabled' config setting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danpoltawski committed Aug 6, 2012
1 parent db9d7be commit 850d2db
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 25 deletions.
3 changes: 1 addition & 2 deletions admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 1 addition & 5 deletions admin/settings/subsystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion blocks/blog_menu/block_blog_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/blog_recent/block_blog_recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion blog/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
$id = required_param('entryid', PARAM_INT);
}

if (empty($CFG->bloglevel)) {
if (empty($CFG->enableblogs)) {
print_error('blogdisable', 'blog');
}

Expand Down
2 changes: 1 addition & 1 deletion blog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
$PAGE->set_url('/blog/index.php', $url_params);

if (empty($CFG->bloglevel)) {
if (empty($CFG->enableblogs)) {
print_error('blogdisable', 'blog');
}

Expand Down
7 changes: 3 additions & 4 deletions blog/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)));
}

/**
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion blog/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
$context = context_course::instance($courseid);
}

if (empty($CFG->bloglevel)) {
if (empty($CFG->enableblogs)) {
print_error('blogdisable', 'blog');
}

Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <strong>hotmail.com yahoo.co.uk .live.com</strong>';
$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.';
Expand Down Expand Up @@ -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';
Expand Down
1 change: 0 additions & 1 deletion lang/en/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions lib/cronlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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...", '');
Expand Down
20 changes: 20 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
6 changes: 3 additions & 3 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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())) {
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 850d2db

Please sign in to comment.