From f191e6320f237f70f1b641a1dd85588f33bd4b28 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sun, 17 Jun 2012 09:46:30 +0200 Subject: [PATCH] (bug 32382) Allow descending order for list=iwbacklinks Change-Id: If9425f3d6dbee3da34e875c1b02088478c3d6d53 --- RELEASE-NOTES-1.20 | 1 + includes/api/ApiQueryIWBacklinks.php | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 002d177b68..bec181800f 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -172,6 +172,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki. * The paraminfo module now also contains result properties for most modules * (bug 32348) Allow descending order for list=alllinks * (bug 31777) Upload unknown error ``fileexists-forbidden'' +* (bug 32382) Allow descending order for list=iwbacklinks === Languages updated in 1.20 === diff --git a/includes/api/ApiQueryIWBacklinks.php b/includes/api/ApiQueryIWBacklinks.php index d2837e9d46..37f347d733 100644 --- a/includes/api/ApiQueryIWBacklinks.php +++ b/includes/api/ApiQueryIWBacklinks.php @@ -62,15 +62,16 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase { } $db = $this->getDB(); + $op = $params['dir'] == 'descending' ? '<' : '>'; $prefix = $db->addQuotes( $cont[0] ); $title = $db->addQuotes( $this->titleToKey( $cont[1] ) ); $from = intval( $cont[2] ); $this->addWhere( - "iwl_prefix > $prefix OR " . + "iwl_prefix $op $prefix OR " . "(iwl_prefix = $prefix AND " . - "(iwl_title > $title OR " . + "(iwl_title $op $title OR " . "(iwl_title = $title AND " . - "iwl_from >= $from)))" + "iwl_from $op= $from)))" ); } @@ -84,22 +85,23 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase { $this->addFields( array( 'page_id', 'page_title', 'page_namespace', 'page_is_redirect', 'iwl_from', 'iwl_prefix', 'iwl_title' ) ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); if ( isset( $params['prefix'] ) ) { $this->addWhereFld( 'iwl_prefix', $params['prefix'] ); if ( isset( $params['title'] ) ) { $this->addWhereFld( 'iwl_title', $params['title'] ); - $this->addOption( 'ORDER BY', 'iwl_from' ); + $this->addOption( 'ORDER BY', 'iwl_from' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'iwl_title', - 'iwl_from' + 'iwl_title' . $sort, + 'iwl_from' . $sort )); } } else { $this->addOption( 'ORDER BY', array( - 'iwl_prefix', - 'iwl_title', - 'iwl_from' + 'iwl_prefix' . $sort, + 'iwl_title' . $sort, + 'iwl_from' . $sort )); } @@ -178,6 +180,13 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase { 'iwtitle', ), ), + 'dir' => array( + ApiBase::PARAM_DFLT => 'ascending', + ApiBase::PARAM_TYPE => array( + 'ascending', + 'descending' + ) + ), ); } @@ -192,6 +201,7 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase { ' iwtitle - Adds the title of the interwiki', ), 'limit' => 'How many total pages to return', + 'dir' => 'The direction in which to list', ); } -- 2.20.1