Add hook to extract namespace in prefix search
authorNik Everett <neverett@wikimedia.org>
Wed, 22 Oct 2014 20:00:03 +0000 (16:00 -0400)
committerNik Everett <neverett@wikimedia.org>
Wed, 22 Oct 2014 20:05:19 +0000 (16:05 -0400)
This will allow extensions (namely CirrusSearch) to match namespaces using
their own rules if core can't find the namespace on its own.

Bug: 62322
Change-Id: I17337cd8ce90190bd335c9159e9d3bbb39ba89cd

docs/hooks.txt
includes/PrefixSearch.php

index 6fb10b1..b71c347 100644 (file)
@@ -2139,6 +2139,13 @@ $search : search term (not guaranteed to be conveniently normalized)
 $limit : maximum number of results to return
 &$results : out param: array of page names (strings)
 
+'PrefixSearchExtractNamespace': Called if core was not able to extract a
+namespace from the search string so that extensions can attempt it.
+$namespaces : array of int namespace keys to search in (change this if you can
+extract namespaces)
+$search : search term (replace this with term without the namespace if you can
+extract one)
+
 'PrefsEmailAudit': Called when user changes their email address.
 $user: User (object) changing his email address
 $oldaddr: old email address (string)
index 5df0ce7..839fedc 100644 (file)
@@ -60,10 +60,12 @@ abstract class PrefixSearch {
                $title = Title::newFromText( $search );
                if ( $title && !$title->isExternal() ) {
                        $ns = array( $title->getNamespace() );
+                       $search = $title->getText();
                        if ( $ns[0] == NS_MAIN ) {
                                $ns = $namespaces; // no explicit prefix, use default namespaces
+                               wfRunHooks( 'PrefixSearchExtractNamespace', array( &$ns, &$search ) );
                        }
-                       return $this->searchBackend( $ns, $title->getText(), $limit );
+                       return $this->searchBackend( $ns, $search, $limit );
                }
 
                // Is this a namespace prefix?
@@ -74,6 +76,8 @@ abstract class PrefixSearch {
                {
                        $namespaces = array( $title->getNamespace() );
                        $search = '';
+               } else {
+                       wfRunHooks( 'PrefixSearchExtractNamespace', array( &$namespaces, &$search ) );
                }
 
                return $this->searchBackend( $namespaces, $search, $limit );