26use InvalidArgumentException;
35use Psr\Log\LoggerInterface;
37use Wikimedia\Assert\Assert;
57 private $pageIdentities =
null;
72 private $titleFormatter;
77 private $contentLanguage;
90 private $linksMigration;
116 LoggerInterface $logger
118 $this->linkCache = $linkCache;
119 $this->titleFormatter = $titleFormatter;
120 $this->contentLanguage = $contentLanguage;
121 $this->genderCache = $genderCache;
122 $this->dbProvider = $dbProvider;
123 $this->linksMigration = $linksMigration;
124 $this->logger = $logger;
126 foreach ( $arr as $item ) {
152 $this->logger->warning(
153 'Skipping null link, probably due to a bad title.',
154 [
'exception' =>
new RuntimeException() ]
159 $this->logger->warning(
160 'Skipping interwiki link',
161 [
'exception' =>
new RuntimeException() ]
166 Assert::parameterType( [ LinkTarget::class, PageReference::class ], $link,
'$link' );
167 $this->
add( $link->getNamespace(), $link->getDBkey() );
174 public function add( $ns, $dbkey ) {
175 if ( $ns < 0 || $dbkey ===
'' ) {
179 $this->data[$ns][strtr( $dbkey,
' ',
'_' )] = 1;
189 $this->data = $array;
207 return count( $this->data );
227 if ( $this->pageIdentities === null ) {
231 return $this->pageIdentities;
242 $res = $this->doQuery();
243 $this->doGenderQuery();
244 return $this->addResultToCache( $cache, $res );
264 $this->pageIdentities ??= [];
267 $remaining = $this->data;
268 foreach ( $res as $row ) {
270 $title =
new TitleValue( (
int)$row->page_namespace, $row->page_title );
272 $cache->addGoodLinkObjFromRow( $title, $row );
273 $pdbk = $this->titleFormatter->getPrefixedDBkey( $title );
274 $ids[$pdbk] = $row->page_id;
278 (
int)$row->page_namespace,
280 ProperPageIdentity::LOCAL
284 $this->pageIdentities[$key] = $pageIdentity;
285 }
catch ( InvalidArgumentException $ex ) {
286 $this->logger->warning(
287 'Encountered invalid title',
288 [
'title_namespace' => $row->page_namespace,
'title_dbkey' => $row->page_title ]
292 unset( $remaining[$row->page_namespace][$row->page_title] );
296 foreach ( $remaining as $ns => $dbkeys ) {
297 foreach ( $dbkeys as $dbkey => $unused ) {
299 $title =
new TitleValue( (
int)$ns, (
string)$dbkey );
301 $cache->addBadLinkObj( $title );
302 $pdbk = $this->titleFormatter->getPrefixedDBkey( $title );
305 $pageIdentity =
new PageIdentityValue( 0, (
int)$ns, $dbkey, ProperPageIdentity::LOCAL );
307 $this->pageIdentities[$key] = $pageIdentity;
308 }
catch ( InvalidArgumentException $ex ) {
309 $this->logger->warning(
310 'Encountered invalid title',
311 [
'title_namespace' => $ns,
'title_dbkey' => $dbkey ]
325 if ( $this->isEmpty() ) {
330 $dbr = $this->dbProvider->getReplicaDatabase();
331 $queryBuilder = $dbr->newSelectQueryBuilder()
334 ->where( $this->constructSet(
'page', $dbr ) );
336 $caller = __METHOD__;
337 if ( strval( $this->caller ) !==
'' ) {
338 $caller .=
" (for {$this->caller})";
341 return $queryBuilder->caller( $caller )->fetchResultSet();
350 if ( $this->isEmpty() || !$this->contentLanguage->needsGenderDistinction() ) {
354 $this->genderCache->doLinkBatch( $this->data, $this->caller );
371 if ( isset( $this->linksMigration::$prefixToTableMapping[$prefix] ) ) {
372 [ $blNamespace, $blTitle ] = $this->linksMigration->getTitleFields(
373 $this->linksMigration::$prefixToTableMapping[$prefix]
376 $blNamespace =
"{$prefix}_namespace";
377 $blTitle =
"{$prefix}_title";
379 return $db->makeWhereFrom2d( $this->data, $blNamespace, $blTitle );
384class_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.