88 $services = MediaWikiServices::getInstance();
90 $this->linkCache =
$linkCache ?? $services->getLinkCache();
91 $this->titleFormatter =
$titleFormatter ?? $services->getTitleFormatter();
92 $this->contentLanguage =
$contentLanguage ?? $services->getContentLanguage();
93 $this->genderCache =
$genderCache ?? $services->getGenderCache();
94 $this->loadBalancer =
$loadBalancer ?? $services->getDBLoadBalancer();
96 foreach ( $arr as $item ) {
119 if ( is_object( $linkTarget ) ) {
120 $this->
add( $linkTarget->getNamespace(), $linkTarget->getDBkey() );
122 wfDebug(
"Warning: LinkBatch::addObj got invalid LinkTarget object" );
130 public function add( $ns, $dbkey ) {
131 if ( $ns < 0 || $dbkey ===
'' ) {
134 if ( !array_key_exists( $ns, $this->data ) ) {
135 $this->data[$ns] = [];
138 $this->data[$ns][strtr( $dbkey,
' ',
'_' )] = 1;
148 $this->data = $array;
166 return count( $this->data );
211 $remaining = $this->data;
212 foreach (
$res as $row ) {
216 $pdbk = $this->titleFormatter->getPrefixedDBkey(
$title );
217 $ids[$pdbk] = $row->page_id;
219 wfLogWarning( __METHOD__ .
': encountered invalid title: ' .
220 $row->page_namespace .
'-' . $row->page_title );
223 unset( $remaining[$row->page_namespace][$row->page_title] );
227 foreach ( $remaining as $ns => $dbkeys ) {
228 foreach ( $dbkeys as $dbkey => $unused ) {
232 $pdbk = $this->titleFormatter->getPrefixedDBkey(
$title );
235 wfLogWarning( __METHOD__ .
': encountered invalid title: ' . $ns .
'-' . $dbkey );
255 $fields = array_merge(
256 LinkCache::getSelectFields(),
257 [
'page_namespace',
'page_title' ]
264 if ( strval( $this->caller ) !==
'' ) {
265 $caller .=
" (for {$this->caller})";
282 if ( !$this->contentLanguage->needsGenderDistinction() ) {
286 $this->genderCache->doLinkBatch( $this->data, $this->caller );
299 return $db->makeWhereFrom2d( $this->data,
"{$prefix}_namespace",
"{$prefix}_title" );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
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 ...
Language null $contentLanguage
__construct(iterable $arr=[], ?LinkCache $linkCache=null, ?TitleFormatter $titleFormatter=null, ?Language $contentLanguage=null, ?GenderCache $genderCache=null, ?ILoadBalancer $loadBalancer=null)
ILoadBalancer null $loadBalancer
doGenderQuery()
Do (and cache) {{GENDER:...}} information for userpages in this LinkBatch.
TitleFormatter null $titleFormatter
$data
2-d array, first index namespace, second index dbkey, value arbitrary
getSize()
Returns the size of the batch.
addResultToCache( $cache, $res)
Add a result wrapper containing IDs and titles to a LinkCache object.
$caller
For debugging which method is using this class.
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.
execute()
Do the query and add the results to the LinkCache object.
LinkCache null $linkCache
setArray( $array)
Set the link list to a given 2-d array First key is the namespace, second is the DB key,...
GenderCache null $genderCache
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.
static tryNew( $namespace, $title, $fragment='', $interwiki='')
Constructs a TitleValue, or returns null if the parameters are not valid.