Manual:Hooks/GetPreferences
From MediaWiki.org
| GetPreferences | |
|---|---|
| Available from version 1.16.0 Modify user preferences. |
|
*Define function: |
function fnMyHook( User $user, array &$preferences ) { ... }
|
*Attach hook: |
$wgHooks['GetPreferences'][] = 'MyExtensionHooks::someExample'; |
| Called from: | Preferences.php |
*For more information about attaching hooks, see Manual:Hooks.
*For examples of extensions using this hook, see Category:GetPreferences extensions.
Contents |
[edit] Details
- $user: User whose preferences are being modified.
- &$preferences: Preferences description array, to be fed to an HTMLForm object
[edit] Example
$wgHooks['GetPreferences'][] = 'wfPrefHook'; function wfPrefHook( $user, &$preferences ) { // A checkbox $preferences['mypref'] = array( 'type' => 'toggle', 'label-message' => 'tog-mypref', // a system message 'section' => 'personal/info', ); // A set of radio buttons. Notice that in the 'options' array, // the keys are the text (not system messages), and the values are the HTML values. // They keys/values might be the opposite of what you expect. PHP's array_flip() // can be helpful here. $preferences['mypref2'] = array( 'type' => 'radio', 'label-message' => 'tog-mypref2', // a system message 'section' => 'personal/info', // Array of options. Key = text to display. Value = HTML <option> value. 'options' => array( 'Pick me please' => 'choice1', 'No, pick me!' => 'choice2', 'Seriously, pick me right now' => 'choice3', ), 'default' => 'choice1', // A 'default' key is required! ); // Required return value of a hook function. return true; }
[edit] Tabs and sections
The section array key specifies which tab and section of My preferences contains your preferences. If your section value is foo/bar, this means your preference will appear on the foo tab (named by system message prefs-foo) within the bar section (named by system message prefs-bar). If no such tab or section exists, it is created automatically.
[edit] Supported types
The type can take on various values found in class HTMLForm in the file includes/HTMLForm.php.