Merge "SpecialNewFiles: Swap from/to date serverside"
[lhc/web/wiklou.git] / includes / search / SearchEngine.php
index 6bb4e5a..70117db 100644 (file)
@@ -60,6 +60,12 @@ abstract class SearchEngine {
        /** @const string profile type for query independent ranking features */
        const FT_QUERY_INDEP_PROFILE_TYPE = 'fulltextQueryIndepProfile';
 
+       /** @const int flag for legalSearchChars: includes all chars allowed in a search query */
+       const CHARS_ALL = 1;
+
+       /** @const int flag for legalSearchChars: includes all chars allowed in a search term */
+       const CHARS_NO_SYNTAX = 2;
+
        /**
         * Perform a full text search query and return a result set.
         * If full text searches are not supported or disabled, return null.
@@ -206,11 +212,13 @@ abstract class SearchEngine {
        }
 
        /**
-        * Get chars legal for search.
+        * Get chars legal for search
         * NOTE: usage as static is deprecated and preserved only as BC measure
+        * @param int $type type of search chars (see self::CHARS_ALL
+        * and self::CHARS_NO_SYNTAX). Defaults to CHARS_ALL
         * @return string
         */
-       public static function legalSearchChars() {
+       public static function legalSearchChars( $type = self::CHARS_ALL ) {
                return "A-Za-z_'.0-9\\x80-\\xFF\\-";
        }
 
@@ -236,7 +244,7 @@ abstract class SearchEngine {
                if ( $namespaces ) {
                        // Filter namespaces to only keep valid ones
                        $validNs = $this->searchableNamespaces();
-                       $namespaces = array_filter( $namespaces, function( $ns ) use( $validNs ) {
+                       $namespaces = array_filter( $namespaces, function ( $ns ) use( $validNs ) {
                                return $ns < 0 || isset( $validNs[$ns] );
                        } );
                } else {
@@ -455,8 +463,8 @@ abstract class SearchEngine {
                        $title = Title::newFromText( $search . 'Dummy' );
                        if ( $title && $title->getText() == 'Dummy'
                                        && $title->getNamespace() != NS_MAIN
-                                       && !$title->isExternal() )
-                       {
+                                       && !$title->isExternal()
+                       {
                                $ns = [ $title->getNamespace() ];
                                $search = '';
                        } else {
@@ -464,7 +472,7 @@ abstract class SearchEngine {
                        }
                }
 
-               $ns = array_map( function( $space ) {
+               $ns = array_map( function ( $space ) {
                        return $space == NS_MEDIA ? NS_FILE : $space;
                }, $ns );
 
@@ -550,7 +558,7 @@ abstract class SearchEngine {
         * @return Title[]
         */
        public function extractTitles( SearchSuggestionSet $completionResults ) {
-               return $completionResults->map( function( SearchSuggestion $sugg ) {
+               return $completionResults->map( function ( SearchSuggestion $sugg ) {
                        return $sugg->getSuggestedTitle();
                } );
        }
@@ -564,14 +572,14 @@ abstract class SearchEngine {
        protected function processCompletionResults( $search, SearchSuggestionSet $suggestions ) {
                $search = trim( $search );
                // preload the titles with LinkBatch
-               $titles = $suggestions->map( function( SearchSuggestion $sugg ) {
+               $titles = $suggestions->map( function ( SearchSuggestion $sugg ) {
                        return $sugg->getSuggestedTitle();
                } );
                $lb = new LinkBatch( $titles );
                $lb->setCaller( __METHOD__ );
                $lb->execute();
 
-               $results = $suggestions->map( function( SearchSuggestion $sugg ) {
+               $results = $suggestions->map( function ( SearchSuggestion $sugg ) {
                        return $sugg->getSuggestedTitle()->getPrefixedText();
                } );