run(); } public function executeGenerator( $resultPageSet ) { $this->run( $resultPageSet ); } /** * @param ApiPageSet|null $resultPageSet */ private function run( $resultPageSet = null ) { $params = $this->extractRequestParams(); $search = $params['search']; $limit = $params['limit']; $offset = $params['offset']; $searchEngine = $this->buildSearchEngine( $params ); $suggestions = $searchEngine->completionSearchWithVariants( $search ); $titles = $searchEngine->extractTitles( $suggestions ); if ( $suggestions->hasMoreResults() ) { $this->setContinueEnumParameter( 'offset', $offset + $limit ); } if ( $resultPageSet ) { $resultPageSet->setRedirectMergePolicy( function ( array $current, array $new ) { if ( !isset( $current['index'] ) || $new['index'] < $current['index'] ) { $current['index'] = $new['index']; } return $current; } ); $resultPageSet->populateFromTitles( $titles ); foreach ( $titles as $index => $title ) { $resultPageSet->setGeneratorData( $title, [ 'index' => $index + $offset + 1 ] ); } } else { $result = $this->getResult(); $count = 0; foreach ( $titles as $title ) { $vals = [ 'ns' => (int)$title->getNamespace(), 'title' => $title->getPrefixedText(), ]; if ( $title->isSpecialPage() ) { $vals['special'] = true; } else { $vals['pageid'] = (int)$title->getArticleID(); } $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals ); ++$count; if ( !$fit ) { $this->setContinueEnumParameter( 'offset', $offset + $count ); break; } } $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $this->getModulePrefix() ); } } public function getCacheMode( $params ) { return 'public'; } public function getAllowedParams() { if ( $this->allowedParams !== null ) { return $this->allowedParams; } $this->allowedParams = $this->buildCommonApiParams(); return $this->allowedParams; } public function getSearchProfileParams() { return [ 'profile' => [ 'profile-type' => SearchEngine::COMPLETION_PROFILE_TYPE, 'help-message' => 'apihelp-query+prefixsearch-param-profile', ], ]; } protected function getExamplesMessages() { return [ 'action=query&list=prefixsearch&pssearch=meaning' => 'apihelp-query+prefixsearch-example-simple', ]; } public function getHelpUrls() { return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Prefixsearch'; } }