32use Psr\Log\LoggerInterface;
33use Wikimedia\Assert\Assert;
53 private $pageIdentities =
null;
68 private $titleFormatter;
73 private $contentLanguage;
86 private $linksMigration;
112 LoggerInterface $logger
114 $this->linkCache = $linkCache;
115 $this->titleFormatter = $titleFormatter;
116 $this->contentLanguage = $contentLanguage;
117 $this->genderCache = $genderCache;
118 $this->dbProvider = $dbProvider;
119 $this->linksMigration = $linksMigration;
120 $this->logger = $logger;
122 foreach ( $arr as $item ) {
148 $this->logger->warning(
149 'Skipping null link, probably due to a bad title.',
150 [
'exception' =>
new RuntimeException() ]
155 $this->logger->warning(
156 'Skipping interwiki link',
157 [
'exception' =>
new RuntimeException() ]
162 Assert::parameterType( [ LinkTarget::class, PageReference::class ], $link,
'$link' );
163 $this->
add( $link->getNamespace(), $link->getDBkey() );
170 public function add( $ns, $dbkey ) {
171 if ( $ns < 0 || $dbkey ===
'' ) {
175 $this->data[$ns][strtr( $dbkey,
' ',
'_' )] = 1;
185 $this->data = $array;
203 return count( $this->data );
223 if ( $this->pageIdentities === null ) {
227 return $this->pageIdentities;
238 $res = $this->doQuery();
239 $this->doGenderQuery();
240 return $this->addResultToCache( $cache, $res );
260 $this->pageIdentities ??= [];
263 $remaining = $this->data;
264 foreach ( $res as $row ) {
266 $title =
new TitleValue( (
int)$row->page_namespace, $row->page_title );
268 $cache->addGoodLinkObjFromRow( $title, $row );
269 $pdbk = $this->titleFormatter->getPrefixedDBkey( $title );
270 $ids[$pdbk] = $row->page_id;
274 (
int)$row->page_namespace,
276 ProperPageIdentity::LOCAL
279 $key = CacheKeyHelper::getKeyForPage( $pageIdentity );
280 $this->pageIdentities[$key] = $pageIdentity;
281 }
catch ( InvalidArgumentException $ex ) {
282 $this->logger->warning(
283 'Encountered invalid title',
284 [
'title_namespace' => $row->page_namespace,
'title_dbkey' => $row->page_title ]
288 unset( $remaining[$row->page_namespace][$row->page_title] );
292 foreach ( $remaining as $ns => $dbkeys ) {
293 foreach ( $dbkeys as $dbkey => $unused ) {
295 $title =
new TitleValue( (
int)$ns, (
string)$dbkey );
297 $cache->addBadLinkObj( $title );
298 $pdbk = $this->titleFormatter->getPrefixedDBkey( $title );
301 $pageIdentity =
new PageIdentityValue( 0, (
int)$ns, $dbkey, ProperPageIdentity::LOCAL );
302 $key = CacheKeyHelper::getKeyForPage( $pageIdentity );
303 $this->pageIdentities[$key] = $pageIdentity;
304 }
catch ( InvalidArgumentException $ex ) {
305 $this->logger->warning(
306 'Encountered invalid title',
307 [
'title_namespace' => $ns,
'title_dbkey' => $dbkey ]
321 if ( $this->isEmpty() ) {
326 $dbr = $this->dbProvider->getReplicaDatabase();
327 $queryBuilder = $dbr->newSelectQueryBuilder()
328 ->select( LinkCache::getSelectFields() )
330 ->where( $this->constructSet(
'page', $dbr ) );
332 $caller = __METHOD__;
333 if ( strval( $this->caller ) !==
'' ) {
334 $caller .=
" (for {$this->caller})";
337 return $queryBuilder->caller( $caller )->fetchResultSet();
346 if ( $this->isEmpty() || !$this->contentLanguage->needsGenderDistinction() ) {
350 $this->genderCache->doLinkBatch( $this->data, $this->caller );
367 if ( isset( $this->linksMigration::$prefixToTableMapping[$prefix] ) ) {
368 [ $blNamespace, $blTitle ] = $this->linksMigration->getTitleFields(
369 $this->linksMigration::$prefixToTableMapping[$prefix]
372 $blNamespace =
"{$prefix}_namespace";
373 $blTitle =
"{$prefix}_title";
375 return $db->makeWhereFrom2d( $this->data, $blNamespace, $blTitle );
if(!defined('MW_SETUP_CALLBACK'))
Look up "gender" user preference.
Base class for language-specific code.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
doGenderQuery()
Do (and cache) {{GENDER:...}} information for userpages in this LinkBatch.
__construct(iterable $arr, LinkCache $linkCache, TitleFormatter $titleFormatter, Language $contentLanguage, GenderCache $genderCache, IConnectionProvider $dbProvider, LinksMigration $linksMigration, LoggerInterface $logger)
getSize()
Returns the size of the batch.
addResultToCache( $cache, $res)
Add a result wrapper containing IDs and titles to a LinkCache object.
isEmpty()
Returns true if no pages have been added, false otherwise.
setCaller( $caller)
Use ->setCaller( METHOD ) to indicate which code is using this class.
constructSet( $prefix, $db)
Construct a WHERE clause which will match all the given titles.
getPageIdentities()
Do the query, add the results to the LinkCache object, and return ProperPageIdentity instances corres...
execute()
Do the query and add the results to the LinkCache object.
setArray( $array)
Set the link list to a given 2-d array First key is the namespace, second is the DB key,...
string null $caller
For debugging which method is using this class.
array< int, array< string, mixed > > $data
2-d array, first index namespace, second index dbkey, value arbitrary
executeInto( $cache)
Do the query and add the results to a given LinkCache object Return an array mapping PDBK to ID.
doQuery()
Perform the existence test query, return a result wrapper with page_id fields.
Cache for article titles (prefixed DB keys) and ids linked from one source.
Immutable value object representing a page identity.
Interface for a page that is (or could be, or used to be) an editable wiki page.