Merge "Remove unused 'XMPGetInfo' and 'XMPGetResults' hooks"
[lhc/web/wiklou.git] / includes / search / SearchEngine.php
index c6cbfbe..e5ed23f 100644 (file)
@@ -33,7 +33,7 @@ class SearchEngine {
        /** @var string */
        public $prefix = '';
 
-       /** @var int[] */
+       /** @var int[]|null */
        public $namespaces = array( NS_MAIN );
 
        /** @var int */
@@ -47,6 +47,7 @@ class SearchEngine {
 
        /** @var bool */
        protected $showSuggestion = true;
+       private $sort = 'relevance';
 
        /** @var array Feature values */
        protected $features = array();
@@ -137,7 +138,7 @@ class SearchEngine {
        public static function getNearMatch( $searchterm ) {
                $title = self::getNearMatchInternal( $searchterm );
 
-               wfRunHooks( 'SearchGetNearMatchComplete', array( $searchterm, &$title ) );
+               Hooks::run( 'SearchGetNearMatchComplete', array( $searchterm, &$title ) );
                return $title;
        }
 
@@ -170,7 +171,7 @@ class SearchEngine {
                }
 
                $titleResult = null;
-               if ( !wfRunHooks( 'SearchGetNearMatchBefore', array( $allSearchTerms, &$titleResult ) ) ) {
+               if ( !Hooks::run( 'SearchGetNearMatchBefore', array( $allSearchTerms, &$titleResult ) ) ) {
                        return $titleResult;
                }
 
@@ -197,7 +198,7 @@ class SearchEngine {
                                return $title;
                        }
 
-                       if ( !wfRunHooks( 'SearchAfterNoDirectMatch', array( $term, &$title ) ) ) {
+                       if ( !Hooks::run( 'SearchAfterNoDirectMatch', array( $term, &$title ) ) ) {
                                return $title;
                        }
 
@@ -227,7 +228,7 @@ class SearchEngine {
 
                        // Give hooks a chance at better match variants
                        $title = null;
-                       if ( !wfRunHooks( 'SearchGetNearMatch', array( $term, &$title ) ) ) {
+                       if ( !Hooks::run( 'SearchGetNearMatch', array( $term, &$title ) ) ) {
                                return $title;
                        }
                }
@@ -292,7 +293,7 @@ class SearchEngine {
         * Set which namespaces the search should include.
         * Give an array of namespace index numbers.
         *
-        * @param array $namespaces
+        * @param int[]|null $namespaces
         */
        function setNamespaces( $namespaces ) {
                $this->namespaces = $namespaces;
@@ -309,6 +310,43 @@ class SearchEngine {
                $this->showSuggestion = $showSuggestion;
        }
 
+       /**
+        * Get the valid sort directions.  All search engines support 'relevance' but others
+        * might support more. The default in all implementations should be 'relevance.'
+        *
+        * @since 1.25
+        * @return array(string) the valid sort directions for setSort
+        */
+       public function getValidSorts() {
+               return array( 'relevance' );
+       }
+
+       /**
+        * Set the sort direction of the search results. Must be one returned by
+        * SearchEngine::getValidSorts()
+        *
+        * @since 1.25
+        * @throws InvalidArgumentException
+        * @param string $sort sort direction for query result
+        */
+       public function setSort( $sort ) {
+               if ( !in_array( $sort, $this->getValidSorts() ) ) {
+                       throw new InvalidArgumentException( "Invalid sort: $sort. " .
+                               "Must be one of: " . implode( ', ', $this->getValidSorts() ) );
+               }
+               $this->sort = $sort;
+       }
+
+       /**
+        * Get the sort direction of the search results
+        *
+        * @since 1.25
+        * @return string
+        */
+       public function getSort() {
+               return $this->sort;
+       }
+
        /**
         * Parse some common prefixes: all (search everything)
         * or namespace names
@@ -356,7 +394,7 @@ class SearchEngine {
                        }
                }
 
-               wfRunHooks( 'SearchableNamespaces', array( &$arr ) );
+               Hooks::run( 'SearchableNamespaces', array( &$arr ) );
                return $arr;
        }