Merge "[FileBackend] Made supported ops check more explicit for sanity."
[lhc/web/wiklou.git] / includes / api / ApiQueryAllCategories.php
index a8f09b1..233ea75 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
 /**
- * Created on December 12, 2007
  *
- * API for MediaWiki 1.8+
  *
- * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Created on December 12, 2007
+ *
+ * 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
  * 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' );
-}
-
 /**
  * Query module to enumerate all categories, even the ones that don't have
  * category pages.
@@ -52,6 +48,9 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                $this->run( $resultPageSet );
        }
 
+       /**
+        * @param $resultPageSet ApiPageSet
+        */
        private function run( $resultPageSet = null ) {
                $db = $this->getDB();
                $params = $this->extractRequestParams();
@@ -64,12 +63,22 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                $to = ( is_null( $params['to'] ) ? null : $this->titlePartToKey( $params['to'] ) );
                $this->addWhereRange( 'cat_title', $dir, $from, $to );
 
+               $min = $params['min'];
+               $max = $params['max'];
+               if ( $dir == 'newer' ) {
+                       $this->addWhereRange( 'cat_pages', 'newer', $min, $max );
+               } else {
+                       $this->addWhereRange( 'cat_pages', 'older', $max, $min);
+               }
+    
+
                if ( isset( $params['prefix'] ) ) {
                        $this->addWhere( 'cat_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) );
                }
 
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
-               $this->addOption( 'ORDER BY', 'cat_title' . ( $params['dir'] == 'descending' ? ' DESC' : '' ) );
+               $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
+               $this->addOption( 'ORDER BY', 'cat_title' . $sort );
 
                $prop = array_flip( $params['prop'] );
                $this->addFieldsIf( array( 'cat_pages', 'cat_subcats', 'cat_files' ), isset( $prop['size'] ) );
@@ -103,7 +112,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                        // Normalize titles
                        $titleObj = Title::makeTitle( NS_CATEGORY, $row->cat_title );
                        if ( !is_null( $resultPageSet ) ) {
-                               $pages[] = $titleObj->getPrefixedText();
+                               $pages[] = $titleObj;
                        } else {
                                $item = array();
                                $result->setContent( $item, $titleObj->getText() );
@@ -143,6 +152,14 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                                        'descending'
                                ),
                        ),
+                       'min' => array(
+                               ApiBase::PARAM_DFLT => null,
+                               ApiBase::PARAM_TYPE => 'integer'
+                       ),
+                       'max' => array(
+                               ApiBase::PARAM_DFLT => null,
+                               ApiBase::PARAM_TYPE => 'integer'
+                       ),
                        'limit' => array(
                                ApiBase::PARAM_DFLT => 10,
                                ApiBase::PARAM_TYPE => 'limit',
@@ -164,6 +181,8 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                        'to' => 'The category to stop enumerating at',
                        'prefix' => 'Search for all category titles that begin with this value',
                        'dir' => 'Direction to sort in',
+                       'min' => 'Minimum number of category members',
+                       'max' => 'Maximum number of category members',
                        'limit' => 'How many categories to return',
                        'prop' => array(
                                'Which properties to get',
@@ -177,13 +196,17 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                return 'Enumerate all categories';
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=query&list=allcategories&acprop=size',
                        'api.php?action=query&generator=allcategories&gacprefix=List&prop=info',
                );
        }
 
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:Allcategories';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }