31 private const CORE_LIST = [
33 'class' => CategoryLinksTable::class,
35 'LanguageConverterFactory',
39 'needCollation' =>
true,
42 'class' => ExternalLinksTable::class,
45 'class' => ImageLinksTable::class
48 'class' => InterwikiLinksTable::class
51 'class' => LangLinksTable::class
54 'class' => PageLinksTable::class,
60 'class' => PagePropsTable::class,
67 'class' => TemplateLinksTable::class,
72 private $objectFactory;
78 private $collationFactory;
87 private $parserOutput;
90 private $linkTargetLookup;
102 private $tables = [];
105 private $tempCollations;
117 ObjectFactory $objectFactory,
123 array $tempCollations
125 $this->objectFactory = $objectFactory;
126 $this->lbFactory = $lbFactory;
127 $this->collationFactory = $collationFactory;
129 $this->batchSize = $batchSize;
130 $this->linkTargetLookup = $linkTargetLookup;
131 $this->tempCollations = [];
132 foreach ( $tempCollations as $info ) {
133 $this->tempCollations[$info[
'table']] = $info;
143 $this->parserOutput = $parserOutput;
144 foreach ( $this->tables as $table ) {
145 $table->setParserOutput( $parserOutput );
155 $this->movedPage = $oldPage;
156 foreach ( $this->tables as $table ) {
157 $table->setMoveDetails( $oldPage );
167 $this->ticket = $ticket;
168 foreach ( $this->tables as $table ) {
169 $table->setTransactionTicket( $ticket );
179 $this->revision = $revision;
180 foreach ( $this->tables as $table ) {
181 $table->setRevision( $revision );
191 foreach ( $this->
getAll() as $table ) {
192 $table->setStrictTestMode( $mode );
202 private function getSpec( $tableName ) {
203 if ( isset( self::CORE_LIST[$tableName] ) ) {
204 $spec = self::CORE_LIST[$tableName];
205 return $this->addCollationArgs( $spec, $tableName,
false );
207 if ( isset( $this->tempCollations[$tableName] ) ) {
208 $info = $this->tempCollations[$tableName];
209 $spec = self::CORE_LIST[
'categorylinks'];
210 return $this->addCollationArgs( $spec, $tableName,
true, $info );
212 throw new InvalidArgumentException(
213 __CLASS__ .
": unknown table name \"$tableName\"" );
225 private function addCollationArgs( $spec, $tableName, $isTempTable, $info = [] ) {
226 if ( isset( $spec[
'needCollation'] ) ) {
227 if ( isset( $info[
'collation'] ) ) {
228 $collation = $this->collationFactory->makeCollation( $info[
'collation'] );
229 $collationName = $info[
'fakeCollation'] ?? $info[
'collation'];
231 $collation = $this->collationFactory->getCategoryCollation();
232 $collationName = $this->collationFactory->getDefaultCollationName();
236 $info[
'fakeCollation'] ?? $collationName,
240 unset( $spec[
'needCollation'] );
251 public function get( $tableName ) {
252 if ( !isset( $this->tables[$tableName] ) ) {
253 $spec = $this->getSpec( $tableName );
254 if ( isset( $spec[
'serviceOptions'] ) ) {
256 $extraArgs = [
new ServiceOptions( $spec[
'serviceOptions'], $config ) ];
257 unset( $spec[
'serviceOptions'] );
262 $table = $this->objectFactory->createObject( $spec, [
'extraArgs' => $extraArgs ] );
263 $table->injectBaseDependencies(
265 $this->linkTargetLookup,
269 if ( $this->parserOutput ) {
270 $table->setParserOutput( $this->parserOutput );
272 if ( $this->movedPage ) {
273 $table->setMoveDetails( $this->movedPage );
275 if ( $this->ticket ) {
276 $table->setTransactionTicket( $this->ticket );
278 if ( $this->revision ) {
279 $table->setRevision( $this->revision );
281 $this->tables[$tableName] = $table;
283 return $this->tables[$tableName];
291 foreach ( self::CORE_LIST as $tableName => $spec ) {
292 yield $this->
get( $tableName );
294 foreach ( $this->tempCollations as $tableName => $collation ) {
295 yield $this->
get( $tableName );