Bug 19996 (backend hooks) Finally adding the four hooks.
authorPlatonides <platonides@users.mediawiki.org>
Sat, 16 Jan 2010 23:27:55 +0000 (23:27 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Sat, 16 Jan 2010 23:27:55 +0000 (23:27 +0000)
RELEASE-NOTES
docs/hooks.txt
includes/search/SearchEngine.php

index 0408340..afdc5f0 100644 (file)
@@ -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 <guid> 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 ==
 
index 0635a81..6eb4fd5 100644 (file)
@@ -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
index 44e7733..669d3de 100644 (file)
@@ -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;
        }