(bug 32348) Allow descending order for list=alllinks
authorumherirrender <umherirrender_de.wp@web.de>
Sun, 17 Jun 2012 07:33:23 +0000 (09:33 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Sun, 17 Jun 2012 07:33:23 +0000 (09:33 +0200)
Change-Id: Ia87f743d2a28594d32fe092bc839051ac7a37729

RELEASE-NOTES-1.20
includes/api/ApiQueryAllLinks.php

index 7b53839..69a0e87 100644 (file)
@@ -139,6 +139,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 36761) "Mark pages as visited" now submits previously established filter options
 * (bug 32643) action=purge with forcelinkupdate no longer crashes when ratelimit is reached
 * The paraminfo module now also contains result properties for most modules
+* (bug 32348) Allow descending order for list=alllinks
 
 === Languages updated in 1.20 ===
 
index 6b8fe57..70b6656 100644 (file)
@@ -80,12 +80,13 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                        if ( count( $continueArr ) != 2 ) {
                                $this->dieUsage( 'Invalid continue parameter', 'badcontinue' );
                        }
+                       $op = $params['dir'] == 'descending' ? '<' : '>';
                        $continueTitle = $db->addQuotes( $this->titleToKey( $continueArr[0] ) );
                        $continueFrom = intval( $continueArr[1] );
                        $this->addWhere(
-                               "pl_title > $continueTitle OR " .
+                               "pl_title $op $continueTitle OR " .
                                "(pl_title = $continueTitle AND " .
-                               "pl_from > $continueFrom)"
+                               "pl_from $op= $continueFrom)"
                        );
                }
 
@@ -104,12 +105,13 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                $limit = $params['limit'];
                $this->addOption( 'LIMIT', $limit + 1 );
 
+               $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
+               $orderBy = array();
+               $orderBy[] = 'pl_title' . $sort;
                if ( !$params['unique'] ) {
-                       $this->addOption( 'ORDER BY', array(
-                               'pl_title',
-                               'pl_from'
-                       ));
+                       $orderBy[] = 'pl_from' . $sort;
                }
+               $this->addOption( 'ORDER BY', $orderBy );
 
                $res = $this->select( __METHOD__ );
 
@@ -183,7 +185,14 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                                ApiBase::PARAM_MIN => 1,
                                ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
                                ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
-                       )
+                       ),
+                       'dir' => array(
+                               ApiBase::PARAM_DFLT => 'ascending',
+                               ApiBase::PARAM_TYPE => array(
+                                       'ascending',
+                                       'descending'
+                               )
+                       ),
                );
        }
 
@@ -202,6 +211,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                        'namespace' => 'The namespace to enumerate',
                        'limit' => 'How many total links to return',
                        'continue' => 'When more results are available, use this to continue',
+                       'dir' => 'The direction in which to list',
                );
        }