https://bugzilla.wikimedia.org/show_bug.cgi?id=62946

            Bug ID: 62946
           Summary: Boolean preferences with default value of true cannot
                    be changed if they do not have a key in
                    $wgDefaultUserOptions
           Product: MediaWiki
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: Unprioritized
         Component: User preferences
          Assignee: wikibugs-l@lists.wikimedia.org
          Reporter: gti...@wikimedia.org
                CC: agarr...@wikimedia.org
       Web browser: ---
   Mobile Platform: ---

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...)

-- 
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
Wikibugs-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to