MediaWiki REL1_37
|
A service class to control user options. More...
Public Member Functions | ||||||||||||||||
__construct (ServiceOptions $options, DefaultOptionsLookup $defaultOptionsLookup, LanguageConverterFactory $languageConverterFactory, ILoadBalancer $loadBalancer, LoggerInterface $logger, HookContainer $hookContainer) | ||||||||||||||||
clearUserOptionsCache (UserIdentity $user) | ||||||||||||||||
Clears cached user options. | ||||||||||||||||
getDefaultOptions () | ||||||||||||||||
Combine the language default options with any site-specific options and add the default language variants.
| ||||||||||||||||
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.
| ||||||||||||||||
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.
| ||||||||||||||||
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. | ||||||||||||||||
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 |
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) | |
Private Member Functions | |
canUseCachedValues (UserIdentity $user, int $queryFlags) | |
Determines if it's ok to use cached options values for a given user and query flags. | |
getCacheKey (UserIdentity $user) | |
Gets a key for various caches. | |
getDBAndOptionsForQueryFlags ( $queryFlags) | |
isValueEqual ( $a, $b) | |
Determines whether two values are sufficiently similar that the database does not need to be updated to reflect the change. | |
loadOptionsFromDb (UserIdentity $user, int $queryFlags, array $prefetchedOptions=null) | |
Fetches the options directly from the database with no caches. | |
loadOriginalOptions (UserIdentity $user, int $queryFlags=self::READ_NORMAL, array $data=null) | |
Loads the original user options from the database and applies various transforms, like timecorrection. | |
setOptionsFromDb (UserIdentity $user, int $queryFlags, iterable $rows) | |
Builds associative options array from rows fetched from DB. | |
Private Attributes | |
DefaultOptionsLookup | $defaultOptionsLookup |
HookRunner | $hookRunner |
LanguageConverterFactory | $languageConverterFactory |
ILoadBalancer | $loadBalancer |
LoggerInterface | $logger |
array | $modifiedOptions = [] |
options modified withing this request | |
array | $optionsFromDb = [] |
Cached original user options as fetched from database, no adjustments applied. | |
array | $originalOptionsCache = [] |
Cached original user options with all the adjustments like time correction and hook changes applied. | |
array | $queryFlagsUsedForCaching = [] |
Query flags used to retrieve options from database. | |
ServiceOptions | $serviceOptions |
A service class to control user options.
Definition at line 43 of file UserOptionsManager.php.
MediaWiki\User\UserOptionsManager::__construct | ( | ServiceOptions | $options, |
DefaultOptionsLookup | $defaultOptionsLookup, | ||
LanguageConverterFactory | $languageConverterFactory, | ||
ILoadBalancer | $loadBalancer, | ||
LoggerInterface | $logger, | ||
HookContainer | $hookContainer | ||
) |
ServiceOptions | $options | |
DefaultOptionsLookup | $defaultOptionsLookup | |
LanguageConverterFactory | $languageConverterFactory | |
ILoadBalancer | $loadBalancer | |
LoggerInterface | $logger | |
HookContainer | $hookContainer |
Definition at line 98 of file UserOptionsManager.php.
References MediaWiki\User\UserOptionsManager\$defaultOptionsLookup, MediaWiki\User\UserOptionsManager\$languageConverterFactory, MediaWiki\User\UserOptionsManager\$loadBalancer, MediaWiki\User\UserOptionsManager\$logger, and MediaWiki\Config\ServiceOptions\assertRequiredOptions().
|
private |
Determines if it's ok to use cached options values for a given user and query flags.
UserIdentity | $user | |
int | $queryFlags |
Definition at line 663 of file UserOptionsManager.php.
MediaWiki\User\UserOptionsManager::clearUserOptionsCache | ( | UserIdentity | $user | ) |
Clears cached user options.
UserIdentity | $user |
Definition at line 503 of file UserOptionsManager.php.
|
private |
Gets a key for various caches.
UserIdentity | $user |
Definition at line 644 of file UserOptionsManager.php.
|
private |
int | $queryFlags | a bit field composed of READ_XXX flags |
Definition at line 652 of file UserOptionsManager.php.
MediaWiki\User\UserOptionsManager::getDefaultOptions | ( | ) |
Combine the language default options with any site-specific options and add the default language variants.
Reimplemented from MediaWiki\User\UserOptionsLookup.
Definition at line 118 of file UserOptionsManager.php.
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.
UserIdentity | $user | The user to get the option for |
string | $oname | The option to check |
mixed | null | $defaultOverride | A default value returned if the option does not exist |
bool | $ignoreHidden | Whether to ignore the effects of $wgHiddenPrefs |
int | $queryFlags | A bit field composed of READ_XXX flags |
Reimplemented from MediaWiki\User\UserOptionsLookup.
Definition at line 125 of file UserOptionsManager.php.
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.
UserIdentity | $userIdentity | |
IContextSource | $context | |
array | null | $options | Assoc. array with options keys to check as keys. Defaults user options. |
Definition at line 295 of file UserOptionsManager.php.
MediaWiki\User\UserOptionsManager::getOptions | ( | UserIdentity | $user, |
int | $flags = 0 , |
||
int | $queryFlags = self::READ_NORMAL |
||
) |
Get all user's options.
UserIdentity | $user | The user to get the option for |
int | $flags | Bitwise combination of: UserOptionsManager::EXCLUDE_DEFAULTS Exclude user options that are set to the default value. |
int | $queryFlags | A bit field composed of READ_XXX flags |
Reimplemented from MediaWiki\User\UserOptionsLookup.
Definition at line 151 of file UserOptionsManager.php.
|
private |
Determines whether two values are sufficiently similar that the database does not need to be updated to reflect the change.
This is basically the same as comparing the result of Database::addQuotes().
mixed | $a | |
mixed | $b |
Definition at line 683 of file UserOptionsManager.php.
MediaWiki\User\UserOptionsManager::listOptionKinds | ( | ) |
Return a list of the types of user options currently returned by UserOptionsManager::getOptionKinds().
Currently, the option kinds are:
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.
Definition at line 271 of file UserOptionsManager.php.
|
private |
Fetches the options directly from the database with no caches.
UserIdentity | $user | |
int | $queryFlags | |
array | null | $prefetchedOptions |
Definition at line 519 of file UserOptionsManager.php.
References $dbr, $res, and MediaWiki\User\UserIdentity\getId().
|
private |
Loads the original user options from the database and applies various transforms, like timecorrection.
Runs hooks.
UserIdentity | $user | |
int | $queryFlags | |
array | null | $data | associative array of non-default options |
Definition at line 586 of file UserOptionsManager.php.
MediaWiki\User\UserOptionsManager::loadUserOptions | ( | UserIdentity | $user, |
int | $queryFlags = self::READ_NORMAL , |
||
array | $data = null |
||
) |
Loads user options either from cache or from the database.
UserIdentity | $user | |
int | $queryFlags | |
array | null | $data | associative array of non-default options. |
Definition at line 488 of file UserOptionsManager.php.
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.
UserIdentity | $user | |
IContextSource | $context | Context source used when $resetKinds does not contain 'all'. |
array | string | $resetKinds | Which kinds of preferences to reset. Defaults to [ 'registered', 'registered-multiselect', 'registered-checkmatrix', 'unused' ] |
Definition at line 208 of file UserOptionsManager.php.
References User\newFromIdentity().
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. Usually used via saveSettings().
UserIdentity | $user |
Definition at line 381 of file UserOptionsManager.php.
References DB_PRIMARY, MediaWiki\User\UserIdentity\getId(), MediaWiki\User\UserIdentity\isRegistered(), and User\newFromIdentity().
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.
UserIdentity | $user | |
string | $oname | The option to set |
mixed | $val | New value to set |
Definition at line 186 of file UserOptionsManager.php.
|
private |
Builds associative options array from rows fetched from DB.
UserIdentity | $user | |
int | $queryFlags | |
iterable<object|array> | $rows |
Definition at line 554 of file UserOptionsManager.php.
|
private |
Definition at line 57 of file UserOptionsManager.php.
Referenced by MediaWiki\User\UserOptionsManager\__construct().
|
private |
Definition at line 85 of file UserOptionsManager.php.
|
private |
Definition at line 60 of file UserOptionsManager.php.
Referenced by MediaWiki\User\UserOptionsManager\__construct().
|
private |
Definition at line 63 of file UserOptionsManager.php.
Referenced by MediaWiki\User\UserOptionsManager\__construct().
|
private |
Definition at line 66 of file UserOptionsManager.php.
Referenced by MediaWiki\User\UserOptionsManager\__construct().
|
private |
options modified withing this request
Definition at line 69 of file UserOptionsManager.php.
|
private |
Cached original user options as fetched from database, no adjustments applied.
Definition at line 82 of file UserOptionsManager.php.
|
private |
Cached original user options with all the adjustments like time correction and hook changes applied.
Ready to be returned.
Definition at line 76 of file UserOptionsManager.php.
|
private |
Query flags used to retrieve options from database.
Definition at line 88 of file UserOptionsManager.php.
|
private |
Definition at line 54 of file UserOptionsManager.php.
const MediaWiki\User\UserOptionsManager::CONSTRUCTOR_OPTIONS |
Definition at line 48 of file UserOptionsManager.php.