From 39cbbab021a2d8f36562008f9317d86e5c8206b4 Mon Sep 17 00:00:00 2001 From: David Causse Date: Fri, 11 May 2018 15:04:49 +0200 Subject: [PATCH] Allow 'all:' on all wikis in addition to 'searchall' translation This allows to have a common syntax useable everywhere. Bug: T165110 Change-Id: If71fe5df045fb754925946088f8f793197bc8301 --- includes/search/SearchEngine.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 7e6e8e6d0d..0f65711bf6 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -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 ); -- 2.20.1