From d6495c2a4ee30207f6fa9c00714ea8de97d0bc77 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 6 Nov 2012 14:01:16 +0100 Subject: [PATCH] (Bug 41580) Hook for custom search hit rendering. Introducing ShowSearchHit hook into SpecialSearch, so extensions can control of how search results are displayed. This does not fix bug 41580, but it's a precondition to fixing it in Wikibase. Change-Id: I9158684b92e320a486266c45dc3f7cf466ec5a24 --- docs/hooks.txt | 15 +++++++++++++++ includes/specials/SpecialSearch.php | 18 ++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 998523f334..f93203fea7 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1831,6 +1831,21 @@ $result: The search result $terms: The search terms entered $page: The SpecialSearch object. +'ShowSearchHit': Customize display of search hit. +$searchPage: The SpecialSearch instance. +$result: The SearchResult to show +$terms: Search terms, for highlighting +&$link: HTML of link to the matching page. May be modified. +&$redirect: HTML of redirect info. May be modified. +&$section: HTML of matching section. May be modified. +&$extract: HTML of content extract. May be modified. +&$score: HTML of score. May be modified. +&$size: HTML of page size. May be modified. +&$date: HTML of of page modification date. May be modified. +&$related: HTML of additional info for the matching page. May be modified. +&$html: May be set to the full HTML that should be used to represent the search hit. Must include +the
  • ...
  • tags. Will only be used if the hook function returned false. + 'SiteNoticeBefore': Before the sitenotice/anonnotice is composed &$siteNotice: HTML returned as the sitenotice $skin: Skin object diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 6c33bb8040..7c8ff84c4e 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -684,11 +684,21 @@ class SpecialSearch extends SpecialPage { } } - wfProfileOut( __METHOD__ ); - return "
  • {$link} {$redirect} {$section}
    {$extract}\n" . - "
    {$score}{$size} - {$date}{$related}
    " . - "
  • \n"; + $html = null; + + if ( wfRunHooks( 'ShowSearchHit', array ( + $this, $result, $terms, + &$link, &$redirect, &$section, &$extract, + &$score, &$size, &$date, &$related, + &$html + ) ) ) { + $html = "
  • {$link} {$redirect} {$section}
    {$extract}\n" . + "
    {$score}{$size} - {$date}{$related}
    " . + "
  • \n"; + } + wfProfileOut( __METHOD__ ); + return $html; } /** -- 2.20.1