There are two places the default value for an extension-specific preference can 
be specified:

        (1) DefaultUserOptions in extension.json

        (2) onGetPreferences (or whatever function hooks GetPreferences) in 
MyExtension.hooks.php

Which is better?

If you do it in both places, and the defaults are in conflict, evidently 
onGetPreferences wins. This can be seen as follows:

In extension.json add

        "DefaultUserOptions": { 
                "BeSilly": false
        }

In onGetPreferences add

                $preferences['BeSilly'] = array(
                        'type' => 'toggle',
                        'label' => 'Be silly',
                        'section' => "$sillySection",
                        'default' => true
                );

The result is that the checkbox is checked by default. If you omit the default 
from extension.json and include it only in onGetPreferences, the result is the 
same.

It seems that using onGetPreferences is preferable, since the default can be 
combined there (encapsulated) with the other information about the preference, 
while putting the default in DefaultUserOptions separates it from the related 
information, a dependency to be avoided unless there’s some advantage I’m 
missing. Putting it in both places is at best redundant.

However, the documentation in 
https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences appears to recommend 
$wgDefaultUserOptions or DefaultUserOptions. While it shows one example of 
specifying 'default' in onGetPreferences, it also shows an example in which 
'default' is not specified in onGetPreferences. So what’s best? I don’t want to 
use onGetPreferences for the default if a future version of MediaWiki is going 
to turn that into a mistake. Also, does DefaultUserOptions serve any purpose, 
if onGetPreferences accomplishes the same thing better?

Thanks in advance for any advice or clarification.

Tom

Wenlin Institute, Inc. SPC (a Social Purpose Corporation)
文林研究所社会目的公司
Software for Learning Chinese
E-mail: [email protected]     Web: http://www.wenlin.com
Telephone: 1-877-4-WENLIN (1-877-493-6546)
☯


_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to