Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
124 / 124 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
PageCommandFactory | |
100.00% |
124 / 124 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
1 | |||
newContentModelChange | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
newDeletePage | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
newMergeHistory | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
newMovePage | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
1 | |||
newRollbackPage | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
newUndeletePage | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
1 |
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 | * @author DannyS712 |
20 | */ |
21 | |
22 | namespace MediaWiki\Page; |
23 | |
24 | use BagOStuff; |
25 | use ContentModelChange; |
26 | use JobQueueGroup; |
27 | use MediaWiki\Cache\BacklinkCacheFactory; |
28 | use MediaWiki\Collation\CollationFactory; |
29 | use MediaWiki\CommentStore\CommentStore; |
30 | use MediaWiki\Config\Config; |
31 | use MediaWiki\Config\ServiceOptions; |
32 | use MediaWiki\Content\IContentHandlerFactory; |
33 | use MediaWiki\EditPage\SpamChecker; |
34 | use MediaWiki\HookContainer\HookContainer; |
35 | use MediaWiki\Linker\LinkTargetLookup; |
36 | use MediaWiki\Permissions\Authority; |
37 | use MediaWiki\Permissions\RestrictionStore; |
38 | use MediaWiki\Revision\ArchivedRevisionLookup; |
39 | use MediaWiki\Revision\RevisionStore; |
40 | use MediaWiki\Storage\PageUpdaterFactory; |
41 | use MediaWiki\Title\NamespaceInfo; |
42 | use MediaWiki\Title\Title; |
43 | use MediaWiki\Title\TitleFactory; |
44 | use MediaWiki\Title\TitleFormatter; |
45 | use MediaWiki\User\ActorMigration; |
46 | use MediaWiki\User\ActorNormalization; |
47 | use MediaWiki\User\UserEditTracker; |
48 | use MediaWiki\User\UserFactory; |
49 | use MediaWiki\User\UserIdentity; |
50 | use Psr\Log\LoggerInterface; |
51 | use RepoGroup; |
52 | use WatchedItemStoreInterface; |
53 | use Wikimedia\Message\ITextFormatter; |
54 | use Wikimedia\Rdbms\LBFactory; |
55 | use Wikimedia\Rdbms\ReadOnlyMode; |
56 | use WikiPage; |
57 | |
58 | /** |
59 | * Implementation of various page action services. |
60 | * |
61 | * @internal |
62 | */ |
63 | class PageCommandFactory implements |
64 | ContentModelChangeFactory, |
65 | DeletePageFactory, |
66 | MergeHistoryFactory, |
67 | MovePageFactory, |
68 | RollbackPageFactory, |
69 | UndeletePageFactory |
70 | { |
71 | |
72 | /** @var Config */ |
73 | private $config; |
74 | |
75 | /** @var LBFactory */ |
76 | private $lbFactory; |
77 | |
78 | /** @var NamespaceInfo */ |
79 | private $namespaceInfo; |
80 | |
81 | /** @var WatchedItemStoreInterface */ |
82 | private $watchedItemStore; |
83 | |
84 | /** @var RepoGroup */ |
85 | private $repoGroup; |
86 | |
87 | /** @var ReadOnlyMode */ |
88 | private $readOnlyMode; |
89 | |
90 | /** @var IContentHandlerFactory */ |
91 | private $contentHandlerFactory; |
92 | |
93 | /** @var RevisionStore */ |
94 | private $revisionStore; |
95 | |
96 | /** @var SpamChecker */ |
97 | private $spamChecker; |
98 | |
99 | /** @var TitleFormatter */ |
100 | private $titleFormatter; |
101 | |
102 | /** @var HookContainer */ |
103 | private $hookContainer; |
104 | |
105 | /** @var WikiPageFactory */ |
106 | private $wikiPageFactory; |
107 | |
108 | /** @var UserFactory */ |
109 | private $userFactory; |
110 | |
111 | /** @var ActorMigration */ |
112 | private $actorMigration; |
113 | |
114 | /** @var ActorNormalization */ |
115 | private $actorNormalization; |
116 | |
117 | /** @var TitleFactory */ |
118 | private $titleFactory; |
119 | |
120 | /** @var UserEditTracker */ |
121 | private $userEditTracker; |
122 | |
123 | /** @var CollationFactory */ |
124 | private $collationFactory; |
125 | |
126 | /** @var JobQueueGroup */ |
127 | private $jobQueueGroup; |
128 | |
129 | /** @var CommentStore */ |
130 | private $commentStore; |
131 | |
132 | /** @var BagOStuff */ |
133 | private $mainStash; |
134 | |
135 | /** @var string */ |
136 | private $localWikiID; |
137 | |
138 | /** @var string */ |
139 | private $webRequestID; |
140 | |
141 | /** @var BacklinkCacheFactory */ |
142 | private $backlinkCacheFactory; |
143 | |
144 | /** @var LoggerInterface */ |
145 | private $undeletePageLogger; |
146 | |
147 | /** @var PageUpdaterFactory */ |
148 | private $pageUpdaterFactory; |
149 | |
150 | /** @var ITextFormatter */ |
151 | private $contLangMsgTextFormatter; |
152 | |
153 | /** @var ArchivedRevisionLookup */ |
154 | private $archivedRevisionLookup; |
155 | |
156 | /** @var RestrictionStore */ |
157 | private $restrictionStore; |
158 | private LinkTargetLookup $linkTargetLookup; |
159 | |
160 | public function __construct( |
161 | Config $config, |
162 | LBFactory $lbFactory, |
163 | NamespaceInfo $namespaceInfo, |
164 | WatchedItemStoreInterface $watchedItemStore, |
165 | RepoGroup $repoGroup, |
166 | ReadOnlyMode $readOnlyMode, |
167 | IContentHandlerFactory $contentHandlerFactory, |
168 | RevisionStore $revisionStore, |
169 | SpamChecker $spamChecker, |
170 | TitleFormatter $titleFormatter, |
171 | HookContainer $hookContainer, |
172 | WikiPageFactory $wikiPageFactory, |
173 | UserFactory $userFactory, |
174 | ActorMigration $actorMigration, |
175 | ActorNormalization $actorNormalization, |
176 | TitleFactory $titleFactory, |
177 | UserEditTracker $userEditTracker, |
178 | CollationFactory $collationFactory, |
179 | JobQueueGroup $jobQueueGroup, |
180 | CommentStore $commentStore, |
181 | BagOStuff $mainStash, |
182 | string $localWikiID, |
183 | string $webRequestID, |
184 | BacklinkCacheFactory $backlinkCacheFactory, |
185 | LoggerInterface $undeletePageLogger, |
186 | PageUpdaterFactory $pageUpdaterFactory, |
187 | ITextFormatter $contLangMsgTextFormatter, |
188 | ArchivedRevisionLookup $archivedRevisionLookup, |
189 | RestrictionStore $restrictionStore, |
190 | LinkTargetLookup $linkTargetLookup |
191 | ) { |
192 | $this->config = $config; |
193 | $this->lbFactory = $lbFactory; |
194 | $this->namespaceInfo = $namespaceInfo; |
195 | $this->watchedItemStore = $watchedItemStore; |
196 | $this->repoGroup = $repoGroup; |
197 | $this->readOnlyMode = $readOnlyMode; |
198 | $this->contentHandlerFactory = $contentHandlerFactory; |
199 | $this->revisionStore = $revisionStore; |
200 | $this->spamChecker = $spamChecker; |
201 | $this->titleFormatter = $titleFormatter; |
202 | $this->hookContainer = $hookContainer; |
203 | $this->wikiPageFactory = $wikiPageFactory; |
204 | $this->userFactory = $userFactory; |
205 | $this->actorMigration = $actorMigration; |
206 | $this->actorNormalization = $actorNormalization; |
207 | $this->titleFactory = $titleFactory; |
208 | $this->userEditTracker = $userEditTracker; |
209 | $this->collationFactory = $collationFactory; |
210 | $this->jobQueueGroup = $jobQueueGroup; |
211 | $this->commentStore = $commentStore; |
212 | $this->mainStash = $mainStash; |
213 | $this->localWikiID = $localWikiID; |
214 | $this->webRequestID = $webRequestID; |
215 | $this->backlinkCacheFactory = $backlinkCacheFactory; |
216 | $this->undeletePageLogger = $undeletePageLogger; |
217 | $this->pageUpdaterFactory = $pageUpdaterFactory; |
218 | $this->contLangMsgTextFormatter = $contLangMsgTextFormatter; |
219 | $this->archivedRevisionLookup = $archivedRevisionLookup; |
220 | $this->restrictionStore = $restrictionStore; |
221 | $this->linkTargetLookup = $linkTargetLookup; |
222 | } |
223 | |
224 | /** |
225 | * @param Authority $performer |
226 | * @param WikiPage $wikipage |
227 | * @param string $newContentModel |
228 | * @return ContentModelChange |
229 | */ |
230 | public function newContentModelChange( |
231 | Authority $performer, |
232 | WikiPage $wikipage, |
233 | string $newContentModel |
234 | ): ContentModelChange { |
235 | return new ContentModelChange( |
236 | $this->contentHandlerFactory, |
237 | $this->hookContainer, |
238 | $this->revisionStore, |
239 | $this->userFactory, |
240 | $performer, |
241 | $wikipage, |
242 | $newContentModel |
243 | ); |
244 | } |
245 | |
246 | /** |
247 | * @inheritDoc |
248 | */ |
249 | public function newDeletePage( ProperPageIdentity $page, Authority $deleter ): DeletePage { |
250 | return new DeletePage( |
251 | $this->hookContainer, |
252 | $this->revisionStore, |
253 | $this->lbFactory, |
254 | $this->jobQueueGroup, |
255 | $this->commentStore, |
256 | new ServiceOptions( DeletePage::CONSTRUCTOR_OPTIONS, $this->config ), |
257 | $this->mainStash, |
258 | $this->localWikiID, |
259 | $this->webRequestID, |
260 | $this->wikiPageFactory, |
261 | $this->userFactory, |
262 | $this->backlinkCacheFactory, |
263 | $this->namespaceInfo, |
264 | $this->contLangMsgTextFormatter, |
265 | $page, |
266 | $deleter |
267 | ); |
268 | } |
269 | |
270 | /** |
271 | * @param PageIdentity $source |
272 | * @param PageIdentity $destination |
273 | * @param string|null $timestamp |
274 | * @return MergeHistory |
275 | */ |
276 | public function newMergeHistory( |
277 | PageIdentity $source, |
278 | PageIdentity $destination, |
279 | string $timestamp = null |
280 | ): MergeHistory { |
281 | return new MergeHistory( |
282 | $source, |
283 | $destination, |
284 | $timestamp, |
285 | $this->lbFactory, |
286 | $this->contentHandlerFactory, |
287 | $this->revisionStore, |
288 | $this->watchedItemStore, |
289 | $this->spamChecker, |
290 | $this->hookContainer, |
291 | $this->wikiPageFactory, |
292 | $this->titleFormatter, |
293 | $this->titleFactory, |
294 | $this->linkTargetLookup |
295 | ); |
296 | } |
297 | |
298 | /** |
299 | * @param Title $from |
300 | * @param Title $to |
301 | * @return MovePage |
302 | */ |
303 | public function newMovePage( Title $from, Title $to ): MovePage { |
304 | return new MovePage( |
305 | $from, |
306 | $to, |
307 | new ServiceOptions( MovePage::CONSTRUCTOR_OPTIONS, $this->config ), |
308 | $this->lbFactory, |
309 | $this->namespaceInfo, |
310 | $this->watchedItemStore, |
311 | $this->repoGroup, |
312 | $this->contentHandlerFactory, |
313 | $this->revisionStore, |
314 | $this->spamChecker, |
315 | $this->hookContainer, |
316 | $this->wikiPageFactory, |
317 | $this->userFactory, |
318 | $this->userEditTracker, |
319 | $this, |
320 | $this->collationFactory, |
321 | $this->pageUpdaterFactory, |
322 | $this->restrictionStore |
323 | ); |
324 | } |
325 | |
326 | /** |
327 | * Create a new command instance for page rollback. |
328 | * |
329 | * @param PageIdentity $page |
330 | * @param Authority $performer |
331 | * @param UserIdentity $byUser |
332 | * @return RollbackPage |
333 | */ |
334 | public function newRollbackPage( |
335 | PageIdentity $page, |
336 | Authority $performer, |
337 | UserIdentity $byUser |
338 | ): RollbackPage { |
339 | return new RollbackPage( |
340 | new ServiceOptions( RollbackPage::CONSTRUCTOR_OPTIONS, $this->config ), |
341 | $this->lbFactory, |
342 | $this->userFactory, |
343 | $this->readOnlyMode, |
344 | $this->revisionStore, |
345 | $this->titleFormatter, |
346 | $this->hookContainer, |
347 | $this->wikiPageFactory, |
348 | $this->actorMigration, |
349 | $this->actorNormalization, |
350 | $page, |
351 | $performer, |
352 | $byUser |
353 | ); |
354 | } |
355 | |
356 | /** |
357 | * @inheritDoc |
358 | */ |
359 | public function newUndeletePage( ProperPageIdentity $page, Authority $authority ): UndeletePage { |
360 | return new UndeletePage( |
361 | $this->hookContainer, |
362 | $this->jobQueueGroup, |
363 | $this->lbFactory, |
364 | $this->readOnlyMode, |
365 | $this->repoGroup, |
366 | $this->undeletePageLogger, |
367 | $this->revisionStore, |
368 | $this->wikiPageFactory, |
369 | $this->pageUpdaterFactory, |
370 | $this->contentHandlerFactory, |
371 | $this->archivedRevisionLookup, |
372 | $this->namespaceInfo, |
373 | $this->contLangMsgTextFormatter, |
374 | $page, |
375 | $authority |
376 | ); |
377 | } |
378 | } |