From 0e93f96c9a82b9210ab6fcfa65bf4b21af00faf3 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Mon, 23 Oct 2017 15:42:41 -0700 Subject: [PATCH 1/1] Add attributes parameter to ShowSearchHitTitle This would allow extensions to define custom attributes on title link, such as put information in "title", change attributes depending on specific search hit, etc. Now Wikidata does the same by overriding LinkBegin, but this applies to all links, not specifically to search result link. Since ShowSearchHitTitle is always used with the link, I think it makes sense to enable this specific customization. Change-Id: I19f64e0909d92e32ddf6271f74c014e8b65d5014 --- docs/hooks.txt | 1 + includes/widget/search/FullSearchResultWidget.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index b7fe8c1f35..5740040e53 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2947,6 +2947,7 @@ $result: The SearchResult object $terms: String of the search terms entered $specialSearch: The SpecialSearch object &$query: Array of query string parameters for the link representing the search result. +&$attributes: Array of title link attributes, can be modified by extension. 'SidebarBeforeOutput': Allows to edit sidebar just before it is output by skins. Warning: This hook is run on each display. You should consider to use diff --git a/includes/widget/search/FullSearchResultWidget.php b/includes/widget/search/FullSearchResultWidget.php index 0d0fa12411..4c9839966b 100644 --- a/includes/widget/search/FullSearchResultWidget.php +++ b/includes/widget/search/FullSearchResultWidget.php @@ -133,13 +133,14 @@ class FullSearchResultWidget implements SearchResultWidget { $title = clone $result->getTitle(); $query = []; + $attributes = [ 'data-serp-pos' => $position ]; Hooks::run( 'ShowSearchHitTitle', - [ &$title, &$snippet, $result, $terms, $this->specialPage, &$query ] ); + [ &$title, &$snippet, $result, $terms, $this->specialPage, &$query, &$attributes ] ); $link = $this->linkRenderer->makeLink( $title, $snippet, - [ 'data-serp-pos' => $position ], + $attributes, $query ); -- 2.20.1