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