Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
96.43% |
27 / 28 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
UserGroupManagerFactory | |
96.43% |
27 / 28 |
|
50.00% |
1 / 2 |
5 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
getUserGroupManager | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
4.00 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\User; |
22 | |
23 | use MediaWiki\Config\ServiceOptions; |
24 | use MediaWiki\HookContainer\HookContainer; |
25 | use MediaWiki\JobQueue\JobQueueGroupFactory; |
26 | use MediaWiki\Permissions\GroupPermissionsLookup; |
27 | use MediaWiki\User\TempUser\TempUserConfig; |
28 | use Psr\Log\LoggerInterface; |
29 | use Wikimedia\Rdbms\ILBFactory; |
30 | use Wikimedia\Rdbms\ReadOnlyMode; |
31 | |
32 | /** |
33 | * Factory service for UserGroupManager instances. This allows UserGroupManager to be created for |
34 | * cross-wiki access. |
35 | * |
36 | * @since 1.35 |
37 | */ |
38 | class UserGroupManagerFactory { |
39 | private ServiceOptions $options; |
40 | private ReadOnlyMode $readOnlyMode; |
41 | private ILBFactory $dbLoadBalancerFactory; |
42 | private UserEditTracker $userEditTracker; |
43 | private GroupPermissionsLookup $groupPermissionLookup; |
44 | private JobQueueGroupFactory $jobQueueGroupFactory; |
45 | private LoggerInterface $logger; |
46 | |
47 | /** @var callable[] */ |
48 | private $clearCacheCallbacks; |
49 | |
50 | private HookContainer $hookContainer; |
51 | private TempUserConfig $tempUserConfig; |
52 | |
53 | /** |
54 | * @var UserGroupManager[] User group manager instances indexed by wiki |
55 | */ |
56 | private $instances = []; |
57 | |
58 | /** |
59 | * @param ServiceOptions $options |
60 | * @param ReadOnlyMode $readOnlyMode |
61 | * @param ILBFactory $dbLoadBalancerFactory |
62 | * @param HookContainer $hookContainer |
63 | * @param UserEditTracker $userEditTracker |
64 | * @param GroupPermissionsLookup $groupPermissionsLookup |
65 | * @param JobQueueGroupFactory $jobQueueGroupFactory |
66 | * @param LoggerInterface $logger |
67 | * @param TempUserConfig $tempUserConfig Assumed to be the same across all domains. |
68 | * @param callable[] $clearCacheCallbacks |
69 | */ |
70 | public function __construct( |
71 | ServiceOptions $options, |
72 | ReadOnlyMode $readOnlyMode, |
73 | ILBFactory $dbLoadBalancerFactory, |
74 | HookContainer $hookContainer, |
75 | UserEditTracker $userEditTracker, |
76 | GroupPermissionsLookup $groupPermissionsLookup, |
77 | JobQueueGroupFactory $jobQueueGroupFactory, |
78 | LoggerInterface $logger, |
79 | TempUserConfig $tempUserConfig, |
80 | array $clearCacheCallbacks = [] |
81 | ) { |
82 | $this->options = $options; |
83 | $this->readOnlyMode = $readOnlyMode; |
84 | $this->dbLoadBalancerFactory = $dbLoadBalancerFactory; |
85 | $this->hookContainer = $hookContainer; |
86 | $this->userEditTracker = $userEditTracker; |
87 | $this->groupPermissionLookup = $groupPermissionsLookup; |
88 | $this->jobQueueGroupFactory = $jobQueueGroupFactory; |
89 | $this->logger = $logger; |
90 | $this->tempUserConfig = $tempUserConfig; |
91 | $this->clearCacheCallbacks = $clearCacheCallbacks; |
92 | } |
93 | |
94 | /** |
95 | * @param string|false $wikiId |
96 | * @return UserGroupManager |
97 | */ |
98 | public function getUserGroupManager( $wikiId = UserIdentity::LOCAL ): UserGroupManager { |
99 | if ( is_string( $wikiId ) && $this->dbLoadBalancerFactory->getLocalDomainID() === $wikiId ) { |
100 | $wikiId = UserIdentity::LOCAL; |
101 | } |
102 | $key = (string)$wikiId; |
103 | if ( !isset( $this->instances[$key] ) ) { |
104 | $this->instances[$key] = new UserGroupManager( |
105 | $this->options, |
106 | $this->readOnlyMode, |
107 | $this->dbLoadBalancerFactory, |
108 | $this->hookContainer, |
109 | $this->userEditTracker, |
110 | $this->groupPermissionLookup, |
111 | $this->jobQueueGroupFactory->makeJobQueueGroup( $wikiId ), |
112 | $this->logger, |
113 | $this->tempUserConfig, |
114 | $this->clearCacheCallbacks, |
115 | $wikiId |
116 | ); |
117 | } |
118 | return $this->instances[$key]; |
119 | } |
120 | } |