summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryCategories.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryCategories.php')
-rw-r--r--includes/api/ApiQueryCategories.php32
1 files changed, 19 insertions, 13 deletions
diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php
index a6bca698..1c1f1550 100644
--- a/includes/api/ApiQueryCategories.php
+++ b/includes/api/ApiQueryCategories.php
@@ -24,11 +24,6 @@
* @file
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( "ApiQueryBase.php" );
-}
-
/**
* A query module to enumerate categories the set of pages belong to.
*
@@ -80,7 +75,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
foreach ( $params['categories'] as $cat ) {
$title = Title::newFromText( $cat );
if ( !$title || $title->getNamespace() != NS_CATEGORY ) {
- $this->setWarning( "``$cat'' is not a category" );
+ $this->setWarning( "\"$cat\" is not a category" );
} else {
$cats[] = $title->getDBkey();
}
@@ -127,11 +122,16 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
}
$this->addOption( 'USE INDEX', array( 'categorylinks' => 'cl_from' ) );
+
+ $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' );
// Don't order by cl_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
- $this->addOption( 'ORDER BY', 'cl_to' );
+ $this->addOption( 'ORDER BY', 'cl_to' . $dir );
} else {
- $this->addOption( 'ORDER BY', "cl_from, cl_to" );
+ $this->addOption( 'ORDER BY', array(
+ 'cl_from' . $dir,
+ 'cl_to' . $dir
+ ));
}
$res = $this->select( __METHOD__ );
@@ -213,6 +213,13 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
'categories' => array(
ApiBase::PARAM_ISMULTI => true,
),
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
@@ -228,6 +235,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
'show' => 'Which kind of categories to show',
'continue' => 'When more results are available, use this to continue',
'categories' => 'Only list these categories. Useful for checking whether a certain page is in a certain category',
+ 'dir' => 'The direction in which to list',
);
}
@@ -241,12 +249,10 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
) );
}
- protected function getExamples() {
+ public function getExamples() {
return array(
- 'Get a list of categories [[Albert Einstein]] belongs to:',
- ' api.php?action=query&prop=categories&titles=Albert%20Einstein',
- 'Get information about all categories used in the [[Albert Einstein]]:',
- ' api.php?action=query&generator=categories&titles=Albert%20Einstein&prop=info'
+ 'api.php?action=query&prop=categories&titles=Albert%20Einstein' => 'Get a list of categories [[Albert Einstein]] belongs to',
+ 'api.php?action=query&generator=categories&titles=Albert%20Einstein&prop=info' => 'Get information about all categories used in the [[Albert Einstein]]',
);
}