Last modified: 2014-03-24 13:46:11 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 62946 - Boolean preferences with default value of true cannot be changed if they do not have a key in $wgDefaultUserOptions
Boolean preferences with default value of true cannot be changed if they do n...
Status: NEW
Product: MediaWiki
Classification: Unclassified
User preferences (Other open bugs)
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
Depends on:
Blocks: documentation
  Show dependency treegraph
Reported: 2014-03-22 01:18 UTC by Tisza Gergő
Modified: 2014-03-24 13:46 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Description Tisza Gergő 2014-03-22 01:18:58 UTC
Steps to reproduce: 
1. in the GetPreferences hook, add a preference with type=toggle and default=true
2. go to Special:Preferences, unset that preference, save.
The preference will not be saved (unless $wgDefaultUserOptions[$preferenceName] is set).

This is caused by the check in User::saveOptions() to only save preferences with non-default values:

	$defaultOption = self::getDefaultOption( $key );
	if ( ( is_null( $defaultOption ) &&
		!( $value === false || is_null( $value ) ) ) ||
		$value != $defaultOption
	) {
		// save

User::getDefaultOptions() returns null if it does not find the key in $wgDefaultUserOptions, and $value will be false, so both parts of the condition fail.

If setting $wgDefaultUserOptions is required when adding a new preference, that should be clearly documented (neither [[mw:Manual:$wgDefaultUserOptions]] nor [[mw:Manual:Hooks/GetPreferences]] gives that impression). Otherwise, the correct logic is IMO something like this:

	$siteDefaultOption = self::getDefaultOption( $key );
	$defaultOption = Preferences::getPreferences( $user, $context)[$key];
	if ( is_null( $siteDefaultOption ) ) {
		$changed = ( $value != $defaultOption );
	} else {
		$changed = ( $value != $siteDefaultOption );
	if ( $changed ) {
		// save

(Except that getPreferences depends on the context which is not available here. Ugh...)

Note You need to log in before you can comment on or make changes to this bug.