Add attributes parameter to ShowSearchHitTitle
authorStanislav Malyshev <smalyshev@gmail.com>
Mon, 23 Oct 2017 22:42:41 +0000 (15:42 -0700)
committerStanislav Malyshev <smalyshev@gmail.com>
Mon, 23 Oct 2017 22:42:41 +0000 (15:42 -0700)
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
includes/widget/search/FullSearchResultWidget.php

index b7fe8c1..5740040 100644 (file)
@@ -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
index 0d0fa12..4c98399 100644 (file)
@@ -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
                );