Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
GlobalRenameUserValidator | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validate | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CentralAuth\GlobalRename; |
4 | |
5 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
6 | use MediaWiki\Status\Status; |
7 | use MediaWiki\User\UserIdentity; |
8 | use MediaWiki\User\UserNameUtils; |
9 | |
10 | /** |
11 | * Verify whether a potential global rename is valid |
12 | * |
13 | * @license GPL-2.0-or-later |
14 | * @author Marius Hoch < hoo@online.de > |
15 | */ |
16 | class GlobalRenameUserValidator { |
17 | /** @var UserNameUtils */ |
18 | private $userNameUtils; |
19 | |
20 | /** |
21 | * @param UserNameUtils $userNameUtils |
22 | */ |
23 | public function __construct( UserNameUtils $userNameUtils ) { |
24 | $this->userNameUtils = $userNameUtils; |
25 | } |
26 | |
27 | /** |
28 | * Check that we can perform the rename |
29 | * |
30 | * @param UserIdentity $oldUser |
31 | * @param UserIdentity $newUser |
32 | * |
33 | * @return Status |
34 | */ |
35 | public function validate( UserIdentity $oldUser, UserIdentity $newUser ) { |
36 | $status = new Status(); |
37 | |
38 | if ( !$this->userNameUtils->isCreatable( $newUser->getName() ) ) { |
39 | $status->fatal( 'centralauth-rename-badusername' ); |
40 | } |
41 | |
42 | $caOldUser = CentralAuthUser::getInstance( $oldUser ); |
43 | if ( !$caOldUser->exists() ) { |
44 | $status->fatal( 'centralauth-rename-doesnotexist' ); |
45 | } |
46 | $caNewUser = CentralAuthUser::getInstance( $newUser ); |
47 | if ( $caNewUser->exists() ) { |
48 | $status->fatal( 'centralauth-rename-alreadyexists' ); |
49 | } |
50 | |
51 | $unattached = $caNewUser->listUnattached(); |
52 | if ( $unattached ) { |
53 | $status->fatal( 'centralauth-rename-unattached-intheway' ); |
54 | } |
55 | |
56 | // Check we're not currently renaming the user |
57 | $renameState = $caOldUser->renameInProgress(); |
58 | if ( $renameState ) { |
59 | $status->fatal( 'centralauth-rename-alreadyinprogress', $renameState[1] ); |
60 | } |
61 | |
62 | return $status; |
63 | } |
64 | } |