Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| RenameUserFactory | |
0.00% |
0 / 41 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| newRenameUser | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| newDerivedRenameUser | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\RenameUser; |
| 4 | |
| 5 | use MediaWiki\Config\ServiceOptions; |
| 6 | use MediaWiki\JobQueue\JobQueueGroupFactory; |
| 7 | use MediaWiki\Page\MovePageFactory; |
| 8 | use MediaWiki\Permissions\PermissionManager; |
| 9 | use MediaWiki\Title\TitleFactory; |
| 10 | use MediaWiki\User\CentralId\CentralIdLookupFactory; |
| 11 | use MediaWiki\User\User; |
| 12 | use MediaWiki\User\UserFactory; |
| 13 | use MediaWiki\User\UserNameUtils; |
| 14 | |
| 15 | /** |
| 16 | * @since 1.44 |
| 17 | */ |
| 18 | class RenameUserFactory { |
| 19 | private ServiceOptions $options; |
| 20 | private CentralIdLookupFactory $centralIdLookupFactory; |
| 21 | private JobQueueGroupFactory $jobQueueGroupFactory; |
| 22 | private MovePageFactory $movePageFactory; |
| 23 | private UserFactory $userFactory; |
| 24 | private UserNameUtils $userNameUtils; |
| 25 | private PermissionManager $permissionManager; |
| 26 | private TitleFactory $titleFactory; |
| 27 | |
| 28 | /** |
| 29 | * @internal Use only in ServiceWiring |
| 30 | */ |
| 31 | public const CONSTRUCTOR_OPTIONS = RenameUser::CONSTRUCTOR_OPTIONS; |
| 32 | |
| 33 | public function __construct( |
| 34 | ServiceOptions $options, |
| 35 | CentralIdLookupFactory $centralIdLookupFactory, |
| 36 | JobQueueGroupFactory $jobQueueGroupFactory, |
| 37 | MovePageFactory $movePageFactory, |
| 38 | UserFactory $userFactory, |
| 39 | UserNameUtils $userNameUtils, |
| 40 | PermissionManager $permissionManager, |
| 41 | TitleFactory $titleFactory |
| 42 | ) { |
| 43 | $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
| 44 | |
| 45 | $this->options = $options; |
| 46 | $this->centralIdLookupFactory = $centralIdLookupFactory; |
| 47 | $this->movePageFactory = $movePageFactory; |
| 48 | $this->jobQueueGroupFactory = $jobQueueGroupFactory; |
| 49 | $this->userFactory = $userFactory; |
| 50 | $this->userNameUtils = $userNameUtils; |
| 51 | $this->permissionManager = $permissionManager; |
| 52 | $this->titleFactory = $titleFactory; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Creates a RenameUser for performing a new rename operation. |
| 57 | * |
| 58 | * The operation should not have been performed on any wikis yet. |
| 59 | * |
| 60 | * @param User $performer |
| 61 | * @param User $target |
| 62 | * @param string $newName |
| 63 | * @param string $reason |
| 64 | * @param array $renameOptions |
| 65 | * @return RenameUser |
| 66 | */ |
| 67 | public function newRenameUser( |
| 68 | User $performer, |
| 69 | $target, |
| 70 | string $newName, |
| 71 | string $reason, |
| 72 | array $renameOptions = [] |
| 73 | ): RenameUser { |
| 74 | return new RenameUser( |
| 75 | $this->options, |
| 76 | $this->centralIdLookupFactory, |
| 77 | $this->jobQueueGroupFactory, |
| 78 | $this->movePageFactory, |
| 79 | $this->userFactory, |
| 80 | $this->userNameUtils, |
| 81 | $this->permissionManager, |
| 82 | $this->titleFactory, |
| 83 | $performer, |
| 84 | $target, |
| 85 | $target->getName(), |
| 86 | $newName, |
| 87 | $reason, |
| 88 | $renameOptions |
| 89 | ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Creates a RenameUser for performing a local rename operation derived from a global rename. |
| 94 | * |
| 95 | * The operation must have been performed on central wiki and not locally. |
| 96 | * |
| 97 | * @param User $performer |
| 98 | * @param int $uid |
| 99 | * @param string $oldName |
| 100 | * @param string $newName |
| 101 | * @param string $reason |
| 102 | * @param array $renameOptions |
| 103 | * @return RenameUser |
| 104 | */ |
| 105 | public function newDerivedRenameUser( |
| 106 | User $performer, |
| 107 | int $uid, |
| 108 | string $oldName, |
| 109 | string $newName, |
| 110 | string $reason, |
| 111 | array $renameOptions = [] |
| 112 | ): RenameUser { |
| 113 | return new RenameUser( |
| 114 | $this->options, |
| 115 | $this->centralIdLookupFactory, |
| 116 | $this->jobQueueGroupFactory, |
| 117 | $this->movePageFactory, |
| 118 | $this->userFactory, |
| 119 | $this->userNameUtils, |
| 120 | $this->permissionManager, |
| 121 | $this->titleFactory, |
| 122 | $performer, |
| 123 | $this->userFactory->newFromId( $uid ), |
| 124 | $oldName, |
| 125 | $newName, |
| 126 | $reason, |
| 127 | array_merge( $renameOptions, [ 'derived' => true ] ) |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | } |