From: Ryan Finnie Date: Fri, 18 Jan 2013 00:46:40 +0000 (-0800) Subject: Adding SpecialSearchResultsPrepend/Append hooks X-Git-Tag: 1.31.0-rc.0~21004^2 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=1c3b2a1;p=lhc%2Fweb%2Fwiklou.git Adding SpecialSearchResultsPrepend/Append hooks 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 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 8905d7eec4..36279a5c82 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 7c8ff84c4e..bc90d2b3d4 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -288,6 +288,13 @@ class SpecialSearch extends SpecialPage { $this->didYouMeanHtml = '
' . $this->msg( 'search-suggest' )->rawParams( $suggestLink )->text() . '
'; } + + 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( "

{$prevnext}

\n" ); } + wfRunHooks( 'SpecialSearchResultsAppend', array( $this, $out, $term ) ); wfProfileOut( __METHOD__ ); }