* @ingroup Cache
*/
use MediaWiki\Linker\LinkTarget;
+use MediaWiki\MediaWikiServices;
/**
* Class representing a list of titles
*/
protected $caller;
- function __construct( $arr = [] ) {
+ /**
+ * LinkBatch constructor.
+ * @param LinkTarget[] $arr Initial items to be added to the batch
+ */
+ public function __construct( $arr = [] ) {
foreach ( $arr as $item ) {
$this->addObj( $item );
}
* @param string $dbkey
*/
public function add( $ns, $dbkey ) {
- if ( $ns < 0 ) {
- return;
+ if ( $ns < 0 || $dbkey === '' ) {
+ return; // T137083
}
if ( !array_key_exists( $ns, $this->data ) ) {
$this->data[$ns] = [];
* @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, (string)$dbkey );
$cache->addBadLinkObj( $title );
- $ids[$title->getPrefixedDBkey()] = 0;
+ $pdbk = $titleFormatter->getPrefixedDBkey( $title );
+ $ids[$pdbk] = 0;
}
}
}
// This is similar to LinkHolderArray::replaceInternal
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_REPLICA );
$table = 'page';
$fields = array_merge(
LinkCache::getSelectFields(),
return false;
}
- $genderCache = GenderCache::singleton();
+ $genderCache = MediaWikiServices::getInstance()->getGenderCache();
$genderCache->doLinkBatch( $this->data, $this->caller );
return true;