MediaWiki  master
MediaWiki\User\ActorStore Class Reference
Inheritance diagram for MediaWiki\User\ActorStore:
Collaboration diagram for MediaWiki\User\ActorStore:

Public Member Functions

 __construct (ILoadBalancer $loadBalancer, UserNameUtils $userNameUtils, LoggerInterface $logger, $wikiId=WikiAwareEntity::LOCAL)
 
 acquireActorId (UserIdentity $user, IDatabase $dbw)
 Attempt to assign an actor ID to the given $user. More...
 
 acquireSystemActorId (UserIdentity $user, IDatabase $dbw)
 Attempt to assign an ID to an actor for a system user. More...
 
 clearCaches ()
 
 createNewActor (UserIdentity $user, IDatabase $dbw)
 Create a new actor for the given $user. More...
 
 deleteActor (UserIdentity $actor, IDatabase $dbw)
 Delete the actor from the actor table. More...
 
 deleteUserIdentityFromCache (UserIdentity $actor)
 
 findActorId (UserIdentity $user, IDatabase $db)
 Find the actor_id of the given $user. More...
 
 findActorIdByName ( $name, IDatabase $db)
 Find the actor_id of the given $name. More...
 
 getActorById (int $actorId, IDatabase $db)
 Find an actor by $id. More...
 
 getUnknownActor ()
 In case all reasonable attempts of initializing a proper actor from the database have failed, entities can be attributed to special 'Unknown user' actor. More...
 
 getUserIdentityByName (string $name, int $queryFlags=self::READ_NORMAL)
 Find an actor by $name. More...
 
 getUserIdentityByUserId (int $userId, int $queryFlags=self::READ_NORMAL)
 Find an actor by $userId. More...
 
 newActorFromRow (stdClass $row)
 Instantiate a new UserIdentity object based on a $row from the actor table. More...
 
 newActorFromRowFields ( $userId, $name, $actorId)
 Instantiate a new UserIdentity object based on field values from a DB row. More...
 
 newSelectQueryBuilder ( $dbOrQueryFlags=self::READ_NORMAL)
 Returns a specialized SelectQueryBuilder for querying the UserIdentity objects. More...
 
 normalizeUserName (string $name)
 Returns a canonical form of user name suitable for storage. More...
 
- Public Member Functions inherited from MediaWiki\User\ActorNormalization
 findActorIdByName (string $name, IDatabase $db)
 Find the actor_id for the given name. More...
 

Public Attributes

const UNKNOWN_USER_NAME = 'Unknown user'
 
- Public Attributes inherited from IDBAccessObject
const READ_NONE = -1
 Constants for object loading bitfield flags (higher => higher QoS) More...
 

Private Member Functions

 attachActorId (UserIdentity $user, int $id, bool $assigned)
 Attach the actor ID to $user for backwards compatibility. More...
 
 checkDatabaseDomain (IDatabase $db)
 Throws an exception if the given database connection does not belong to the wiki this RevisionStore is bound to. More...
 
 deprecateInvalidCrossWikiParam (UserIdentity $user)
 Emits a deprecation warning if $user does not belong to the same wiki this store belongs to. More...
 
 detachActorId (UserIdentity $user)
 Detach the actor ID from $user for backwards compatibility. More...
 
 findActorIdInternal (string $name, IDatabase $db, array $queryOptions=[])
 Find actor_id of the given $user using the passed $db connection. More...
 
 getDBConnectionRefForQueryFlags (int $queryFlags)
 
 setUpRollbackHandler (IDatabase $dbw, UserIdentity $cachedActor, UserIdentity $originalActor)
 Clear in-process caches if transaction gets rolled back. More...
 
 validateActorForInsertion (UserIdentity $user)
 Validates actor before insertion. More...
 
 wikiIdToString ( $wikiId)
 Convert $wikiId to a string for logging. More...
 

Private Attributes

ActorCache $cache
 
ILoadBalancer $loadBalancer
 
LoggerInterface $logger
 
UserNameUtils $userNameUtils
 
string false $wikiId
 
const LOCAL_CACHE_SIZE = 100
 

Detailed Description

Definition at line 43 of file ActorStore.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\ActorStore::__construct ( ILoadBalancer  $loadBalancer,
UserNameUtils  $userNameUtils,
LoggerInterface  $logger,
  $wikiId = WikiAwareEntity::LOCAL 
)
Parameters
ILoadBalancer$loadBalancer
UserNameUtils$userNameUtils
LoggerInterface$logger
string | false$wikiId

