Bug ID: 62946
           Summary: Boolean preferences with default value of true cannot
                    be changed if they do not have a key in
           Product: MediaWiki
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: Unprioritized
         Component: User preferences
       Web browser: ---
   Mobile Platform: ---

Steps to reproduce: 
1. in the GetPreferences hook, add a preference with type=toggle and
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

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.

You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.
Wikibugs-l mailing list

Reply via email to