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, ObjectFactory $objectFactory, array $storeProviders) | ||||||||||||||||
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) | ||||||||||||||||
getOptions (UserIdentity $user, int $flags=0, int $queryFlags=IDBAccessObject::READ_NORMAL) | ||||||||||||||||
Get all user's options.
| ||||||||||||||||
isOptionGlobal (UserIdentity $user, string $key) | ||||||||||||||||
Determine if a user option came from a source other than the local store or the defaults. | ||||||||||||||||
listOptionKinds () | ||||||||||||||||
loadUserOptions (UserIdentity $user, int $queryFlags=IDBAccessObject::READ_NORMAL) | ||||||||||||||||
Loads user options either from cache or from the database. | ||||||||||||||||
resetAllOptions (UserIdentity $user) | ||||||||||||||||
Reset all options that were set to a non-default value by the given user. | ||||||||||||||||
resetOptions (UserIdentity $user, IContextSource $context, $resetKinds=[ 'registered', 'registered-multiselect', 'registered-checkmatrix', 'unused']) | ||||||||||||||||
Reset certain (or all) options to the site defaults. | ||||||||||||||||
resetOptionsByName (UserIdentity $user, array $optionNames) | ||||||||||||||||
Reset a list of options to the site defaults. | ||||||||||||||||
saveOptions (UserIdentity $user) | ||||||||||||||||
Saves the non-default options for this user, as previously set e.g. | ||||||||||||||||
saveOptionsInternal (UserIdentity $user) | ||||||||||||||||
Saves the non-default options for this user, as previously set e.g. | ||||||||||||||||
setOption (UserIdentity $user, string $oname, $val, $global=self::GLOBAL_IGNORE) | ||||||||||||||||
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. | ||||||||||||||||
Static Public Member Functions | |
static | isValueEqual ( $a, $b) |
Determines whether two values are sufficiently similar that the database does not need to be updated to reflect the change. | |
Public Attributes | |
const | CONSTRUCTOR_OPTIONS |
const | GLOBAL_IGNORE = 'ignore' |
If the option was set globally, ignore the update. | |
const | GLOBAL_OVERRIDE = 'override' |
If the option was set globally, add a local override. | |
const | GLOBAL_UPDATE = 'update' |
If the option was set globally, update the global value. | |
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. | |
const | LOCAL_EXCEPTION_SUFFIX = '-local-exception' |
The suffix appended to preference names for the associated preference that tracks whether they have a local override. | |
A service class to control user options.
Definition at line 46 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, | ||
ObjectFactory | $objectFactory, | ||
array | $storeProviders ) |
ServiceOptions | $options | |
DefaultOptionsLookup | $defaultOptionsLookup | |
LanguageConverterFactory | $languageConverterFactory | |
IConnectionProvider | $dbProvider | |
LoggerInterface | $logger | |
HookContainer | $hookContainer | |
UserFactory | $userFactory | |
UserNameUtils | $userNameUtils | |
ObjectFactory | $objectFactory | |
array | $storeProviders |
Definition at line 111 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 474 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 146 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 139 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 153 of file UserOptionsManager.php.
References MediaWiki\MainConfigNames\HiddenPrefs.
MediaWiki\User\Options\UserOptionsManager::getOptionKinds | ( | UserIdentity | $userIdentity, |
IContextSource | $context, | ||
$options = null ) |
UserIdentity | $userIdentity | |
IContextSource | $context | |
array | null | $options |
Definition at line 345 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 179 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::isOptionGlobal | ( | UserIdentity | $user, |
string | $key ) |
Determine if a user option came from a source other than the local store or the defaults.
If this is true, setting the option will be ignored unless GLOBAL_OVERRIDE or GLOBAL_UPDATE is passed to setOption().
UserIdentity | $user | |
string | $key |
Reimplemented from MediaWiki\User\Options\UserOptionsLookup.
Definition at line 214 of file UserOptionsManager.php.
References $source, and getCacheKey().
|
static |
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 632 of file UserOptionsManager.php.
Referenced by MediaWiki\User\Options\LocalUserOptionsStore\store().
MediaWiki\User\Options\UserOptionsManager::listOptionKinds | ( | ) |
Definition at line 331 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::loadUserOptions | ( | UserIdentity | $user, |
int | $queryFlags = IDBAccessObject::READ_NORMAL ) |
Loads user options either from cache or from the database.
UserIdentity | $user | |
int | $queryFlags |
Definition at line 455 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::resetAllOptions | ( | UserIdentity | $user | ) |
Reset all options that were set to a non-default value by the given user.
UserIdentity | $user |
Definition at line 320 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 284 of file UserOptionsManager.php.
References wfDeprecated().
MediaWiki\User\Options\UserOptionsManager::resetOptionsByName | ( | UserIdentity | $user, |
array | $optionNames ) |
Reset a list of options to the site defaults.
UserIdentity | $user | |
string[] | $optionNames |
Definition at line 304 of file UserOptionsManager.php.
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 363 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::saveOptionsInternal | ( | 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 388 of file UserOptionsManager.php.
MediaWiki\User\Options\UserOptionsManager::setOption | ( | UserIdentity | $user, |
string | $oname, | ||
$val, | |||
$global = self::GLOBAL_IGNORE ) |
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.
If a global user option exists with the given name, the behaviour depends on the value of $global.
UserIdentity | $user | |
string | $oname | The option to set |
mixed | $val | New value to set. |
string | $global | Since 1.43. What to do if the option was set globally using the GlobalPreferences extension. One of the self::GLOBAL_* constants:
|
Definition at line 257 of file UserOptionsManager.php.
References getCacheKey().
const MediaWiki\User\Options\UserOptionsManager::CONSTRUCTOR_OPTIONS |
Definition at line 51 of file UserOptionsManager.php.
const MediaWiki\User\Options\UserOptionsManager::GLOBAL_IGNORE = 'ignore' |
If the option was set globally, ignore the update.
Definition at line 65 of file UserOptionsManager.php.
const MediaWiki\User\Options\UserOptionsManager::GLOBAL_OVERRIDE = 'override' |
If the option was set globally, add a local override.
Definition at line 71 of file UserOptionsManager.php.
const MediaWiki\User\Options\UserOptionsManager::GLOBAL_UPDATE = 'update' |
If the option was set globally, update the global value.
Definition at line 77 of file UserOptionsManager.php.
const MediaWiki\User\Options\UserOptionsManager::MAX_BYTES_OPTION_VALUE = 65530 |
Definition at line 59 of file UserOptionsManager.php.
Referenced by MediaWiki\User\Options\LocalUserOptionsStore\store().