From c4dd73000a734ddf8f8cf65ca5c82b406da00a92 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 25 Oct 2008 08:13:40 +0000 Subject: [PATCH] * Fix r41814: totally broken use of empty(), ignores conditions that compare with numeric zero. I've told you before, don't use empty() to test for zero-length arrays. * Fix r34767: wrong indexes used in ApiQueryLogEvents --- includes/api/ApiQueryBase.php | 8 +++++--- includes/api/ApiQueryLogEvents.php | 13 ++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 26792a7a51..e2c43acae6 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -136,7 +136,7 @@ abstract class ApiQueryBase extends ApiBase { 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 @@ -160,10 +160,12 @@ abstract class ApiQueryBase extends ApiBase { /** * 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; } diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 1fd156787e..492da5d392 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -93,7 +93,8 @@ class ApiQueryLogEvents extends ApiQueryBase { $limit = $params['limit']; $this->addOption('LIMIT', $limit +1); - + + $index = false; $user = $params['user']; if (!is_null($user)) { $userid = $db->selectField('user', 'user_id', array ( @@ -102,7 +103,7 @@ class ApiQueryLogEvents extends ApiQueryBase { 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']; @@ -112,8 +113,14 @@ class ApiQueryLogEvents extends ApiQueryBase { $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; -- 2.20.1