MediaWiki master
MediaWiki\User\TempUser\TempUserCreator Class Reference

Service for temporary user creation. More...

Inherits MediaWiki\User\TempUser\TempUserConfig.

Collaboration diagram for MediaWiki\User\TempUser\TempUserCreator:

Public Member Functions

 __construct (RealTempUserConfig $config, ObjectFactory $objectFactory, UserFactory $userFactory, AuthManager $authManager, CentralIdLookup $centralIdLookup, ?Throttler $throttler)
 
 acquireAndStashName (Session $session)
 Permanently acquire a username, stash it in a session, and return it.
 
 create ( $name=null, WebRequest $request=null)
 Acquire a serial number, create the corresponding user and log in.
 
 getExpireAfterDays ()
 After how many days do temporary users expire?
 
 getMatchCondition (IReadableDatabase $db, string $field, string $op)
 Get a SQL query condition that will match (or not match) temporary accounts.
 
 getMatchPattern ()
 Get a Pattern indicating how temporary account can be detected.
 
 getMatchPatterns ()
 Get Patterns indicating how temporary account can be detected.
 
 getNotifyBeforeExpirationDays ()
 How many days before expiration should temporary users be notified?
 
 getPlaceholderName ()
 Get a placeholder name which matches the reserved prefix.
 
 getStashedName (Session $session)
 Return a possible acquired and stashed username in a session.
 
 isAutoCreateAction (string $action)
 Is the action valid for user auto-creation?
 
 isEnabled ()
 Is temp user creation enabled?
 
 isReservedName (string $name)
 Does the name match a configured pattern which indicates that it conflicts with temporary user names? Should manual user creation be denied?
 
 isTempName (string $name)
 Does the name match the configured pattern indicating that it is a temporary auto-created user?
 
 shouldAutoCreate (Authority $authority, string $action)
 Should/would auto-create be performed if the user attempts to perform the given action?
 

Detailed Description

Service for temporary user creation.

For convenience this also proxies the TempUserConfig methods.

This is separate from TempUserConfig to avoid dependency loops. Special pages and actions are free to use this class, but services should take it as a constructor parameter only if necessary.

Since
1.39

Definition at line 30 of file TempUserCreator.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\TempUser\TempUserCreator::__construct ( RealTempUserConfig $config,
ObjectFactory $objectFactory,
UserFactory $userFactory,
AuthManager $authManager,
CentralIdLookup $centralIdLookup,
?Throttler $throttler )

Member Function Documentation

◆ acquireAndStashName()

MediaWiki\User\TempUser\TempUserCreator::acquireAndStashName ( Session $session)

Permanently acquire a username, stash it in a session, and return it.

Do not create the user.

If this method was called before with the same session ID, return the previously stashed username instead of acquiring a new one.

Parameters
Session$session
Returns
string|null The username, or null if no username could be acquired

Definition at line 329 of file TempUserCreator.php.

References MediaWiki\Session\Session\get(), MediaWiki\Session\Session\save(), and MediaWiki\Session\Session\set().

◆ create()

MediaWiki\User\TempUser\TempUserCreator::create ( $name = null,
WebRequest $request = null )

Acquire a serial number, create the corresponding user and log in.

Parameters
string | null$namePreviously acquired name
WebRequest | null$requestRequest details, used for throttling
Returns
CreateStatus

Definition at line 92 of file TempUserCreator.php.

References StatusValue\fatal(), and wfMessage().

◆ getExpireAfterDays()

MediaWiki\User\TempUser\TempUserCreator::getExpireAfterDays ( )

After how many days do temporary users expire?

Note
expireTemporaryAccounts.php maintenance script needs to be periodically executed for temp account expiry to work.
Since
1.42
Returns
int|null Null if temp accounts should never expire

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 163 of file TempUserCreator.php.

◆ getMatchCondition()

MediaWiki\User\TempUser\TempUserCreator::getMatchCondition ( IReadableDatabase $db,
string $field,
string $op )

Get a SQL query condition that will match (or not match) temporary accounts.

Since
1.42
Parameters
IReadableDatabase$db
string$fieldDatabase field to match against
string$opOperator: IExpression::LIKE or IExpression::NOT_LIKE
Returns
IExpression

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 159 of file TempUserCreator.php.

◆ getMatchPattern()

MediaWiki\User\TempUser\TempUserCreator::getMatchPattern ( )

Get a Pattern indicating how temporary account can be detected.

Used to avoid selecting a temp account via select queries.

Deprecated
since 1.42. Use ::getMatchPatterns as multiple patterns may be defined.
Returns
Pattern

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 151 of file TempUserCreator.php.

◆ getMatchPatterns()

MediaWiki\User\TempUser\TempUserCreator::getMatchPatterns ( )

Get Patterns indicating how temporary account can be detected.

Used to avoid selecting a temp account via select queries.

Since
1.42
Returns
Pattern[]

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 155 of file TempUserCreator.php.

◆ getNotifyBeforeExpirationDays()

MediaWiki\User\TempUser\TempUserCreator::getNotifyBeforeExpirationDays ( )

How many days before expiration should temporary users be notified?

Note
expireTemporaryAccounts.php maintenance script needs to be periodically executed for temp account expiry to work.
Since
1.42
Returns
int|null Null if temp accounts should never be notified before expiration

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 167 of file TempUserCreator.php.

◆ getPlaceholderName()

MediaWiki\User\TempUser\TempUserCreator::getPlaceholderName ( )

Get a placeholder name which matches the reserved prefix.

Returns
string

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 147 of file TempUserCreator.php.

◆ getStashedName()

MediaWiki\User\TempUser\TempUserCreator::getStashedName ( Session $session)

Return a possible acquired and stashed username in a session.

Do not acquire or create the user.

If this method is called with the same session ID as function acquireAndStashName(), it returns the previously stashed username.

Since
1.41
Parameters
Session$session
Returns
?string The username, if it was already acquired

Definition at line 353 of file TempUserCreator.php.

◆ isAutoCreateAction()

MediaWiki\User\TempUser\TempUserCreator::isAutoCreateAction ( string $action)

Is the action valid for user auto-creation?

Parameters
string$action
Returns
bool

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 131 of file TempUserCreator.php.

◆ isEnabled()

MediaWiki\User\TempUser\TempUserCreator::isEnabled ( )

Is temp user creation enabled?

Returns
bool

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 127 of file TempUserCreator.php.

◆ isReservedName()

MediaWiki\User\TempUser\TempUserCreator::isReservedName ( string $name)

Does the name match a configured pattern which indicates that it conflicts with temporary user names? Should manual user creation be denied?

Parameters
string$name
Returns
mixed

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 143 of file TempUserCreator.php.

◆ isTempName()

MediaWiki\User\TempUser\TempUserCreator::isTempName ( string $name)

Does the name match the configured pattern indicating that it is a temporary auto-created user?

Parameters
string$name
Returns
bool

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 139 of file TempUserCreator.php.

◆ shouldAutoCreate()

MediaWiki\User\TempUser\TempUserCreator::shouldAutoCreate ( Authority $authority,
string $action )

Should/would auto-create be performed if the user attempts to perform the given action?

Since
1.41
Parameters
Authority$authority
string$action
Returns
bool

Implements MediaWiki\User\TempUser\TempUserConfig.

Definition at line 135 of file TempUserCreator.php.


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