MediaWiki  1.29.1
Preferences Class Reference

We're now using the HTMLForm object with some customisation to generate the Preferences form. More...

Static Public Member Functions

static cleanSignature ( $signature, $alldata, $form)
 
static datetimePreferences ( $user, IContextSource $context, &$defaultPreferences)
 
static editingPreferences ( $user, IContextSource $context, &$defaultPreferences)
 
static filesPreferences ( $user, IContextSource $context, &$defaultPreferences)
 
static filterIntval ( $value, $alldata)
 
static filterTimezoneInput ( $tz, $alldata)
 
static generateSkinOptions ( $user, IContextSource $context)
 
static getDateOptions (IContextSource $context)
 
static getFormObject ( $user, IContextSource $context, $formClass='PreferencesForm', array $remove=[])
 
static getImageSizes (IContextSource $context)
 
static getOptionFromUser ( $name, $info, $user)
 Pull option from a user account. More...
 
static getPreferences ( $user, IContextSource $context)
 
static getSaveBlacklist ()
 
static getThumbSizes (IContextSource $context)
 
static getTimeZoneList (Language $language)
 Get a list of all time zones. More...
 
static getTimezoneOptions (IContextSource $context)
 
static loadPreferenceValues ( $user, $context, &$defaultPreferences)
 Loads existing values for a given array of preferences. More...
 
static miscPreferences ( $user, IContextSource $context, &$defaultPreferences)
 Dummy, kept for backwards-compatibility. More...
 
static profilePreferences ( $user, IContextSource $context, &$defaultPreferences)
 
static rcPreferences ( $user, IContextSource $context, &$defaultPreferences)
 
static renderingPreferences ( $user, IContextSource $context, &$defaultPreferences)
 
static searchPreferences ( $user, IContextSource $context, &$defaultPreferences)
 
static skinPreferences ( $user, IContextSource $context, &$defaultPreferences)
 
static tryFormSubmit ( $formData, $form)
 Handle the form submission if everything validated properly. More...
 
static tryUISubmit ( $formData, $form)
 
static validateSignature ( $signature, $alldata, $form)
 
static watchlistPreferences ( $user, IContextSource $context, &$defaultPreferences)
 

Static Protected Attributes

static array $defaultPreferences = null
 
static array $saveFilters
 

Static Private Attributes

static $saveBlacklist
 

Detailed Description

We're now using the HTMLForm object with some customisation to generate the Preferences form.

This object handles generic submission, CSRF protection, layout and other logic in a reusable manner. We subclass it as a PreferencesForm to make some minor customisations.

In order to generate the form, the HTMLForm object needs an array structure detailing the form fields available, and that's what this class is for. Each element of the array is a basic property-list, including the type of field, the label it is to be given in the form, callbacks for validation and 'filtering', and other pertinent information. Note that the 'default' field is named for generic forms, and does not represent the preference's default (which is stored in $wgDefaultUserOptions), but the default for the form field, which should be whatever the user has set for that preference. There is no need to override it unless you have some special storage logic (for instance, those not presently stored as options, but which are best set from the user preferences view).

Field types are implemented as subclasses of the generic HTMLFormField object, and typically implement at least getInputHTML, which generates the HTML for the input field to be placed in the table.

Once fields have been retrieved and validated, submission logic is handed over to the tryUISubmit static method of this class.

Definition at line 51 of file Preferences.php.

Member Function Documentation

◆ cleanSignature()

static Preferences::cleanSignature (   $signature,
  $alldata,
  $form 
)
static
Parameters
string$signature
array$alldata
HTMLForm$form
Returns
string

Definition at line 1291 of file Preferences.php.

References $wgParser, and global.

◆ datetimePreferences()

static Preferences::datetimePreferences (   $user,
IContextSource  $context,
$defaultPreferences 
)
static

◆ editingPreferences()

static Preferences::editingPreferences (   $user,
IContextSource  $context,
$defaultPreferences 
)
static
Parameters
User$user
IContextSource$context
array$defaultPreferences

Definition at line 816 of file Preferences.php.

References $context, $defaultPreferences, $user, ContextSource\getConfig(), and ContextSource\msg().

Referenced by getPreferences().

