"Hooks"
:
{
"GetPreferences"
:
[
"MediaWiki\\Extension\\ExampleExtension\\Hooks::onGetPreferences"
]
}
namespace
MediaWiki\Extension\ExampleExtension
;
class
Hooks
{
/**
* @param User $user
* @param array $preferences
*/
public
static
function
onGetPreferences
(
$user
,
&
$preferences
)
{
// A checkbox
$preferences
[
'mypref'
]
=
[
'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'
]
=
[
'type'
=>
'radio'
,
'label-message'
=>
'tog-mypref2'
,
// a system message
'section'
=>
'personal/info'
,
// Array of options. Key = text to display. Value = HTML <option> value.
'options'
=>
[
'Pick me please'
=>
'choice1'
,
'No, pick me!'
=>
'choice2'
,
'Seriously, pick me right now'
=>
'choice3'
,
],
'default'
=>
'choice1'
,
// A 'default' key is required!
'help-message'
=>
'tog-help-mypref2'
,
// a system message (optional)
];
}
}