X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryAllCategories.php;h=09f6edbd3bbfc55eaf00e0c8e36c04d69423d7d0;hb=125d6d5feceba4d3d740efb5be0be83058546a20;hp=60b57bfc3a23a6950308a58013480bc87ae3967d;hpb=a4419129749e97b09217b3a1f7ec8024013c932b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php index 60b57bfc3a..09f6edbd3b 100644 --- a/includes/api/ApiQueryAllCategories.php +++ b/includes/api/ApiQueryAllCategories.php @@ -4,7 +4,7 @@ * * Created on December 12, 2007 * - * Copyright © 2007 Roan Kattouw .@gmail.com + * Copyright © 2007 Roan Kattouw ".@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'] ) ); @@ -104,8 +115,7 @@ 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; } @@ -127,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; } } @@ -143,6 +153,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { public function getAllowedParams() { return array( 'from' => null, + 'continue' => null, 'to' => null, 'prefix' => null, 'dir' => array( @@ -178,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', @@ -213,6 +225,12 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { 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',