User:Austin J. Che/Extensions/PreferencesExtension: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
No edit summary
No edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 7: Line 7:
* name: the name of the preference (the name for the form element)
* name: the name of the preference (the name for the form element)
* section: the name of the section in the preferences dialog. This should be the internal name used not the displayed name (e.g. 'prefs-misc'). To create a new section, simply use a different name. The actual display text will be whatever is returned using wfMsg(section) so you can set the text by adding the appropriate value to the message cache.
* section: the name of the section in the preferences dialog. This should be the internal name used not the displayed name (e.g. 'prefs-misc'). To create a new section, simply use a different name. The actual display text will be whatever is returned using wfMsg(section) so you can set the text by adding the appropriate value to the message cache.
* type: The type of form element being added. The valid types are the constants PREF_USER_T, PREF_TOGGLE_T, PREF_TEXT_T, and PREF_INT_T. The default is PREF_USER_T.  
* type: The type of form element being added. The valid types are the constants PREF_USER_T, PREF_TOGGLE_T, PREF_TEXT_T, PREF_PASSWORD_T, PREF_INT_T, PREF_DROPDOWN_T. The default is PREF_USER_T.  
* size: For type=PREF_TEXT_T and PREF_INT_T, defines the size of the textbox
* size: For type=PREF_TEXT_T, PREF_PASSWORD_T, and PREF_INT_T, defines the size of the textbox
* html: For PREF_USER_T, allows specification of the complete html to be inserted into the preferences form. The string @VALUE@ inside this html will be expanded to the current value of this element
* html: For PREF_USER_T, allows specification of the complete html to be inserted into the preferences form. The string @VALUE@ inside this html will be expanded to the current value of this element.
* caption: Specifies the caption for the label for PREF_INT_T, PREF_TEXT_T, PREF_PASSWORD_T, PREF_DROPDOWN_T. If not given, uses wfMsg(name).
* pos: For PREF_INT_T, PREF_TEXT_T, PREF_PASSWORD_T, PREF_DROPDOWN_T, specifies the position in a table. It can be 'first', 'last', or empty.
* min: Defines the minimum allowed integer value for PREF_INT_T types
* min: Defines the minimum allowed integer value for PREF_INT_T types
* max: Defines the maximum allowed integer value for PREF_INT_T types
* max: Defines the maximum allowed integer value for PREF_INT_T types
* validate: The name of a function. If defined, for PREF_TEXT_T and PREF_USER_T, this function will be called to validate the form value on submission. The function should take one argument (the form value) and return the value that should be used as the submitted value.
* validate: The name of a function. If defined, for PREF_TEXT_T, PREF_PASSWORD_T, and PREF_USER_T, this function will be called to validate the form value on submission. The function should take one argument (the form value) and return the value that should be used as the submitted value.
* save: The name of a function. If defined, this function will be called to set the element's value instead of using the default of setting the value via $wgUser->setOption. The function takes two arguments ($name, $value).
* load: The name of a function. If defined, this function will be called to load an element's value instead of the default using $wgUser->getOption. This function takes one argument $name and should return the value.
* default: The default value to use for this element in displaying the form.
* default: The default value to use for this element in displaying the form.
* onchange: For PREF_DROPDOWN_T, provides an onchange handler
* options: For PREF_DROPDOWN_T, should be an array containing the dropdown options


See the source of [[../UserDefaultPage]] for a simple example of using this extension.
See the source of [[../UserDefaultPage/]] for a simple example of using this extension.


----
==Source==
Send bugs and comments to [[Austin Che]]. Other extensions including  sources can be found at [[../]].
<syntax type="php" file="http://austinche.name/mediawiki/PreferencesExtension.php.txt">http://austinche.name/mediawiki/PreferencesExtension.php.txt</syntax>
 
[[Category:Extensions]]

Latest revision as of 16:57, 10 February 2008

This extension hooks into the default Special:Preferences page and allows other extensions to easily add new preferences.

Usage

A typical usage is in your extension function to call wfAddPreferences with an array of new preferences to be added. Each preference is specified as another associative array. The valid keys for this associative array are (everything is optional):

  • name: the name of the preference (the name for the form element)
  • section: the name of the section in the preferences dialog. This should be the internal name used not the displayed name (e.g. 'prefs-misc'). To create a new section, simply use a different name. The actual display text will be whatever is returned using wfMsg(section) so you can set the text by adding the appropriate value to the message cache.
  • type: The type of form element being added. The valid types are the constants PREF_USER_T, PREF_TOGGLE_T, PREF_TEXT_T, PREF_PASSWORD_T, PREF_INT_T, PREF_DROPDOWN_T. The default is PREF_USER_T.
  • size: For type=PREF_TEXT_T, PREF_PASSWORD_T, and PREF_INT_T, defines the size of the textbox
  • html: For PREF_USER_T, allows specification of the complete html to be inserted into the preferences form. The string @VALUE@ inside this html will be expanded to the current value of this element.
  • caption: Specifies the caption for the label for PREF_INT_T, PREF_TEXT_T, PREF_PASSWORD_T, PREF_DROPDOWN_T. If not given, uses wfMsg(name).
  • pos: For PREF_INT_T, PREF_TEXT_T, PREF_PASSWORD_T, PREF_DROPDOWN_T, specifies the position in a table. It can be 'first', 'last', or empty.
  • min: Defines the minimum allowed integer value for PREF_INT_T types
  • max: Defines the maximum allowed integer value for PREF_INT_T types
  • validate: The name of a function. If defined, for PREF_TEXT_T, PREF_PASSWORD_T, and PREF_USER_T, this function will be called to validate the form value on submission. The function should take one argument (the form value) and return the value that should be used as the submitted value.
  • save: The name of a function. If defined, this function will be called to set the element's value instead of using the default of setting the value via $wgUser->setOption. The function takes two arguments ($name, $value).
  • load: The name of a function. If defined, this function will be called to load an element's value instead of the default using $wgUser->getOption. This function takes one argument $name and should return the value.
  • default: The default value to use for this element in displaying the form.
  • onchange: For PREF_DROPDOWN_T, provides an onchange handler
  • options: For PREF_DROPDOWN_T, should be an array containing the dropdown options

See the source of UserDefaultPage for a simple example of using this extension.

Source

<syntax type="php" file="http://austinche.name/mediawiki/PreferencesExtension.php.txt">http://austinche.name/mediawiki/PreferencesExtension.php.txt</syntax>