MediaWiki master
|
A service class to control user options. More...
Inherits MediaWiki\User\Options\UserOptionsLookup.
Public Member Functions | ||||||||||||||||
__construct (ServiceOptions $options, DefaultOptionsLookup $defaultOptionsLookup, LanguageConverterFactory $languageConverterFactory, IConnectionProvider $dbProvider, LoggerInterface $logger, HookContainer $hookContainer, UserFactory $userFactory, UserNameUtils $userNameUtils) | ||||||||||||||||
clearUserOptionsCache (UserIdentity $user) | ||||||||||||||||
Clears cached user options. | ||||||||||||||||
getDefaultOption (string $opt, ?UserIdentity $userIdentity=null) | ||||||||||||||||
Get a given default option value.
| ||||||||||||||||
getDefaultOptions (?UserIdentity $userIdentity=null) | ||||||||||||||||
Combine the language default options with any site-specific and user-specific defaults and add the default language variants.
| ||||||||||||||||
getOption (UserIdentity $user, string $oname, $defaultOverride=null, bool $ignoreHidden=false, int $queryFlags=IDBAccessObject::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=IDBAccessObject::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=IDBAccessObject::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\Options\UserOptionsLookup | ||||||||||||||||
getBoolOption (UserIdentity $user, string $oname, int $queryFlags=IDBAccessObject::READ_NORMAL) | ||||||||||||||||
Get the user's current setting for a given option, as a boolean value. | ||||||||||||||||
getIntOption (UserIdentity $user, string $oname, int $defaultOverride=0, int $queryFlags=IDBAccessObject::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\Options\UserOptionsLookup | |
const | EXCLUDE_DEFAULTS = 1 |
Exclude user options that are set to their default value. | |
A service class to control user options.
Definition at line 50 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::__construct | ( | ServiceOptions | $options, |
DefaultOptionsLookup | $defaultOptionsLookup, | ||
LanguageConverterFactory | $languageConverterFactory, | ||
IConnectionProvider | $dbProvider, | ||
LoggerInterface | $logger, | ||
HookContainer | $hookContainer, | ||
UserFactory | $userFactory, | ||
UserNameUtils | $userNameUtils ) |
ServiceOptions | $options | |
DefaultOptionsLookup | $defaultOptionsLookup | |
LanguageConverterFactory | $languageConverterFactory | |
IConnectionProvider | $dbProvider | |
LoggerInterface | $logger | |
HookContainer | $hookContainer | |
UserFactory | $userFactory | |
UserNameUtils | $userNameUtils |
Definition at line 105 of file UserOptionsManager.php.
References MediaWiki\Config\ServiceOptions\assertRequiredOptions().
MediaWiki\User\Options\UserOptionsManager::clearUserOptionsCache | ( | UserIdentity | $user | ) |
Clears cached user options.
UserIdentity | $user |
Definition at line 541 of file UserOptionsManager.php.
References getCacheKey().
MediaWiki\User\Options\UserOptionsManager::getDefaultOption | ( | string | $opt, |
?UserIdentity | $userIdentity = null ) |
Get a given default option value.
string | $opt | Name of option to retrieve |
UserIdentity | null | $userIdentity | User to look the defaults up for; set to null to ignore any user-specific defaults (since 1.42) |
Reimplemented from MediaWiki\User\Options\UserOptionsLookup.
Definition at line 136 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::getDefaultOptions | ( | ?UserIdentity | $userIdentity = null | ) |
Combine the language default options with any site-specific and user-specific defaults and add the default language variants.
UserIdentity | null | $userIdentity | User to look the default up for; set to null to ignore any user-specific defaults (since 1.42) |
Reimplemented from MediaWiki\User\Options\UserOptionsLookup.
Definition at line 129 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::getOption | ( | UserIdentity | $user, |
string | $oname, | ||
$defaultOverride = null, | |||
bool | $ignoreHidden = false, | ||
int | $queryFlags = IDBAccessObject::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\Options\UserOptionsLookup.
Definition at line 143 of file UserOptionsManager.php.
References MediaWiki\MainConfigNames\HiddenPrefs.
MediaWiki\User\Options\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 333 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::getOptions | ( | UserIdentity | $user, |
int | $flags = 0, | ||
int | $queryFlags = IDBAccessObject::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. Options that are set to their conditionally default value are not excluded. |
int | $queryFlags | A bit field composed of READ_XXX flags |
Reimplemented from MediaWiki\User\Options\UserOptionsLookup.
Definition at line 169 of file UserOptionsManager.php.
MediaWiki\User\Options\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 309 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::loadUserOptions | ( | UserIdentity | $user, |
int | $queryFlags = IDBAccessObject::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 526 of file UserOptionsManager.php.
MediaWiki\User\Options\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 252 of file UserOptionsManager.php.
References getCacheKey().
MediaWiki\User\Options\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.
UserIdentity | $user |
Definition at line 419 of file UserOptionsManager.php.
MediaWiki\User\Options\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.
UserIdentity | $user | |
IDatabase | $dbw |
Definition at line 445 of file UserOptionsManager.php.
MediaWiki\User\Options\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.
$val should be null or a string. Other types are accepted for B/C with legacy code but can result in surprising behavior and are discouraged. Values are always stored as strings in the database, so if you pass a non-string value, it will be eventually converted; but before the call to saveOptions(), getOption() will return the passed value from instance cache without any type conversion.
A null value means resetting the option to its default value (removing the user_properties row). Passing in the same value as the default value fo the user has the same result. This behavior supports some level of type juggling - e.g. if the default value is 1, and you pass in '1', the option will be reset to its default value.
When an option is reset to its default value, that means whenever the default value is changed in the site configuration, the user preference for this user will also change. There is no way to set a user preference to be the same as the default but avoid it changing when the default changes. You can instead use $wgConditionalUserOptions to split the default based on user registration date.
UserIdentity | $user | |
string | $oname | The option to set |
mixed | $val | New value to set. |
Definition at line 230 of file UserOptionsManager.php.
References getCacheKey().
const MediaWiki\User\Options\UserOptionsManager::CONSTRUCTOR_OPTIONS |
Definition at line 55 of file UserOptionsManager.php.
const MediaWiki\User\Options\UserOptionsManager::MAX_BYTES_OPTION_VALUE = 65530 |
Definition at line 63 of file UserOptionsManager.php.