Adding SpecialSearchResultsPrepend/Append hooks
authorRyan Finnie <ryan@finnie.org>
Fri, 18 Jan 2013 00:46:40 +0000 (16:46 -0800)
committerRyan Finnie <ryan@finnie.org>
Fri, 18 Jan 2013 08:05:31 +0000 (00:05 -0800)
These hooks allow you to prepend, append or replace the search results
in Special:Search.

SpecialSearchResultsPrepend is executed immediately before the results
HTML begin to output.  It can be used to include an external search
provider like Google CSE, for example.  If the hook returns true, the
MediaWiki search results continue to output.  If returned false, they
are suppressed.

SpecialSearchResultsAppend is executed immediately after the last
results HTML (including search navigation) are output.  This hook is of
limited use since it will not be run in certain circumstances (there are
several points in the previous output logic where the function returns),
but is included for completeness.

Change-Id: Ib38433141979de999cdcab5eca26ba5416331aaa

docs/hooks.txt
includes/specials/SpecialSearch.php

index 8905d7e..36279a5 100644 (file)
@@ -2199,6 +2199,22 @@ $search: SpecialSearch special page object
 $profile: String: current search profile
 $engine: the search engine
 
+'SpecialSearchResultsPrepend': Called immediately before returning HTML
+on the search results page.  Useful for including an external search
+provider.  To disable the output of MediaWiki search output, return
+false.
+$specialSearch: SpecialSearch object ($this)
+$output: $wgOut
+$term: Search term specified by the user
+
+'SpecialSearchResultsAppend': Called after all search results HTML has
+been output.  Note that in some cases, this hook will not be called (no
+results, too many results, SpecialSearchResultsPrepend returned false,
+etc).
+$specialSearch: SpecialSearch object ($this)
+$output: $wgOut
+$term: Search term specified by the user
+
 'SpecialSearchResults': Called before search result display when there are
 matches.
 $term: string of search term
index 7c8ff84..bc90d2b 100644 (file)
@@ -288,6 +288,13 @@ class SpecialSearch extends SpecialPage {
 
                        $this->didYouMeanHtml = '<div class="searchdidyoumean">' . $this->msg( 'search-suggest' )->rawParams( $suggestLink )->text() . '</div>';
                }
+
+               if ( !wfRunHooks( 'SpecialSearchResultsPrepend', array( $this, $out, $term ) ) ) {
+                       # Hook requested termination
+                       wfProfileOut( __METHOD__ );
+                       return;
+               }
+
                // start rendering the page
                $out->addHtml(
                        Xml::openElement(
@@ -404,6 +411,7 @@ class SpecialSearch extends SpecialPage {
                if( $num || $this->offset ) {
                        $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
                }
+               wfRunHooks( 'SpecialSearchResultsAppend', array( $this, $out, $term ) );
                wfProfileOut( __METHOD__ );
        }