Index: branches/querypage-work2/phase3/includes/QueryPage.php |
— | — | @@ -127,16 +127,34 @@ |
128 | 128 | * an integer; non-numeric values are useful only for sorting the |
129 | 129 | * initial query (except if they're timestamps, see usesTimestamps()). |
130 | 130 | * |
131 | | - * Don't include an ORDER or LIMIT clause, they will be added |
| 131 | + * Don't include an ORDER or LIMIT clause, they will be added. |
| 132 | + * |
| 133 | + * If this function is not overridden or returns something other than |
| 134 | + * an array, getSQL() will be used instead. This is for backwards |
| 135 | + * compatibility only and is strongly deprecated. |
132 | 136 | * @return array |
| 137 | + * @since 1.18 |
133 | 138 | */ |
134 | | - abstract function getQueryInfo(); |
| 139 | + function getQueryInfo() { |
| 140 | + return null; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * For back-compat, subclasses may return a raw SQL query here, as a string. |
| 145 | + * This is stronly deprecated; getQueryInfo() should be overridden instead. |
| 146 | + * @return string |
| 147 | + * @deprecated |
| 148 | + */ |
| 149 | + function getSQL() { |
| 150 | + throw new MWException( "Bug in a QueryPage: doesn't implement getQueryInfo() nor getQuery() properly" ); |
| 151 | + } |
135 | 152 | |
136 | 153 | /** |
137 | 154 | * Subclasses return an array of fields to order by here. Don't append |
138 | 155 | * DESC to the field names, that'll be done automatically if |
139 | | - * sortDescending() returns true |
| 156 | + * sortDescending() returns true. |
140 | 157 | * @return array |
| 158 | + * @since 1.18 |
141 | 159 | */ |
142 | 160 | function getOrderFields() { |
143 | 161 | return array( 'value' ); |
— | — | @@ -333,25 +351,33 @@ |
334 | 352 | $field .= ' DESC'; |
335 | 353 | } |
336 | 354 | } |
337 | | - if ( !is_array( @$query['options'] ) ) { |
338 | | - $options = array (); |
| 355 | + if ( is_array( $query ) ) { |
| 356 | + if ( !is_array( @$query['options'] ) ) { |
| 357 | + $options = array (); |
| 358 | + } |
| 359 | + if ( count( $order ) ) { |
| 360 | + $query['options']['ORDER BY'] = implode( ', ', $order ); |
| 361 | + } |
| 362 | + if ( $limit !== false ) { |
| 363 | + $query['options']['LIMIT'] = intval( $limit ); |
| 364 | + } |
| 365 | + if ( $offset !== false ) { |
| 366 | + $query['options']['OFFSET'] = intval( $offset ); |
| 367 | + } |
| 368 | + |
| 369 | + $dbr = wfGetDB( DB_SLAVE ); |
| 370 | + $res = $dbr->select( (array)@$query['tables'], |
| 371 | + (array)@$query['fields'], |
| 372 | + (array)@$query['conds'], $fname, |
| 373 | + $query['options'], (array)@$query['join_conds'] |
| 374 | + ); |
| 375 | + } else { |
| 376 | + // Old-fashioned raw SQL style, deprecated |
| 377 | + $sql = $this->getSQL(); |
| 378 | + $sql .= ' ORDER BY ' . implode( ', ', $order ); |
| 379 | + $sql = $dbr->limitResult( $sql, $limit, $offset ); |
| 380 | + $res = $dbr->query( $sql ); |
339 | 381 | } |
340 | | - if ( count( $order ) ) { |
341 | | - $query['options']['ORDER BY'] = implode( ', ', $order ); |
342 | | - } |
343 | | - if ( $limit !== false ) { |
344 | | - $query['options']['LIMIT'] = intval( $limit ); |
345 | | - } |
346 | | - if ( $offset !== false ) { |
347 | | - $query['options']['OFFSET'] = intval( $offset ); |
348 | | - } |
349 | | - |
350 | | - $dbr = wfGetDB( DB_SLAVE ); |
351 | | - $res = $dbr->select( (array)@$query['tables'], |
352 | | - (array)@$query['fields'], |
353 | | - (array)@$query['conds'], $fname, |
354 | | - $query['options'], (array)@$query['join_conds'] |
355 | | - ); |
356 | 382 | return $dbr->resultObject( $res ); |
357 | 383 | } |
358 | 384 | |