From b84ffc114a0985de498bc9a8387aa481f5c4e510 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sun, 17 Jun 2012 09:33:23 +0200 Subject: [PATCH] (bug 32348) Allow descending order for list=alllinks Change-Id: Ia87f743d2a28594d32fe092bc839051ac7a37729 --- RELEASE-NOTES-1.20 | 1 + includes/api/ApiQueryAllLinks.php | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 7b53839306..69a0e870b0 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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 === diff --git a/includes/api/ApiQueryAllLinks.php b/includes/api/ApiQueryAllLinks.php index 6b8fe57f39..70b6656236 100644 --- a/includes/api/ApiQueryAllLinks.php +++ b/includes/api/ApiQueryAllLinks.php @@ -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', ); } -- 2.20.1