MediaWiki master
PreviouslyRenamedAccountPreAuthenticationProvider.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Auth;
4
11
16
17 public function __construct(
18 private readonly IConnectionProvider $dbProvider,
19 private readonly UserFactory $userFactory,
20 array $params = [],
21 ) {
22 }
23
28 public function getAuthenticationRequests( $action, array $options ) {
29 if ( $action === AuthManager::ACTION_CREATE ) {
30 if ( $options['username'] ) {
31 $creator = $this->userFactory->newFromName( $options['username'] )
32 ?: $this->userFactory->newAnonymous();
33 } else {
34 $creator = $this->userFactory->newAnonymous();
35 }
36 if ( $creator->isAllowed( 'createpreviouslyrenamedaccount' ) ) {
38 }
39 }
40 return [];
41 }
42
47 public function testForAccountCreation( $user, $creator, array $reqs ) {
50 PreviouslyRenamedAccountAuthenticationRequest::class );
51 if (
53 $req->allowPreviouslyRenamedAccount &&
54 $creator->authorizeAction( 'createpreviouslyrenamedaccount' )
55 ) {
56 // Check overridden by the user
57 return StatusValue::newGood();
58 }
59 return $this->previouslyRenamedAccountStatus( $user->getName(), IDBAccessObject::READ_LATEST );
60 }
61
66 public function testUserForCreation( $user, $autocreate, array $options = [] ) {
67 // This is used by the "cancreate" API, so don't check permissions here to allow users
68 // who can override to still see whether normal registration attempt would be an error.
69 if ( $autocreate || !empty( $options['creating'] ) ) {
70 return StatusValue::newGood();
71 }
72 return $this->previouslyRenamedAccountStatus( $user->getName(), IDBAccessObject::READ_NORMAL );
73 }
74
81 protected function previouslyRenamedAccountStatus( string $username, int $flags ): StatusValue {
82 $db = DBAccessObjectUtils::getDBFromRecency( $this->dbProvider, $flags );
83 if ( RenameuserSQL::isPreviouslyRenamedAccount( $username, $db ) ) {
84 return StatusValue::newFatal( 'username-previously-renamed-account' );
85 }
86 return StatusValue::newGood();
87 }
88}
A base class that implements some of the boilerplate for a PreAuthenticationProvider.
const ACTION_CREATE
Create a new user.
static getRequestByClass(array $reqs, $class, $allowSubclasses=false)
Select a request by class name.
An authentication request that allows users with sufficiently high privileges to create a new account...
testForAccountCreation( $user, $creator, array $reqs)
Determine whether an account creation may begin.Called from AuthManager::beginAccountCreation()No nee...
__construct(private readonly IConnectionProvider $dbProvider, private readonly UserFactory $userFactory, array $params=[],)
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.Possible values for $action depend on whether th...
testUserForCreation( $user, $autocreate, array $options=[])
Determine whether an account may be created.StatusValueto override
Class which performs the actual renaming of users.
static isPreviouslyRenamedAccount(string $username, IReadableDatabase $db)
This method does not check log_deleted, and thus will reveal the existence of hidden rename log entri...
Create User objects.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Provide primary and replica IDatabase connections.
Interface for database access objects.