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