Definition at line 70 of file ActorStore.php.

References MediaWiki\User\ActorStore\$loadBalancer, MediaWiki\User\ActorStore\$logger, MediaWiki\User\ActorStore\$userNameUtils, and MediaWiki\User\ActorStore\$wikiId.

Member Function Documentation

◆ acquireActorId()

MediaWiki\User\ActorStore::acquireActorId ( UserIdentity  $user,
IDatabase  $dbw 
)

Attempt to assign an actor ID to the given $user.

If it is already assigned, return the existing ID.

Note
If called within a transaction, the returned ID might become invalid if the transaction is rolled back, so it should not be passed outside of the transaction context.
Parameters
UserIdentity$user
IDatabase$dbwThe database connection to acquire the ID from. The database must correspond to ActorStore's wiki ID.
Returns
int actor ID greater then 0
Exceptions
CannotCreateActorExceptionif no actor ID has been assigned to this $user

Implements MediaWiki\User\ActorNormalization.

Definition at line 407 of file ActorStore.php.

References Wikimedia\Rdbms\IDatabase\affectedRows(), MediaWiki\User\ActorStore\attachActorId(), MediaWiki\User\ActorStore\checkDatabaseDomain(), MediaWiki\User\ActorStore\findActorIdInternal(), Wikimedia\Rdbms\IDatabase\insert(), Wikimedia\Rdbms\IDatabase\insertId(), MediaWiki\User\ActorStore\newActorFromRowFields(), MediaWiki\User\ActorStore\setUpRollbackHandler(), and MediaWiki\User\ActorStore\validateActorForInsertion().

Referenced by MediaWiki\User\ActorStore\getUnknownActor().

◆ acquireSystemActorId()

MediaWiki\User\ActorStore::acquireSystemActorId ( UserIdentity  $user,
IDatabase  $dbw 
)

Attempt to assign an ID to an actor for a system user.

If an actor ID already exists, return it.

Note
For reserved user names this method will overwrite the user ID of the existing anon actor.
If called within a transaction, the returned ID might become invalid if the transaction is rolled back, so it should not be passed outside of the transaction context.
Parameters
UserIdentity$user
IDatabase$dbw
Returns
int actor ID greater then zero
Exceptions
CannotCreateActorExceptionif the existing actor is associated with registered user.
Access: internal
for use in user account creation only.

Definition at line 511 of file ActorStore.php.

References Wikimedia\Rdbms\IDatabase\affectedRows(), MediaWiki\User\ActorStore\attachActorId(), MediaWiki\User\ActorStore\checkDatabaseDomain(), MediaWiki\User\ActorStore\findActorIdInternal(), MediaWiki\User\UserIdentity\getId(), Wikimedia\Rdbms\IDatabase\insertId(), MediaWiki\User\ActorStore\newActorFromRowFields(), MediaWiki\User\ActorStore\setUpRollbackHandler(), Wikimedia\Rdbms\IDatabase\upsert(), and MediaWiki\User\ActorStore\validateActorForInsertion().

◆ attachActorId()

MediaWiki\User\ActorStore::attachActorId ( UserIdentity  $user,
int  $id,
bool  $assigned 
)
private

Attach the actor ID to $user for backwards compatibility.

Todo:
remove this method when no longer needed (T273974).
Parameters
UserIdentity$user
int$id
bool$assigned- whether a new actor ID was just assigned.

Definition at line 277 of file ActorStore.php.

Referenced by MediaWiki\User\ActorStore\acquireActorId(), MediaWiki\User\ActorStore\acquireSystemActorId(), and MediaWiki\User\ActorStore\createNewActor().

◆ checkDatabaseDomain()

MediaWiki\User\ActorStore::checkDatabaseDomain ( IDatabase  $db)
private

Throws an exception if the given database connection does not belong to the wiki this RevisionStore is bound to.

Parameters
IDatabase$db

Definition at line 689 of file ActorStore.php.

References Wikimedia\Rdbms\IDatabase\getDomainID().

Referenced by MediaWiki\User\ActorStore\acquireActorId(), MediaWiki\User\ActorStore\acquireSystemActorId(), MediaWiki\User\ActorStore\createNewActor(), MediaWiki\User\ActorStore\deleteActor(), MediaWiki\User\ActorStore\getActorById(), and MediaWiki\User\ActorStore\newSelectQueryBuilder().

