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