X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FLinkBatch.php;h=db1114c93875295b0e70f880269a6af3caa6820b;hb=f5c5abd1eade5be126b5aa97f4a66dae21c791c8;hp=e385edea4ea41300057b53127c00b39f01d7aa57;hpb=bc14eb8045cb02dead76a1c4203c45ab6e31cb36;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/LinkBatch.php b/includes/LinkBatch.php index e385edea4e..db1114c938 100644 --- a/includes/LinkBatch.php +++ b/includes/LinkBatch.php @@ -3,18 +3,16 @@ /** * 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 { /** * 2-d array, first index namespace, second index dbkey, value arbitrary - * @todo FIXME should it really be public ? */ - public $data = array(); + var $data = array(); - function LinkBatch( $arr = array() ) { + function __construct( $arr = array() ) { foreach( $arr as $item ) { $this->addObj( $item ); } @@ -36,7 +34,7 @@ class LinkBatch { $this->data[$ns] = array(); } - $this->data[$ns][$dbkey] = 1; + $this->data[$ns][str_replace( ' ', '_', $dbkey )] = 1; } /** @@ -67,7 +65,7 @@ class LinkBatch { */ function execute() { $linkCache =& LinkCache::singleton(); - $this->executeInto( $linkCache ); + return $this->executeInto( $linkCache ); } /** @@ -98,7 +96,7 @@ class LinkBatch { // 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; @@ -113,7 +111,6 @@ class LinkBatch { */ function doQuery() { $fname = 'LinkBatch::doQuery'; - $namespaces = array(); if ( $this->isEmpty() ) { return false; @@ -122,7 +119,7 @@ class LinkBatch { // 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 ) { @@ -159,19 +156,26 @@ class LinkBatch { } 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 @@ -182,4 +186,4 @@ class LinkBatch { } } -?> +