From eb6880736738d3d5267122776a53e9569a2f47f3 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 22 Oct 2014 16:00:03 -0400 Subject: [PATCH] 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 --- docs/hooks.txt | 7 +++++++ includes/PrefixSearch.php | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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 ); -- 2.20.1