3 namespace MediaWiki\Widget\Search
;
6 use MediaWiki\Linker\LinkRenderer
;
12 * Renders a simple one-line result
14 class SimpleSearchResultWidget
implements SearchResultWidget
{
15 /** @var SpecialSearch */
16 protected $specialSearch;
17 /** @var LinkRenderer */
18 protected $linkRenderer;
20 public function __construct( SpecialSearch
$specialSearch, LinkRenderer
$linkRenderer ) {
21 $this->specialSearch
= $specialSearch;
22 $this->linkRenderer
= $linkRenderer;
26 * @param SearchResult $result The result to render
27 * @param string $terms Terms to be highlighted (@see SearchResult::getTextSnippet)
28 * @param int $position The result position, including offset
31 public function render( SearchResult
$result, $terms, $position ) {
32 $title = $result->getTitle();
33 $titleSnippet = $result->getTitleSnippet();
34 if ( $titleSnippet ) {
35 $titleSnippet = new HtmlArmor( $titleSnippet );
40 $link = $this->linkRenderer
->makeLink( $title, $titleSnippet );
42 $redirectTitle = $result->getRedirectTitle();
44 if ( $redirectTitle !== null ) {
45 $redirectText = $result->getRedirectSnippet();
46 if ( $redirectText ) {
47 $redirectText = new HtmlArmor( $redirectText );
52 "<span class='searchalttitle'>" .
53 $this->specialSearch
->msg( 'search-redirect' )->rawParams(
54 $this->linkRenderer
->makeLink( $redirectTitle, $redirectText )
59 return "<li>{$link} {$redirect}</li>";