MediaWiki master
MediaWiki\User\CentralId\CentralIdLookup Class Reference

Find central user IDs associated with local user IDs, e.g. More...

Inherited by MediaWiki\User\CentralId\LocalIdLookup.

Public Member Functions

 centralIdFromLocalUser (UserIdentity $user, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL)
 Given a local UserIdentity object, return the central ID.
 
 centralIdFromName ( $name, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL)
 Given a (local) user name, return the central ID.
 
 centralIdsFromNames (array $names, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL)
 Given an array of (local) user names, return the central IDs.
 
 getProviderId ()
 
 init (string $providerId, UserIdentityLookup $userIdentityLookup, UserFactory $userFactory)
 Initialize the provider.
 
 isAttached (UserIdentity $user, $wikiId=UserIdentity::LOCAL)
 Check that a user is attached on the specified wiki.
 
 isOwned (UserIdentity $user, $wikiId=UserIdentity::LOCAL)
 Check that a username is owned by the central user on the specified wiki.
 
 localUserFromCentralId ( $id, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL)
 Given a central user ID, return a local user object.
 
 lookupAttachedUserNames (array $nameToId, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL, $wikiId=UserIdentity::LOCAL)
 Given user names on the wiki specified by $wikiId, return the central IDs, but only include IDs for local users attached to the central user, i.e.
 
 lookupCentralIds (array $idToName, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL)
 Given central user IDs, return the (local) user names.
 
 lookupOwnedUserNames (array $nameToId, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL, $wikiId=UserIdentity::LOCAL)
 Given user names on the wiki specified by $wikiId, return the central IDs, but only include IDs for local users owned by the central user, i.e.
 
 lookupUserNames (array $nameToId, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL)
 Given (local) user names, return the central IDs.
 
 nameFromCentralId ( $id, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL)
 Given a central user ID, return the (local) user name.
 
 namesFromCentralIds (array $ids, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::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.
 

Public Attributes

const AUDIENCE_PUBLIC = 1
 
const AUDIENCE_RAW = 2
 
const FILTER_ATTACHED = 'attached'
 
const FILTER_NONE = 'none'
 
const FILTER_OWNED = 'owned'
 

Protected Member Functions

 checkAudience ( $audience)
 Check that the "audience" parameter is valid.
 
 lookupUserNamesWithFilter (array $nameToId, $filter, $audience=self::AUDIENCE_PUBLIC, $flags=IDBAccessObject::READ_NORMAL, $wikiId=UserIdentity::LOCAL)
 Given user names on the wiki specified by $wikiId, return the central IDs.
 

Detailed Description

Find central user IDs associated with local user IDs, e.g.

across a wiki farm.

Default implementation is MediaWiki\User\CentralId\LocalIdLookup.

Since
1.27
Stability: stable
to extend

Definition at line 42 of file CentralIdLookup.php.

Member Function Documentation

◆ centralIdFromLocalUser()

MediaWiki\User\CentralId\CentralIdLookup::centralIdFromLocalUser ( UserIdentity $user,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::READ_NORMAL )

Given a local UserIdentity object, return the central ID.

Stability: stable
to override
Note
Unlike centralIdFromName(), this does guarantee that the local user is attached to the central account.
Parameters
UserIdentity$userLocal user
int | Authority$audienceOne of the audience constants, or a specific authority
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 371 of file CentralIdLookup.php.

◆ centralIdFromName()

MediaWiki\User\CentralId\CentralIdLookup::centralIdFromName ( $name,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::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 | Authority$audienceOne of the audience constants, or a specific authority
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 305 of file CentralIdLookup.php.

◆ centralIdsFromNames()

MediaWiki\User\CentralId\CentralIdLookup::centralIdsFromNames ( array $names,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::READ_NORMAL )

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

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

Definition at line 320 of file CentralIdLookup.php.

◆ checkAudience()

MediaWiki\User\CentralId\CentralIdLookup::checkAudience ( $audience)
protected

Check that the "audience" parameter is valid.

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

Definition at line 102 of file CentralIdLookup.php.

◆ factory()

static MediaWiki\User\CentralId\CentralIdLookup::factory ( $providerId = null)
static

Fetch a CentralIdLookup.

Deprecated
since 1.37 Use MediaWikiServices to obtain an instance.
Parameters
string | null$providerIdProvider ID from $wgCentralIdLookupProviders
Returns
CentralIdLookup|null

Definition at line 63 of file CentralIdLookup.php.

References MediaWiki\MediaWikiServices\getInstance(), and wfDeprecated().

◆ getProviderId()

MediaWiki\User\CentralId\CentralIdLookup::getProviderId ( )

Definition at line 92 of file CentralIdLookup.php.

◆ init()

MediaWiki\User\CentralId\CentralIdLookup::init ( string $providerId,
UserIdentityLookup $userIdentityLookup,
UserFactory $userFactory )

Initialize the provider.

Access: internal

Definition at line 79 of file CentralIdLookup.php.

◆ isAttached()

MediaWiki\User\CentralId\CentralIdLookup::isAttached ( UserIdentity $user,
$wikiId = UserIdentity::LOCAL )
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
UserIdentity$user
string | false$wikiIdWiki to check attachment status. If false, check the current wiki.
Returns
bool

Reimplemented in MediaWiki\User\CentralId\LocalIdLookup.

◆ isOwned()

MediaWiki\User\CentralId\CentralIdLookup::isOwned ( UserIdentity $user,
$wikiId = UserIdentity::LOCAL )

Check that a username is owned by the central user on the specified wiki.

This should return true if the local account exists and is attached (see isAttached()), or if it does not exist but is reserved for the central user (it's guaranteed that if it's ever created, then it will be attached to the central user).

Since
1.43
Stability: stable
to override
Parameters
UserIdentity$user
string | false$wikiIdWiki to check attachment status. If false, check the current wiki.
Returns
bool

Definition at line 143 of file CentralIdLookup.php.

◆ localUserFromCentralId()

MediaWiki\User\CentralId\CentralIdLookup::localUserFromCentralId ( $id,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::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.
Stability: stable
to override
Parameters
int$idCentral user ID
int | Authority$audienceOne of the audience constants, or a specific authority
int$flagsIDBAccessObject read flags
Returns
UserIdentity|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 345 of file CentralIdLookup.php.

◆ lookupAttachedUserNames()

MediaWiki\User\CentralId\CentralIdLookup::lookupAttachedUserNames ( array $nameToId,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::READ_NORMAL,
$wikiId = UserIdentity::LOCAL )

Given user names on the wiki specified by $wikiId, return the central IDs, but only include IDs for local users attached to the central user, i.e.

isAttached() would be true.

Since
1.44
Parameters
array$nameToIdArray with keys being canonicalized user names
int | Authority$audienceOne of the audience constants, or a specific authority
int$flagsIDBAccessObject read flags
string | false$wikiIdWiki to check attachment status. If false, check the current wiki.
Returns
int[] Copy of $nameToId with values set to central IDs. Names not attached to the central user are unchanged.

Definition at line 220 of file CentralIdLookup.php.

◆ lookupCentralIds()

MediaWiki\User\CentralId\CentralIdLookup::lookupCentralIds ( array $idToName,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::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 | Authority$audienceOne of the audience constants, or a specific authority
int$flagsIDBAccessObject read flags
Returns
string[] 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 MediaWiki\User\CentralId\LocalIdLookup.

◆ lookupOwnedUserNames()

MediaWiki\User\CentralId\CentralIdLookup::lookupOwnedUserNames ( array $nameToId,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::READ_NORMAL,
$wikiId = UserIdentity::LOCAL )

Given user names on the wiki specified by $wikiId, return the central IDs, but only include IDs for local users owned by the central user, i.e.

isOwned() would be true.

Since
1.44
Parameters
array$nameToIdArray with keys being canonicalized user names
int | Authority$audienceOne of the audience constants, or a specific authority
int$flagsIDBAccessObject read flags
string | false$wikiIdWiki to check attachment status. If false, check the current wiki.
Returns
int[] Copy of $nameToId with values set to central IDs. Names not owned by the central user are unchanged.

Definition at line 195 of file CentralIdLookup.php.

◆ lookupUserNames()

MediaWiki\User\CentralId\CentralIdLookup::lookupUserNames ( array $nameToId,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::READ_NORMAL )

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 | Authority$audienceOne of the audience constants, or a specific authority
int$flagsIDBAccessObject read flags
Returns
int[] 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.

Definition at line 173 of file CentralIdLookup.php.

◆ lookupUserNamesWithFilter()

MediaWiki\User\CentralId\CentralIdLookup::lookupUserNamesWithFilter ( array $nameToId,
$filter,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::READ_NORMAL,
$wikiId = UserIdentity::LOCAL )
abstractprotected

Given user names on the wiki specified by $wikiId, return the central IDs.

If $filter is not FILTER_NONE, filter the users by owned or attached status.

Since
1.44
Parameters
array$nameToIdArray with keys being canonicalized user names
string$filterOne of:
  • self::FILTER_NONE: Get all users with the specified names
  • self::FILTER_ATTACHED: Only get IDs for attached users
  • self::FILTER_OWNED: Only get IDs for owned users
int | Authority$audienceOne of the audience constants, or a specific authority
int$flagsIDBAccessObject read flags
string | false$wikiIdWiki to check attachment status. If false, check the current wiki.
Returns
int[] Copy of $nameToId with values set to central IDs. Names not owned by the central user are unchanged.

Reimplemented in MediaWiki\User\CentralId\LocalIdLookup.

◆ nameFromCentralId()

MediaWiki\User\CentralId\CentralIdLookup::nameFromCentralId ( $id,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::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 | Authority$audienceOne of the audience constants, or a specific authority
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 267 of file CentralIdLookup.php.

◆ namesFromCentralIds()

MediaWiki\User\CentralId\CentralIdLookup::namesFromCentralIds ( array $ids,
$audience = self::AUDIENCE_PUBLIC,
$flags = IDBAccessObject::READ_NORMAL )

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

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

Definition at line 282 of file CentralIdLookup.php.

Member Data Documentation

◆ AUDIENCE_PUBLIC

const MediaWiki\User\CentralId\CentralIdLookup::AUDIENCE_PUBLIC = 1

Definition at line 44 of file CentralIdLookup.php.

◆ AUDIENCE_RAW

const MediaWiki\User\CentralId\CentralIdLookup::AUDIENCE_RAW = 2

Definition at line 45 of file CentralIdLookup.php.

◆ FILTER_ATTACHED

const MediaWiki\User\CentralId\CentralIdLookup::FILTER_ATTACHED = 'attached'

Definition at line 48 of file CentralIdLookup.php.

◆ FILTER_NONE

const MediaWiki\User\CentralId\CentralIdLookup::FILTER_NONE = 'none'

Definition at line 47 of file CentralIdLookup.php.

◆ FILTER_OWNED

const MediaWiki\User\CentralId\CentralIdLookup::FILTER_OWNED = 'owned'

Definition at line 49 of file CentralIdLookup.php.


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