* @file
* @ingroup Cache
*/
+use MediaWiki\Linker\LinkTarget;
+use MediaWiki\MediaWikiServices;
/**
* Class representing a list of titles
/**
* @param LinkTarget $linkTarget
*/
- public function addObj( LinkTarget $linkTarget ) {
- $this->add( $linkTarget->getNamespace(), $linkTarget->getDBkey() );
+ public function addObj( $linkTarget ) {
+ if ( is_object( $linkTarget ) ) {
+ $this->add( $linkTarget->getNamespace(), $linkTarget->getDBkey() );
+ } else {
+ wfDebug( "Warning: LinkBatch::addObj got invalid LinkTarget object\n" );
+ }
}
/**
* @return array Mapping PDBK to ID
*/
public function execute() {
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
return $this->executeInto( $linkCache );
}
return [];
}
+ $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
// For each returned entry, add it to the list of good links, and remove it from $remaining
$ids = [];
$remaining = $this->data;
foreach ( $res as $row ) {
- $title = Title::makeTitle( $row->page_namespace, $row->page_title );
+ $title = new TitleValue( (int)$row->page_namespace, $row->page_title );
$cache->addGoodLinkObjFromRow( $title, $row );
- $ids[$title->getPrefixedDBkey()] = $row->page_id;
+ $pdbk = $titleFormatter->getPrefixedDBkey( $title );
+ $ids[$pdbk] = $row->page_id;
unset( $remaining[$row->page_namespace][$row->page_title] );
}
// The remaining links in $data are bad links, register them as such
foreach ( $remaining as $ns => $dbkeys ) {
foreach ( $dbkeys as $dbkey => $unused ) {
- $title = Title::makeTitle( $ns, $dbkey );
+ $title = new TitleValue( (int)$ns, $dbkey );
$cache->addBadLinkObj( $title );
- $ids[$title->getPrefixedDBkey()] = 0;
+ $pdbk = $titleFormatter->getPrefixedDBkey( $title );
+ $ids[$pdbk] = 0;
}
}
* @return bool|ResultWrapper
*/
public function doQuery() {
- global $wgContentHandlerUseDB, $wgPageLanguageUseDB;
-
if ( $this->isEmpty() ) {
return false;
}
// This is similar to LinkHolderArray::replaceInternal
$dbr = wfGetDB( DB_SLAVE );
$table = 'page';
- $fields = [ 'page_id', 'page_namespace', 'page_title', 'page_len',
- 'page_is_redirect', 'page_latest' ];
-
- if ( $wgContentHandlerUseDB ) {
- $fields[] = 'page_content_model';
- }
- if ( $wgPageLanguageUseDB ) {
- $fields[] = 'page_lang';
- }
+ $fields = array_merge(
+ LinkCache::getSelectFields(),
+ [ 'page_namespace', 'page_title' ]
+ );
$conds = $this->constructSet( 'page', $dbr );
return false;
}
- $genderCache = GenderCache::singleton();
+ $genderCache = MediaWikiServices::getInstance()->getGenderCache();
$genderCache->doLinkBatch( $this->data, $this->caller );
return true;