From e6e9b7fc9c8391cffca9c7c006bd3336a48a03cf Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Fri, 18 Mar 2011 13:03:26 +0000 Subject: [PATCH] (bug 27403) saved user preferences which are subsequently disabled with $wgHiddenPrefs are not used in output, but are retained in the database in case the preference is subsequently re-enabled. --- includes/Preferences.php | 10 ++++++++++ includes/User.php | 30 ++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/includes/Preferences.php b/includes/Preferences.php index 57dab312b5..37563ddfdf 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -1315,6 +1315,16 @@ class Preferences { unset( $formData[$b] ); } + # If users have saved a value for a preference which has subsequently been disabled + # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference + # is subsequently re-enabled + # TODO: maintenance script to actually delete these + foreach( $wgHiddenPrefs as $pref ){ + # If the user has not set a non-default value here, the default will be returned + # and subsequently discarded + $formData[$pref] = $wgUser->getOption( $pref, null, true ); + } + // Keeps old preferences from interfering due to back-compat // code, etc. $wgUser->resetOptions(); diff --git a/includes/User.php b/includes/User.php index 94fb46262b..8be2b3c42c 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1963,11 +1963,13 @@ class User { * * @param $oname String The option to check * @param $defaultOverride String A default value returned if the option does not exist + * @bool $ignoreHidden = whether to ignore the effects of $wgHiddenPrefs * @return String User's current value for the option * @see getBoolOption() * @see getIntOption() */ - function getOption( $oname, $defaultOverride = null ) { + function getOption( $oname, $defaultOverride = null, $ignoreHidden = false ) { + global $wgHiddenPrefs; $this->loadOptions(); if ( is_null( $this->mOptions ) ) { @@ -1977,6 +1979,15 @@ class User { $this->mOptions = User::getDefaultOptions(); } + # We want 'disabled' preferences to always behave as the default value for + # users, even if they have set the option explicitly in their settings (ie they + # set it, and then it was disabled removing their ability to change it). But + # we don't want to erase the preferences in the database in case the preference + # is re-enabled again. So don't touch $mOptions, just override the returned value + if( in_array( $oname, $wgHiddenPrefs ) && !$ignoreHidden ){ + return self::getDefaultOption( $oname ); + } + if ( array_key_exists( $oname, $this->mOptions ) ) { return $this->mOptions[$oname]; } else { @@ -1990,8 +2001,23 @@ class User { * @return array */ public function getOptions() { + global $wgHiddenPrefs; $this->loadOptions(); - return $this->mOptions; + $options = $this->mOptions; + + # We want 'disabled' preferences to always behave as the default value for + # users, even if they have set the option explicitly in their settings (ie they + # set it, and then it was disabled removing their ability to change it). But + # we don't want to erase the preferences in the database in case the preference + # is re-enabled again. So don't touch $mOptions, just override the returned value + foreach( $wgHiddenPrefs as $pref ){ + $default = self::getDefaultOption( $pref ); + if( $default !== null ){ + $options[$pref] = $default; + } + } + + return $options; } /** -- 2.20.1