(bug 27403) saved user preferences which are subsequently disabled with $wgHiddenPref...
authorHappy-melon <happy-melon@users.mediawiki.org>
Fri, 18 Mar 2011 13:03:26 +0000 (13:03 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Fri, 18 Mar 2011 13:03:26 +0000 (13:03 +0000)
includes/Preferences.php
includes/User.php

index 57dab31..37563dd 100644 (file)
@@ -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();
index 94fb462..8be2b3c 100644 (file)
@@ -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;
        }
 
        /**