Merge "AJAXify watchlist editor"
[lhc/web/wiklou.git] / includes / api / ApiQueryAllCategories.php
index a2fb5c3..09f6edb 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Created on December 12, 2007
  *
- * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@gmail.com
+ * Copyright © 2007 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
@@ -57,7 +57,17 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
 
                $this->addTables( 'category' );
                $this->addFields( 'cat_title' );
-               $this->addWhere( 'cat_pages > 0' );
+
+               if ( !is_null( $params['continue'] ) ) {
+                       $cont = explode( '|', $params['continue'] );
+                       if ( count( $cont ) != 1 ) {
+                               $this->dieUsage( "Invalid continue param. You should pass the " .
+                                       "original value returned by the previous query", "_badcontinue" );
+                       }
+                       $op = $params['dir'] == 'descending' ? '<' : '>';
+                       $cont_from = $db->addQuotes( $cont[0] );
+                       $this->addWhere( "cat_title $op= $cont_from" );
+               }
 
                $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
                $from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) );
@@ -105,8 +115,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                foreach ( $res as $row ) {
                        if ( ++ $count > $params['limit'] ) {
                                // We've reached the one extra which shows that there are additional cats to be had. Stop here...
-                               // TODO: Security issue - if the user has no right to view next title, it will still be shown
-                               $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->cat_title ) );
+                               $this->setContinueEnumParameter( 'continue', $row->cat_title );
                                break;
                        }
 
@@ -128,7 +137,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                                }
                                $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $item );
                                if ( !$fit ) {
-                                       $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->cat_title ) );
+                                       $this->setContinueEnumParameter( 'continue', $row->cat_title );
                                        break;
                                }
                        }
@@ -144,6 +153,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
        public function getAllowedParams() {
                return array(
                        'from' => null,
+                       'continue' => null,
                        'to' => null,
                        'prefix' => null,
                        'dir' => array(
@@ -179,6 +189,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
        public function getParamDescription() {
                return array(
                        'from' => 'The category to start enumerating from',
+                       'continue' => 'When more results are available, use this to continue',
                        'to' => 'The category to stop enumerating at',
                        'prefix' => 'Search for all category titles that begin with this value',
                        'dir' => 'Direction to sort in',
@@ -214,6 +225,12 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                return 'Enumerate all categories';
        }
 
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+                       array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
+               ) );
+       }
+
        public function getExamples() {
                return array(
                        'api.php?action=query&list=allcategories&acprop=size',