1<?php 2 3/** 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 * http://www.gnu.org/copyleft/gpl.html 18 * 19 * @file 20 * @author DannyS712 21 */ 22 23namespace MediaWiki\Page; 24 25use ContentModelChange; 26use MediaWiki\Config\ServiceOptions; 27use MediaWiki\Content\IContentHandlerFactory; 28use MediaWiki\EditPage\SpamChecker; 29use MediaWiki\HookContainer\HookContainer; 30use MediaWiki\Permissions\Authority; 31use MediaWiki\Revision\RevisionStore; 32use MediaWiki\User\UserFactory; 33use MergeHistory; 34use MovePage; 35use NamespaceInfo; 36use RepoGroup; 37use Title; 38use WatchedItemStoreInterface; 39use Wikimedia\Rdbms\ILoadBalancer; 40use WikiPage; 41 42/** 43 * Common factory to construct page handling classes. 44 * 45 * @since 1.35 46 */ 47class PageCommandFactory implements ContentModelChangeFactory, MergeHistoryFactory, MovePageFactory { 48 /** @var ServiceOptions */ 49 private $options; 50 51 /** @var ILoadBalancer */ 52 private $loadBalancer; 53 54 /** @var NamespaceInfo */ 55 private $namespaceInfo; 56 57 /** @var WatchedItemStoreInterface */ 58 private $watchedItemStore; 59 60 /** @var RepoGroup */ 61 private $repoGroup; 62 63 /** @var IContentHandlerFactory */ 64 private $contentHandlerFactory; 65 66 /** @var RevisionStore */ 67 private $revisionStore; 68 69 /** @var SpamChecker */ 70 private $spamChecker; 71 72 /** @var HookContainer */ 73 private $hookContainer; 74 75 /** @var WikiPageFactory */ 76 private $wikiPageFactory; 77 78 /** @var UserFactory */ 79 private $userFactory; 80 81 /** 82 * @internal For use by ServiceWiring 83 */ 84 public const CONSTRUCTOR_OPTIONS = [ 85 'CategoryCollation', 86 'MaximumMovedPages', 87 ]; 88 89 public function __construct( 90 ServiceOptions $options, 91 ILoadBalancer $loadBalancer, 92 NamespaceInfo $namespaceInfo, 93 WatchedItemStoreInterface $watchedItemStore, 94 RepoGroup $repoGroup, 95 IContentHandlerFactory $contentHandlerFactory, 96 RevisionStore $revisionStore, 97 SpamChecker $spamChecker, 98 HookContainer $hookContainer, 99 WikiPageFactory $wikiPageFactory, 100 UserFactory $userFactory 101 ) { 102 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); 103 104 $this->options = $options; 105 $this->loadBalancer = $loadBalancer; 106 $this->namespaceInfo = $namespaceInfo; 107 $this->watchedItemStore = $watchedItemStore; 108 $this->repoGroup = $repoGroup; 109 $this->contentHandlerFactory = $contentHandlerFactory; 110 $this->revisionStore = $revisionStore; 111 $this->spamChecker = $spamChecker; 112 $this->hookContainer = $hookContainer; 113 $this->wikiPageFactory = $wikiPageFactory; 114 $this->userFactory = $userFactory; 115 } 116 117 /** 118 * @param Authority $performer 119 * @param WikiPage $wikipage 120 * @param string $newContentModel 121 * @return ContentModelChange 122 */ 123 public function newContentModelChange( 124 Authority $performer, 125 WikiPage $wikipage, 126 string $newContentModel 127 ) : ContentModelChange { 128 return new ContentModelChange( 129 $this->contentHandlerFactory, 130 $this->hookContainer, 131 $this->revisionStore, 132 $this->userFactory, 133 $performer, 134 $wikipage, 135 $newContentModel 136 ); 137 } 138 139 /** 140 * @param Title $source 141 * @param Title $destination 142 * @param string|null $timestamp 143 * @return MergeHistory 144 */ 145 public function newMergeHistory( 146 Title $source, 147 Title $destination, 148 string $timestamp = null 149 ) : MergeHistory { 150 if ( $timestamp === null ) { 151 // For compatibility with MergeHistory constructor until it can be changed 152 $timestamp = false; 153 } 154 return new MergeHistory( 155 $source, 156 $destination, 157 $timestamp, 158 $this->loadBalancer, 159 $this->contentHandlerFactory, 160 $this->revisionStore, 161 $this->watchedItemStore, 162 $this->spamChecker, 163 $this->hookContainer, 164 $this->wikiPageFactory, 165 $this->userFactory 166 ); 167 } 168 169 /** 170 * @param Title $from 171 * @param Title $to 172 * @return MovePage 173 */ 174 public function newMovePage( Title $from, Title $to ) : MovePage { 175 return new MovePage( 176 $from, 177 $to, 178 $this->options, 179 $this->loadBalancer, 180 $this->namespaceInfo, 181 $this->watchedItemStore, 182 $this->repoGroup, 183 $this->contentHandlerFactory, 184 $this->revisionStore, 185 $this->spamChecker, 186 $this->hookContainer, 187 $this->wikiPageFactory, 188 $this->userFactory 189 ); 190 } 191} 192