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.
| ||||||||||||||||
getOptionBatchForUserNames (array $users, string $key) | ||||||||||||||||
Get a single option for a batch of users, given their names. | ||||||||||||||||
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. | ||||||||||||||||
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. | ||||||||||||||||
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. | ||||||||||||||||
![]() | ||||||||||||||||
__construct (UserNameUtils $userNameUtils) | ||||||||||||||||
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_CREATE = 'create' |
Create a new global preference in the first available global store. | |
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 |
![]() | |
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. | |
Additional Inherited Members | |
![]() | |
getCacheKey (UserIdentity $user) | |
Get a cache key for a user. | |
A service class to control user options.
Definition at line 45 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 118 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 466 of file UserOptionsManager.php.
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 154 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 147 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 161 of file UserOptionsManager.php.
References MediaWiki\MainConfigNames\HiddenPrefs.
MediaWiki\User\Options\UserOptionsManager::getOptionBatchForUserNames | ( | array | $users, |
string | $key ) |
Get a single option for a batch of users, given their names.
Results are uncached. Use getOption() to get options with a per-user cache.
User names are used because that's what GenderCache has. If you're calling this and you're not GenderCache, consider adding a method taking an array of UserIdentity objects instead.
string[] | $users | A normalized list of usernames |
string | $key | The option to get |
Reimplemented from MediaWiki\User\Options\UserOptionsLookup.
Definition at line 228 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 187 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 222 of file UserOptionsManager.php.
References $source.
|
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 606 of file UserOptionsManager.php.
Referenced by MediaWiki\User\Options\LocalUserOptionsStore\store().
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 447 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 337 of file UserOptionsManager.php.
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 321 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 350 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 375 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. The global update behaviour, used if GlobalPreferences is installed:
|
Definition at line 302 of file UserOptionsManager.php.
const MediaWiki\User\Options\UserOptionsManager::CONSTRUCTOR_OPTIONS |
Definition at line 50 of file UserOptionsManager.php.
const MediaWiki\User\Options\UserOptionsManager::GLOBAL_CREATE = 'create' |
Create a new global preference in the first available global store.
If there are no global stores, update the local value. If there was already a global preference, update it.
Definition at line 84 of file UserOptionsManager.php.
const MediaWiki\User\Options\UserOptionsManager::GLOBAL_IGNORE = 'ignore' |
If the option was set globally, ignore the update.
Definition at line 64 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 70 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 76 of file UserOptionsManager.php.
const MediaWiki\User\Options\UserOptionsManager::MAX_BYTES_OPTION_VALUE = 65530 |
Definition at line 58 of file UserOptionsManager.php.
Referenced by MediaWiki\User\Options\LocalUserOptionsStore\store().