Index: trunk/phase3/includes/api/ApiQueryBase.php |
— | — | @@ -136,7 +136,7 @@ |
137 | 137 | if (is_array($value)) { |
138 | 138 | // Sanity check: don't insert empty arrays, |
139 | 139 | // Database::makeList() chokes on them |
140 | | - if(!empty($value)) |
| 140 | + if ( count( $value ) ) |
141 | 141 | $this->where = array_merge($this->where, $value); |
142 | 142 | } |
143 | 143 | else |
— | — | @@ -160,10 +160,12 @@ |
161 | 161 | /** |
162 | 162 | * Equivalent to addWhere(array($field => $value)) |
163 | 163 | * @param string $field Field name |
164 | | - * @param string $value Value; ignored if nul; |
| 164 | + * @param string $value Value; ignored if null or empty array; |
165 | 165 | */ |
166 | 166 | 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 ) ) |
168 | 170 | $this->where[$field] = $value; |
169 | 171 | } |
170 | 172 | |
Index: trunk/phase3/includes/api/ApiQueryLogEvents.php |
— | — | @@ -93,7 +93,8 @@ |
94 | 94 | |
95 | 95 | $limit = $params['limit']; |
96 | 96 | $this->addOption('LIMIT', $limit +1); |
97 | | - |
| 97 | + |
| 98 | + $index = false; |
98 | 99 | $user = $params['user']; |
99 | 100 | if (!is_null($user)) { |
100 | 101 | $userid = $db->selectField('user', 'user_id', array ( |
— | — | @@ -102,7 +103,7 @@ |
103 | 104 | if (!$userid) |
104 | 105 | $this->dieUsage("User name $user not found", 'param_user'); |
105 | 106 | $this->addWhereFld('log_user', $userid); |
106 | | - $this->addOption('USE INDEX', array('logging' => array('user_time','page_time'))); |
| 107 | + $index = 'user_time'; |
107 | 108 | } |
108 | 109 | |
109 | 110 | $title = $params['title']; |
— | — | @@ -112,9 +113,15 @@ |
113 | 114 | $this->dieUsage("Bad title value '$title'", 'param_title'); |
114 | 115 | $this->addWhereFld('log_namespace', $titleObj->getNamespace()); |
115 | 116 | $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'; |
117 | 120 | } |
| 121 | + if ( $index ) { |
| 122 | + $this->addOption( 'USE INDEX', array( 'logging' => $index ) ); |
| 123 | + } |
118 | 124 | |
| 125 | + |
119 | 126 | $data = array (); |
120 | 127 | $count = 0; |
121 | 128 | $res = $this->select(__METHOD__); |