Merge "Avoid passing "false" as keys to MapCacheLRU in RepoGroup"
[lhc/web/wiklou.git] / includes / PrefixSearch.php
index 48b1d72..63a4d9c 100644 (file)
@@ -58,54 +58,14 @@ abstract class PrefixSearch {
                        return []; // Return empty result
                }
 
-               $hasNamespace = $this->extractNamespace( $search );
-               if ( $hasNamespace ) {
-                       list( $namespace, $search ) = $hasNamespace;
-                       $namespaces = [ $namespace ];
-               } else {
-                       $namespaces = $this->validateNamespaces( $namespaces );
-                       Hooks::run( 'PrefixSearchExtractNamespace', [ &$namespaces, &$search ] );
+               $hasNamespace = SearchEngine::parseNamespacePrefixes( $search, false, true );
+               if ( $hasNamespace !== false ) {
+                       list( $search, $namespaces ) = $hasNamespace;
                }
 
                return $this->searchBackend( $namespaces, $search, $limit, $offset );
        }
 
-       /**
-        * Figure out if given input contains an explicit namespace.
-        *
-        * @param string $input
-        * @return false|array Array of namespace and remaining text, or false if no namespace given.
-        */
-       protected function extractNamespace( $input ) {
-               if ( strpos( $input, ':' ) === false ) {
-                       return false;
-               }
-
-               // Namespace prefix only
-               $title = Title::newFromText( $input . 'Dummy' );
-               if (
-                       $title &&
-                       $title->getText() === 'Dummy' &&
-                       !$title->inNamespace( NS_MAIN ) &&
-                       !$title->isExternal()
-               ) {
-                       return [ $title->getNamespace(), '' ];
-               }
-
-               // Namespace prefix with additional input
-               $title = Title::newFromText( $input );
-               if (
-                       $title &&
-                       !$title->inNamespace( NS_MAIN ) &&
-                       !$title->isExternal()
-               ) {
-                       // getText provides correct capitalization
-                       return [ $title->getNamespace(), $title->getText() ];
-               }
-
-               return false;
-       }
-
        /**
         * Do a prefix search for all possible variants of the prefix
         * @param string $search
@@ -211,7 +171,7 @@ abstract class PrefixSearch {
 
                $searchParts = explode( '/', $search, 2 );
                $searchKey = $searchParts[0];
-               $subpageSearch = isset( $searchParts[1] ) ? $searchParts[1] : null;
+               $subpageSearch = $searchParts[1] ?? null;
 
                // Handle subpage search separately.
                if ( $subpageSearch !== null ) {
@@ -231,7 +191,7 @@ abstract class PrefixSearch {
                        }
                }
 
-               # normalize searchKey, so aliases with spaces can be found - bug 25675
+               # normalize searchKey, so aliases with spaces can be found - T27675
                $searchKey = str_replace( ' ', '_', $searchKey );
                $searchKey = $wgContLang->caseFold( $searchKey );
 
@@ -243,7 +203,7 @@ abstract class PrefixSearch {
                }
 
                foreach ( $wgContLang->getSpecialPageAliases() as $page => $aliases ) {
-                       if ( !in_array( $page, SpecialPageFactory::getNames() ) ) {# bug 20885
+                       if ( !in_array( $page, SpecialPageFactory::getNames() ) ) {# T22885
                                continue;
                        }
 
@@ -256,7 +216,7 @@ abstract class PrefixSearch {
                $matches = [];
                foreach ( $keys as $pageKey => $page ) {
                        if ( $searchKey === '' || strpos( $pageKey, $searchKey ) === 0 ) {
-                               // bug 27671: Don't use SpecialPage::getTitleFor() here because it
+                               // T29671: Don't use SpecialPage::getTitleFor() here because it
                                // localizes its input leading to searches for e.g. Special:All
                                // returning Spezial:MediaWiki-Systemnachrichten and returning
                                // Spezial:Alle_Seiten twice when $wgLanguageCode == 'de'