Merge "Add Special:Search sort parameter without ui"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 21 Aug 2018 14:57:13 +0000 (14:57 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 21 Aug 2018 14:57:13 +0000 (14:57 +0000)
includes/search/SearchEngine.php
includes/specials/SpecialSearch.php

index 965a413..ad9f934 100644 (file)
@@ -32,6 +32,8 @@ use MediaWiki\MediaWikiServices;
  * @ingroup Search
  */
 abstract class SearchEngine {
+       const DEFAULT_SORT = 'relevance';
+
        /** @var string */
        public $prefix = '';
 
@@ -49,7 +51,7 @@ abstract class SearchEngine {
 
        /** @var bool */
        protected $showSuggestion = true;
-       private $sort = 'relevance';
+       private $sort = self::DEFAULT_SORT;
 
        /** @var array Feature values */
        protected $features = [];
@@ -346,13 +348,13 @@ abstract class SearchEngine {
 
        /**
         * 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 ];
        }
 
        /**
index 513d276..86dcb72 100644 (file)
@@ -76,6 +76,11 @@ class SpecialSearch extends SpecialPage {
         */
        protected $fulltext;
 
+       /**
+        * @var string
+        */
+       protected $sort;
+
        /**
         * @var bool
         */
@@ -198,6 +203,11 @@ class SpecialSearch extends SpecialPage {
                        $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
@@ -301,6 +311,7 @@ class SpecialSearch extends SpecialPage {
                $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 ] );