r84233 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84232‎ | r84233 | r84234 >
Date:13:03, 18 March 2011
Author:happy-melon
Status:ok (Comments)
Tags:todo 
Comment:
(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.
Modified paths:
  • /trunk/phase3/includes/Preferences.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -1963,11 +1963,13 @@
19641964 *
19651965 * @param $oname String The option to check
19661966 * @param $defaultOverride String A default value returned if the option does not exist
 1967+ * @bool $ignoreHidden = whether to ignore the effects of $wgHiddenPrefs
19671968 * @return String User's current value for the option
19681969 * @see getBoolOption()
19691970 * @see getIntOption()
19701971 */
1971 - function getOption( $oname, $defaultOverride = null ) {
 1972+ function getOption( $oname, $defaultOverride = null, $ignoreHidden = false ) {
 1973+ global $wgHiddenPrefs;
19721974 $this->loadOptions();
19731975
19741976 if ( is_null( $this->mOptions ) ) {
@@ -1977,6 +1979,15 @@
19781980 $this->mOptions = User::getDefaultOptions();
19791981 }
19801982
 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+
19811992 if ( array_key_exists( $oname, $this->mOptions ) ) {
19821993 return $this->mOptions[$oname];
19831994 } else {
@@ -1990,8 +2001,23 @@
19912002 * @return array
19922003 */
19932004 public function getOptions() {
 2005+ global $wgHiddenPrefs;
19942006 $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;
19962022 }
19972023
19982024 /**
Index: trunk/phase3/includes/Preferences.php
@@ -1315,6 +1315,16 @@
13161316 unset( $formData[$b] );
13171317 }
13181318
 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+
13191329 // Keeps old preferences from interfering due to back-compat
13201330 // code, etc.
13211331 $wgUser->resetOptions();

Sign-offs

UserFlagDate
Aaron Schulzinspected22:34, 16 June 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r84235Follow-up r84233: fix documentation formathappy-melon13:23, 18 March 2011

Comments

#Comment by Jack Phoenix (talk | contribs)   13:21, 18 March 2011
+	 * @bool $ignoreHidden = whether to ignore the effects of $wgHiddenPrefs

I think that that should be * @param $ignoreHidden Boolean: whether to ignore the effects of $wgHiddenPrefs instead (as per Manual:Coding conventions#Inline documentation).

#Comment by Aaron Schulz (talk | contribs)   04:39, 7 July 2011

Can you make $ignoreHidden use a const or string param "ignoreHidden". I really don't like opaque Booleans like this.

#Comment by Happy-melon (talk | contribs)   11:00, 3 August 2011

The only nice way to do that is to repurpose the second parameter and refactor $ignoreHidden too, and I really can't see a clean way to do that... :S

#Comment by Aaron Schulz (talk | contribs)   16:31, 3 August 2011

Why would that effect the $defaultOverride parameter?

#Comment by Happy-melon (talk | contribs)   16:33, 4 August 2011

So you want to mix boolean parameters with flags? That's even more unintuitive...

#Comment by Aaron Schulz (talk | contribs)   16:37, 4 August 2011

Not really IMO, it's an improvement at least over the current state.

Marking this "OK" since it's not urgent and we want 1.18 out the door.

Status & tagging log