◆ filesPreferences()

static Preferences::filesPreferences (   $user,
IContextSource  $context,
$defaultPreferences 
)
static
Parameters
User$user
IContextSource$context
array$defaultPreferences

Definition at line 655 of file Preferences.php.

References $context, $defaultPreferences, getImageSizes(), and getThumbSizes().

Referenced by getPreferences().

◆ filterIntval()

static Preferences::filterIntval (   $value,
  $alldata 
)
static
Parameters
string$value
array$alldata
Returns
int

Definition at line 1395 of file Preferences.php.

References $value.

◆ filterTimezoneInput()

static Preferences::filterTimezoneInput (   $tz,
  $alldata 
)
static
Parameters
string$tz
array$alldata
Returns
string

Definition at line 1404 of file Preferences.php.

References $e, and captcha-old\count.

◆ generateSkinOptions()

static Preferences::generateSkinOptions (   $user,
IContextSource  $context 
)
static
Parameters
User$userThe User object
IContextSource$context
Returns
array Text/links to display as key; $skinkey as value

Definition at line 1126 of file Preferences.php.

References $context, $linkRenderer, $ret, $user, as, Skin\getAllowedSkins(), ContextSource\getConfig(), ContextSource\getLanguage(), Title\makeTitleSafe(), ContextSource\msg(), Title\newMainPage(), and NS_USER.

Referenced by skinPreferences().

◆ getDateOptions()

static Preferences::getDateOptions ( IContextSource  $context)
static
Parameters
IContextSource$context
Returns
array

Definition at line 1196 of file Preferences.php.

References $context, $lang, $ret, $wgDefaultUserOptions, as, ContextSource\getLanguage(), global, ContextSource\msg(), and wfTimestampNow().

Referenced by datetimePreferences().

◆ getFormObject()

static Preferences::getFormObject (   $user,
IContextSource  $context,
  $formClass = 'PreferencesForm',
array  $remove = [] 
)
static
Parameters
User$user
IContextSource$context
string$formClass
array$removeArray of items to remove
Returns
PreferencesForm|HtmlForm

Definition at line 1310 of file Preferences.php.

References $context, $name, $user, as, captcha-old\count, getPreferences(), and ContextSource\msg().

Referenced by SpecialPreferences\execute().

◆ getImageSizes()

static Preferences::getImageSizes ( IContextSource  $context)
static
Parameters
IContextSource$context
Returns
array

Definition at line 1230 of file Preferences.php.

References $context, $ret, as, ContextSource\getConfig(), and ContextSource\msg().

Referenced by filesPreferences().

◆ getOptionFromUser()

static Preferences::getOptionFromUser (   $name,
  $info,
  $user 
)
static

Pull option from a user account.

Handles stuff like array-type preferences.

Parameters
string$name
array$info
User$user
Returns
array|string

Definition at line 165 of file Preferences.php.

References $name, $options, $user, $value, as, and HTMLFormField\flattenOptions().

Referenced by loadPreferenceValues().

◆ getPreferences()

◆ getSaveBlacklist()

static Preferences::getSaveBlacklist ( )
static
Returns
array

Definition at line 72 of file Preferences.php.

References $saveBlacklist.

Referenced by User\getOptionKinds().

◆ getThumbSizes()

static Preferences::getThumbSizes ( IContextSource  $context)
static
Parameters
IContextSource$context
Returns
array

Definition at line 1247 of file Preferences.php.

References $context, $ret, as, ContextSource\getConfig(), and ContextSource\msg().

Referenced by filesPreferences().

◆ getTimeZoneList()

static Preferences::getTimeZoneList ( Language  $language)
static

Get a list of all time zones.

Parameters
Language$languageLanguage used for the localized names
Returns
array A list of all time zones. The system name of the time zone is used as key and the value is an array which contains localized name, the timecorrection value used for preferences and the region
Since
1.26

Definition at line 1551 of file Preferences.php.

References $value, as, captcha-old\count, and wfMessage().

Referenced by getTimezoneOptions().

◆ getTimezoneOptions()

static Preferences::getTimezoneOptions ( IContextSource  $context)
static

◆ loadPreferenceValues()

