26use InvalidArgumentException;
37use Psr\Log\LoggerInterface;
39use Wikimedia\Assert\Assert;
59 private array $users = [];
64 private $pageIdentities =
null;
79 private $titleFormatter;
84 private $contentLanguage;
97 private $linksMigration;
127 LoggerInterface $logger
129 $this->linkCache = $linkCache;
130 $this->titleFormatter = $titleFormatter;
131 $this->contentLanguage = $contentLanguage;
132 $this->genderCache = $genderCache;
133 $this->dbProvider = $dbProvider;
134 $this->linksMigration = $linksMigration;
135 $this->tempUserDetailsLookup = $tempUserDetailsLookup;
136 $this->logger = $logger;
138 foreach ( $arr as $item ) {
165 $this->users[$user->getName()] = $user;
178 $this->logger->warning(
179 'Skipping null link, probably due to a bad title.',
180 [
'exception' =>
new RuntimeException() ]
185 $this->logger->warning(
186 'Skipping interwiki link',
187 [
'exception' =>
new RuntimeException() ]
192 Assert::parameterType( [ LinkTarget::class, PageReference::class ], $link,
'$link' );
193 $this->add( $link->getNamespace(), $link->getDBkey() );
200 public function add( $ns, $dbkey ) {
201 if ( $ns < 0 || $dbkey ===
'' ) {
205 $this->data[$ns][strtr( $dbkey,
' ',
'_' )] = 1;
215 $this->data = $array;
224 return $this->getSize() == 0;
233 return count( $this->data );
242 return $this->executeInto( $this->linkCache );
253 if ( $this->pageIdentities === null ) {
257 return $this->pageIdentities;
268 $res = $this->doQuery();
269 $this->doGenderQuery();
273 if ( count( $this->users ) > 0 ) {
274 $this->tempUserDetailsLookup->preloadExpirationStatus( $this->users );
277 return $this->addResultToCache( $cache, $res );
297 $this->pageIdentities ??= [];
300 $remaining = $this->data;
301 foreach ( $res as $row ) {
303 $title =
new TitleValue( (
int)$row->page_namespace, $row->page_title );
305 $cache->addGoodLinkObjFromRow( $title, $row );
306 $pdbk = $this->titleFormatter->getPrefixedDBkey( $title );
307 $ids[$pdbk] = $row->page_id;
309 $pageIdentity = PageIdentityValue::localIdentity(
311 (
int)$row->page_namespace,
315 $key = CacheKeyHelper::getKeyForPage( $pageIdentity );
316 $this->pageIdentities[$key] = $pageIdentity;
317 }
catch ( InvalidArgumentException ) {
318 $this->logger->warning(
319 'Encountered invalid title',
320 [
'title_namespace' => $row->page_namespace,
'title_dbkey' => $row->page_title ]
324 unset( $remaining[$row->page_namespace][$row->page_title] );
328 foreach ( $remaining as $ns => $dbkeys ) {
329 foreach ( $dbkeys as $dbkey => $unused ) {
331 $title =
new TitleValue( (
int)$ns, (
string)$dbkey );
333 $cache->addBadLinkObj( $title );
334 $pdbk = $this->titleFormatter->getPrefixedDBkey( $title );
337 $pageIdentity = PageIdentityValue::localIdentity( 0, (
int)$ns, $dbkey );
338 $key = CacheKeyHelper::getKeyForPage( $pageIdentity );
339 $this->pageIdentities[$key] = $pageIdentity;
340 }
catch ( InvalidArgumentException ) {
341 $this->logger->warning(
342 'Encountered invalid title',
343 [
'title_namespace' => $ns,
'title_dbkey' => $dbkey ]
357 if ( $this->isEmpty() ) {
361 $caller = __METHOD__;
362 if ( strval( $this->caller ) !==
'' ) {
363 $caller .=
" (for {$this->caller})";
367 $dbr = $this->dbProvider->getReplicaDatabase();
368 return $dbr->newSelectQueryBuilder()
369 ->select( LinkCache::getSelectFields() )
371 ->where( $this->constructSet(
'page', $dbr ) )
382 if ( $this->isEmpty() || !$this->contentLanguage->needsGenderDistinction() ) {
386 $this->genderCache->doLinkBatch( $this->data, $this->caller );
403 if ( isset( $this->linksMigration::$prefixToTableMapping[$prefix] ) ) {
404 [ $blNamespace, $blTitle ] = $this->linksMigration->getTitleFields(
405 $this->linksMigration::$prefixToTableMapping[$prefix]
408 $blNamespace =
"{$prefix}_namespace";
409 $blTitle =
"{$prefix}_title";
411 return $db->makeWhereFrom2d( $this->data, $blNamespace, $blTitle );
416class_alias( LinkBatch::class,
'LinkBatch' );
if(!defined('MW_SETUP_CALLBACK'))
Immutable value object representing a page identity.
Interface for a page that is (or could be, or used to be) an editable wiki page.