MediaWiki master
MediaWiki\User\Options\UserOptionsStore Interface Reference

Get or change options for a given user in a given backend store. More...

Inherited by MediaWiki\User\Options\LocalUserOptionsStore.

Public Member Functions

 fetch (UserIdentity $user, int $recency)
 Fetch all options for a given user from the store.
 
 fetchBatchForUserNames (array $keys, array $userNames)
 Fetch specific options for multiple users from the store.
 
 store (UserIdentity $user, array $updates)
 Process a batch of option updates.
 

Detailed Description

Get or change options for a given user in a given backend store.

Usage

To read or save a user option, use the UserOptionsManager service instead. UserOptionsStore is the backend key-value abstraction used to differentiate between local and global preferences. This interface is considered internal and should only be called by the UserOptionsManager service. Unless you know which backend store an option belongs to, do not call this.

Extension such as GlobalPreferences may implement this interface to create additional backend stores, but extensions should not instantiate or call classes with this interface.

When creating a new implementation, register it via the UserOptionsStoreProviders extension attribute. The UserOptionsManager service will automatically discover and merge values from your backend. When calling UserOptionsManager::setOption or ApiOptions, we automatically write to the appropiate store, based on where a previous value existed, and the global flag.

Launch task: https://phabricator.wikimedia.org/T323076

See also

Default implementation is MediaWiki\User\Options\LocalUserOptionsStore.

For the frontend "Preferences" concept, and for registering and describing which user options can exist, refer to PreferencesFactory, $wgDefaultUserOptions and DefaultPreferencesFactory instead.

Stability: stable
to implement
Since
1.43

Definition at line 42 of file UserOptionsStore.php.

Member Function Documentation

◆ fetch()

MediaWiki\User\Options\UserOptionsStore::fetch ( UserIdentity $user,
int $recency )

Fetch all options for a given user from the store.

Note that OptionsStore does not handle fallback to default. Options are either present or absent.

Parameters
UserIdentity$userA user with a non-zero ID
int$recencya bit field composed of READ_XXX flags
Returns
array<string,string>

Implemented in MediaWiki\User\Options\LocalUserOptionsStore.

◆ fetchBatchForUserNames()

MediaWiki\User\Options\UserOptionsStore::fetchBatchForUserNames ( array $keys,
array $userNames )

Fetch specific options for multiple users from the store.

Return an array indexed first by option key, and second by user name.

Since
1.44
Parameters
array$keys
array$userNames
Returns
array<string,array<string,string>>

Implemented in MediaWiki\User\Options\LocalUserOptionsStore.

◆ store()

MediaWiki\User\Options\UserOptionsStore::store ( UserIdentity $user,
array $updates )

Process a batch of option updates.

The store may assume that fetch() was previously called with a recency sufficient to provide reference values for a differential update. It is the caller's responsibility to manage recency.

Note that OptionsStore does not have a concept of defaults. The store is not required to check whether the value matches the default.

Parameters
UserIdentity$userA user with a non-zero ID
array<string,string|null>$updates A map of option names to new values. If the value is null, the key should be deleted from the store and subsequently not returned from fetch(). Absent keys should be left unchanged.
Returns
bool Whether any change was made

Implemented in MediaWiki\User\Options\LocalUserOptionsStore.


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