MediaWiki  1.34.0
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 }
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:28
MediaWiki\Widget\Search\InterwikiSearchResultWidget\__construct
__construct(SpecialSearch $specialSearch, LinkRenderer $linkRenderer)
Definition: InterwikiSearchResultWidget.php:20
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:41
MediaWiki\Widget\Search
Definition: BasicSearchResultSetWidget.php:3
SearchResult
NOTE: this class is being refactored into an abstract base class.
Definition: SearchResult.php:38
MediaWiki\Widget\Search\InterwikiSearchResultWidget\render
render(SearchResult $result, $position)
Definition: InterwikiSearchResultWidget.php:30
MediaWiki\Widget\Search\SearchResultWidget
Renders a single search result to HTML.
Definition: SearchResultWidget.php:10
$title
$title
Definition: testCompression.php:34
MediaWiki\Widget\Search\InterwikiSearchResultWidget\$specialSearch
SpecialSearch $specialSearch
Definition: InterwikiSearchResultWidget.php:16
SpecialSearch
implements Special:Search - Run text & title search and display the output
Definition: SpecialSearch.php:38
MediaWiki\Widget\Search\InterwikiSearchResultWidget
Renders an enhanced interwiki result.
Definition: InterwikiSearchResultWidget.php:14
MediaWiki\Widget\Search\InterwikiSearchResultWidget\$linkRenderer
LinkRenderer $linkRenderer
Definition: InterwikiSearchResultWidget.php:18