MediaWiki  master
InterwikiSearchResultWidget.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Html;
6 use HtmlArmor;
8 use SearchResult;
9 use SpecialSearch;
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 }
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
MediaWiki\Search\SearchWidgets\InterwikiSearchResultWidget\$specialSearch
SpecialSearch $specialSearch
Definition: InterwikiSearchResultWidget.php:16
MediaWiki\Search\SearchWidgets\InterwikiSearchResultWidget
Renders an enhanced interwiki result.
Definition: InterwikiSearchResultWidget.php:14
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:41
MediaWiki\Search\SearchWidgets\InterwikiSearchResultWidget\__construct
__construct(SpecialSearch $specialSearch, LinkRenderer $linkRenderer)
Definition: InterwikiSearchResultWidget.php:20
MediaWiki\Search\SearchWidgets\InterwikiSearchResultWidget\render
render(SearchResult $result, $position)
Definition: InterwikiSearchResultWidget.php:30
SearchResult
NOTE: this class is being refactored into an abstract base class.
Definition: SearchResult.php:38
$title
$title
Definition: testCompression.php:38
MediaWiki\Search\SearchWidgets\InterwikiSearchResultWidget\$linkRenderer
LinkRenderer $linkRenderer
Definition: InterwikiSearchResultWidget.php:18
SpecialSearch
implements Special:Search - Run text & title search and display the output
Definition: SpecialSearch.php:38
MediaWiki\Search\SearchWidgets\SearchResultWidget
Renders a single search result to HTML.
Definition: SearchResultWidget.php:10
MediaWiki\Search\SearchWidgets
Definition: BasicSearchResultSetWidget.php:3
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
Html
This class is a collection of static functions that serve two purposes:
Definition: Html.php:49