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