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