From c4654f3fb267498f89776f0ebd34626defd64882 Mon Sep 17 00:00:00 2001 From: mrbluesky Date: Thu, 29 Mar 2012 23:15:32 +0200 Subject: [PATCH] (bug 32384) API: Allow descending order for list=watchlistraw Patchset2: add parentheses around conditional expression Change-Id: Ibfc3cdce6a0f30f2086ede9fb91030ded174a1fb --- RELEASE-NOTES-1.20 | 1 + includes/api/ApiQueryWatchlistRaw.php | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 5e42184611..6220cd1f80 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -59,6 +59,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 === diff --git a/includes/api/ApiQueryWatchlistRaw.php b/includes/api/ApiQueryWatchlistRaw.php index 506944f0b3..4adadf1e32 100644 --- a/includes/api/ApiQueryWatchlistRaw.php +++ b/includes/api/ApiQueryWatchlistRaw.php @@ -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', ); } -- 2.20.1