Extension:PreferencesExtension

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

Installation
Copy code to extensions/PreferencesExtension/PreferencesExtension.php and add this to LocalSettings.php:

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

Parameters

 * 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, and PREF_INT_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
 * 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.

Examples
To speed up implementation, there are some examples of usages of this extension.

Code
" ;                       break;                    case PREF_USER_T:                    default:                        $addhtml = preg_replace("/@VALUE@/", $value, isset($p['html']) ? $p['html'] : "");                        break;                }                // the section exists                $html = preg_replace($regex, "$1 $addhtml $2", $html);            }            $wgOut->addHTML($html);            // debugging            //$wgOut->addHTML($wgUser->encodeOptions);        }    }    global $wgRequest;    $prefs = new SpecialPreferencesExtension($wgRequest);    $prefs->execute; }