Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / api / ApiQueryWatchlistRaw.php
index 93dd018..5e96dd5 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
 /**
- * Created on Oct 4, 2008
  *
- * API for MediaWiki 1.8+
  *
- * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Created on Oct 4, 2008
+ *
+ * Copyright © 2008 Roan Kattouw <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
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * This query action allows clients to retrieve a list of pages
  * on the logged-in user's watchlist.
@@ -48,6 +44,10 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
                $this->run( $resultPageSet );
        }
 
+       /**
+        * @param $resultPageSet ApiPageSet
+        * @return void
+        */
        private function run( $resultPageSet = null ) {
                $this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
 
@@ -58,7 +58,7 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
                $prop = array_flip( (array)$params['prop'] );
                $show = array_flip( (array)$params['show'] );
                if ( isset( $show['changed'] ) && isset( $show['!changed'] ) ) {
-                       $this->dieUsageMsg( array( 'show' ) );
+                       $this->dieUsageMsg( 'show' );
                }
 
                $this->addTables( 'watchlist' );
@@ -76,19 +76,24 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
                                        "original value returned by the previous query", "_badcontinue" );
                        }
                        $ns = intval( $cont[0] );
-                       $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
+                       $title = $this->getDB()->addQuotes( $this->titleToKey( $cont[1] ) );
+                       $op = $params['dir'] == 'ascending' ? '>' : '<';
                        $this->addWhere(
-                               "wl_namespace > '$ns' OR " .
-                               "(wl_namespace = '$ns' AND " .
-                               "wl_title >= '$title')"
+                               "wl_namespace $op $ns OR " .
+                               "(wl_namespace = $ns AND " .
+                               "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', array(
+                               'wl_namespace' . $sort,
+                               'wl_title' . $sort
+                       ));
                }
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
                $res = $this->select( __METHOD__ );
@@ -160,7 +165,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 +188,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',
                );
        }
 
@@ -192,7 +205,7 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
                ) );
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=query&list=watchlistraw',
                        'api.php?action=query&generator=watchlistraw&gwrshow=changed&prop=revisions',
@@ -202,4 +215,4 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }
-}
\ No newline at end of file
+}