From: Nik Everett Date: Wed, 22 Oct 2014 20:00:03 +0000 (-0400) Subject: Add hook to extract namespace in prefix search X-Git-Tag: 1.31.0-rc.0~13489^2~1 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=eb6880736738d3d5267122776a53e9569a2f47f3;p=lhc%2Fweb%2Fwiklou.git Add hook to extract namespace in prefix search 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 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 6fb10b12cd..b71c347279 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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) diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php index 5df0ce715b..839fedcd15 100644 --- a/includes/PrefixSearch.php +++ b/includes/PrefixSearch.php @@ -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 );