Allow 'all:' on all wikis in addition to 'searchall' translation
authorDavid Causse <dcausse@wikimedia.org>
Fri, 11 May 2018 13:04:49 +0000 (15:04 +0200)
committerDavid Causse <dcausse@wikimedia.org>
Fri, 11 May 2018 13:20:27 +0000 (15:20 +0200)
This allows to have a common syntax useable everywhere.

Bug: T165110
Change-Id: If71fe5df045fb754925946088f8f793197bc8301

includes/search/SearchEngine.php

index 7e6e8e6..0f65711 100644 (file)
@@ -335,12 +335,25 @@ abstract class SearchEngine {
                        return false;
                }
                $extractedNamespace = null;
+               $allkeywords = [];
 
-               $allkeyword = wfMessage( 'searchall' )->inContentLanguage()->text() . ":";
-               if ( strncmp( $query, $allkeyword, strlen( $allkeyword ) ) == 0 ) {
-                       $extractedNamespace = null;
-                       $parsed = substr( $query, strlen( $allkeyword ) );
-               } elseif ( strpos( $query, ':' ) !== false ) {
+               $allkeywords[] = wfMessage( 'searchall' )->inContentLanguage()->text() . ":";
+               // force all: so that we have a common syntax for all the wikis
+               if ( !in_array( 'all:', $allkeywords ) ) {
+                       $allkeywords[] = 'all:';
+               }
+
+               $allQuery = false;
+               foreach ( $allkeywords as $kw ) {
+                       if ( strncmp( $query, $kw, strlen( $kw ) ) == 0 ) {
+                               $extractedNamespace = null;
+                               $parsed = substr( $query, strlen( $kw ) );
+                               $allQuery = true;
+                               break;
+                       }
+               }
+
+               if ( !$allQuery && strpos( $query, ':' ) !== false ) {
                        // TODO: should we unify with PrefixSearch::extractNamespace ?
                        $prefix = str_replace( ' ', '_', substr( $query, 0, strpos( $query, ':' ) ) );
                        $index = $wgContLang->getNsIndex( $prefix );