◆ clearCaches()

MediaWiki\User\ActorStore::clearCaches ( )
Access: internal
only exists until User::resetIdByNameCache is removed. Wipe-out the in-process caches.

Definition at line 196 of file ActorStore.php.

◆ createNewActor()

MediaWiki\User\ActorStore::createNewActor ( UserIdentity  $user,
IDatabase  $dbw 
)

Create a new actor for the given $user.

If an actor with this name already exists, this method throws.

Note
If called within a transaction, the returned ID might become invalid if the transaction is rolled back, so it should not be passed outside of the transaction context.
Parameters
UserIdentity$user
IDatabase$dbw
Returns
int actor ID greater then 0
Exceptions
CannotCreateActorExceptionif an actor with this name already exist.
Access: internal
for use in user account creation only.

Definition at line 467 of file ActorStore.php.

References MediaWiki\User\ActorStore\attachActorId(), MediaWiki\User\ActorStore\checkDatabaseDomain(), Wikimedia\Rdbms\IDatabase\insert(), Wikimedia\Rdbms\IDatabase\insertId(), MediaWiki\User\ActorStore\newActorFromRowFields(), MediaWiki\User\ActorStore\setUpRollbackHandler(), and MediaWiki\User\ActorStore\validateActorForInsertion().

◆ deleteActor()

MediaWiki\User\ActorStore::deleteActor ( UserIdentity  $actor,
IDatabase  $dbw 
)

Delete the actor from the actor table.

Warning
this method does very limited validation and is extremely dangerous since it can break referential integrity of the database if used incorrectly. Use at your own risk!
Since
1.37
Parameters
UserIdentity$actor
IDatabase$dbw
Returns
bool true on success, false if nothing was deleted.

Definition at line 570 of file ActorStore.php.

References Wikimedia\Rdbms\IDatabase\affectedRows(), MediaWiki\User\ActorStore\checkDatabaseDomain(), Wikimedia\Rdbms\IDatabase\delete(), MediaWiki\User\ActorStore\deprecateInvalidCrossWikiParam(), MediaWiki\User\UserIdentity\getName(), and MediaWiki\User\ActorStore\normalizeUserName().

◆ deleteUserIdentityFromCache()

MediaWiki\User\ActorStore::deleteUserIdentityFromCache ( UserIdentity  $actor)
Parameters
UserIdentity$actor
Access: internal
for use in User object only

Definition at line 188 of file ActorStore.php.

◆ deprecateInvalidCrossWikiParam()

MediaWiki\User\ActorStore::deprecateInvalidCrossWikiParam ( UserIdentity  $user)
private

Emits a deprecation warning if $user does not belong to the same wiki this store belongs to.

Parameters
UserIdentity$user

Definition at line 741 of file ActorStore.php.

References MediaWiki\DAO\WikiAwareEntity\getWikiId(), wfDeprecatedMsg(), and MediaWiki\User\ActorStore\wikiIdToString().

Referenced by MediaWiki\User\ActorStore\deleteActor(), MediaWiki\User\ActorStore\findActorId(), and MediaWiki\User\ActorStore\validateActorForInsertion().

◆ detachActorId()

MediaWiki\User\ActorStore::detachActorId ( UserIdentity  $user)
private

Detach the actor ID from $user for backwards compatibility.

Todo:
remove this method when no longer needed (T273974).
Parameters
UserIdentity$user

Definition at line 293 of file ActorStore.php.

Referenced by MediaWiki\User\ActorStore\setUpRollbackHandler().

◆ findActorId()

MediaWiki\User\ActorStore::findActorId ( UserIdentity  $user,
IDatabase  $db 
)

Find the actor_id of the given $user.

Parameters
UserIdentity$user
IDatabase$dbThe database connection to operate on. The database must correspond to ActorStore's wiki ID.
Returns
int|null

Implements MediaWiki\User\ActorNormalization.

Definition at line 307 of file ActorStore.php.

References MediaWiki\User\ActorStore\deprecateInvalidCrossWikiParam(), MediaWiki\User\ActorStore\findActorIdInternal(), MediaWiki\User\UserIdentity\getName(), and MediaWiki\User\ActorStore\normalizeUserName().

◆ findActorIdByName()

MediaWiki\User\ActorStore::findActorIdByName (   $name,
IDatabase  $db 
)

Find the actor_id of the given $name.

