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