* @file
*/
-use MediaWiki\MediaWikiServices;
-
/**
* Query module to perform full text search within wiki titles and content
*
/** @var array list of api allowed params */
private $allowedParams;
- /**
- * When $wgSearchType is null, $wgSearchAlternatives[0] is null. Null isn't
- * a valid option for an array for PARAM_TYPE, so we'll use a fake name
- * that can't possibly be a class name and describes what the null behavior
- * does
- */
- const BACKEND_NULL_PARAM = 'database-backed';
-
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'sr' );
}
global $wgContLang;
$params = $this->extractRequestParams();
- if ( isset( $params['backend'] ) && $params['backend'] == self::BACKEND_NULL_PARAM ) {
- unset( $params['backend'] );
- }
-
// Extract parameters
$query = $params['search'];
$what = $params['what'];
$hasInterwikiResults = false;
$totalhits = null;
if ( $interwiki && $resultPageSet === null && $matches->hasInterwikiResults() ) {
- foreach ( $matches->getInterwikiResults() as $matches ) {
- $matches = $matches->getInterwikiResults();
+ foreach ( $matches->getInterwikiResults() as $interwikiMatches ) {
$hasInterwikiResults = true;
// Include number of results if requested
if ( $resultPageSet === null && isset( $searchInfo['totalhits'] ) ) {
- $totalhits += $matches->getTotalHits();
+ $totalhits += $interwikiMatches->getTotalHits();
}
- $result = $matches->next();
+ $result = $interwikiMatches->next();
while ( $result ) {
$title = $result->getTitle();
$vals = [
'namespace' => $result->getInterwikiNamespaceText(),
'title' => $title->getText(),
- 'url' => $title->getFullUrl(),
+ 'url' => $title->getFullURL(),
];
// Add item to results and see whether it fits
$titles[] = $title;
}
- $result = $matches->next();
+ $result = $interwikiMatches->next();
}
}
if ( $totalhits !== null ) {
return $this->allowedParams;
}
- $this->allowedParams = [
- 'search' => [
- ApiBase::PARAM_TYPE => 'string',
- ApiBase::PARAM_REQUIRED => true
- ],
- 'namespace' => [
- ApiBase::PARAM_DFLT => NS_MAIN,
- ApiBase::PARAM_TYPE => 'namespace',
- ApiBase::PARAM_ISMULTI => true,
- ],
+ $this->allowedParams = $this->buildCommonApiParams() + [
'what' => [
ApiBase::PARAM_TYPE => [
'title',
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
],
- 'offset' => [
- ApiBase::PARAM_DFLT => 0,
- ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
- ],
- 'limit' => [
- ApiBase::PARAM_DFLT => 10,
- ApiBase::PARAM_TYPE => 'limit',
- ApiBase::PARAM_MIN => 1,
- ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
- ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
- ],
'interwiki' => false,
'enablerewrites' => false,
];
- $searchConfig = MediaWikiServices::getInstance()->getSearchEngineConfig();
- $alternatives = $searchConfig->getSearchTypes();
- if ( count( $alternatives ) > 1 ) {
- if ( $alternatives[0] === null ) {
- $alternatives[0] = self::BACKEND_NULL_PARAM;
- }
- $this->allowedParams['backend'] = [
- ApiBase::PARAM_DFLT => $searchConfig->getSearchType(),
- ApiBase::PARAM_TYPE => $alternatives,
- ];
- // @todo: support profile selection when multiple
- // backends are available. The solution could be to
- // merge all possible profiles and let ApiBase
- // subclasses do the check. Making ApiHelp and ApiSandbox
- // comprehensive might be more difficult.
- } else {
- $profileParam = $this->buildProfileApiParam( SearchEngine::FT_QUERY_INDEP_PROFILE_TYPE,
- 'apihelp-query+search-param-qiprofile' );
- if ( $profileParam ) {
- $this->allowedParams['qiprofile'] = $profileParam;
- }
- }
-
return $this->allowedParams;
}
public function getSearchProfileParams() {
- if ( isset( $this->getAllowedParams()['qiprofile'] ) ) {
- return [ SearchEngine::FT_QUERY_INDEP_PROFILE_TYPE => 'qiprofile' ];
- }
- return [];
+ return [
+ 'qiprofile' => [
+ 'profile-type' => SearchEngine::FT_QUERY_INDEP_PROFILE_TYPE,
+ 'help-message' => 'apihelp-query+search-param-qiprofile',
+ ],
+ ];
}
protected function getExamplesMessages() {