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