* @file
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( "ApiQueryBase.php" );
-}
-
/**
* A query module to enumerate pages that belong to a category.
*
private function run( $resultPageSet = null ) {
$params = $this->extractRequestParams();
- $this->requireOnlyOneParameter( $params, 'title', 'pageid' );
-
- if ( isset( $params['title'] ) ) {
- $categoryTitle = Title::newFromText( $params['title'] );
-
- if ( is_null( $categoryTitle ) || $categoryTitle->getNamespace() != NS_CATEGORY ) {
- $this->dieUsage( 'The category name you entered is not valid', 'invalidcategory' );
- }
- } elseif( isset( $params['pageid'] ) ) {
- $categoryTitle = Title::newFromID( $params['pageid'] );
-
- if ( !$categoryTitle ) {
- $this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) );
- } elseif ( $categoryTitle->getNamespace() != NS_CATEGORY ) {
- $this->dieUsage( 'The category name you entered is not valid', 'invalidcategory' );
- }
+ $categoryTitle = $this->getTitleOrPageId( $params )->getTitle();
+ if ( $categoryTitle->getNamespace() != NS_CATEGORY ) {
+ $this->dieUsage( 'The category name you entered is not valid', 'invalidcategory' );
}
$prop = array_flip( $params['prop'] );
$this->addWhereFld( 'page_namespace', $params['namespace'] );
}
- $dir = $params['dir'] == 'asc' ? 'newer' : 'older';
+ $dir = in_array( $params['dir'], array( 'asc', 'ascending', 'newer' ) ) ? 'newer' : 'older';
if ( $params['sort'] == 'timestamp' ) {
- $this->addWhereRange( 'cl_timestamp',
+ $this->addTimestampWhereRange( 'cl_timestamp',
$dir,
$params['start'],
$params['end'] );
$contWhere = "cl_sortkey $op $escSortkey OR " .
"(cl_sortkey = $escSortkey AND " .
"cl_from $op= $from)";
-
+ // The below produces ORDER BY cl_sortkey, cl_from, possibly with DESC added to each of them
+ $this->addWhereRange( 'cl_sortkey', $dir, null, null );
+ $this->addWhereRange( 'cl_from', $dir, null, null );
} else {
+ $startsortkey = $params['startsortkeyprefix'] !== null ?
+ Collation::singleton()->getSortkey( $params['startsortkeyprefix'] ) :
+ $params['startsortkey'];
+ $endsortkey = $params['endsortkeyprefix'] !== null ?
+ Collation::singleton()->getSortkey( $params['endsortkeyprefix'] ) :
+ $params['endsortkey'];
+
// The below produces ORDER BY cl_sortkey, cl_from, possibly with DESC added to each of them
$this->addWhereRange( 'cl_sortkey',
$dir,
- $params['startsortkey'],
- $params['endsortkey'] );
+ $startsortkey,
+ $endsortkey );
$this->addWhereRange( 'cl_from', $dir, null, null );
}
$this->addOption( 'USE INDEX', 'cl_sortkey' );
)
),
'dir' => array(
- ApiBase::PARAM_DFLT => 'asc',
+ ApiBase::PARAM_DFLT => 'ascending',
ApiBase::PARAM_TYPE => array(
'asc',
- 'desc'
+ 'desc',
+ // Normalising with other modules
+ 'ascending',
+ 'descending',
+ 'newer',
+ 'older',
)
),
'start' => array(
),
'startsortkey' => null,
'endsortkey' => null,
+ 'startsortkeyprefix' => null,
+ 'endsortkeyprefix' => null,
);
}
'end' => "Timestamp to end listing at. Can only be used with {$p}sort=timestamp",
'startsortkey' => "Sortkey to start listing from. Must be given in binary format. Can only be used with {$p}sort=sortkey",
'endsortkey' => "Sortkey to end listing at. Must be given in binary format. Can only be used with {$p}sort=sortkey",
- 'continue' => 'For large categories, give the value retured from previous query',
+ 'startsortkeyprefix' => "Sortkey prefix to start listing from. Can only be used with {$p}sort=sortkey. Overrides {$p}startsortkey",
+ 'endsortkeyprefix' => "Sortkey prefix to end listing BEFORE (not at, if this value occurs it will not be included!). Can only be used with {$p}sort=sortkey. Overrides {$p}endsortkey",
+ 'continue' => 'For large categories, give the value returned from previous query',
'limit' => 'The maximum number of pages to return.',
);
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(),
- $this->getRequireOnlyOneParameterErrorMessages( array( 'title', 'pageid' ) ),
+ $this->getTitleOrPageIdErrorMessage(),
array(
array( 'code' => 'invalidcategory', 'info' => 'The category name you entered is not valid' ),
array( 'code' => 'badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
- array( 'nosuchpageid', 'pageid' ),
)
);
}
- protected function getExamples() {
+ public function getExamples() {
return array(
- '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',
+ 'api.php?action=query&list=categorymembers&cmtitle=Category:Physics' => 'Get first 10 pages in [[Category:Physics]]',
+ 'api.php?action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info' => 'Get page info about first 10 pages in [[Category:Physics]]',
);
}
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Categorymembers';
+ }
+
public function getVersion() {
return __CLASS__ . ': $Id$';
}