if (is_array($value)) {
// Sanity check: don't insert empty arrays,
// Database::makeList() chokes on them
- if(!empty($value))
+ if ( count( $value ) )
$this->where = array_merge($this->where, $value);
}
else
/**
* Equivalent to addWhere(array($field => $value))
* @param string $field Field name
- * @param string $value Value; ignored if nul;
+ * @param string $value Value; ignored if null or empty array;
*/
protected function addWhereFld($field, $value) {
- if (!is_null($value) && !empty($value))
+ // Use count() to its full documented capabilities to simultaneously
+ // test for null, empty array or empty countable object
+ if ( count( $value ) )
$this->where[$field] = $value;
}
$limit = $params['limit'];
$this->addOption('LIMIT', $limit +1);
-
+
+ $index = false;
$user = $params['user'];
if (!is_null($user)) {
$userid = $db->selectField('user', 'user_id', array (
if (!$userid)
$this->dieUsage("User name $user not found", 'param_user');
$this->addWhereFld('log_user', $userid);
- $this->addOption('USE INDEX', array('logging' => array('user_time','page_time')));
+ $index = 'user_time';
}
$title = $params['title'];
$this->dieUsage("Bad title value '$title'", 'param_title');
$this->addWhereFld('log_namespace', $titleObj->getNamespace());
$this->addWhereFld('log_title', $titleObj->getDBkey());
- $this->addOption('USE INDEX', array('logging' => array('user_time','page_time')));
+
+ // Use the title index in preference to the user index if there is a conflict
+ $index = 'page_time';
}
+ if ( $index ) {
+ $this->addOption( 'USE INDEX', array( 'logging' => $index ) );
+ }
+
$data = array ();
$count = 0;