r42536 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42535‎ | r42536 | r42537 >
Date:08:13, 25 October 2008
Author:tstarling
Status:old
Tags:
Comment:
* 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
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryLogEvents.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -136,7 +136,7 @@
137137 if (is_array($value)) {
138138 // Sanity check: don't insert empty arrays,
139139 // Database::makeList() chokes on them
140 - if(!empty($value))
 140+ if ( count( $value ) )
141141 $this->where = array_merge($this->where, $value);
142142 }
143143 else
@@ -160,10 +160,12 @@
161161 /**
162162 * Equivalent to addWhere(array($field => $value))
163163 * @param string $field Field name
164 - * @param string $value Value; ignored if nul;
 164+ * @param string $value Value; ignored if null or empty array;
165165 */
166166 protected function addWhereFld($field, $value) {
167 - if (!is_null($value) && !empty($value))
 167+ // Use count() to its full documented capabilities to simultaneously
 168+ // test for null, empty array or empty countable object
 169+ if ( count( $value ) )
168170 $this->where[$field] = $value;
169171 }
170172
Index: trunk/phase3/includes/api/ApiQueryLogEvents.php
@@ -93,7 +93,8 @@
9494
9595 $limit = $params['limit'];
9696 $this->addOption('LIMIT', $limit +1);
97 -
 97+
 98+ $index = false;
9899 $user = $params['user'];
99100 if (!is_null($user)) {
100101 $userid = $db->selectField('user', 'user_id', array (
@@ -102,7 +103,7 @@
103104 if (!$userid)
104105 $this->dieUsage("User name $user not found", 'param_user');
105106 $this->addWhereFld('log_user', $userid);
106 - $this->addOption('USE INDEX', array('logging' => array('user_time','page_time')));
 107+ $index = 'user_time';
107108 }
108109
109110 $title = $params['title'];
@@ -112,9 +113,15 @@
113114 $this->dieUsage("Bad title value '$title'", 'param_title');
114115 $this->addWhereFld('log_namespace', $titleObj->getNamespace());
115116 $this->addWhereFld('log_title', $titleObj->getDBkey());
116 - $this->addOption('USE INDEX', array('logging' => array('user_time','page_time')));
 117+
 118+ // Use the title index in preference to the user index if there is a conflict
 119+ $index = 'page_time';
117120 }
 121+ if ( $index ) {
 122+ $this->addOption( 'USE INDEX', array( 'logging' => $index ) );
 123+ }
118124
 125+
119126 $data = array ();
120127 $count = 0;
121128 $res = $this->select(__METHOD__);

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r34767* Totally redo index use....aaron22:17, 13 May 2008
r41814(bug 15881) API: Empty or invalid parameters cause database errorscatrope18:23, 7 October 2008

Status & tagging log