/**
* Class representing a list of titles
* The execute() method checks them all for existence and adds them to a LinkCache object
- +
- * @package MediaWiki
- * @subpackage Cache
+ *
+ * @addtogroup Cache
*/
class LinkBatch {
/**
*/
var $data = array();
- function LinkBatch( $arr = array() ) {
+ function __construct( $arr = array() ) {
foreach( $arr as $item ) {
$this->addObj( $item );
}
$this->data[$ns] = array();
}
- $this->data[$ns][$dbkey] = 1;
+ $this->data[$ns][str_replace( ' ', '_', $dbkey )] = 1;
}
/**
*/
function execute() {
$linkCache =& LinkCache::singleton();
- $this->executeInto( $linkCache );
+ return $this->executeInto( $linkCache );
}
/**
// The remaining links in $data are bad links, register them as such
foreach ( $remaining as $ns => $dbkeys ) {
- foreach ( $dbkeys as $dbkey => $nothing ) {
+ foreach ( $dbkeys as $dbkey => $unused ) {
$title = Title::makeTitle( $ns, $dbkey );
$cache->addBadLinkObj( $title );
$ids[$title->getPrefixedDBkey()] = 0;
*/
function doQuery() {
$fname = 'LinkBatch::doQuery';
- $namespaces = array();
if ( $this->isEmpty() ) {
return false;
// Construct query
// This is very similar to Parser::replaceLinkHolders
- $dbr =& wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE );
$page = $dbr->tableName( 'page' );
$set = $this->constructSet( 'page', $dbr );
if ( $set === false ) {
} else {
$sql .= ' OR ';
}
- $sql .= "({$prefix}_namespace=$ns AND {$prefix}_title IN (";
-
- $firstTitle = true;
- foreach( $dbkeys as $dbkey => $nothing ) {
- if ( $firstTitle ) {
- $firstTitle = false;
- } else {
- $sql .= ',';
+
+ if (count($dbkeys)==1) { // avoid multiple-reference syntax if simple equality can be used
+ $singleKey = array_keys($dbkeys);
+ $sql .= "({$prefix}_namespace=$ns AND {$prefix}_title=".
+ $db->addQuotes($singleKey[0]).
+ ")";
+ } else {
+ $sql .= "({$prefix}_namespace=$ns AND {$prefix}_title IN (";
+
+ $firstTitle = true;
+ foreach( $dbkeys as $dbkey => $unused ) {
+ if ( $firstTitle ) {
+ $firstTitle = false;
+ } else {
+ $sql .= ',';
+ }
+ $sql .= $db->addQuotes( $dbkey );
}
- $sql .= $db->addQuotes( $dbkey );
+ $sql .= '))';
}
-
- $sql .= '))';
}
if ( $first && $firstTitle ) {
# No titles added
}
}
-?>
+