Index: trunk/phase3/includes/User.php |
— | — | @@ -1963,11 +1963,13 @@ |
1964 | 1964 | * |
1965 | 1965 | * @param $oname String The option to check |
1966 | 1966 | * @param $defaultOverride String A default value returned if the option does not exist |
| 1967 | + * @bool $ignoreHidden = whether to ignore the effects of $wgHiddenPrefs |
1967 | 1968 | * @return String User's current value for the option |
1968 | 1969 | * @see getBoolOption() |
1969 | 1970 | * @see getIntOption() |
1970 | 1971 | */ |
1971 | | - function getOption( $oname, $defaultOverride = null ) { |
| 1972 | + function getOption( $oname, $defaultOverride = null, $ignoreHidden = false ) { |
| 1973 | + global $wgHiddenPrefs; |
1972 | 1974 | $this->loadOptions(); |
1973 | 1975 | |
1974 | 1976 | if ( is_null( $this->mOptions ) ) { |
— | — | @@ -1977,6 +1979,15 @@ |
1978 | 1980 | $this->mOptions = User::getDefaultOptions(); |
1979 | 1981 | } |
1980 | 1982 | |
| 1983 | + # We want 'disabled' preferences to always behave as the default value for |
| 1984 | + # users, even if they have set the option explicitly in their settings (ie they |
| 1985 | + # set it, and then it was disabled removing their ability to change it). But |
| 1986 | + # we don't want to erase the preferences in the database in case the preference |
| 1987 | + # is re-enabled again. So don't touch $mOptions, just override the returned value |
| 1988 | + if( in_array( $oname, $wgHiddenPrefs ) && !$ignoreHidden ){ |
| 1989 | + return self::getDefaultOption( $oname ); |
| 1990 | + } |
| 1991 | + |
1981 | 1992 | if ( array_key_exists( $oname, $this->mOptions ) ) { |
1982 | 1993 | return $this->mOptions[$oname]; |
1983 | 1994 | } else { |
— | — | @@ -1990,8 +2001,23 @@ |
1991 | 2002 | * @return array |
1992 | 2003 | */ |
1993 | 2004 | public function getOptions() { |
| 2005 | + global $wgHiddenPrefs; |
1994 | 2006 | $this->loadOptions(); |
1995 | | - return $this->mOptions; |
| 2007 | + $options = $this->mOptions; |
| 2008 | + |
| 2009 | + # We want 'disabled' preferences to always behave as the default value for |
| 2010 | + # users, even if they have set the option explicitly in their settings (ie they |
| 2011 | + # set it, and then it was disabled removing their ability to change it). But |
| 2012 | + # we don't want to erase the preferences in the database in case the preference |
| 2013 | + # is re-enabled again. So don't touch $mOptions, just override the returned value |
| 2014 | + foreach( $wgHiddenPrefs as $pref ){ |
| 2015 | + $default = self::getDefaultOption( $pref ); |
| 2016 | + if( $default !== null ){ |
| 2017 | + $options[$pref] = $default; |
| 2018 | + } |
| 2019 | + } |
| 2020 | + |
| 2021 | + return $options; |
1996 | 2022 | } |
1997 | 2023 | |
1998 | 2024 | /** |
Index: trunk/phase3/includes/Preferences.php |
— | — | @@ -1315,6 +1315,16 @@ |
1316 | 1316 | unset( $formData[$b] ); |
1317 | 1317 | } |
1318 | 1318 | |
| 1319 | + # If users have saved a value for a preference which has subsequently been disabled |
| 1320 | + # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference |
| 1321 | + # is subsequently re-enabled |
| 1322 | + # TODO: maintenance script to actually delete these |
| 1323 | + foreach( $wgHiddenPrefs as $pref ){ |
| 1324 | + # If the user has not set a non-default value here, the default will be returned |
| 1325 | + # and subsequently discarded |
| 1326 | + $formData[$pref] = $wgUser->getOption( $pref, null, true ); |
| 1327 | + } |
| 1328 | + |
1319 | 1329 | // Keeps old preferences from interfering due to back-compat |
1320 | 1330 | // code, etc. |
1321 | 1331 | $wgUser->resetOptions(); |