MediaWiki REL1_39
LinksTableGroup.php
Go to the documentation of this file.
1<?php
2
4
12use ParserOutput;
13use Wikimedia\ObjectFactory\ObjectFactory;
15
30 private const CORE_LIST = [
31 'categorylinks' => [
32 'class' => CategoryLinksTable::class,
33 'services' => [
34 'LanguageConverterFactory',
35 'NamespaceInfo',
36 'WikiPageFactory'
37 ],
38 'needCollation' => true,
39 ],
40 'externallinks' => [
41 'class' => ExternalLinksTable::class
42 ],
43 'imagelinks' => [
44 'class' => ImageLinksTable::class
45 ],
46 'iwlinks' => [
47 'class' => InterwikiLinksTable::class
48 ],
49 'langlinks' => [
50 'class' => LangLinksTable::class
51 ],
52 'pagelinks' => [
53 'class' => PageLinksTable::class
54 ],
55 'page_props' => [
56 'class' => PagePropsTable::class,
57 'services' => [
58 'JobQueueGroup'
59 ],
60 'serviceOptions' => PagePropsTable::CONSTRUCTOR_OPTIONS
61 ],
62 'templatelinks' => [
63 'class' => TemplateLinksTable::class,
64 'services' => [
65 'MainConfig'
66 ],
67 ]
68 ];
69
71 private $objectFactory;
72
74 private $lbFactory;
75
77 private $collationFactory;
78
80 private $page;
81
83 private $movedPage;
84
86 private $parserOutput;
87
89 private $linkTargetLookup;
90
92 private $batchSize;
93
95 private $afterUpdateHook;
96
98 private $ticket;
99
101 private $revision;
102
104 private $tables = [];
105
107 private $tempCollations;
108
119 public function __construct(
120 ObjectFactory $objectFactory,
121 LBFactory $lbFactory,
122 CollationFactory $collationFactory,
123 PageIdentity $page,
124 LinkTargetLookup $linkTargetLookup,
125 $batchSize,
126 $afterUpdateHook,
127 array $tempCollations
128 ) {
129 $this->objectFactory = $objectFactory;
130 $this->lbFactory = $lbFactory;
131 $this->collationFactory = $collationFactory;
132 $this->page = $page;
133 $this->batchSize = $batchSize;
134 $this->afterUpdateHook = $afterUpdateHook;
135 $this->linkTargetLookup = $linkTargetLookup;
136 $this->tempCollations = [];
137 foreach ( $tempCollations as $info ) {
138 $this->tempCollations[$info['table']] = $info;
139 }
140 }
141
147 public function setParserOutput( ParserOutput $parserOutput ) {
148 $this->parserOutput = $parserOutput;
149 foreach ( $this->tables as $table ) {
150 $table->setParserOutput( $parserOutput );
151 }
152 }
153
159 public function setMoveDetails( PageReference $oldPage ) {
160 $this->movedPage = $oldPage;
161 foreach ( $this->tables as $table ) {
162 $table->setMoveDetails( $oldPage );
163 }
164 }
165
171 public function setTransactionTicket( $ticket ) {
172 $this->ticket = $ticket;
173 foreach ( $this->tables as $table ) {
174 $table->setTransactionTicket( $ticket );
175 }
176 }
177
183 public function setRevision( RevisionRecord $revision ) {
184 $this->revision = $revision;
185 foreach ( $this->tables as $table ) {
186 $table->setRevision( $revision );
187 }
188 }
189
195 public function setStrictTestMode( $mode = true ) {
196 foreach ( $this->getAll() as $table ) {
197 $table->setStrictTestMode( $mode );
198 }
199 }
200
207 private function getSpec( $tableName ) {
208 if ( isset( self::CORE_LIST[$tableName] ) ) {
209 $spec = self::CORE_LIST[$tableName];
210 return $this->addCollationArgs( $spec, $tableName, false );
211 }
212 if ( isset( $this->tempCollations[$tableName] ) ) {
213 $info = $this->tempCollations[$tableName];
214 $spec = self::CORE_LIST['categorylinks'];
215 return $this->addCollationArgs( $spec, $tableName, true, $info );
216 }
217 throw new \InvalidArgumentException(
218 __CLASS__ . ": unknown table name \"$tableName\"" );
219 }
220
230 private function addCollationArgs( $spec, $tableName, $isTempTable, $info = [] ) {
231 if ( isset( $spec['needCollation'] ) ) {
232 if ( isset( $info['collation'] ) ) {
233 $collation = $this->collationFactory->makeCollation( $info['collation'] );
234 $collationName = $info['fakeCollation'] ?? $info['collation'];
235 } else {
236 $collation = $this->collationFactory->getCategoryCollation();
237 $collationName = $this->collationFactory->getDefaultCollationName();
238 }
239 $spec['args'] = [
240 $collation,
241 $info['fakeCollation'] ?? $collationName,
242 $tableName,
243 $isTempTable
244 ];
245 unset( $spec['needCollation'] );
246 }
247 return $spec;
248 }
249
256 public function get( $tableName ) {
257 if ( !isset( $this->tables[$tableName] ) ) {
258 $spec = $this->getSpec( $tableName );
259 if ( isset( $spec['serviceOptions'] ) ) {
260 $config = MediaWikiServices::getInstance()->getMainConfig();
261 $extraArgs = [ new ServiceOptions( $spec['serviceOptions'], $config ) ];
262 unset( $spec['serviceOptions'] );
263 } else {
264 $extraArgs = [];
265 }
267 $table = $this->objectFactory->createObject( $spec, [ 'extraArgs' => $extraArgs ] );
268 $table->injectBaseDependencies(
269 $this->lbFactory,
270 $this->linkTargetLookup,
271 $this->page,
272 $this->batchSize,
273 $this->afterUpdateHook
274 );
275 if ( $this->parserOutput ) {
276 $table->setParserOutput( $this->parserOutput );
277 }
278 if ( $this->movedPage ) {
279 $table->setMoveDetails( $this->movedPage );
280 }
281 if ( $this->ticket ) {
282 $table->setTransactionTicket( $this->ticket );
283 }
284 if ( $this->revision ) {
285 $table->setRevision( $this->revision );
286 }
287 $this->tables[$tableName] = $table;
288 }
289 return $this->tables[$tableName];
290 }
291
296 public function getAll() {
297 foreach ( self::CORE_LIST as $tableName => $spec ) {
298 yield $this->get( $tableName );
299 }
300 foreach ( $this->tempCollations as $tableName => $collation ) {
301 yield $this->get( $tableName );
302 }
303 }
304}
Common factory to construct collation classes.
A class for passing options to services.
setParserOutput(ParserOutput $parserOutput)
Set the ParserOutput object to be used in new and existing objects.
setTransactionTicket( $ticket)
Set the transaction ticket to be used in new and existing objects.
getAll()
Get LinksTable objects for all known links tables.
setRevision(RevisionRecord $revision)
Set the revision to be used in new and existing objects.
setStrictTestMode( $mode=true)
Set the strict test mode.
setMoveDetails(PageReference $oldPage)
Set the original title in the case of a page move.
__construct(ObjectFactory $objectFactory, LBFactory $lbFactory, CollationFactory $collationFactory, PageIdentity $page, LinkTargetLookup $linkTargetLookup, $batchSize, $afterUpdateHook, array $tempCollations)
The base class for classes which update a single link table.
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Page revision base class.
Interface for objects (potentially) representing an editable wiki page.
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.