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

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T64946, the corresponding Phabricator task for complete and up-to-date bug report information.
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.