$search = $params['search'];
$limit = $params['limit'];
$namespaces = $params['namespace'];
+ $offset = $params['offset'];
$searcher = new TitlePrefixSearch;
- $titles = $searcher->searchWithVariants( $search, $limit, $namespaces );
+ $titles = $searcher->searchWithVariants( $search, $limit + 1, $namespaces, $offset );
if ( $resultPageSet ) {
$resultPageSet->populateFromTitles( $titles );
+ foreach ( $titles as $index => $title ) {
+ $resultPageSet->setGeneratorData( $title, array( 'index' => $index + $offset + 1 ) );
+ }
} else {
$result = $this->getResult();
+ $count = 0;
foreach ( $titles as $title ) {
- if ( !$limit-- ) {
+ if ( ++$count > $limit ) {
+ $this->setContinueEnumParameter( 'offset', $offset + $params['limit'] );
break;
}
$vals = array(
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
if ( !$fit ) {
+ $this->setContinueEnumParameter( 'offset', $offset + $count - 1 );
break;
}
}
ApiBase::PARAM_MAX => 100,
ApiBase::PARAM_MAX2 => 200,
),
+ 'offset' => array(
+ ApiBase::PARAM_DFLT => 0,
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
);
}
- public function getParamDescription() {
- return array(
- 'search' => 'Search string',
- 'limit' => 'Maximum amount of results to return',
- 'namespace' => 'Namespaces to search',
- );
- }
-
- public function getDescription() {
- return 'Perform a prefix search for page titles';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=prefixsearch&pssearch=meaning',
+ 'action=query&list=prefixsearch&pssearch=meaning'
+ => 'apihelp-query+prefixsearch-example-simple',
);
}