r78731 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78730‎ | r78731 | r78732 >
Date:20:25, 21 December 2010
Author:catrope
Status:deferred
Tags:
Comment:
Add some back compat support to QueryPage. getQueryInfo() is no longer abstract, but now returns null by default. Failure to override getQueryInfo() in a way that returns an array will cause QueryPage to fall back to old-style getSQL(). This is not fully b/c since getOrder() isn't brought back (replaced with getOrderFields()) but it'll allow us to leave extension QueryPages with horrendous raw SQL queries alone. Unmodified pre-1.18 code also won't explode badly like it did before (fatal due to failure to implement abstract method); instead any custom ordering (i.e. different from ORDER BY value) will break.
Modified paths:
  • /branches/querypage-work2/phase3/includes/QueryPage.php (modified) (history)

Diff [purge]

Index: branches/querypage-work2/phase3/includes/QueryPage.php
@@ -127,16 +127,34 @@
128128 * an integer; non-numeric values are useful only for sorting the
129129 * initial query (except if they're timestamps, see usesTimestamps()).
130130 *
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.
132136 * @return array
 137+ * @since 1.18
133138 */
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+ }
135152
136153 /**
137154 * Subclasses return an array of fields to order by here. Don't append
138155 * DESC to the field names, that'll be done automatically if
139 - * sortDescending() returns true
 156+ * sortDescending() returns true.
140157 * @return array
 158+ * @since 1.18
141159 */
142160 function getOrderFields() {
143161 return array( 'value' );
@@ -333,25 +351,33 @@
334352 $field .= ' DESC';
335353 }
336354 }
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 );
339381 }
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 - );
356382 return $dbr->resultObject( $res );
357383 }
358384

Status & tagging log