X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryAllCategories.php;h=60b57bfc3a23a6950308a58013480bc87ae3967d;hb=9e41908dc0a3629da35cd8dd6c00abed59098227;hp=c733703d096a2bf2855cc42fddbb024d4cbe6b67;hpb=fa6402516114f900194ab0203ff8878f9094bcab;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php index c733703d09..60b57bfc3a 100644 --- a/includes/api/ApiQueryAllCategories.php +++ b/includes/api/ApiQueryAllCategories.php @@ -24,11 +24,6 @@ * @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. @@ -55,7 +50,6 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { /** * @param $resultPageSet ApiPageSet - * @return void */ private function run( $resultPageSet = null ) { $db = $this->getDB(); @@ -69,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'] ) ); @@ -108,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() ); @@ -148,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', @@ -169,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', @@ -178,17 +192,38 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { ); } + public function getResultProperties() { + return array( + '' => array( + '*' => 'string' + ), + 'size' => array( + 'size' => 'integer', + 'pages' => 'integer', + 'files' => 'integer', + 'subcats' => 'integer' + ), + 'hidden' => array( + 'hidden' => 'boolean' + ) + ); + } + public function getDescription() { 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$'; }