Merge "Salt the "nsToken" used for Special:Search namespace remembering"
[lhc/web/wiklou.git] / includes / search / SearchEngine.php
index 827d8c3..56bb0ac 100644 (file)
  * @ingroup Search
  */
 class SearchEngine {
-       var $limit = 10;
-       var $offset = 0;
-       var $prefix = '';
-       var $searchTerms = array();
-       var $namespaces = array( NS_MAIN );
+       /** @var string */
+       public $prefix = '';
+
+       /** @var int[] */
+       public $namespaces = array( NS_MAIN );
+
+       /** @var int */
+       protected $limit = 10;
+
+       /** @var int */
+       protected $offset = 0;
+
+       /** @var array|string */
+       protected $searchTerms = array();
+
+       /** @var bool */
        protected $showSuggestion = true;
 
        /** @var array Feature values */
@@ -106,8 +117,9 @@ class SearchEngine {
        }
 
        /**
-        * Transform search term in cases when parts of the query came as different GET params (when supported)
-        * e.g. for prefix queries: search=test&prefix=Main_Page/Archive -> test prefix:Main Page/Archive
+        * Transform search term in cases when parts of the query came as different
+        * GET params (when supported), e.g. for prefix queries:
+        * search=test&prefix=Main_Page/Archive -> test prefix:Main Page/Archive
         */
        function transformSearchTerm( $term ) {
                return $term;
@@ -148,7 +160,10 @@ class SearchEngine {
                $allSearchTerms = array( $searchterm );
 
                if ( $wgContLang->hasVariants() ) {
-                       $allSearchTerms = array_merge( $allSearchTerms, $wgContLang->autoConvertToAllVariants( $searchterm ) );
+                       $allSearchTerms = array_merge(
+                               $allSearchTerms,
+                               $wgContLang->autoConvertToAllVariants( $searchterm )
+                       );
                }
 
                $titleResult = null;
@@ -303,7 +318,6 @@ class SearchEngine {
 
                $parsed = $query;
                if ( strpos( $query, ':' ) === false ) { // nothing to do
-                       wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) );
                        return $parsed;
                }
 
@@ -323,8 +337,6 @@ class SearchEngine {
                        $parsed = $query; // prefix was the whole query
                }
 
-               wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) );
-
                return $parsed;
        }
 
@@ -353,20 +365,8 @@ class SearchEngine {
         * @return array
         */
        public static function userNamespaces( $user ) {
-               global $wgSearchEverythingOnlyLoggedIn;
-
-               $searchableNamespaces = SearchEngine::searchableNamespaces();
-
-               // get search everything preference, that can be set to be read for logged-in users
-               // it overrides other options
-               if ( !$wgSearchEverythingOnlyLoggedIn || $user->isLoggedIn() ) {
-                       if ( $user->getOption( 'searcheverything' ) ) {
-                               return array_keys( $searchableNamespaces );
-                       }
-               }
-
                $arr = array();
-               foreach ( $searchableNamespaces as $ns => $name ) {
+               foreach ( SearchEngine::searchableNamespaces() as $ns => $name ) {
                        if ( $user->getOption( 'searchNs' . $ns ) ) {
                                $arr[] = $ns;
                        }
@@ -416,28 +416,6 @@ class SearchEngine {
                return $formatted;
        }
 
-       /**
-        * Return the help namespaces to be shown on Special:Search
-        *
-        * @return array
-        */
-       public static function helpNamespaces() {
-               global $wgNamespacesToBeSearchedHelp;
-
-               return array_keys( $wgNamespacesToBeSearchedHelp, true );
-       }
-
-       /**
-        * Return a 'cleaned up' search string
-        *
-        * @param string $text
-        * @return string
-        */
-       function filter( $text ) {
-               $lc = $this->legalSearchChars();
-               return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
-       }
-
        /**
         * Load up the appropriate search engine class for the currently
         * active database backend, and return a configured instance.
@@ -523,6 +501,7 @@ class SearchEngine {
         */
        public static function getOpenSearchTemplate() {
                global $wgOpenSearchTemplate, $wgCanonicalServer;
+
                if ( $wgOpenSearchTemplate ) {
                        return $wgOpenSearchTemplate;
                } else {
@@ -530,7 +509,9 @@ class SearchEngine {
                        if ( !$ns ) {
                                $ns = "0";
                        }
-                       return $wgCanonicalServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns;
+
+                       return $wgCanonicalServer . wfScript( 'api' )
+                               . '?action=opensearch&search={searchTerms}&namespace=' . $ns;
                }
        }
 
@@ -560,13 +541,6 @@ class SearchEngine {
        }
 }
 
-/**
- * @ingroup Search
- */
-class SearchResultTooMany {
-       # # Some search engines may bail out if too many matches are found
-}
-
 /**
  * Dummy class to be used when non-supported Database engine is present.
  * @todo FIXME: Dummy class should probably try something at least mildly useful,