MediaWiki  master
InterwikiSearchResultWidget.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use HtmlArmor;
7 use SearchResult;
8 use SpecialSearch;
9 use Html;
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 }
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
__construct(SpecialSearch $specialSearch, LinkRenderer $linkRenderer)
Class that generates HTML links for pages.
Renders a single search result to HTML.