diff options
Diffstat (limited to 'includes/api/ApiQueryCategoryMembers.php')
-rw-r--r-- | includes/api/ApiQueryCategoryMembers.php | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/includes/api/ApiQueryCategoryMembers.php b/includes/api/ApiQueryCategoryMembers.php index 58a454a5..e831f291 100644 --- a/includes/api/ApiQueryCategoryMembers.php +++ b/includes/api/ApiQueryCategoryMembers.php @@ -51,12 +51,18 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { $params = $this->extractRequestParams(); - $category = $params['category']; - if (is_null($category)) - $this->dieUsage("Category parameter is required", 'param_category'); - $categoryTitle = Title::makeTitleSafe( NS_CATEGORY, $category ); - if ( is_null( $categoryTitle ) ) - $this->dieUsage("Category name $category is not valid", 'param_category'); + if (is_null($params['category'])) { + if (is_null($params['title'])) + $this->dieUsage("Either the cmcategory or the cmtitle parameter is required", 'notitle'); + else + $categoryTitle = Title::newFromText($params['title']); + } else if(is_null($params['title'])) + $categoryTitle = Title::makeTitleSafe(NS_CATEGORY, $params['category']); + else + $this->dieUsage("The cmcategory and cmtitle parameters can't be used together", 'titleandcategory'); + + if ( is_null( $categoryTitle ) || $categoryTitle->getNamespace() != NS_CATEGORY ) + $this->dieUsage("The category name you entered is not valid", 'invalidcategory'); $prop = array_flip($params['prop']); $fld_ids = isset($prop['ids']); @@ -78,18 +84,19 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { if($params['sort'] == 'timestamp') { $this->addOption('USE INDEX', 'cl_timestamp'); - $this->addOption('ORDER BY', 'cl_to, cl_timestamp'); + $this->addOption('ORDER BY', 'cl_to, cl_timestamp' . ($params['dir'] == 'desc' ? ' DESC' : '')); } else { $this->addOption('USE INDEX', 'cl_sortkey'); - $this->addOption('ORDER BY', 'cl_to, cl_sortkey, cl_from'); + $this->addOption('ORDER BY', 'cl_to, cl_sortkey' . ($params['dir'] == 'desc' ? ' DESC' : '') . ', cl_from'); } $this->addWhere('cl_from=page_id'); $this->setContinuation($params['continue']); $this->addWhereFld('cl_to', $categoryTitle->getDBkey()); $this->addWhereFld('page_namespace', $params['namespace']); + $this->addWhereRange('cl_timestamp', ($params['dir'] == 'asc' ? 'newer' : 'older'), $params['start'], $params['end']); $limit = $params['limit']; $this->addOption('LIMIT', $limit +1); @@ -172,9 +179,10 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { } } - protected function getAllowedParams() { + public function getAllowedParams() { return array ( - 'category' => null, + 'title' => null, + 'category' => null, // DEPRECATED, will be removed in early March 'prop' => array ( ApiBase :: PARAM_DFLT => 'ids|title', ApiBase :: PARAM_ISMULTI => true, @@ -203,36 +211,53 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { 'sortkey', 'timestamp' ) + ), + 'dir' => array( + ApiBase :: PARAM_DFLT => 'asc', + ApiBase :: PARAM_TYPE => array( + 'asc', + 'desc' + ) + ), + 'start' => array( + ApiBase :: PARAM_TYPE => 'timestamp' + ), + 'end' => array( + ApiBase :: PARAM_TYPE => 'timestamp' ) ); } - protected function getParamDescription() { + public function getParamDescription() { return array ( - 'category' => 'Which category to enumerate (required)', + 'title' => 'Which category to enumerate (required). Must include Category: prefix', 'prop' => 'What pieces of information to include', 'namespace' => 'Only include pages in these namespaces', 'sort' => 'Property to sort by', + 'dir' => 'In which direction to sort', + 'start' => 'Timestamp to start listing from', + 'end' => 'Timestamp to end listing at', 'continue' => 'For large categories, give the value retured from previous query', 'limit' => 'The maximum number of pages to return.', + 'category' => 'DEPRECATED. Like title, but without the Category: prefix.', ); } - protected function getDescription() { + public function getDescription() { return 'List all pages in a given category'; } protected function getExamples() { return array ( - "Get first 10 pages in the categories [[Physics]]:", - " api.php?action=query&list=categorymembers&cmcategory=Physics", - "Get page info about first 10 pages in the categories [[Physics]]:", - " api.php?action=query&generator=categorymembers&gcmcategory=Physics&prop=info", + "Get first 10 pages in [[Category:Physics]]:", + " api.php?action=query&list=categorymembers&cmtitle=Category:Physics", + "Get page info about first 10 pages in [[Category:Physics]]:", + " api.php?action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info", ); } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryCategoryMembers.php 25474 2007-09-04 14:30:31Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryCategoryMembers.php 30670 2008-02-07 15:17:42Z catrope $'; } } |