Merge "(bug 32384) API: Allow descending order for list=watchlistraw"
authorBrion VIBBER <brion@wikimedia.org>
Tue, 3 Apr 2012 03:16:09 +0000 (03:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 3 Apr 2012 03:16:09 +0000 (03:16 +0000)
RELEASE-NOTES-1.20
includes/api/ApiQueryWatchlistRaw.php

index e6e85b7..c51722e 100644 (file)
@@ -63,6 +63,7 @@ production.
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
 * (bug 34313) MediaWiki API intro message about "HTML format" should mention
   the format parameter.
+* (bug 32384) Allow descending order for list=watchlistraw
 
 === Languages updated in 1.20 ===
 
index 506944f..4adadf1 100644 (file)
@@ -77,18 +77,20 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
                        }
                        $ns = intval( $cont[0] );
                        $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
+                       $op = $params['dir'] == 'ascending' ? '>' : '<';
                        $this->addWhere(
-                               "wl_namespace > '$ns' OR " .
+                               "wl_namespace $op '$ns' OR " .
                                "(wl_namespace = '$ns' AND " .
-                               "wl_title >= '$title')"
+                               "wl_title $op= '$title')"
                        );
                }
 
+               $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
                // Don't ORDER BY wl_namespace if it's constant in the WHERE clause
                if ( count( $params['namespace'] ) == 1 ) {
-                       $this->addOption( 'ORDER BY', 'wl_title' );
+                       $this->addOption( 'ORDER BY', 'wl_title' . $sort );
                } else {
-                       $this->addOption( 'ORDER BY', 'wl_namespace, wl_title' );
+                       $this->addOption( 'ORDER BY', 'wl_namespace' . $sort . ', wl_title' . $sort );
                }
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
                $res = $this->select( __METHOD__ );
@@ -160,7 +162,14 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
                        ),
                        'token' => array(
                                ApiBase::PARAM_TYPE => 'string'
-                       )
+                       ),
+                       'dir' => array(
+                               ApiBase::PARAM_DFLT => 'ascending',
+                               ApiBase::PARAM_TYPE => array(
+                                       'ascending',
+                                       'descending'
+                               ),
+                       ),
                );
        }
 
@@ -176,6 +185,7 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
                        'show' => 'Only list items that meet these criteria',
                        'owner' => 'The name of the user whose watchlist you\'d like to access',
                        'token' => 'Give a security token (settable in preferences) to allow access to another user\'s watchlist',
+                       'dir' => 'Direction to sort the titles and namespaces in',
                );
        }