MediaWiki  master
MediaWiki\User\UserFactory Class Reference

Creates User objects. More...

Inheritance diagram for MediaWiki\User\UserFactory:
Collaboration diagram for MediaWiki\User\UserFactory:

Public Member Functions

 __construct (ILoadBalancer $loadBalancer, UserNameUtils $userNameUtils)
 
 newAnonymous ( $ip=null)
 Returns a new anonymous User based on ip. More...
 
 newFromActorId (int $actorId)
 Factory method for creation from a given actor ID, replacing User::newFromActorId. More...
 
 newFromAnyId (?int $userId, ?string $userName, ?int $actorId, $dbDomain=false)
 Factory method for creation from an ID, name, and/or actor ID, replacing User::newFromAnyId. More...
 
 newFromConfirmationCode (string $confirmationCode, int $flags=self::READ_NORMAL)
 Factory method to fetch the user for a given email confirmation code, replacing User::newFromConfirmationCode. More...
 
 newFromId (int $id)
 Factory method for creation from a given user ID, replacing User::newFromId. More...
 
 newFromName (string $name, string $validate=self::RIGOR_VALID)
 Factory method for creating users by name, replacing static User::newFromName. More...
 
 newFromRow ( $row, $data=null)
 
 newFromUserIdentity (UserIdentity $userIdentity)
 Factory method for creation fom a given UserIdentity, replacing User::newFromIdentity. More...
 

Private Attributes

ILoadBalancer $loadBalancer
 RIGOR_* constants are inherited from UserRigorOptions READ_* constants are inherited from IDBAccessObject. More...
 
UserNameUtils $userNameUtils
 

Additional Inherited Members

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

Detailed Description

Creates User objects.

For now, there is nothing much interesting in this class. It was meant for preventing static User methods causing problems in unit tests.

Since
1.35

Definition at line 40 of file UserFactory.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\UserFactory::__construct ( ILoadBalancer  $loadBalancer,
UserNameUtils  $userNameUtils 
)
Parameters
ILoadBalancer$loadBalancer
UserNameUtils$userNameUtils

Definition at line 57 of file UserFactory.php.

References MediaWiki\User\UserFactory\$loadBalancer, and MediaWiki\User\UserFactory\$userNameUtils.

Member Function Documentation

◆ newAnonymous()

MediaWiki\User\UserFactory::newAnonymous (   $ip = null)

Returns a new anonymous User based on ip.

Since
1.35
Parameters
string | null$ipIP address
Returns
User

Definition at line 108 of file UserFactory.php.

References User\isIP(), and MediaWiki\User\UserFactory\newFromName().

◆ newFromActorId()

MediaWiki\User\UserFactory::newFromActorId ( int  $actorId)

Factory method for creation from a given actor ID, replacing User::newFromActorId.

Since
1.35
Parameters
int$actorId
Returns
User

Definition at line 146 of file UserFactory.php.

◆ newFromAnyId()

MediaWiki\User\UserFactory::newFromAnyId ( ?int  $userId,
?string  $userName,
?int  $actorId,
  $dbDomain = false 
)

Factory method for creation from an ID, name, and/or actor ID, replacing User::newFromAnyId.

Note
This does not check that the ID, name, and actor ID all correspond to the same user.
Since
1.35
Parameters
?int$userId
?string$userName
?int$actorId
bool | string$dbDomain
Returns
User
Exceptions
InvalidArgumentExceptionif none of userId, userName, and actorId are specified

Definition at line 189 of file UserFactory.php.

References User\setItemLoaded().

Referenced by MediaWiki\User\UserFactory\newFromUserIdentity().

◆ newFromConfirmationCode()

MediaWiki\User\UserFactory::newFromConfirmationCode ( string  $confirmationCode,
int  $flags = self::READ_NORMAL 
)

Factory method to fetch the user for a given email confirmation code, replacing User::newFromConfirmationCode.

This code is generated when an account is created or its e-mail address has changed. If the code is invalid or has expired, returns null.

Since
1.35
Parameters
string$confirmationCode
int$flags
Returns
User|null

Definition at line 249 of file UserFactory.php.

References DBAccessObjectUtils\getDBOptions(), and MediaWiki\User\UserFactory\newFromId().

◆ newFromId()

MediaWiki\User\UserFactory::newFromId ( int  $id)

Factory method for creation from a given user ID, replacing User::newFromId.

Since
1.35
Parameters
int$idValid user ID
Returns
User The corresponding User object

Definition at line 130 of file UserFactory.php.

Referenced by MediaWiki\User\UserFactory\newFromConfirmationCode().

◆ newFromName()

MediaWiki\User\UserFactory::newFromName ( string  $name,
string  $validate = self::RIGOR_VALID 
)

Factory method for creating users by name, replacing static User::newFromName.

This is slightly less efficient than newFromId(), so use newFromId() if you have both an ID and a name handy.

Note
unlike User::newFromName, this returns null instead of false for invalid usernames
Since
1.35
1.36 returns null instead of false for invalid user names
Parameters
string$nameUsername, validated by Title::newFromText
string$validateValidation strategy, one of the RIGOR_* constants. For no validation, use RIGOR_NONE.
Returns
?User User object, or null if the username is invalid (e.g. if it contains illegal characters or is an IP address). If the username is not present in the database, the result will be a user object with a name, a user id of 0, and default settings.

Definition at line 83 of file UserFactory.php.

Referenced by MediaWiki\User\UserFactory\newAnonymous().

◆ newFromRow()

MediaWiki\User\UserFactory::newFromRow (   $row,
  $data = null 
)
See also
User::newFromRow
Since
1.36
Parameters
stdClass$rowA row from the user table
array | null$dataFurther data to load into the object
Returns
User

Definition at line 284 of file UserFactory.php.

References User\newFromRow().

◆ newFromUserIdentity()

MediaWiki\User\UserFactory::newFromUserIdentity ( UserIdentity  $userIdentity)

Factory method for creation fom a given UserIdentity, replacing User::newFromIdentity.

Since
1.35
Parameters
UserIdentity$userIdentity
Returns
User

Definition at line 162 of file UserFactory.php.

References MediaWiki\User\UserIdentity\getActorId(), MediaWiki\User\UserIdentity\getId(), MediaWiki\User\UserIdentity\getName(), and MediaWiki\User\UserFactory\newFromAnyId().

Member Data Documentation

◆ $loadBalancer

ILoadBalancer MediaWiki\User\UserFactory::$loadBalancer
private

RIGOR_* constants are inherited from UserRigorOptions READ_* constants are inherited from IDBAccessObject.

Definition at line 48 of file UserFactory.php.

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

◆ $userNameUtils

UserNameUtils MediaWiki\User\UserFactory::$userNameUtils
private

Definition at line 51 of file UserFactory.php.

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


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