MediaWiki REL1_32
CentralIdLookup Class Reference

The CentralIdLookup service allows for connecting local users with cluster-wide IDs. More...

Inheritance diagram for CentralIdLookup:
Collaboration diagram for CentralIdLookup:

Public Member Functions

 centralIdFromLocalUser (User $user, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
 Given a local User object, return the central ID.
 
 centralIdFromName ( $name, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
 Given a (local) user name, return the central ID.
 
 centralIdsFromNames (array $names, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
 Given an array of (local) user names, return the central IDs.
 
 getProviderId ()
 
 isAttached (User $user, $wikiId=null)
 Check that a User is attached on the specified wiki.
 
 localUserFromCentralId ( $id, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
 Given a central user ID, return a local User object.
 
 lookupCentralIds (array $idToName, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
 Given central user IDs, return the (local) user names.
 
 lookupUserNames (array $nameToId, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
 Given (local) user names, return the central IDs.
 
 nameFromCentralId ( $id, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
 Given a central user ID, return the (local) user name.
 
 namesFromCentralIds (array $ids, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
 Given a an array of central user IDs, return the (local) user names.
 

Static Public Member Functions

static factory ( $providerId=null)
 Fetch a CentralIdLookup.
 
static resetCache ()
 Reset internal cache for unit testing.
 

Public Attributes

const AUDIENCE_PUBLIC = 1
 
const AUDIENCE_RAW = 2
 
- Public Attributes inherited from IDBAccessObject
const READ_LOCKING = self::READ_LATEST | 2
 Constants for object loading bitfield flags (higher => higher QoS)
 
const READ_NONE = -1
 

Protected Member Functions

 checkAudience ( $audience)
 Check that the "audience" parameter is valid.
 

Private Attributes

string $providerId
 

Static Private Attributes

static CentralIdLookup[] $instances = []
 

Detailed Description

The CentralIdLookup service allows for connecting local users with cluster-wide IDs.

Since
1.27

Definition at line 30 of file CentralIdLookup.php.

Member Function Documentation

◆ centralIdFromLocalUser()

CentralIdLookup::centralIdFromLocalUser ( User $user,
$audience = self::AUDIENCE_PUBLIC,
$flags = self::READ_NORMAL )

Given a local User object, return the central ID.

Note
Unlike centralIdFromName(), this does guarantee that the local user is attached to the central account.
Parameters
User$userLocal user
int | User$audienceOne of the audience constants, or a specific user
int$flagsIDBAccessObject read flags
Returns
int User ID; 0 if the local user does not correspond to a central user, $audience lacks the rights needed to see it, or the central user isn't locally attached.

Definition at line 256 of file CentralIdLookup.php.

References centralIdFromName(), and isAttached().

◆ centralIdFromName()

CentralIdLookup::centralIdFromName ( $name,
$audience = self::AUDIENCE_PUBLIC,
$flags = self::READ_NORMAL )

Given a (local) user name, return the central ID.

Note
There's no requirement that the user name actually exists locally, or if it does that it's actually attached to the central account.
Parameters
string$nameCanonicalized user name
int | User$audienceOne of the audience constants, or a specific user
int$flagsIDBAccessObject read flags
Returns
int User ID; 0 if the name does not correspond to a user or $audience lacks the rights needed to see it.

Definition at line 193 of file CentralIdLookup.php.

References $name, and lookupUserNames().

Referenced by centralIdFromLocalUser().

◆ centralIdsFromNames()

CentralIdLookup::centralIdsFromNames ( array $names,
$audience = self::AUDIENCE_PUBLIC,
$flags = self::READ_NORMAL )

Given an array of (local) user names, return the central IDs.

Parameters
string[]$namesCanonicalized user names
int | User$audienceOne of the audience constants, or a specific user
int$flagsIDBAccessObject read flags
Returns
int[] User IDs
Since
1.30

Definition at line 208 of file CentralIdLookup.php.

References lookupUserNames().

◆ checkAudience()

CentralIdLookup::checkAudience ( $audience)
protected

Check that the "audience" parameter is valid.

Parameters
int | User$audienceOne of the audience constants, or a specific user
Returns
User|null User to check against, or null if no checks are needed
Exceptions
InvalidArgumentException

Definition at line 89 of file CentralIdLookup.php.

Referenced by LocalIdLookup\lookupCentralIds(), and LocalIdLookup\lookupUserNames().

◆ factory()

static CentralIdLookup::factory ( $providerId = null)
static

Fetch a CentralIdLookup.

Parameters
string | null$providerIdProvider ID from $wgCentralIdLookupProviders
Returns
CentralIdLookup|null

Definition at line 46 of file CentralIdLookup.php.

References $wgCentralIdLookupProvider, and $wgCentralIdLookupProviders.

Referenced by MediaWiki\Preferences\MultiUsernameFilter\getLookup().

◆ getProviderId()

CentralIdLookup::getProviderId ( )
final

Definition at line 79 of file CentralIdLookup.php.

◆ isAttached()

CentralIdLookup::isAttached ( User $user,
$wikiId = null )
abstract

Check that a User is attached on the specified wiki.

If unattached local accounts don't exist in your extension, this comes down to a check whether the central account exists at all and that $wikiId is using the same central database.

Parameters
User$user
string | null$wikiIdWiki to check attachment status. If null, check the current wiki.
Returns
bool

Reimplemented in LocalIdLookup.

Referenced by centralIdFromLocalUser().

◆ localUserFromCentralId()

CentralIdLookup::localUserFromCentralId ( $id,
$audience = self::AUDIENCE_PUBLIC,
$flags = self::READ_NORMAL )

Given a central user ID, return a local User object.

Note
Unlike nameFromCentralId(), this does guarantee that the local user exists and is attached to the central account.
Parameters
int$idCentral user ID
int | User$audienceOne of the audience constants, or a specific user
int$flagsIDBAccessObject read flags
Returns
User|null Local user, or null if: $id doesn't correspond to a user, $audience lacks the rights needed to see the user, the user doesn't exist locally, or the user isn't locally attached.

Definition at line 232 of file CentralIdLookup.php.

References $user, nameFromCentralId(), and User\newFromName().

◆ lookupCentralIds()

CentralIdLookup::lookupCentralIds ( array $idToName,
$audience = self::AUDIENCE_PUBLIC,
$flags = self::READ_NORMAL )
abstract

Given central user IDs, return the (local) user names.

Note
There's no requirement that the user names actually exist locally, or if they do that they're actually attached to the central account.
Parameters
array$idToNameArray with keys being central user IDs
int | User$audienceOne of the audience constants, or a specific user
int$flagsIDBAccessObject read flags
Returns
array Copy of $idToName with values set to user names (or empty-string if the user exists but $audience lacks the rights needed to see it). IDs not corresponding to a user are unchanged.

Reimplemented in LocalIdLookup.

Referenced by nameFromCentralId(), and namesFromCentralIds().

◆ lookupUserNames()

CentralIdLookup::lookupUserNames ( array $nameToId,
$audience = self::AUDIENCE_PUBLIC,
$flags = self::READ_NORMAL )
abstract

Given (local) user names, return the central IDs.

Note
There's no requirement that the user names actually exist locally, or if they do that they're actually attached to the central account.
Parameters
array$nameToIdArray with keys being canonicalized user names
int | User$audienceOne of the audience constants, or a specific user
int$flagsIDBAccessObject read flags
Returns
array Copy of $nameToId with values set to central IDs. Names not corresponding to a user (or $audience lacks the rights needed to see it) are unchanged.

Reimplemented in LocalIdLookup.

Referenced by centralIdFromName(), and centralIdsFromNames().

◆ nameFromCentralId()

CentralIdLookup::nameFromCentralId ( $id,
$audience = self::AUDIENCE_PUBLIC,
$flags = self::READ_NORMAL )

Given a central user ID, return the (local) user name.

Note
There's no requirement that the user name actually exists locally, or if it does that it's actually attached to the central account.
Parameters
int$idCentral user ID
int | User$audienceOne of the audience constants, or a specific user
int$flagsIDBAccessObject read flags
Returns
string|null User name, or empty string if $audience lacks the rights needed to see it, or null if $id doesn't correspond to a user

Definition at line 155 of file CentralIdLookup.php.

References lookupCentralIds().

Referenced by localUserFromCentralId().

◆ namesFromCentralIds()

CentralIdLookup::namesFromCentralIds ( array $ids,
$audience = self::AUDIENCE_PUBLIC,
$flags = self::READ_NORMAL )

Given a an array of central user IDs, return the (local) user names.

Parameters
int[]$idsCentral user IDs
int | User$audienceOne of the audience constants, or a specific user
int$flagsIDBAccessObject read flags
Returns
string[] User names
Since
1.30

Definition at line 170 of file CentralIdLookup.php.

References lookupCentralIds().

◆ resetCache()

static CentralIdLookup::resetCache ( )
static

Reset internal cache for unit testing.

Definition at line 72 of file CentralIdLookup.php.

Member Data Documentation

◆ $instances

CentralIdLookup [] CentralIdLookup::$instances = []
staticprivate

Definition at line 36 of file CentralIdLookup.php.

◆ $providerId

string CentralIdLookup::$providerId
private

Definition at line 39 of file CentralIdLookup.php.

◆ AUDIENCE_PUBLIC

const CentralIdLookup::AUDIENCE_PUBLIC = 1

Definition at line 32 of file CentralIdLookup.php.

◆ AUDIENCE_RAW

const CentralIdLookup::AUDIENCE_RAW = 2

Definition at line 33 of file CentralIdLookup.php.


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