MediaWiki REL1_33
InterwikiSearchResultWidget.php
Go to the documentation of this file.
1<?php
2
4
5use HtmlArmor;
9use Html;
10
16 protected $specialSearch;
18 protected $linkRenderer;
19
21 $this->specialSearch = $specialSearch;
22 $this->linkRenderer = $linkRenderer;
23 }
24
31 public function render( SearchResult $result, $terms, $position ) {
32 $title = $result->getTitle();
33 $titleSnippet = $result->getTitleSnippet();
34 $snippet = $result->getTextSnippet( $terms );
35
36 if ( $titleSnippet ) {
37 $titleSnippet = new HtmlArmor( $titleSnippet );
38 } else {
39 $titleSnippet = null;
40 }
41
42 $link = $this->linkRenderer->makeLink( $title, $titleSnippet );
43
44 $redirectTitle = $result->getRedirectTitle();
45 $redirect = '';
46 if ( $redirectTitle !== null ) {
47 $redirectText = $result->getRedirectSnippet();
48
49 if ( $redirectText ) {
50 $redirectText = new HtmlArmor( $redirectText );
51 } else {
52 $redirectText = null;
53 }
54
55 $redirect = Html::rawElement( 'span', [ 'class' => 'iw-result__redirect' ],
56 $this->specialSearch->msg( 'search-redirect' )->rawParams(
57 $this->linkRenderer->makeLink( $redirectTitle, $redirectText )
58 )->escaped()
59 );
60 }
61
62 return Html::rawElement( 'div', [ 'class' => 'iw-result__title' ], $link . ' ' . $redirect ) .
63 Html::rawElement( 'div', [ 'class' => 'iw-result__content' ], $snippet );
64 }
65}
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:28
This class is a collection of static functions that serve two purposes:
Definition Html.php:49
Class that generates HTML links for pages.
__construct(SpecialSearch $specialSearch, LinkRenderer $linkRenderer)
implements Special:Search - Run text & title search and display the output
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:3069
Renders a single search result to HTML.