31 private const CORE_LIST = [
33 'class' => CategoryLinksTable::class,
35 'LanguageConverterFactory',
44 'needCollation' =>
true,
47 'class' => ExternalLinksTable::class,
50 'class' => ExistenceLinksTable::class,
53 'class' => ImageLinksTable::class,
56 'class' => InterwikiLinksTable::class
59 'class' => LangLinksTable::class
62 'class' => PageLinksTable::class,
65 'class' => PagePropsTable::class,
72 'class' => TemplateLinksTable::class,
77 private $objectFactory;
83 private $collationFactory;
92 private $parserOutput;
95 private $linkTargetLookup;
107 private $tables = [];
110 private $tempCollations;
122 ObjectFactory $objectFactory,
128 array $tempCollations
130 $this->objectFactory = $objectFactory;
131 $this->lbFactory = $lbFactory;
132 $this->collationFactory = $collationFactory;
134 $this->batchSize = $batchSize;
135 $this->linkTargetLookup = $linkTargetLookup;
136 $this->tempCollations = [];
137 foreach ( $tempCollations as $info ) {
138 $this->tempCollations[$info[
'table']] = $info;
146 $this->parserOutput = $parserOutput;
147 foreach ( $this->tables as $table ) {
148 $table->setParserOutput( $parserOutput );
156 $this->movedPage = $oldPage;
157 foreach ( $this->tables as $table ) {
158 $table->setMoveDetails( $oldPage );
168 $this->ticket = $ticket;
169 foreach ( $this->tables as $table ) {
170 $table->setTransactionTicket( $ticket );
178 $this->revision = $revision;
179 foreach ( $this->tables as $table ) {
180 $table->setRevision( $revision );
190 foreach ( $this->
getAll() as $table ) {
191 $table->setStrictTestMode( $mode );
201 private function getSpec( $tableName ) {
202 if ( isset( self::CORE_LIST[$tableName] ) ) {
203 $spec = self::CORE_LIST[$tableName];
204 return $this->addCollationArgs( $spec, $tableName,
false );
206 if ( isset( $this->tempCollations[$tableName] ) ) {
207 $info = $this->tempCollations[$tableName];
208 $spec = self::CORE_LIST[
'categorylinks'];
209 return $this->addCollationArgs( $spec, $tableName,
true, $info );
211 throw new InvalidArgumentException(
212 __CLASS__ .
": unknown table name \"$tableName\"" );
224 private function addCollationArgs( $spec, $tableName, $isTempTable, $info = [] ) {
225 if ( isset( $spec[
'needCollation'] ) ) {
226 if ( isset( $info[
'collation'] ) ) {
227 $collation = $this->collationFactory->makeCollation( $info[
'collation'] );
228 $collationName = $info[
'fakeCollation'] ?? $info[
'collation'];
230 $collation = $this->collationFactory->getCategoryCollation();
231 $collationName = $this->collationFactory->getDefaultCollationName();
235 $info[
'fakeCollation'] ?? $collationName,
239 unset( $spec[
'needCollation'] );
250 public function get( $tableName ) {
251 if ( !isset( $this->tables[$tableName] ) ) {
252 $spec = $this->getSpec( $tableName );
253 if ( isset( $spec[
'serviceOptions'] ) ) {
255 $extraArgs = [
new ServiceOptions( $spec[
'serviceOptions'], $config ) ];
256 unset( $spec[
'serviceOptions'] );
261 $table = $this->objectFactory->createObject(
263 [
'extraArgs' => $extraArgs,
'assertClass' => LinksTable::class ]
265 $table->injectBaseDependencies(
267 $this->linkTargetLookup,
271 if ( $this->parserOutput ) {
272 $table->setParserOutput( $this->parserOutput );
274 if ( $this->movedPage ) {
275 $table->setMoveDetails( $this->movedPage );
277 if ( $this->ticket ) {
278 $table->setTransactionTicket( $this->ticket );
280 if ( $this->revision ) {
281 $table->setRevision( $this->revision );
283 $this->tables[$tableName] = $table;
285 return $this->tables[$tableName];
293 foreach ( self::CORE_LIST as $tableName => $spec ) {
294 yield $this->
get( $tableName );
296 foreach ( $this->tempCollations as $tableName => $collation ) {
297 yield $this->
get( $tableName );