31use Wikimedia\Assert\Assert;
100 $getServices =
static function () {
102 return MediaWikiServices::getInstance();
105 $this->linkCache =
$linkCache ?? $getServices()->getLinkCache();
106 $this->titleFormatter =
$titleFormatter ?? $getServices()->getTitleFormatter();
107 $this->contentLanguage =
$contentLanguage ?? $getServices()->getContentLanguage();
108 $this->genderCache =
$genderCache ?? $getServices()->getGenderCache();
109 $this->loadBalancer =
$loadBalancer ?? $getServices()->getDBLoadBalancer();
111 foreach ( $arr as $item ) {
137 LoggerFactory::getInstance(
'LinkBatch' )->warning(
138 'Skipping null link, probably due to a bad title.',
144 Assert::parameterType( [ LinkTarget::class, PageReference::class ], $link,
'$link' );
145 $this->
add( $link->getNamespace(), $link->getDBkey() );
152 public function add( $ns, $dbkey ) {
153 if ( $ns < 0 || $dbkey ===
'' ) {
156 if ( !array_key_exists( $ns, $this->data ) ) {
157 $this->data[$ns] = [];
160 $this->data[$ns][strtr( $dbkey,
' ',
'_' )] = 1;
170 $this->data = $array;
188 return count( $this->data );
208 if ( $this->pageIdentities === null ) {
212 return $this->pageIdentities;
223 $res = $this->doQuery();
224 $this->doGenderQuery();
225 $ids = $this->addResultToCache(
$cache,
$res );
247 if ( $this->pageIdentities ===
null ) {
248 $this->pageIdentities = [];
252 $remaining = $this->data;
253 foreach (
$res as $row ) {
258 $pdbk = $this->titleFormatter->getPrefixedDBkey(
$title );
259 $ids[$pdbk] = $row->page_id;
263 (
int)$row->page_namespace,
268 $key = CacheKeyHelper::getKeyForPage( $pageIdentity );
269 $this->pageIdentities[$key] = $pageIdentity;
270 }
catch ( InvalidArgumentException $ex ) {
271 LoggerFactory::getInstance(
'LinkBatch' )->warning(
272 'Encountered invalid title',
273 [
'title_namespace' => $row->page_namespace,
'title_dbkey' => $row->page_title ]
277 unset( $remaining[$row->page_namespace][$row->page_title] );
281 foreach ( $remaining as $ns => $dbkeys ) {
282 foreach ( $dbkeys as $dbkey => $unused ) {
287 $pdbk = $this->titleFormatter->getPrefixedDBkey(
$title );
290 $pageIdentity =
new PageIdentityValue( 0, (
int)$ns, $dbkey, PageIdentity::LOCAL );
291 $key = CacheKeyHelper::getKeyForPage( $pageIdentity );
292 $this->pageIdentities[$key] = $pageIdentity;
293 }
catch ( InvalidArgumentException $ex ) {
294 LoggerFactory::getInstance(
'LinkBatch' )->warning(
295 'Encountered invalid title',
296 [
'title_namespace' => $ns,
'title_dbkey' => $dbkey ]
310 if ( $this->isEmpty() ) {
317 $fields = array_merge(
318 LinkCache::getSelectFields(),
319 [
'page_namespace',
'page_title' ]
322 $conds = $this->constructSet(
'page',
$dbr );
325 $caller = __METHOD__;
326 if ( strval( $this->caller ) !==
'' ) {
327 $caller .=
" (for {$this->caller})";
329 $res =
$dbr->select( $table, $fields, $conds, $caller );
340 if ( $this->isEmpty() ) {
344 if ( !$this->contentLanguage->needsGenderDistinction() ) {
348 $this->genderCache->doLinkBatch( $this->data, $this->caller );
361 return $db->makeWhereFrom2d( $this->data,
"{$prefix}_namespace",
"{$prefix}_title" );
wfBacktrace( $raw=null)
Get a debug backtrace as a string.
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Caches user genders when needed to use correct namespace aliases.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Class representing a list of titles The execute() method checks them all for existence and adds them ...
PageIdentity[] null $pageIdentities
PageIdentity objects corresponding to the links in the batch.
__construct(iterable $arr=[], ?LinkCache $linkCache=null, ?TitleFormatter $titleFormatter=null, ?Language $contentLanguage=null, ?GenderCache $genderCache=null, ?ILoadBalancer $loadBalancer=null)
doGenderQuery()
Do (and cache) {{GENDER:...}} information for userpages in this LinkBatch.
ILoadBalancer $loadBalancer
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.
TitleFormatter $titleFormatter
getPageIdentities()
Do the query, add the results to the LinkCache object, and return PageIdentity instances correspondin...
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,...
Language $contentLanguage
string null $caller
For debugging which method is using this class.
array[] $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.
Represents a page (or page fragment) title within MediaWiki.
Interface for objects (potentially) representing an editable wiki page.