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.
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.
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
21 namespace MediaWiki\Storage
;
25 use MediaWiki\Config\ServiceOptions
;
26 use MediaWiki\Content\IContentHandlerFactory
;
27 use MediaWiki\Content\Transform\ContentTransformer
;
28 use MediaWiki\HookContainer\HookContainer
;
29 use MediaWiki\MainConfigNames
;
30 use MediaWiki\Page\PageIdentity
;
31 use MediaWiki\Page\WikiPageFactory
;
32 use MediaWiki\Parser\Parsoid\ParsoidOutputAccess
;
33 use MediaWiki\Permissions\PermissionManager
;
34 use MediaWiki\Revision\RevisionRenderer
;
35 use MediaWiki\Revision\RevisionStore
;
36 use MediaWiki\Revision\SlotRoleRegistry
;
37 use MediaWiki\User\TalkPageNotificationManager
;
38 use MediaWiki\User\UserEditTracker
;
39 use MediaWiki\User\UserGroupManager
;
40 use MediaWiki\User\UserIdentity
;
41 use MediaWiki\User\UserNameUtils
;
44 use Psr\Log\LoggerInterface
;
47 use Wikimedia\Rdbms\ILBFactory
;
51 * A factory for PageUpdater and DerivedPageDataUpdater instances.
56 class PageUpdaterFactory
{
59 * Options that have to be present in the ServiceOptions object passed to the constructor.
60 * @note must include PageUpdater::CONSTRUCTOR_OPTIONS
63 public const CONSTRUCTOR_OPTIONS
= [
64 MainConfigNames
::ArticleCountMethod
,
65 MainConfigNames
::RCWatchCategoryMembership
,
66 MainConfigNames
::PageCreationLog
,
67 MainConfigNames
::UseAutomaticEditSummaries
,
68 MainConfigNames
::ManualRevertSearchRadius
,
69 MainConfigNames
::UseRCPatrol
,
70 MainConfigNames
::ParsoidCacheConfig
,
73 /** @var RevisionStore */
74 private $revisionStore;
76 /** @var RevisionRenderer */
77 private $revisionRenderer;
79 /** @var SlotRoleRegistry */
80 private $slotRoleRegistry;
82 /** @var ParserCache */
85 /** @var JobQueueGroup */
86 private $jobQueueGroup;
88 /** @var MessageCache */
89 private $messageCache;
94 /** @var ILBFactory */
95 private $loadbalancerFactory;
97 /** @var IContentHandlerFactory */
98 private $contentHandlerFactory;
100 /** @var HookContainer */
101 private $hookContainer;
103 /** @var EditResultCache */
104 private $editResultCache;
106 /** @var UserNameUtils */
107 private $userNameUtils;
109 /** @var LoggerInterface */
112 /** @var ServiceOptions */
115 /** @var UserEditTracker */
116 private $userEditTracker;
118 /** @var UserGroupManager */
119 private $userGroupManager;
121 /** @var TitleFormatter */
122 private $titleFormatter;
124 /** @var ContentTransformer */
125 private $contentTransformer;
127 /** @var PageEditStash */
128 private $pageEditStash;
130 /** @var TalkPageNotificationManager */
131 private $talkPageNotificationManager;
133 /** @var WANObjectCache */
134 private $mainWANObjectCache;
136 /** @var PermissionManager */
137 private $permissionManager;
139 /** @var WikiPageFactory */
140 private $wikiPageFactory;
143 private $softwareTags;
145 /** @var ParsoidOutputAccess */
146 private $parsoidOutputAccess;
149 * @param RevisionStore $revisionStore
150 * @param RevisionRenderer $revisionRenderer
151 * @param SlotRoleRegistry $slotRoleRegistry
152 * @param ParserCache $parserCache
153 * @param ParsoidOutputAccess $parsoidOutputAccess
154 * @param JobQueueGroup $jobQueueGroup
155 * @param MessageCache $messageCache
156 * @param Language $contLang
157 * @param ILBFactory $loadbalancerFactory
158 * @param IContentHandlerFactory $contentHandlerFactory
159 * @param HookContainer $hookContainer
160 * @param EditResultCache $editResultCache
161 * @param UserNameUtils $userNameUtils
162 * @param LoggerInterface $logger
163 * @param ServiceOptions $options
164 * @param UserEditTracker $userEditTracker
165 * @param UserGroupManager $userGroupManager
166 * @param TitleFormatter $titleFormatter
167 * @param ContentTransformer $contentTransformer
168 * @param PageEditStash $pageEditStash
169 * @param TalkPageNotificationManager $talkPageNotificationManager
170 * @param WANObjectCache $mainWANObjectCache
171 * @param PermissionManager $permissionManager
172 * @param WikiPageFactory $wikiPageFactory
173 * @param string[] $softwareTags
175 public function __construct(
176 RevisionStore
$revisionStore,
177 RevisionRenderer
$revisionRenderer,
178 SlotRoleRegistry
$slotRoleRegistry,
179 ParserCache
$parserCache,
180 ParsoidOutputAccess
$parsoidOutputAccess,
181 JobQueueGroup
$jobQueueGroup,
182 MessageCache
$messageCache,
184 ILBFactory
$loadbalancerFactory,
185 IContentHandlerFactory
$contentHandlerFactory,
186 HookContainer
$hookContainer,
187 EditResultCache
$editResultCache,
188 UserNameUtils
$userNameUtils,
189 LoggerInterface
$logger,
190 ServiceOptions
$options,
191 UserEditTracker
$userEditTracker,
192 UserGroupManager
$userGroupManager,
193 TitleFormatter
$titleFormatter,
194 ContentTransformer
$contentTransformer,
195 PageEditStash
$pageEditStash,
196 TalkPageNotificationManager
$talkPageNotificationManager,
197 WANObjectCache
$mainWANObjectCache,
198 PermissionManager
$permissionManager,
199 WikiPageFactory
$wikiPageFactory,
202 $options->assertRequiredOptions( self
::CONSTRUCTOR_OPTIONS
);
204 $this->revisionStore
= $revisionStore;
205 $this->revisionRenderer
= $revisionRenderer;
206 $this->slotRoleRegistry
= $slotRoleRegistry;
207 $this->parserCache
= $parserCache;
208 $this->parsoidOutputAccess
= $parsoidOutputAccess;
209 $this->jobQueueGroup
= $jobQueueGroup;
210 $this->messageCache
= $messageCache;
211 $this->contLang
= $contLang;
212 $this->loadbalancerFactory
= $loadbalancerFactory;
213 $this->contentHandlerFactory
= $contentHandlerFactory;
214 $this->hookContainer
= $hookContainer;
215 $this->editResultCache
= $editResultCache;
216 $this->userNameUtils
= $userNameUtils;
217 $this->logger
= $logger;
218 $this->options
= $options;
219 $this->userEditTracker
= $userEditTracker;
220 $this->userGroupManager
= $userGroupManager;
221 $this->titleFormatter
= $titleFormatter;
222 $this->contentTransformer
= $contentTransformer;
223 $this->pageEditStash
= $pageEditStash;
224 $this->talkPageNotificationManager
= $talkPageNotificationManager;
225 $this->mainWANObjectCache
= $mainWANObjectCache;
226 $this->permissionManager
= $permissionManager;
227 $this->softwareTags
= $softwareTags;
228 $this->wikiPageFactory
= $wikiPageFactory;
232 * Return a PageUpdater for building an update to a page.
234 * @internal For now, most code should keep using WikiPage::newPageUpdater() instead.
235 * @note We can only start using this method everywhere when WikiPage::prepareContentForEdit()
236 * and WikiPage::getCurrentUpdate() have been removed. For now, the WikiPage instance is
237 * used to make the state of an ongoing edit available to hook handlers.
239 * @param PageIdentity $page
240 * @param UserIdentity $user
242 * @return PageUpdater
245 public function newPageUpdater(
249 $page = $this->wikiPageFactory
->newFromTitle( $page );
251 return $this->newPageUpdaterForDerivedPageDataUpdater(
254 $this->newDerivedPageDataUpdater( $page )
259 * Return a PageUpdater for building an update to a page, reusing the state of
260 * an existing DerivedPageDataUpdater.
262 * @param WikiPage $page
263 * @param UserIdentity $user
264 * @param DerivedPageDataUpdater $derivedPageDataUpdater
266 * @return PageUpdater
267 * @internal needed by WikiPage to back the WikiPage::newPageUpdater method.
271 public function newPageUpdaterForDerivedPageDataUpdater(
274 DerivedPageDataUpdater
$derivedPageDataUpdater
276 $pageUpdater = new PageUpdater(
278 $page, // NOTE: eventually, PageUpdater should not know about WikiPage
279 $derivedPageDataUpdater,
280 $this->loadbalancerFactory
,
281 $this->revisionStore
,
282 $this->slotRoleRegistry
,
283 $this->contentHandlerFactory
,
284 $this->hookContainer
,
285 $this->userEditTracker
,
286 $this->userGroupManager
,
287 $this->titleFormatter
,
289 PageUpdater
::CONSTRUCTOR_OPTIONS
,
296 $pageUpdater->setUsePageCreationLog(
297 $this->options
->get( MainConfigNames
::PageCreationLog
) );
298 $pageUpdater->setUseAutomaticEditSummaries(
299 $this->options
->get( MainConfigNames
::UseAutomaticEditSummaries
)
306 * @param WikiPage $page
308 * @return DerivedPageDataUpdater
309 * @internal Needed by WikiPage to back the deprecated prepareContentForEdit() method.
310 * @note Avoid direct usage of DerivedPageDataUpdater.
311 * @see docs/pageupdater.md for more information.
313 public function newDerivedPageDataUpdater( WikiPage
$page ): DerivedPageDataUpdater
{
314 $derivedDataUpdater = new DerivedPageDataUpdater(
316 $page, // NOTE: eventually, PageUpdater should not know about WikiPage
317 $this->revisionStore
,
318 $this->revisionRenderer
,
319 $this->slotRoleRegistry
,
321 $this->parsoidOutputAccess
,
322 $this->jobQueueGroup
,
325 $this->loadbalancerFactory
,
326 $this->contentHandlerFactory
,
327 $this->hookContainer
,
328 $this->editResultCache
,
329 $this->userNameUtils
,
330 $this->contentTransformer
,
331 $this->pageEditStash
,
332 $this->talkPageNotificationManager
,
333 $this->mainWANObjectCache
,
334 $this->permissionManager
337 $derivedDataUpdater->setLogger( $this->logger
);
338 $derivedDataUpdater->setArticleCountMethod(
339 $this->options
->get( MainConfigNames
::ArticleCountMethod
) );
340 $derivedDataUpdater->setRcWatchCategoryMembership(
341 $this->options
->get( MainConfigNames
::RCWatchCategoryMembership
)
344 return $derivedDataUpdater;