MediaWiki REL1_32
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 $iwPrefix = $result->getTitle()->getInterwiki();
34 $titleSnippet = $result->getTitleSnippet();
35 $snippet = $result->getTextSnippet( $terms );
36
37 if ( $titleSnippet ) {
38 $titleSnippet = new HtmlArmor( $titleSnippet );
39 } else {
40 $titleSnippet = null;
41 }
42
43 $link = $this->linkRenderer->makeLink( $title, $titleSnippet );
44
45 $redirectTitle = $result->getRedirectTitle();
46 $redirect = '';
47 if ( $redirectTitle !== null ) {
48 $redirectText = $result->getRedirectSnippet();
49
50 if ( $redirectText ) {
51 $redirectText = new HtmlArmor( $redirectText );
52 } else {
53 $redirectText = null;
54 }
55
56 $redirect = Html::rawElement( 'span', [ 'class' => 'iw-result__redirect' ],
57 $this->specialSearch->msg( 'search-redirect' )->rawParams(
58 $this->linkRenderer->makeLink( $redirectTitle, $redirectText )
59 )->escaped()
60 );
61 }
62
63 return Html::rawElement( 'div', [ 'class' => 'iw-result__title' ], $link . ' ' . $redirect ) .
64 Html::rawElement( 'div', [ 'class' => 'iw-result__content' ], $snippet );
65 }
66}
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:3106
Renders a single search result to HTML.