From: jenkins-bot Date: Tue, 21 Aug 2018 14:57:13 +0000 (+0000) Subject: Merge "Add Special:Search sort parameter without ui" X-Git-Tag: 1.34.0-rc.0~4353 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=9171317645de4d31c61c570a9e4fa765e09ecc4d;hp=-c Merge "Add Special:Search sort parameter without ui" --- 9171317645de4d31c61c570a9e4fa765e09ecc4d diff --combined includes/search/SearchEngine.php index 965a413508,99bdabea7c..ad9f934730 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@@ -32,6 -32,8 +32,8 @@@ use MediaWiki\MediaWikiServices * @ingroup Search */ abstract class SearchEngine { + const DEFAULT_SORT = 'relevance'; + /** @var string */ public $prefix = ''; @@@ -49,7 -51,7 +51,7 @@@ /** @var bool */ protected $showSuggestion = true; - private $sort = 'relevance'; + private $sort = self::DEFAULT_SORT; /** @var array Feature values */ protected $features = []; @@@ -232,8 -234,10 +234,8 @@@ * @return string */ public function normalizeText( $string ) { - global $wgContLang; - // Some languages such as Chinese require word segmentation - return $wgContLang->segmentByWord( $string ); + return MediaWikiServices::getInstance()->getContentLanguage()->segmentByWord( $string ); } /** @@@ -255,8 -259,8 +257,8 @@@ * @return SearchNearMatcher */ public function getNearMatcher( Config $config ) { - global $wgContLang; - return new SearchNearMatcher( $config, $wgContLang ); + return new SearchNearMatcher( $config, + MediaWikiServices::getInstance()->getContentLanguage() ); } /** @@@ -264,9 -268,8 +266,9 @@@ * @return SearchNearMatcher */ protected static function defaultNearMatcher() { - $config = MediaWikiServices::getInstance()->getMainConfig(); - return MediaWikiServices::getInstance()->newSearchEngine()->getNearMatcher( $config ); + $services = MediaWikiServices::getInstance(); + $config = $services->getMainConfig(); + return $services->newSearchEngine()->getNearMatcher( $config ); } /** @@@ -346,13 -349,13 +348,13 @@@ /** * Get the valid sort directions. All search engines support 'relevance' but others - * might support more. The default in all implementations should be 'relevance.' + * might support more. The default in all implementations must be 'relevance.' * * @since 1.25 * @return string[] the valid sort directions for setSort */ public function getValidSorts() { - return [ 'relevance' ]; + return [ self::DEFAULT_SORT ]; } /** @@@ -414,6 -417,8 +416,6 @@@ $withAllKeyword = true, $withPrefixSearchExtractNamespaceHook = false ) { - global $wgContLang; - $parsed = $query; if ( strpos( $query, ':' ) === false ) { // nothing to do return false; @@@ -442,7 -447,7 +444,7 @@@ if ( !$allQuery && strpos( $query, ':' ) !== false ) { $prefix = str_replace( ' ', '_', substr( $query, 0, strpos( $query, ':' ) ) ); - $index = $wgContLang->getNsIndex( $prefix ); + $index = MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $prefix ); if ( $index !== false ) { $extractedNamespace = [ $index ]; $parsed = substr( $query, strlen( $prefix ) + 1 ); @@@ -622,8 -627,9 +624,8 @@@ $results = $this->completionSearchBackendOverfetch( $search ); $fallbackLimit = 1 + $this->limit - $results->getSize(); if ( $fallbackLimit > 0 ) { - global $wgContLang; - - $fallbackSearches = $wgContLang->autoConvertToAllVariants( $search ); + $fallbackSearches = MediaWikiServices::getInstance()->getContentLanguage()-> + autoConvertToAllVariants( $search ); $fallbackSearches = array_diff( array_unique( $fallbackSearches ), [ $search ] ); foreach ( $fallbackSearches as $fbs ) { diff --combined includes/specials/SpecialSearch.php index 513d2763c1,f595b19172..86dcb721f8 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@@ -76,6 -76,11 +76,11 @@@ class SpecialSearch extends SpecialPag */ protected $fulltext; + /** + * @var string + */ + protected $sort; + /** * @var bool */ @@@ -198,6 -203,11 +203,11 @@@ $this->setExtraParam( 'prefix', $this->mPrefix ); } + $this->sort = $request->getVal( 'sort', SearchEngine::DEFAULT_SORT ); + if ( $this->sort !== SearchEngine::DEFAULT_SORT ) { + $this->setExtraParam( 'sort', $this->sort ); + } + $user = $this->getUser(); # Extract manually requested namespaces @@@ -269,6 -279,8 +279,6 @@@ * @param string $term */ public function showResults( $term ) { - global $wgContLang; - if ( $this->searchEngineType !== null ) { $this->setExtraParam( 'srbackend', $this->searchEngineType ); } @@@ -279,8 -291,7 +289,8 @@@ $this->searchConfig, $this->getSearchProfiles() ); - $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':'; + $filePrefix = MediaWikiServices::getInstance()->getContentLanguage()-> + getFormattedNsText( NS_FILE ) . ':'; if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) { // Empty query -- straight view of search form if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) { @@@ -301,6 -312,7 +311,7 @@@ $search->setFeatureData( 'rewrite', $this->runSuggestion ); $search->setLimitOffset( $this->limit, $this->offset ); $search->setNamespaces( $this->namespaces ); + $search->setSort( $this->sort ); $search->prefix = $this->mPrefix; Hooks::run( 'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] ); @@@ -709,10 -721,9 +720,10 @@@ */ public function getSearchEngine() { if ( $this->searchEngine === null ) { + $services = MediaWikiServices::getInstance(); $this->searchEngine = $this->searchEngineType ? - MediaWikiServices::getInstance()->getSearchEngineFactory()->create( $this->searchEngineType ) : - MediaWikiServices::getInstance()->newSearchEngine(); + $services->getSearchEngineFactory()->create( $this->searchEngineType ) : + $services->newSearchEngine(); } return $this->searchEngine;