MediaWiki master
MediaWiki\User\UserFactory Class Reference

Creates User objects. More...

Inherits MediaWiki\User\UserRigorOptions.

Collaboration diagram for MediaWiki\User\UserFactory:

Public Member Functions

 __construct (ServiceOptions $options, ILBFactory $loadBalancerFactory, UserNameUtils $userNameUtils)
 
 invalidateCache (UserIdentity $userIdentity)
 Purge user related caches, "touch" the user table to invalidate further caches.
 
 newAnonymous (?string $ip=null)
 Returns a new anonymous User based on ip.
 
 newFromActorId (int $actorId)
 Factory method for creation from a given actor ID, replacing User::newFromActorId.
 
 newFromAnyId (?int $userId, ?string $userName, ?int $actorId=null, $dbDomain=false)
 Factory method for creation from an ID, name, and/or actor ID, replacing User::newFromAnyId.
 
 newFromAuthority (Authority $authority)
 
 newFromConfirmationCode (string $confirmationCode, int $flags=IDBAccessObject::READ_NORMAL)
 Factory method to fetch the user for a given email confirmation code, replacing User::newFromConfirmationCode.
 
 newFromId (int $id)
 Factory method for creation from a given user ID, replacing User::newFromId.
 
 newFromName (string $name, string $validate=self::RIGOR_VALID)
 Factory method for creating users by name, replacing static User::newFromName.
 
 newFromNameOrIp (string $name)
 Returns either an anonymous or a named User based on the supplied argument.
 
 newFromRow ( $row, $data=null)
 
 newFromUserIdentity (UserIdentity $userIdentity)
 Factory method for creation from a given UserIdentity, replacing User::newFromIdentity.
 
 newTempPlaceholder ()
 Create a placeholder user for an anonymous user who will be upgraded to a temporary user.
 
 newUnsavedTempUser (?string $name)
 Create an unsaved temporary user with a previously acquired name or a placeholder name.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 RIGOR_* constants are inherited from UserRigorOptions.
 
- Public Attributes inherited from MediaWiki\User\UserRigorOptions
const RIGOR_CREATABLE = 'creatable'
 Check that a user name is valid for batch processes, login and account creation.
 
const RIGOR_NONE = 'none'
 No validation at all.
 
const RIGOR_USABLE = 'usable'
 Check that a user name is valid for batch processes and login.
 
const RIGOR_VALID = 'valid'
 Check that a user name is valid for batch processes.
 

Detailed Description

Creates User objects.

Since
1.35

Definition at line 42 of file UserFactory.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\UserFactory::__construct ( ServiceOptions $options,
ILBFactory $loadBalancerFactory,
UserNameUtils $userNameUtils )

Member Function Documentation

◆ invalidateCache()

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

Purge user related caches, "touch" the user table to invalidate further caches.

Since
1.41
Parameters
UserIdentity$userIdentity

Definition at line 383 of file UserFactory.php.

◆ newAnonymous()

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

Returns a new anonymous User based on ip.

Since
1.35
Parameters
string | null$ipIP address
Returns
User

Definition at line 117 of file UserFactory.php.

◆ 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 174 of file UserFactory.php.

◆ newFromAnyId()

MediaWiki\User\UserFactory::newFromAnyId ( ?int $userId,
?string $userName,
?int $actorId = null,
$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
string | false$dbDomain
Returns
User
Exceptions
InvalidArgumentExceptionif none of userId, userName, and actorId are specified

Definition at line 235 of file UserFactory.php.

◆ newFromAuthority()

MediaWiki\User\UserFactory::newFromAuthority ( Authority $authority)
Access: internal
for transition from User to Authority as performer concept.
Parameters
Authority$authority
Returns
User

Definition at line 344 of file UserFactory.php.

◆ newFromConfirmationCode()

MediaWiki\User\UserFactory::newFromConfirmationCode ( string $confirmationCode,
int $flags = IDBAccessObject::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 301 of file UserFactory.php.

References DB_PRIMARY.

◆ 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

Definition at line 158 of file UserFactory.php.

◆ 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. If you just want to create valid user who can be either a named user or an IP, consider using newFromNameOrIp() instead of calling this with 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 92 of file UserFactory.php.

Referenced by MediaWiki\Pager\ContributionsPager\__construct().

◆ newFromNameOrIp()

MediaWiki\User\UserFactory::newFromNameOrIp ( string $name)

Returns either an anonymous or a named User based on the supplied argument.

If IP is supplied, an anonymous user will be created, otherwise a valid named user. If you don't want to have the named user validated, use self::newFromName(). If you want to create simple anonymous user without providing the IP, use self::newAnonymous()

Since
1.44
Parameters
string$nameIP address or username
Returns
User|null

Definition at line 142 of file UserFactory.php.

◆ 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 335 of file UserFactory.php.

◆ newFromUserIdentity()

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

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

Since
1.35
Parameters
UserIdentity$userIdentity
Returns
User

Definition at line 190 of file UserFactory.php.

◆ newTempPlaceholder()

MediaWiki\User\UserFactory::newTempPlaceholder ( )

Create a placeholder user for an anonymous user who will be upgraded to a temporary user.

This will throw an exception if temp user autocreation is disabled.

Since
1.39
Returns
User

Definition at line 359 of file UserFactory.php.

◆ newUnsavedTempUser()

MediaWiki\User\UserFactory::newUnsavedTempUser ( ?string $name)

Create an unsaved temporary user with a previously acquired name or a placeholder name.

Since
1.39
Parameters
?string$nameIf null, a placeholder name is used
Returns
User

Definition at line 372 of file UserFactory.php.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\User\UserFactory::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const SharedDB
Name constant for the SharedDB setting, for use with Config::get()
const SharedTables
Name constant for the SharedTables setting, for use with Config::get()

RIGOR_* constants are inherited from UserRigorOptions.

Access: internal

Definition at line 49 of file UserFactory.php.


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