static Preferences::loadPreferenceValues (   $user,
  $context,
$defaultPreferences 
)
static

Loads existing values for a given array of preferences.

Exceptions
MWException
Parameters
User$user
IContextSource$context
array$defaultPreferencesArray to load values for
Returns
array|null

Definition at line 115 of file Preferences.php.

References $context, $defaultPreferences, $name, $user, as, ContextSource\getConfig(), User\getDefaultOptions(), getOptionFromUser(), and HTMLForm\loadInputFromParameters().

Referenced by getPreferences().

◆ miscPreferences()

static Preferences::miscPreferences (   $user,
IContextSource  $context,
$defaultPreferences 
)
static

Dummy, kept for backwards-compatibility.

Definition at line 1118 of file Preferences.php.

Referenced by getPreferences().

◆ profilePreferences()

◆ rcPreferences()

static Preferences::rcPreferences (   $user,
IContextSource  $context,
$defaultPreferences 
)
static
Parameters
User$user
IContextSource$context
array$defaultPreferences

Definition at line 889 of file Preferences.php.

References $context, $defaultPreferences, $user, ContextSource\getConfig(), and ContextSource\msg().

Referenced by getPreferences().

◆ renderingPreferences()

static Preferences::renderingPreferences (   $user,
IContextSource  $context,
$defaultPreferences 
)
static
Parameters
User$user
IContextSource$context
array$defaultPreferences

Definition at line 754 of file Preferences.php.

References $context, $defaultPreferences, $value, as, ContextSource\getConfig(), and ContextSource\msg().

Referenced by getPreferences().

◆ searchPreferences()

static Preferences::searchPreferences (   $user,
IContextSource  $context,
$defaultPreferences 
)
static
Parameters
User$user
IContextSource$context
array$defaultPreferences

Definition at line 1107 of file Preferences.php.

References $defaultPreferences, as, and MWNamespace\getValidNamespaces().

Referenced by getPreferences().

◆ skinPreferences()

static Preferences::skinPreferences (   $user,
IContextSource  $context,
$defaultPreferences 
)
static
Parameters
User$user
IContextSource$context
array$defaultPreferences
Returns
void

Definition at line 605 of file Preferences.php.

References $context, $defaultPreferences, $linkRenderer, $user, generateSkinOptions(), ContextSource\getConfig(), ContextSource\getLanguage(), Title\makeTitleSafe(), ContextSource\msg(), and NS_USER.

Referenced by getPreferences().

◆ tryFormSubmit()

static Preferences::tryFormSubmit (   $formData,
  $form 
)
static

Handle the form submission if everything validated properly.

Parameters
array$formData
PreferencesForm$form
Returns
bool|Status|string

Definition at line 1456 of file Preferences.php.

References $name, $user, $value, as, MediaWiki\Auth\AuthManager\callLegacyAuthPlugin(), StatusValue\newFatal(), and Hooks\run().

Referenced by tryUISubmit().

◆ tryUISubmit()

static Preferences::tryUISubmit (   $formData,
  $form 
)
static

◆ validateSignature()

static Preferences::validateSignature (   $signature,
  $alldata,
  $form 
)
static
Parameters
string$signature
array$alldata
HTMLForm$form
Returns
bool|string

Definition at line 1265 of file Preferences.php.

References $wgParser, Xml\element(), false, and global.

◆ watchlistPreferences()

static Preferences::watchlistPreferences (   $user,
IContextSource  $context,
$defaultPreferences 
)
static

Member Data Documentation

◆ $defaultPreferences

◆ $saveBlacklist

Preferences::$saveBlacklist
staticprivate
Initial value:
= [
'realname',
'emailaddress',
]

Definition at line 64 of file Preferences.php.

Referenced by getSaveBlacklist().

◆ $saveFilters

array Preferences::$saveFilters
staticprotected
Initial value:
= [
'timecorrection' => [ 'Preferences', 'filterTimezoneInput' ],
'rclimit' => [ 'Preferences', 'filterIntval' ],
'wllimit' => [ 'Preferences', 'filterIntval' ],
'searchlimit' => [ 'Preferences', 'filterIntval' ],
]

Definition at line 56 of file Preferences.php.


The documentation for this class was generated from the following file: