MediaWiki REL1_40
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 'services' => [
43 'MainConfig'
44 ],
45 ],
46 'imagelinks' => [
47 'class' => ImageLinksTable::class
48 ],
49 'iwlinks' => [
50 'class' => InterwikiLinksTable::class
51 ],
52 'langlinks' => [
53 'class' => LangLinksTable::class
54 ],
55 'pagelinks' => [
56 'class' => PageLinksTable::class
57 ],
58 'page_props' => [
59 'class' => PagePropsTable::class,
60 'services' => [
61 'JobQueueGroup'
62 ],
63 'serviceOptions' => PagePropsTable::CONSTRUCTOR_OPTIONS
64 ],
65 'templatelinks' => [
66 'class' => TemplateLinksTable::class,
67 'services' => [
68 'MainConfig'
69 ],
70 ]
71 ];
72
74 private $objectFactory;
75
77 private $lbFactory;
78
80 private $collationFactory;
81
83 private $page;
84
86 private $movedPage;
87
89 private $parserOutput;
90
92 private $linkTargetLookup;
93
95 private $batchSize;
96
98 private $ticket;
99
101 private $revision;
102
104 private $tables = [];
105
107 private $tempCollations;
108
118 public function __construct(
119 ObjectFactory $objectFactory,
120 LBFactory $lbFactory,
121 CollationFactory $collationFactory,
122 PageIdentity $page,
123 LinkTargetLookup $linkTargetLookup,
124 $batchSize,
125 array $tempCollations
126 ) {
127 $this->objectFactory = $objectFactory;
128 $this->lbFactory = $lbFactory;
129 $this->collationFactory = $collationFactory;
130 $this->page = $page;
131 $this->batchSize = $batchSize;
132 $this->linkTargetLookup = $linkTargetLookup;
133 $this->tempCollations = [];
134 foreach ( $tempCollations as $info ) {
135 $this->tempCollations[$info['table']] = $info;
136 }
137 }
138
144 public function setParserOutput( ParserOutput $parserOutput ) {
145 $this->parserOutput = $parserOutput;
146 foreach ( $this->tables as $table ) {
147 $table->setParserOutput( $parserOutput );
148 }
149 }
150
156 public function setMoveDetails( PageReference $oldPage ) {
157 $this->movedPage = $oldPage;
158 foreach ( $this->tables as $table ) {
159 $table->setMoveDetails( $oldPage );
160 }
161 }
162
168 public function setTransactionTicket( $ticket ) {
169 $this->ticket = $ticket;
170 foreach ( $this->tables as $table ) {
171 $table->setTransactionTicket( $ticket );
172 }
173 }
174
180 public function setRevision( RevisionRecord $revision ) {
181 $this->revision = $revision;
182 foreach ( $this->tables as $table ) {
183 $table->setRevision( $revision );
184 }
185 }
186
192 public function setStrictTestMode( $mode = true ) {
193 foreach ( $this->getAll() as $table ) {
194 $table->setStrictTestMode( $mode );
195 }
196 }
197
204 private function getSpec( $tableName ) {
205 if ( isset( self::CORE_LIST[$tableName] ) ) {
206 $spec = self::CORE_LIST[$tableName];
207 return $this->addCollationArgs( $spec, $tableName, false );
208 }
209 if ( isset( $this->tempCollations[$tableName] ) ) {
210 $info = $this->tempCollations[$tableName];
211 $spec = self::CORE_LIST['categorylinks'];
212 return $this->addCollationArgs( $spec, $tableName, true, $info );
213 }
214 throw new \InvalidArgumentException(
215 __CLASS__ . ": unknown table name \"$tableName\"" );
216 }
217
227 private function addCollationArgs( $spec, $tableName, $isTempTable, $info = [] ) {
228 if ( isset( $spec['needCollation'] ) ) {
229 if ( isset( $info['collation'] ) ) {
230 $collation = $this->collationFactory->makeCollation( $info['collation'] );
231 $collationName = $info['fakeCollation'] ?? $info['collation'];
232 } else {
233 $collation = $this->collationFactory->getCategoryCollation();
234 $collationName = $this->collationFactory->getDefaultCollationName();
235 }
236 $spec['args'] = [
237 $collation,
238 $info['fakeCollation'] ?? $collationName,
239 $tableName,
240 $isTempTable
241 ];
242 unset( $spec['needCollation'] );
243 }
244 return $spec;
245 }
246
253 public function get( $tableName ) {
254 if ( !isset( $this->tables[$tableName] ) ) {
255 $spec = $this->getSpec( $tableName );
256 if ( isset( $spec['serviceOptions'] ) ) {
257 $config = MediaWikiServices::getInstance()->getMainConfig();
258 $extraArgs = [ new ServiceOptions( $spec['serviceOptions'], $config ) ];
259 unset( $spec['serviceOptions'] );
260 } else {
261 $extraArgs = [];
262 }
264 $table = $this->objectFactory->createObject( $spec, [ 'extraArgs' => $extraArgs ] );
265 $table->injectBaseDependencies(
266 $this->lbFactory,
267 $this->linkTargetLookup,
268 $this->page,
269 $this->batchSize
270 );
271 if ( $this->parserOutput ) {
272 $table->setParserOutput( $this->parserOutput );
273 }
274 if ( $this->movedPage ) {
275 $table->setMoveDetails( $this->movedPage );
276 }
277 if ( $this->ticket ) {
278 $table->setTransactionTicket( $this->ticket );
279 }
280 if ( $this->revision ) {
281 $table->setRevision( $this->revision );
282 }
283 $this->tables[$tableName] = $table;
284 }
285 return $this->tables[$tableName];
286 }
287
292 public function getAll() {
293 foreach ( self::CORE_LIST as $tableName => $spec ) {
294 yield $this->get( $tableName );
295 }
296 foreach ( $this->tempCollations as $tableName => $collation ) {
297 yield $this->get( $tableName );
298 }
299 }
300}
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.
__construct(ObjectFactory $objectFactory, LBFactory $lbFactory, CollationFactory $collationFactory, PageIdentity $page, LinkTargetLookup $linkTargetLookup, $batchSize, array $tempCollations)
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.
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.