* Fix r41814: totally broken use of empty(), ignores conditions that compare with...
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 25 Oct 2008 08:13:40 +0000 (08:13 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 25 Oct 2008 08:13:40 +0000 (08:13 +0000)
* Fix r34767: wrong indexes used in ApiQueryLogEvents

includes/api/ApiQueryBase.php
includes/api/ApiQueryLogEvents.php

index 26792a7..e2c43ac 100644 (file)
@@ -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;
        }
 
index 1fd1567..492da5d 100644 (file)
@@ -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;