From 64da9d2eb0d569c936e77fb32f0fe2ba2b314b4a Mon Sep 17 00:00:00 2001 From: Platonides Date: Sat, 16 Jan 2010 23:27:55 +0000 Subject: [PATCH] Bug 19996 (backend hooks) Finally adding the four hooks. --- RELEASE-NOTES | 3 +-- docs/hooks.txt | 19 ++++++++++++++++++- includes/search/SearchEngine.php | 32 ++++++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 04083406da..afdc5f0c62 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -304,6 +304,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 16281) Show copyright system message on special pages * Upload license preview now uses the API instead of action=ajax * (bug 7346) Add to RSS to avoid duplicates +* (bug 19996) Added new hooks for Special:Search, which allow to further restrict/expand it. === Bug fixes in 1.16 === @@ -714,8 +715,6 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN skin-specific JS pages * (bug 5061) Use the more precise thumbcaption thumbimage and thumbinner classes for image divs. -* IE50Fixes.css and IE55Fixes.css have been dropped from the Monobook and Chick - skins == API changes in 1.16 == diff --git a/docs/hooks.txt b/docs/hooks.txt index 0635a81de4..6eb4fd55db 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1283,10 +1283,27 @@ $namespace : Page namespace $title : Page title $text : Current text being indexed -'SearchGetNearMatch': An extra chance for exact-title-matches in "go" searches +'SearchGetNearMatchBefore': Perform exact-title-matches in "go" searches before the normal operations +$allSearchTerms : Array of the search terms in all content languages +&$titleResult : Outparam; the value to return. A Title object or null. + +'SearchGetNearMatch': An extra chance for exact-title-matches in "go" searches if nothing was found $term : Search term string &$title : Outparam; set to $title object and return false for a match +'SearchGetNearMatchComplete': A chance to modify exact-title-matches in "go" searches +$term : Search term string +&$title : Current Title object that is being returned (null if none found). + +'SearchEngineReplacePrefixesComplete': Run after SearchEngine::replacePrefixes(). +$searchEngine : The SearchEngine object. Users of this hooks will be interested +in the $searchEngine->namespaces array. +$query : Original query. +&$parsed : Resultant query with the prefixes stripped. + +'SearchableNamespaces': An option to modify which namespaces are searchable. +&$arr : Array of namespaces ($nsId => $name) which will be used. + 'SetupAfterCache': Called in Setup.php, after cache objects are set 'ShowMissingArticle': Called when generating the output for a non-existent page diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 44e7733967..669d3de2a1 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -63,15 +63,29 @@ class SearchEngine { * @return Title */ public static function getNearMatch( $searchterm ) { + $title = self::getNearMatchInternal( $searchterm ); + + wfRunHooks( 'SearchGetNearMatchComplete', array( $searchterm, &$title ) ); + return $title; + } + + /** + * Really find the title match. + */ + private static function getNearMatchInternal( $searchterm ) { global $wgContLang; $allSearchTerms = array($searchterm); - if($wgContLang->hasVariants()){ + if ( $wgContLang->hasVariants() ) { $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm)); } - foreach($allSearchTerms as $term){ + if( !wfRunHooks( 'SearchGetNearMatchBefore', array( $allSearchTerms, &$titleResult ) ) ) { + return $titleResult; + } + + foreach($allSearchTerms as $term) { # Exact match? No need to look further. $title = Title::newFromText( $term ); @@ -196,10 +210,12 @@ class SearchEngine { function replacePrefixes( $query ){ global $wgContLang; - if( strpos($query,':') === false ) - return $query; // nothing to do - $parsed = $query; + if( strpos($query,':') === false ) { // nothing to do + wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) ); + return $parsed; + } + $allkeyword = wfMsgForContent('searchall').":"; if( strncmp($query, $allkeyword, strlen($allkeyword)) == 0 ){ $this->namespaces = null; @@ -213,7 +229,9 @@ class SearchEngine { } } if(trim($parsed) == '') - return $query; // prefix was the whole query + $parsed = $query; // prefix was the whole query + + wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) ); return $parsed; } @@ -230,6 +248,8 @@ class SearchEngine { $arr[$ns] = $name; } } + + wfRunHooks( 'SearchableNamespaces', array( &$arr ) ); return $arr; } -- 2.20.1