Parameters
string$name
IDatabase$dbThe database connection to operate on. The database must correspond to ActorStore's wiki ID.
Returns
int|null

Definition at line 343 of file ActorStore.php.

References MediaWiki\User\ActorStore\findActorIdInternal(), and MediaWiki\User\ActorStore\normalizeUserName().

◆ findActorIdInternal()

MediaWiki\User\ActorStore::findActorIdInternal ( string  $name,
IDatabase  $db,
array  $queryOptions = [] 
)
private

Find actor_id of the given $user using the passed $db connection.

Parameters
string$name
IDatabase$dbThe database connection to operate on. The database must correspond to ActorStore's wiki ID.
array$queryOptions
Returns
int|null

Definition at line 361 of file ActorStore.php.

References MediaWiki\User\ActorStore\newActorFromRow(), and Wikimedia\Rdbms\IDatabase\selectRow().

Referenced by MediaWiki\User\ActorStore\acquireActorId(), MediaWiki\User\ActorStore\acquireSystemActorId(), MediaWiki\User\ActorStore\findActorId(), and MediaWiki\User\ActorStore\findActorIdByName().

◆ getActorById()

MediaWiki\User\ActorStore::getActorById ( int  $actorId,
IDatabase  $db 
)

Find an actor by $id.

Parameters
int$actorId
IDatabase$dbThe database connection to operate on. The database must correspond to ActorStore's wiki ID.
Returns
UserIdentity|null Returns null if no actor with this $actorId exists in the database.

Implements MediaWiki\User\ActorNormalization.

Definition at line 208 of file ActorStore.php.

References MediaWiki\User\ActorStore\checkDatabaseDomain(), and MediaWiki\User\ActorStore\newSelectQueryBuilder().

◆ getDBConnectionRefForQueryFlags()

MediaWiki\User\ActorStore::getDBConnectionRefForQueryFlags ( int  $queryFlags)
private
Parameters
int$queryFlagsa bit field composed of READ_XXX flags
Returns
array [ IDatabase $db, array $options ]

Definition at line 678 of file ActorStore.php.

References DBAccessObjectUtils\getDBOptions().

Referenced by MediaWiki\User\ActorStore\getUnknownActor(), and MediaWiki\User\ActorStore\newSelectQueryBuilder().

◆ getUnknownActor()

MediaWiki\User\ActorStore::getUnknownActor ( )

In case all reasonable attempts of initializing a proper actor from the database have failed, entities can be attributed to special 'Unknown user' actor.

Returns
UserIdentity

Implements MediaWiki\User\ActorNormalization.

Definition at line 705 of file ActorStore.php.

References MediaWiki\User\ActorStore\acquireActorId(), MediaWiki\User\ActorStore\getDBConnectionRefForQueryFlags(), and MediaWiki\User\ActorStore\getUserIdentityByName().

◆ getUserIdentityByName()

MediaWiki\User\ActorStore::getUserIdentityByName ( string  $name,
int  $queryFlags = self::READ_NORMAL 
)

Find an actor by $name.

Parameters
string$name
int$queryFlagsone of IDBAccessObject constants
Returns
UserIdentity|null

Implements MediaWiki\User\UserIdentityLookup.

Definition at line 236 of file ActorStore.php.

References MediaWiki\User\ActorStore\newSelectQueryBuilder(), and MediaWiki\User\ActorStore\normalizeUserName().

Referenced by MediaWiki\User\ActorStore\getUnknownActor().

◆ getUserIdentityByUserId()

MediaWiki\User\ActorStore::getUserIdentityByUserId ( int  $userId,
int  $queryFlags = self::READ_NORMAL 
)

Find an actor by $userId.

Parameters
int$userId
int$queryFlagsone of IDBAccessObject constants
Returns
UserIdentity|null

Implements MediaWiki\User\UserIdentityLookup.

Definition at line 256 of file ActorStore.php.

References MediaWiki\User\ActorStore\newSelectQueryBuilder().

◆ newActorFromRow()

MediaWiki\User\ActorStore::newActorFromRow ( stdClass  $row)

Instantiate a new UserIdentity object based on a $row from the actor table.

Use this method when an actor row was already fetched from the DB via a join. This method just constructs a new instance and does not try fetching missing values from the DB again, use UserIdentityLookup for that.

Parameters
stdClass$rowwith the following fields:
  • int actor_id
  • string actor_name
  • int|null actor_user
