X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQuerySearch.php;h=3955cc5f67a629b870fc84a0b24c2cb74dabcb9f;hb=88f73a5d6567c1f7df53d498be4d0c63b431b881;hp=637fc4ca5ca9ba172bba008a6dc3e3a051eb2677;hpb=ff9f2fa33719753ff0c708f9b4a84c57593b9e58;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 637fc4ca5c..3955cc5f67 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -116,7 +116,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { if ( is_null( $matches ) ) { $this->dieUsage( "{$what} search is disabled", "search-{$what}-disabled" ); } elseif ( $matches instanceof Status && !$matches->isGood() ) { - $this->dieUsage( $matches->getWikiText(), 'search-error' ); + $this->dieUsage( $matches->getWikiText( false, false, 'en' ), 'search-error' ); } if ( $resultPageSet === null ) { @@ -125,27 +125,27 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { if ( isset( $searchInfo['totalhits'] ) ) { $totalhits = $matches->getTotalHits(); if ( $totalhits !== null ) { - $apiResult->addValue( array( 'query', 'searchinfo' ), + $apiResult->addValue( [ 'query', 'searchinfo' ], 'totalhits', $totalhits ); } } if ( isset( $searchInfo['suggestion'] ) && $matches->hasSuggestion() ) { - $apiResult->addValue( array( 'query', 'searchinfo' ), + $apiResult->addValue( [ 'query', 'searchinfo' ], 'suggestion', $matches->getSuggestionQuery() ); - $apiResult->addValue( array( 'query', 'searchinfo' ), + $apiResult->addValue( [ 'query', 'searchinfo' ], 'suggestionsnippet', $matches->getSuggestionSnippet() ); } if ( isset( $searchInfo['rewrittenquery'] ) && $matches->hasRewrittenQuery() ) { - $apiResult->addValue( array( 'query', 'searchinfo' ), + $apiResult->addValue( [ 'query', 'searchinfo' ], 'rewrittenquery', $matches->getQueryAfterRewrite() ); - $apiResult->addValue( array( 'query', 'searchinfo' ), + $apiResult->addValue( [ 'query', 'searchinfo' ], 'rewrittenquerysnippet', $matches->getQueryAfterRewriteSnippet() ); } } // Add the search results to the result $terms = $wgContLang->convertForSearchResult( $matches->termMatches() ); - $titles = array(); + $titles = []; $count = 0; $result = $matches->next(); @@ -165,7 +165,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $title = $result->getTitle(); if ( $resultPageSet === null ) { - $vals = array(); + $vals = []; ApiQueryBase::addTitleInfo( $vals, $title ); if ( isset( $prop['snippet'] ) ) { @@ -207,7 +207,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } // Add item to results and see whether it fits - $fit = $apiResult->addValue( array( 'query', $this->getModuleName() ), + $fit = $apiResult->addValue( [ 'query', $this->getModuleName() ], null, $vals ); if ( !$fit ) { $this->setContinueEnumParameter( 'offset', $params['offset'] + $count - 1 ); @@ -237,15 +237,15 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $title = $result->getTitle(); if ( $resultPageSet === null ) { - $vals = array( + $vals = [ 'namespace' => $result->getInterwikiNamespaceText(), 'title' => $title->getText(), 'url' => $title->getFullUrl(), - ); + ]; // Add item to results and see whether it fits $fit = $apiResult->addValue( - array( 'query', 'interwiki' . $this->getModuleName(), $result->getInterwikiPrefix() ), + [ 'query', 'interwiki' . $this->getModuleName(), $result->getInterwikiPrefix() ], null, $vals ); @@ -263,19 +263,19 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } } if ( $totalhits !== null ) { - $apiResult->addValue( array( 'query', 'interwikisearchinfo' ), + $apiResult->addValue( [ 'query', 'interwikisearchinfo' ], 'totalhits', $totalhits ); } } if ( $resultPageSet === null ) { - $apiResult->addIndexedTagName( array( + $apiResult->addIndexedTagName( [ 'query', $this->getModuleName() - ), 'p' ); + ], 'p' ); if ( $hasInterwikiResults ) { - $apiResult->addIndexedTagName( array( + $apiResult->addIndexedTagName( [ 'query', 'interwiki' . $this->getModuleName() - ), 'p' ); + ], 'p' ); } } else { $resultPageSet->setRedirectMergePolicy( function ( $current, $new ) { @@ -287,7 +287,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $resultPageSet->populateFromTitles( $titles ); $offset = $params['offset'] + 1; foreach ( $titles as $index => $title ) { - $resultPageSet->setGeneratorData( $title, array( 'index' => $index + $offset ) ); + $resultPageSet->setGeneratorData( $title, [ 'index' => $index + $offset ] ); } } } @@ -297,35 +297,35 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } public function getAllowedParams() { - $params = array( - 'search' => array( + $params = [ + 'search' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true - ), - 'namespace' => array( + ], + 'namespace' => [ ApiBase::PARAM_DFLT => NS_MAIN, ApiBase::PARAM_TYPE => 'namespace', ApiBase::PARAM_ISMULTI => true, - ), - 'what' => array( - ApiBase::PARAM_TYPE => array( + ], + 'what' => [ + ApiBase::PARAM_TYPE => [ 'title', 'text', 'nearmatch', - ) - ), - 'info' => array( + ] + ], + 'info' => [ ApiBase::PARAM_DFLT => 'totalhits|suggestion|rewrittenquery', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'totalhits', 'suggestion', 'rewrittenquery', - ), + ], ApiBase::PARAM_ISMULTI => true, - ), - 'prop' => array( + ], + 'prop' => [ ApiBase::PARAM_DFLT => 'size|wordcount|timestamp|snippet', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'size', 'wordcount', 'timestamp', @@ -339,48 +339,48 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { 'categorysnippet', 'score', // deprecated 'hasrelated', // deprecated - ), + ], ApiBase::PARAM_ISMULTI => true, - ApiBase::PARAM_HELP_MSG_PER_VALUE => array(), - ), - 'offset' => array( + ApiBase::PARAM_HELP_MSG_PER_VALUE => [], + ], + 'offset' => [ ApiBase::PARAM_DFLT => 0, ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', - ), - 'limit' => array( + ], + 'limit' => [ ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, - ApiBase::PARAM_MAX => ApiBase::LIMIT_SML1, - ApiBase::PARAM_MAX2 => ApiBase::LIMIT_SML2 - ), + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 + ], 'interwiki' => false, 'enablerewrites' => false, - ); + ]; $alternatives = SearchEngine::getSearchTypes(); if ( count( $alternatives ) > 1 ) { if ( $alternatives[0] === null ) { $alternatives[0] = self::BACKEND_NULL_PARAM; } - $params['backend'] = array( + $params['backend'] = [ ApiBase::PARAM_DFLT => $this->getConfig()->get( 'SearchType' ), ApiBase::PARAM_TYPE => $alternatives, - ); + ]; } return $params; } protected function getExamplesMessages() { - return array( + return [ 'action=query&list=search&srsearch=meaning' => 'apihelp-query+search-example-simple', 'action=query&list=search&srwhat=text&srsearch=meaning' => 'apihelp-query+search-example-text', 'action=query&generator=search&gsrsearch=meaning&prop=info' => 'apihelp-query+search-example-generator', - ); + ]; } public function getHelpUrls() {