MediaWiki REL1_39
MediaWiki\User\UserOptionsManager Class Reference

A service class to control user options. More...

Inheritance diagram for MediaWiki\User\UserOptionsManager:
Collaboration diagram for MediaWiki\User\UserOptionsManager:

Public Member Functions

 __construct (ServiceOptions $options, DefaultOptionsLookup $defaultOptionsLookup, LanguageConverterFactory $languageConverterFactory, ILoadBalancer $loadBalancer, LoggerInterface $logger, HookContainer $hookContainer, UserFactory $userFactory, Language $contentLanguage)
 
 clearUserOptionsCache (UserIdentity $user)
 Clears cached user options.
 
 getDefaultOptions ()
 Combine the language default options with any site-specific options and add the default language variants.
Returns
array

 
 getOption (UserIdentity $user, string $oname, $defaultOverride=null, bool $ignoreHidden=false, int $queryFlags=self::READ_NORMAL)
 Get the user's current setting for a given option.
Parameters
UserIdentity$userThe user to get the option for
string$onameThe option to check
mixed | null$defaultOverrideA default value returned if the option does not exist
bool$ignoreHiddenWhether to ignore the effects of $wgHiddenPrefs
int$queryFlagsA bit field composed of READ_XXX flags
Returns
mixed|null User's current value for the option
See also
getBoolOption()
getIntOption()

 
 getOptionKinds (UserIdentity $userIdentity, IContextSource $context, $options=null)
 Return an associative array mapping preferences keys to the kind of a preference they're used for.
 
 getOptions (UserIdentity $user, int $flags=0, int $queryFlags=self::READ_NORMAL)
 Get all user's options.
Parameters
UserIdentity$userThe user to get the option for
int$flagsBitwise combination of: UserOptionsManager::EXCLUDE_DEFAULTS Exclude user options that are set to the default value.
int$queryFlagsA bit field composed of READ_XXX flags
Returns
array

 
 listOptionKinds ()
 Return a list of the types of user options currently returned by UserOptionsManager::getOptionKinds().
 
 loadUserOptions (UserIdentity $user, int $queryFlags=self::READ_NORMAL, array $data=null)
 Loads user options either from cache or from the database.
 
 resetOptions (UserIdentity $user, IContextSource $context, $resetKinds=[ 'registered', 'registered-multiselect', 'registered-checkmatrix', 'unused'])
 Reset certain (or all) options to the site defaults.
 
 saveOptions (UserIdentity $user)
 Saves the non-default options for this user, as previously set e.g.
 
 saveOptionsInternal (UserIdentity $user, IDatabase $dbw)
 Saves the non-default options for this user, as previously set e.g.
 
 setOption (UserIdentity $user, string $oname, $val)
 Set the given option for a user.
 
- Public Member Functions inherited from MediaWiki\User\UserOptionsLookup
 getBoolOption (UserIdentity $user, string $oname, int $queryFlags=self::READ_NORMAL)
 Get the user's current setting for a given option, as a boolean value.
 
 getDefaultOption (string $opt)
 Get a given default option value.
 
 getIntOption (UserIdentity $user, string $oname, int $defaultOverride=0, int $queryFlags=self::READ_NORMAL)
 Get the user's current setting for a given option, as an integer value.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 
const MAX_BYTES_OPTION_VALUE = 65530
 
- Public Attributes inherited from MediaWiki\User\UserOptionsLookup
const EXCLUDE_DEFAULTS = 1
 Exclude user options that are set to their default value.
 
- Public Attributes inherited from IDBAccessObject
const READ_NONE = -1
 Constants for object loading bitfield flags (higher => higher QoS)
 

Detailed Description

A service class to control user options.

Since
1.35

Definition at line 45 of file UserOptionsManager.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\UserOptionsManager::__construct ( ServiceOptions $options,
DefaultOptionsLookup $defaultOptionsLookup,
LanguageConverterFactory $languageConverterFactory,
ILoadBalancer $loadBalancer,
LoggerInterface $logger,
HookContainer $hookContainer,
UserFactory $userFactory,
Language $contentLanguage )
Parameters
ServiceOptions$options
DefaultOptionsLookup$defaultOptionsLookup
LanguageConverterFactory$languageConverterFactory
ILoadBalancer$loadBalancer
LoggerInterface$logger
HookContainer$hookContainer
UserFactory$userFactory
Language$contentLanguage

Definition at line 113 of file UserOptionsManager.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions().

Member Function Documentation

◆ clearUserOptionsCache()

MediaWiki\User\UserOptionsManager::clearUserOptionsCache ( UserIdentity $user)

Clears cached user options.

Access: internal
To be used by User::clearInstanceCache
Parameters
UserIdentity$user

Definition at line 519 of file UserOptionsManager.php.

◆ getDefaultOptions()

MediaWiki\User\UserOptionsManager::getDefaultOptions ( )

Combine the language default options with any site-specific options and add the default language variants.

Returns
array

Reimplemented from MediaWiki\User\UserOptionsLookup.

Definition at line 137 of file UserOptionsManager.php.

◆ getOption()

MediaWiki\User\UserOptionsManager::getOption ( UserIdentity $user,
string $oname,
$defaultOverride = null,
bool $ignoreHidden = false,
int $queryFlags = self::READ_NORMAL )

Get the user's current setting for a given option.

Parameters
UserIdentity$userThe user to get the option for
string$onameThe option to check
mixed | null$defaultOverrideA default value returned if the option does not exist
bool$ignoreHiddenWhether to ignore the effects of $wgHiddenPrefs
int$queryFlagsA bit field composed of READ_XXX flags
Returns
mixed|null User's current value for the option
See also
getBoolOption()
getIntOption()

