Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 78 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
UserBlockCommandFactory | |
0.00% |
0 / 78 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
newBlockUser | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
2 | |||
newUpdateBlock | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
2 | |||
newUnblockUser | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
newRemoveBlock | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * http://www.gnu.org/copyleft/gpl.html |
18 | * |
19 | * @file |
20 | */ |
21 | |
22 | namespace MediaWiki\Block; |
23 | |
24 | use MediaWiki\Config\ServiceOptions; |
25 | use MediaWiki\HookContainer\HookContainer; |
26 | use MediaWiki\Permissions\Authority; |
27 | use MediaWiki\Title\TitleFactory; |
28 | use MediaWiki\User\UserEditTracker; |
29 | use MediaWiki\User\UserFactory; |
30 | use MediaWiki\User\UserIdentity; |
31 | use Psr\Log\LoggerInterface; |
32 | |
33 | class UserBlockCommandFactory implements BlockUserFactory, UnblockUserFactory { |
34 | private BlockPermissionCheckerFactory $blockPermissionCheckerFactory; |
35 | private BlockTargetFactory $blockTargetFactory; |
36 | private HookContainer $hookContainer; |
37 | private BlockRestrictionStore $blockRestrictionStore; |
38 | private ServiceOptions $options; |
39 | private DatabaseBlockStore $blockStore; |
40 | private UserFactory $userFactory; |
41 | private UserEditTracker $userEditTracker; |
42 | private LoggerInterface $logger; |
43 | private TitleFactory $titleFactory; |
44 | private BlockActionInfo $blockActionInfo; |
45 | |
46 | /** |
47 | * @internal Use only in ServiceWiring |
48 | */ |
49 | public const CONSTRUCTOR_OPTIONS = BlockUser::CONSTRUCTOR_OPTIONS; |
50 | |
51 | public function __construct( |
52 | ServiceOptions $options, |
53 | HookContainer $hookContainer, |
54 | BlockPermissionCheckerFactory $blockPermissionCheckerFactory, |
55 | BlockTargetFactory $blockTargetFactory, |
56 | DatabaseBlockStore $blockStore, |
57 | BlockRestrictionStore $blockRestrictionStore, |
58 | UserFactory $userFactory, |
59 | UserEditTracker $userEditTracker, |
60 | LoggerInterface $logger, |
61 | TitleFactory $titleFactory, |
62 | BlockActionInfo $blockActionInfo |
63 | ) { |
64 | $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
65 | |
66 | $this->options = $options; |
67 | $this->hookContainer = $hookContainer; |
68 | $this->blockPermissionCheckerFactory = $blockPermissionCheckerFactory; |
69 | $this->blockTargetFactory = $blockTargetFactory; |
70 | $this->blockStore = $blockStore; |
71 | $this->blockRestrictionStore = $blockRestrictionStore; |
72 | $this->userFactory = $userFactory; |
73 | $this->userEditTracker = $userEditTracker; |
74 | $this->logger = $logger; |
75 | $this->titleFactory = $titleFactory; |
76 | $this->blockActionInfo = $blockActionInfo; |
77 | } |
78 | |
79 | /** |
80 | * Create BlockUser |
81 | * |
82 | * @param BlockTarget|string|UserIdentity $target Target of the block |
83 | * @param Authority $performer Performer of the block |
84 | * @param string $expiry Expiry of the block (timestamp or 'infinity') |
85 | * @param string $reason Reason of the block |
86 | * @param array $blockOptions |
87 | * @param array $blockRestrictions |
88 | * @param array|null $tags Tags that should be assigned to the log entry |
89 | * |
90 | * @return BlockUser |
91 | */ |
92 | public function newBlockUser( |
93 | $target, |
94 | Authority $performer, |
95 | string $expiry, |
96 | string $reason = '', |
97 | array $blockOptions = [], |
98 | array $blockRestrictions = [], |
99 | $tags = [] |
100 | ): BlockUser { |
101 | return new BlockUser( |
102 | $this->options, |
103 | $this->blockRestrictionStore, |
104 | $this->blockPermissionCheckerFactory, |
105 | $this->blockTargetFactory, |
106 | $this->blockActionInfo, |
107 | $this->hookContainer, |
108 | $this->blockStore, |
109 | $this->userFactory, |
110 | $this->userEditTracker, |
111 | $this->logger, |
112 | $this->titleFactory, |
113 | null, |
114 | $target, |
115 | $performer, |
116 | $expiry, |
117 | $reason, |
118 | $blockOptions, |
119 | $blockRestrictions, |
120 | $tags ?? [] |
121 | ); |
122 | } |
123 | |
124 | /** |
125 | * Create a BlockUser which updates a specified block |
126 | * |
127 | * @since 1.44 |
128 | * |
129 | * @param DatabaseBlock $block |
130 | * @param Authority $performer Performer of the block |
131 | * @param string $expiry New expiry of the block (timestamp or 'infinity') |
132 | * @param string $reason Reason of the block |
133 | * @param array $blockOptions |
134 | * @param array $blockRestrictions |
135 | * @param array|null $tags Tags that should be assigned to the log entry |
136 | * @return BlockUser |
137 | */ |
138 | public function newUpdateBlock( |
139 | DatabaseBlock $block, |
140 | Authority $performer, |
141 | string $expiry, |
142 | string $reason = '', |
143 | array $blockOptions = [], |
144 | array $blockRestrictions = [], |
145 | $tags = [] |
146 | ): BlockUser { |
147 | return new BlockUser( |
148 | $this->options, |
149 | $this->blockRestrictionStore, |
150 | $this->blockPermissionCheckerFactory, |
151 | $this->blockTargetFactory, |
152 | $this->blockActionInfo, |
153 | $this->hookContainer, |
154 | $this->blockStore, |
155 | $this->userFactory, |
156 | $this->userEditTracker, |
157 | $this->logger, |
158 | $this->titleFactory, |
159 | $block, |
160 | null, |
161 | $performer, |
162 | $expiry, |
163 | $reason, |
164 | $blockOptions, |
165 | $blockRestrictions, |
166 | $tags ?? [] |
167 | ); |
168 | } |
169 | |
170 | /** |
171 | * Creates UnblockUser |
172 | * |
173 | * @since 1.44 |
174 | * |
175 | * @param BlockTarget|UserIdentity|string $target |
176 | * @param Authority $performer |
177 | * @param string $reason |
178 | * @param string[] $tags |
179 | * |
180 | * @return UnblockUser |
181 | */ |
182 | public function newUnblockUser( |
183 | $target, |
184 | Authority $performer, |
185 | string $reason, |
186 | array $tags = [] |
187 | ): UnblockUser { |
188 | return new UnblockUser( |
189 | $this->blockPermissionCheckerFactory, |
190 | $this->blockStore, |
191 | $this->blockTargetFactory, |
192 | $this->userFactory, |
193 | $this->hookContainer, |
194 | null, |
195 | $target, |
196 | $performer, |
197 | $reason, |
198 | $tags |
199 | ); |
200 | } |
201 | |
202 | /** |
203 | * Creates UnblockUser to remove a specific block |
204 | * |
205 | * @param DatabaseBlock $block |
206 | * @param Authority $performer |
207 | * @param string $reason |
208 | * @param array $tags |
209 | * |
210 | * @return UnblockUser |
211 | */ |
212 | public function newRemoveBlock( |
213 | DatabaseBlock $block, |
214 | Authority $performer, |
215 | string $reason, |
216 | array $tags = [] |
217 | ): UnblockUser { |
218 | return new UnblockUser( |
219 | $this->blockPermissionCheckerFactory, |
220 | $this->blockStore, |
221 | $this->blockTargetFactory, |
222 | $this->userFactory, |
223 | $this->hookContainer, |
224 | $block, |
225 | null, |
226 | $performer, |
227 | $reason, |
228 | $tags |
229 | ); |
230 | } |
231 | } |