Returns
UserIdentity
Exceptions
InvalidArgumentException

Implements MediaWiki\User\ActorNormalization.

Definition at line 101 of file ActorStore.php.

References if, and MediaWiki\User\ActorStore\normalizeUserName().

Referenced by MediaWiki\User\ActorStore\findActorIdInternal().

◆ newActorFromRowFields()

MediaWiki\User\ActorStore::newActorFromRowFields (   $userId,
  $name,
  $actorId 
)

Instantiate a new UserIdentity object based on field values from a DB row.

Until ActorMigration is completed, the actor table joins alias actor field names to legacy field names. This method is convenience to construct the UserIdentity based on legacy field names. It's more relaxed with typing then ::newFromRow to better support legacy code, so always prefer ::newFromRow in new code. Eventually, once ActorMigration is completed and all queries use explicit join with actor table, this method will be deprecated and removed.

Exceptions
InvalidArgumentException
Parameters
int | null$userId
string | null$name
int | null$actorId
Returns
UserIdentity

Implements MediaWiki\User\ActorNormalization.

Definition at line 144 of file ActorStore.php.

References MediaWiki\User\ActorStore\normalizeUserName().

Referenced by MediaWiki\User\ActorStore\acquireActorId(), MediaWiki\User\ActorStore\acquireSystemActorId(), and MediaWiki\User\ActorStore\createNewActor().

◆ newSelectQueryBuilder()

MediaWiki\User\ActorStore::newSelectQueryBuilder (   $dbOrQueryFlags = self::READ_NORMAL)

Returns a specialized SelectQueryBuilder for querying the UserIdentity objects.

Parameters
IDatabase | int$dbOrQueryFlagsThe database connection to perform the query on, or one of self::READ_* constants.
Returns
UserSelectQueryBuilder

Implements MediaWiki\User\UserIdentityLookup.

Definition at line 724 of file ActorStore.php.

References MediaWiki\User\ActorStore\checkDatabaseDomain(), and MediaWiki\User\ActorStore\getDBConnectionRefForQueryFlags().

Referenced by MediaWiki\User\ActorStore\getActorById(), MediaWiki\User\ActorStore\getUserIdentityByName(), and MediaWiki\User\ActorStore\getUserIdentityByUserId().

◆ normalizeUserName()

MediaWiki\User\ActorStore::normalizeUserName ( string  $name)

◆ setUpRollbackHandler()

MediaWiki\User\ActorStore::setUpRollbackHandler ( IDatabase  $dbw,
UserIdentity  $cachedActor,
UserIdentity  $originalActor 
)
private

◆ validateActorForInsertion()

MediaWiki\User\ActorStore::validateActorForInsertion ( UserIdentity  $user)
private

◆ wikiIdToString()

MediaWiki\User\ActorStore::wikiIdToString (   $wikiId)
private

Convert $wikiId to a string for logging.

Parameters
string | false$wikiId
Returns
string

Definition at line 759 of file ActorStore.php.

References MediaWiki\User\ActorStore\$wikiId.

Referenced by MediaWiki\User\ActorStore\deprecateInvalidCrossWikiParam().

Member Data Documentation

◆ $cache

ActorCache MediaWiki\User\ActorStore::$cache
private

Definition at line 62 of file ActorStore.php.

◆ $loadBalancer

ILoadBalancer MediaWiki\User\ActorStore::$loadBalancer
private

Definition at line 50 of file ActorStore.php.

Referenced by MediaWiki\User\ActorStore\__construct().

◆ $logger

LoggerInterface MediaWiki\User\ActorStore::$logger
private

Definition at line 56 of file ActorStore.php.

Referenced by MediaWiki\User\ActorStore\__construct().

◆ $userNameUtils

UserNameUtils MediaWiki\User\ActorStore::$userNameUtils
private

Definition at line 53 of file ActorStore.php.

Referenced by MediaWiki\User\ActorStore\__construct().

◆ $wikiId

string false MediaWiki\User\ActorStore::$wikiId
private

◆ LOCAL_CACHE_SIZE

const MediaWiki\User\ActorStore::LOCAL_CACHE_SIZE = 100
private

Definition at line 47 of file ActorStore.php.

◆ UNKNOWN_USER_NAME

const MediaWiki\User\ActorStore::UNKNOWN_USER_NAME = 'Unknown user'

Definition at line 45 of file ActorStore.php.


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