* Class representing a list of titles
* The execute() method checks them all for existence and adds them to a LinkCache object
*
- * @addtogroup Cache
+ * @ingroup Cache
*/
class LinkBatch {
/**
/**
* Add a ResultWrapper containing IDs and titles to a LinkCache object.
- * As normal, titles will go into the static Title cache field.
- * This function *also* stores extra fields of the title used for link
+ * As normal, titles will go into the static Title cache field.
+ * This function *also* stores extra fields of the title used for link
* parsing to avoid extra DB queries.
*/
public function addResultToCache( $cache, $res ) {
$sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect FROM $page WHERE $set";
// Do query
- $res = new ResultWrapper( $dbr, $dbr->query( $sql, __METHOD__ ) );
+ $res = $dbr->query( $sql, __METHOD__ );
wfProfileOut( __METHOD__ );
return $res;
}
/**
* Construct a WHERE clause which will match all the given titles.
*
- * @param string $prefix the appropriate table's field name prefix ('page', 'pl', etc)
- * @return string
- * @public
+ * @param $prefix String: the appropriate table's field name prefix ('page', 'pl', etc)
+ * @param $db DatabaseBase object to use
+ * @return mixed string with SQL where clause fragment, or false if no items.
*/
- public function constructSet( $prefix, &$db ) {
- $first = true;
- $firstTitle = true;
- $sql = '';
- foreach ( $this->data as $ns => $dbkeys ) {
- if ( !count( $dbkeys ) ) {
- continue;
- }
-
- if ( $first ) {
- $first = false;
- } else {
- $sql .= ' OR ';
- }
-
- 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 .= '))';
- }
- }
- if ( $first && $firstTitle ) {
- # No titles added
- return false;
- } else {
- return $sql;
- }
+ public function constructSet( $prefix, $db ) {
+ return $db->makeWhereFrom2d( $this->data, "{$prefix}_namespace", "{$prefix}_title" );
}
}
-
-