Reimplemented from MediaWiki\User\UserOptionsLookup.

Definition at line 144 of file UserOptionsManager.php.

References MediaWiki\MainConfigNames\HiddenPrefs.

◆ getOptionKinds()

MediaWiki\User\UserOptionsManager::getOptionKinds ( UserIdentity $userIdentity,
IContextSource $context,
$options = null )

Return an associative array mapping preferences keys to the kind of a preference they're used for.

Different kinds are handled differently when setting or reading preferences.

See UserOptionsManager::listOptionKinds for the list of valid option types that can be provided.

See also
UserOptionsManager::listOptionKinds
Parameters
UserIdentity$userIdentity
IContextSource$context
array | null$optionsAssoc. array with options keys to check as keys. Defaults user options.
Returns
string[] The key => kind mapping data

Definition at line 315 of file UserOptionsManager.php.

◆ getOptions()

MediaWiki\User\UserOptionsManager::getOptions ( UserIdentity $user,
int $flags = 0,
int $queryFlags = self::READ_NORMAL )

Get all user's options.

Parameters
UserIdentity$userThe user to get the option for
int$flagsBitwise combination of: UserOptionsManager::EXCLUDE_DEFAULTS Exclude user options that are set to the default value.
int$queryFlagsA bit field composed of READ_XXX flags
Returns
array

Reimplemented from MediaWiki\User\UserOptionsLookup.

Definition at line 170 of file UserOptionsManager.php.

◆ listOptionKinds()

MediaWiki\User\UserOptionsManager::listOptionKinds ( )

Return a list of the types of user options currently returned by UserOptionsManager::getOptionKinds().

Currently, the option kinds are:

  • 'registered' - preferences which are registered in core MediaWiki or by extensions using the UserGetDefaultOptions hook.
  • 'registered-multiselect' - as above, using the 'multiselect' type.
  • 'registered-checkmatrix' - as above, using the 'checkmatrix' type.
  • 'userjs' - preferences with names starting with 'userjs-', intended to be used by user scripts.
  • 'special' - "preferences" that are not accessible via UserOptionsLookup::getOptions or UserOptionsManager::setOptions.
  • 'unused' - preferences about which MediaWiki doesn't know anything. These are usually legacy options, removed in newer versions.

The API (and possibly others) use this function to determine the possible option types for validation purposes, so make sure to update this when a new option kind is added.

See also
getOptionKinds
Returns
string[] Option kinds

Definition at line 291 of file UserOptionsManager.php.

◆ loadUserOptions()

MediaWiki\User\UserOptionsManager::loadUserOptions ( UserIdentity $user,
int $queryFlags = self::READ_NORMAL,
array $data = null )

Loads user options either from cache or from the database.

Note
Query flags are ignored for anons, since they do not have any options stored in the database. If the UserIdentity was itself obtained from a replica and doesn't have ID set due to replication lag, it will be treated as anon regardless of the query flags passed here.
Parameters
UserIdentity$user
int$queryFlags
array | null$dataassociative array of non-default options.
Returns
array
Access: internal
To be called by User loading code to provide the $data

Definition at line 504 of file UserOptionsManager.php.

◆ resetOptions()

MediaWiki\User\UserOptionsManager::resetOptions ( UserIdentity $user,
IContextSource $context,
$resetKinds = [ 'registered', 'registered-multiselect', 'registered-checkmatrix', 'unused' ] )

Reset certain (or all) options to the site defaults.

The optional parameter determines which kinds of preferences will be reset. Supported values are everything that can be reported by getOptionKinds() and 'all', which forces a reset of all preferences and overrides everything else.

Note
You need to call saveOptions() to actually write to the database.
Parameters
UserIdentity$user
IContextSource$contextContext source used when $resetKinds does not contain 'all'.
array | string$resetKindsWhich kinds of preferences to reset. Defaults to [ 'registered', 'registered-multiselect', 'registered-checkmatrix', 'unused' ]

Definition at line 234 of file UserOptionsManager.php.

◆ saveOptions()

MediaWiki\User\UserOptionsManager::saveOptions ( UserIdentity $user)

Saves the non-default options for this user, as previously set e.g.

via setOption(), in the database's "user_properties" (preferences) table.

Since
1.38, this method was internal before that.
Parameters
UserIdentity$user

Definition at line 401 of file UserOptionsManager.php.

References DB_PRIMARY.

◆ saveOptionsInternal()

MediaWiki\User\UserOptionsManager::saveOptionsInternal ( UserIdentity $user,
IDatabase $dbw )

Saves the non-default options for this user, as previously set e.g.

via setOption(), in the database's "user_properties" (preferences) table.

Parameters
UserIdentity$user
IDatabase$dbw
Returns
bool true if options were changed and new options successfully saved.
Access: internal
only public for use in User::saveSettings

Definition at line 427 of file UserOptionsManager.php.

◆ setOption()

MediaWiki\User\UserOptionsManager::setOption ( UserIdentity $user,
string $oname,
$val )

Set the given option for a user.

You need to call saveOptions() to actually write to the database.

Parameters
UserIdentity$user
string$onameThe option to set
mixed$valNew value to set

Definition at line 212 of file UserOptionsManager.php.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\User\UserOptionsManager::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const HiddenPrefs
Name constant for the HiddenPrefs setting, for use with Config::get()
const LocalTZoffset
Name constant for the LocalTZoffset setting, for use with Config::get()
Access: internal
For use by ServiceWiring

Definition at line 50 of file UserOptionsManager.php.

◆ MAX_BYTES_OPTION_VALUE

const MediaWiki\User\UserOptionsManager::MAX_BYTES_OPTION_VALUE = 65530
Since
1.39.5, 1.40

Definition at line 58 of file UserOptionsManager.php.


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