Debian Codegraph @

includes/Storage/PageUpdaterFactory.php

raw symbols SCIP
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 */
20
21 namespace MediaWiki\Storage;
22
23 use JobQueueGroup;
24 use MediaWiki\Config\ServiceOptions;
25 use MediaWiki\Content\IContentHandlerFactory;
26 use MediaWiki\Content\Transform\ContentTransformer;
27 use MediaWiki\HookContainer\HookContainer;
28 use MediaWiki\Language\Language;
29 use MediaWiki\MainConfigNames;
30 use MediaWiki\Page\PageIdentity;
31 use MediaWiki\Page\WikiPageFactory;
32 use MediaWiki\Parser\ParserCache;
33 use MediaWiki\Permissions\PermissionManager;
34 use MediaWiki\Revision\RevisionRenderer;
35 use MediaWiki\Revision\RevisionStore;
36 use MediaWiki\Revision\SlotRoleRegistry;
37 use MediaWiki\Title\TitleFormatter;
38 use MediaWiki\User\TalkPageNotificationManager;
39 use MediaWiki\User\UserEditTracker;
40 use MediaWiki\User\UserGroupManager;
41 use MediaWiki\User\UserIdentity;
42 use MediaWiki\User\UserNameUtils;
43 use MessageCache;
44 use Psr\Log\LoggerInterface;
45 use Wikimedia\ObjectCache\WANObjectCache;
46 use Wikimedia\Rdbms\ILBFactory;
47
48 /**
49 * A factory for PageUpdater and DerivedPageDataUpdater instances.
50 *
51 * @since 1.37
52 * @ingroup Page
53 */
54 class PageUpdaterFactory {
55
56 /**
57 * Options that have to be present in the ServiceOptions object passed to the constructor.
58 * @note must include PageUpdater::CONSTRUCTOR_OPTIONS
59 * @internal
60 */
61 public const CONSTRUCTOR_OPTIONS = [
62 MainConfigNames::ArticleCountMethod,
63 MainConfigNames::RCWatchCategoryMembership,
64 MainConfigNames::PageCreationLog,
65 MainConfigNames::UseAutomaticEditSummaries,
66 MainConfigNames::ManualRevertSearchRadius,
67 MainConfigNames::UseRCPatrol,
68 MainConfigNames::ParsoidCacheConfig,
69 ];
70
71 /** @var RevisionStore */
72 private $revisionStore;
73
74 /** @var RevisionRenderer */
75 private $revisionRenderer;
76
77 /** @var SlotRoleRegistry */
78 private $slotRoleRegistry;
79
80 /** @var ParserCache */
81 private $parserCache;
82
83 /** @var JobQueueGroup */
84 private $jobQueueGroup;
85
86 /** @var MessageCache */
87 private $messageCache;
88
89 /** @var Language */
90 private $contLang;
91
92 /** @var ILBFactory */
93 private $loadbalancerFactory;
94
95 /** @var IContentHandlerFactory */
96 private $contentHandlerFactory;
97
98 /** @var HookContainer */
99 private $hookContainer;
100
101 /** @var EditResultCache */
102 private $editResultCache;
103
104 /** @var UserNameUtils */
105 private $userNameUtils;
106
107 /** @var LoggerInterface */
108 private $logger;
109
110 /** @var ServiceOptions */
111 private $options;
112
113 /** @var UserEditTracker */
114 private $userEditTracker;
115
116 /** @var UserGroupManager */
117 private $userGroupManager;
118
119 /** @var TitleFormatter */
120 private $titleFormatter;
121
122 /** @var ContentTransformer */
123 private $contentTransformer;
124
125 /** @var PageEditStash */
126 private $pageEditStash;
127
128 /** @var TalkPageNotificationManager */
129 private $talkPageNotificationManager;
130
131 /** @var WANObjectCache */
132 private $mainWANObjectCache;
133
134 /** @var PermissionManager */
135 private $permissionManager;
136
137 /** @var WikiPageFactory */
138 private $wikiPageFactory;
139
140 /** @var string[] */
141 private $softwareTags;
142
143 /**
144 * @param RevisionStore $revisionStore
145 * @param RevisionRenderer $revisionRenderer
146 * @param SlotRoleRegistry $slotRoleRegistry
147 * @param ParserCache $parserCache
148 * @param JobQueueGroup $jobQueueGroup
149 * @param MessageCache $messageCache
150 * @param Language $contLang
151 * @param ILBFactory $loadbalancerFactory
152 * @param IContentHandlerFactory $contentHandlerFactory
153 * @param HookContainer $hookContainer
154 * @param EditResultCache $editResultCache
155 * @param UserNameUtils $userNameUtils
156 * @param LoggerInterface $logger
157 * @param ServiceOptions $options
158 * @param UserEditTracker $userEditTracker
159 * @param UserGroupManager $userGroupManager
160 * @param TitleFormatter $titleFormatter
161 * @param ContentTransformer $contentTransformer
162 * @param PageEditStash $pageEditStash
163 * @param TalkPageNotificationManager $talkPageNotificationManager
164 * @param WANObjectCache $mainWANObjectCache
165 * @param PermissionManager $permissionManager
166 * @param WikiPageFactory $wikiPageFactory
167 * @param string[] $softwareTags
168 */
169 public function __construct(
170 RevisionStore $revisionStore,
171 RevisionRenderer $revisionRenderer,
172 SlotRoleRegistry $slotRoleRegistry,
173 ParserCache $parserCache,
174 JobQueueGroup $jobQueueGroup,
175 MessageCache $messageCache,
176 Language $contLang,
177 ILBFactory $loadbalancerFactory,
178 IContentHandlerFactory $contentHandlerFactory,
179 HookContainer $hookContainer,
180 EditResultCache $editResultCache,
181 UserNameUtils $userNameUtils,
182 LoggerInterface $logger,
183 ServiceOptions $options,
184 UserEditTracker $userEditTracker,
185 UserGroupManager $userGroupManager,
186 TitleFormatter $titleFormatter,
187 ContentTransformer $contentTransformer,
188 PageEditStash $pageEditStash,
189 TalkPageNotificationManager $talkPageNotificationManager,
190 WANObjectCache $mainWANObjectCache,
191 PermissionManager $permissionManager,
192 WikiPageFactory $wikiPageFactory,
193 array $softwareTags
194 ) {
195 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
196
197 $this->revisionStore = $revisionStore;
198 $this->revisionRenderer = $revisionRenderer;
199 $this->slotRoleRegistry = $slotRoleRegistry;
200 $this->parserCache = $parserCache;
201 $this->jobQueueGroup = $jobQueueGroup;
202 $this->messageCache = $messageCache;
203 $this->contLang = $contLang;
204 $this->loadbalancerFactory = $loadbalancerFactory;
205 $this->contentHandlerFactory = $contentHandlerFactory;
206 $this->hookContainer = $hookContainer;
207 $this->editResultCache = $editResultCache;
208 $this->userNameUtils = $userNameUtils;
209 $this->logger = $logger;
210 $this->options = $options;
211 $this->userEditTracker = $userEditTracker;
212 $this->userGroupManager = $userGroupManager;
213 $this->titleFormatter = $titleFormatter;
214 $this->contentTransformer = $contentTransformer;
215 $this->pageEditStash = $pageEditStash;
216 $this->talkPageNotificationManager = $talkPageNotificationManager;
217 $this->mainWANObjectCache = $mainWANObjectCache;
218 $this->permissionManager = $permissionManager;
219 $this->softwareTags = $softwareTags;
220 $this->wikiPageFactory = $wikiPageFactory;
221 }
222
223 /**
224 * Return a PageUpdater for building an update to a page.
225 *
226 * @internal For now, most code should keep using WikiPage::newPageUpdater() instead.
227 * @note We can only start using this method everywhere when WikiPage::prepareContentForEdit()
228 * and WikiPage::getCurrentUpdate() have been removed. For now, the WikiPage instance is
229 * used to make the state of an ongoing edit available to hook handlers.
230 *
231 * @param PageIdentity $page
232 * @param UserIdentity $user
233 *
234 * @return PageUpdater
235 * @since 1.37
236 */
237 public function newPageUpdater(
238 PageIdentity $page,
239 UserIdentity $user
240 ): PageUpdater {
241 return $this->newPageUpdaterForDerivedPageDataUpdater(
242 $page,
243 $user,
244 $this->newDerivedPageDataUpdater( $page )
245 );
246 }
247
248 /**
249 * Return a PageUpdater for building an update to a page, reusing the state of
250 * an existing DerivedPageDataUpdater.
251 *
252 * @param PageIdentity $page
253 * @param UserIdentity $user
254 * @param DerivedPageDataUpdater $derivedPageDataUpdater
255 *
256 * @return PageUpdater
257 * @internal needed by WikiPage to back the WikiPage::newPageUpdater method.
258 *
259 * @since 1.37
260 */
261 public function newPageUpdaterForDerivedPageDataUpdater(
262 PageIdentity $page,
263 UserIdentity $user,
264 DerivedPageDataUpdater $derivedPageDataUpdater
265 ): PageUpdater {
266 $pageUpdater = new PageUpdater(
267 $user,
268 $page,
269 $derivedPageDataUpdater,
270 $this->loadbalancerFactory,
271 $this->revisionStore,
272 $this->slotRoleRegistry,
273 $this->contentHandlerFactory,
274 $this->hookContainer,
275 $this->userEditTracker,
276 $this->userGroupManager,
277 $this->titleFormatter,
278 new ServiceOptions(
279 PageUpdater::CONSTRUCTOR_OPTIONS,
280 $this->options
281 ),
282 $this->softwareTags,
283 $this->logger,
284 $this->wikiPageFactory
285 );
286
287 $pageUpdater->setUsePageCreationLog(
288 $this->options->get( MainConfigNames::PageCreationLog ) );
289 $pageUpdater->setUseAutomaticEditSummaries(
290 $this->options->get( MainConfigNames::UseAutomaticEditSummaries )
291 );
292
293 return $pageUpdater;
294 }
295
296 /**
297 * @param PageIdentity $page
298 *
299 * @return DerivedPageDataUpdater
300 * @internal Needed by WikiPage to back the deprecated prepareContentForEdit() method.
301 * @note Avoid direct usage of DerivedPageDataUpdater.
302 * @see docs/pageupdater.md for more information.
303 */
304 public function newDerivedPageDataUpdater( PageIdentity $page ): DerivedPageDataUpdater {
305 $derivedDataUpdater = new DerivedPageDataUpdater(
306 $this->options,
307 $page,
308 $this->revisionStore,
309 $this->revisionRenderer,
310 $this->slotRoleRegistry,
311 $this->parserCache,
312 $this->jobQueueGroup,
313 $this->messageCache,
314 $this->contLang,
315 $this->loadbalancerFactory,
316 $this->contentHandlerFactory,
317 $this->hookContainer,
318 $this->editResultCache,
319 $this->userNameUtils,
320 $this->contentTransformer,
321 $this->pageEditStash,
322 $this->talkPageNotificationManager,
323 $this->mainWANObjectCache,
324 $this->permissionManager,
325 $this->wikiPageFactory
326 );
327
328 $derivedDataUpdater->setLogger( $this->logger );
329 $derivedDataUpdater->setArticleCountMethod(
330 $this->options->get( MainConfigNames::ArticleCountMethod ) );
331 $derivedDataUpdater->setRcWatchCategoryMembership(
332 $this->options->get( MainConfigNames::RCWatchCategoryMembership )
333 );
334
335 return $derivedDataUpdater;
336 }
337
338 }