summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryAllCategories.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryAllCategories.php')
-rw-r--r--includes/api/ApiQueryAllCategories.php57
1 files changed, 49 insertions, 8 deletions
diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php
index 78367a45..4f4c77f0 100644
--- a/includes/api/ApiQueryAllCategories.php
+++ b/includes/api/ApiQueryAllCategories.php
@@ -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
@@ -58,6 +58,17 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
$this->addTables( 'category' );
$this->addFields( 'cat_title' );
+ 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'] ) );
$to = ( is_null( $params['to'] ) ? null : $this->titlePartToKey( $params['to'] ) );
@@ -65,14 +76,20 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
$min = $params['min'];
$max = $params['max'];
- $this->addWhereRange( 'cat_pages', $dir, $min, $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'] ) );
@@ -86,7 +103,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
'pp_page=page_id',
'pp_propname' => 'hiddencat' ) ),
) );
- $this->addFields( 'pp_propname AS cat_hidden' );
+ $this->addFields( array( 'cat_hidden' => 'pp_propname' ) );
}
$res = $this->select( __METHOD__ );
@@ -98,15 +115,14 @@ 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;
}
// 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() );
@@ -121,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;
}
}
@@ -137,6 +153,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
public function getAllowedParams() {
return array(
'from' => null,
+ 'continue' => null,
'to' => null,
'prefix' => null,
'dir' => array(
@@ -172,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',
@@ -186,10 +204,33 @@ 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';
}
+ 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',