Go to the documentation of this file.
22 use Wikimedia\ObjectFactory;
53 if ( !array_key_exists(
$providerId, self::$instances ) ) {
95 return $centralIdLookup;
103 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
104 throw new MWException( __METHOD__ .
' may only be called from unit tests!' );
106 self::$instances = [];
120 if ( $audience instanceof
User ) {
123 if ( $audience === self::AUDIENCE_PUBLIC ) {
126 if ( $audience === self::AUDIENCE_RAW ) {
129 throw new InvalidArgumentException(
'Invalid audience' );
157 array $idToName, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
172 array $nameToId, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
186 $id, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
189 return $idToName[$id];
201 array $ids, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
203 $idToName = array_fill_keys( $ids,
false );
205 $names = array_unique( $names );
206 $names = array_filter( $names,
function ( $name ) {
207 return $name !==
false && $name !==
'';
210 return array_values( $names );
224 $name, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
226 $nameToId = $this->
lookupUserNames( [ $name => 0 ], $audience, $flags );
227 return $nameToId[$name];
239 array $names, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
241 $nameToId = array_fill_keys( $names,
false );
243 $ids = array_unique( $ids );
244 $ids = array_filter( $ids,
function ( $id ) {
245 return $id !==
false;
248 return array_values( $ids );
263 $id, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
266 if ( $name !==
null && $name !==
'' ) {
268 if ( $user && $user->getId() && $this->isAttached( $user ) ) {
287 User $user, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
namesFromCentralIds(array $ids, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a an array of central user IDs, return the (local) user names.
centralIdFromLocalUser(User $user, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a local User object, return the central ID.
nameFromCentralId( $id, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a central user ID, return the (local) user name.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Interface for database access objects.
string $wgCentralIdLookupProvider
Central ID lookup provider to use by default.
centralIdsFromNames(array $names, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given an array of (local) user names, return the central IDs.
A CentralIdLookup provider that just uses local IDs.
static resetCache()
Reset internal cache for unit testing.
lookupCentralIds(array $idToName, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given central user IDs, return the (local) user names.
static CentralIdLookup[] $instances
$wgCentralIdLookupProviders
Central ID lookup providers Key is the provider ID, value is a specification for ObjectFactory.
centralIdFromName( $name, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a (local) user name, return the central ID.
lookupUserNames(array $nameToId, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given (local) user names, return the central IDs.
The CentralIdLookup service allows for connecting local users with cluster-wide IDs.
isAttached(User $user, $wikiId=null)
Check that a User is attached on the specified wiki.
checkAudience( $audience)
Check that the "audience" parameter is valid.
static factory( $providerId=null)
Fetch a CentralIdLookup.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getName()
Get the user name, or the IP of an anonymous user.
static factoryNonLocal()
Returns a CentralIdLookup that is guaranteed to be non-local.
localUserFromCentralId( $id, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a central user ID, return a local User object.