30 private const CORE_LIST = [
32 'class' => CategoryLinksTable::class,
34 'LanguageConverterFactory',
38 'needCollation' =>
true,
41 'class' => ExternalLinksTable::class
44 'class' => ImageLinksTable::class
47 'class' => InterwikiLinksTable::class
50 'class' => LangLinksTable::class
53 'class' => PageLinksTable::class
56 'class' => PagePropsTable::class,
63 'class' => TemplateLinksTable::class,
71 private $objectFactory;
77 private $collationFactory;
86 private $parserOutput;
89 private $linkTargetLookup;
95 private $afterUpdateHook;
104 private $tables = [];
107 private $tempCollations;
120 ObjectFactory $objectFactory,
127 array $tempCollations
129 $this->objectFactory = $objectFactory;
130 $this->lbFactory = $lbFactory;
131 $this->collationFactory = $collationFactory;
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;
148 $this->parserOutput = $parserOutput;
149 foreach ( $this->tables as $table ) {
150 $table->setParserOutput( $parserOutput );
160 $this->movedPage = $oldPage;
161 foreach ( $this->tables as $table ) {
162 $table->setMoveDetails( $oldPage );
172 $this->ticket = $ticket;
173 foreach ( $this->tables as $table ) {
174 $table->setTransactionTicket( $ticket );
184 $this->revision = $revision;
185 foreach ( $this->tables as $table ) {
186 $table->setRevision( $revision );
196 foreach ( $this->
getAll() as $table ) {
197 $table->setStrictTestMode( $mode );
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 );
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 );
217 throw new \InvalidArgumentException(
218 __CLASS__ .
": unknown table name \"$tableName\"" );
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'];
236 $collation = $this->collationFactory->getCategoryCollation();
237 $collationName = $this->collationFactory->getDefaultCollationName();
241 $info[
'fakeCollation'] ?? $collationName,
245 unset( $spec[
'needCollation'] );
256 public function get( $tableName ) {
257 if ( !isset( $this->tables[$tableName] ) ) {
258 $spec = $this->getSpec( $tableName );
259 if ( isset( $spec[
'serviceOptions'] ) ) {
261 $extraArgs = [
new ServiceOptions( $spec[
'serviceOptions'], $config ) ];
262 unset( $spec[
'serviceOptions'] );
267 $table = $this->objectFactory->createObject( $spec, [
'extraArgs' => $extraArgs ] );
268 $table->injectBaseDependencies(
270 $this->linkTargetLookup,
273 $this->afterUpdateHook
275 if ( $this->parserOutput ) {
276 $table->setParserOutput( $this->parserOutput );
278 if ( $this->movedPage ) {
279 $table->setMoveDetails( $this->movedPage );
281 if ( $this->ticket ) {
282 $table->setTransactionTicket( $this->ticket );
284 if ( $this->revision ) {
285 $table->setRevision( $this->revision );
287 $this->tables[$tableName] = $table;
289 return $this->tables[$tableName];
297 foreach ( self::CORE_LIST as $tableName => $spec ) {
298 yield $this->
get( $tableName );
300 foreach ( $this->tempCollations as $tableName => $collation ) {
301 yield $this->
get( $tableName );