22use Wikimedia\ObjectFactory;
46 public static function factory( $providerId =
null ) {
53 if ( !array_key_exists(
$providerId, self::$instances ) ) {
59 $provider->providerId = $providerId;
60 self::$instances[$providerId] = $provider;
83 $centralIdLookup = self::factory();
95 return $centralIdLookup;
102 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
103 throw new MWException( __METHOD__ .
' may only be called from unit tests!' );
105 self::$instances = [];
109 return $this->providerId;
119 if ( $audience instanceof
User ) {
122 if ( $audience === self::AUDIENCE_PUBLIC ) {
125 if ( $audience === self::AUDIENCE_RAW ) {
128 throw new InvalidArgumentException(
'Invalid audience' );
156 array $idToName, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
171 array $nameToId, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
185 $id, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
188 return $idToName[$id];
200 array $ids, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
202 $idToName = array_fill_keys( $ids,
false );
204 $names = array_unique( $names );
205 $names = array_filter( $names,
function ( $name ) {
206 return $name !==
false && $name !==
'';
209 return array_values( $names );
223 $name, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
225 $nameToId = $this->
lookupUserNames( [ $name => 0 ], $audience, $flags );
226 return $nameToId[
$name];
238 array $names, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
240 $nameToId = array_fill_keys( $names,
false );
242 $ids = array_unique( $ids );
243 $ids = array_filter( $ids,
function ( $id ) {
244 return $id !==
false;
247 return array_values( $ids );
262 $id, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
265 if ( $name !==
null && $name !==
'' ) {
267 if ( $user && $user->getId() && $this->isAttached( $user ) ) {
286 User $user, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
string $wgCentralIdLookupProvider
Central ID lookup provider to use by default.
$wgCentralIdLookupProviders
Central ID lookup providers Key is the provider ID, value is a specification for ObjectFactory.
The CentralIdLookup service allows for connecting local users with cluster-wide IDs.
static resetCache()
Reset internal cache for unit testing.
static factory( $providerId=null)
Fetch a CentralIdLookup.
nameFromCentralId( $id, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a central user ID, return the (local) user name.
static factoryNonLocal()
Returns a CentralIdLookup that is guaranteed to be non-local.
isAttached(User $user, $wikiId=null)
Check that a User is attached on the specified wiki.
centralIdFromLocalUser(User $user, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a local User object, return the central ID.
static CentralIdLookup[] $instances
lookupCentralIds(array $idToName, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given central user IDs, return the (local) user names.
centralIdFromName( $name, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a (local) user name, return the central ID.
namesFromCentralIds(array $ids, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a an array of central user IDs, return the (local) user names.
centralIdsFromNames(array $names, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given an array of (local) user names, return the central IDs.
lookupUserNames(array $nameToId, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given (local) user names, return the central IDs.
checkAudience( $audience)
Check that the "audience" parameter is valid.
localUserFromCentralId( $id, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given a central user ID, return a local User object.
A CentralIdLookup provider that just uses local IDs.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Allows to change the fields on the form that will be generated $name
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Interface for database access objects.