Merge "Replace Pakaran with Punjabi"
[lhc/web/wiklou.git] / includes / api / ApiQueryIWBacklinks.php
index d2837e9..ebae3e7 100644 (file)
@@ -5,7 +5,7 @@
  * Created on May 14, 2010
  *
  * Copyright © 2010 Sam Reed
- * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -56,21 +56,19 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
 
                if ( !is_null( $params['continue'] ) ) {
                        $cont = explode( '|', $params['continue'] );
-                       if ( count( $cont ) != 3 ) {
-                               $this->dieUsage( 'Invalid continue param. You should pass the ' .
-                                       'original value returned by the previous query', '_badcontinue' );
-                       }
+                       $this->dieContinueUsageIf( count( $cont ) != 3 );
 
                        $db = $this->getDB();
+                       $op = $params['dir'] == 'descending' ? '<' : '>';
                        $prefix = $db->addQuotes( $cont[0] );
-                       $title = $db->addQuotes( $this->titleToKey( $cont[1] ) );
+                       $title = $db->addQuotes( $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 +82,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 +177,13 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
                                        'iwtitle',
                                ),
                        ),
+                       'dir' => array(
+                               ApiBase::PARAM_DFLT => 'ascending',
+                               ApiBase::PARAM_TYPE => array(
+                                       'ascending',
+                                       'descending'
+                               )
+                       ),
                );
        }
 
@@ -192,6 +198,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',
                );
        }
 
@@ -223,7 +230,6 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'missingparam', 'prefix' ),
-                       array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
                ) );
        }
 
@@ -234,7 +240,7 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
                );
        }
 
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:Iwbacklinks';
        }
 }