Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
InterwikiSearchResultWidget | |
0.00% |
0 / 23 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
render | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Search\SearchWidgets; |
4 | |
5 | use HtmlArmor; |
6 | use MediaWiki\Html\Html; |
7 | use MediaWiki\Linker\LinkRenderer; |
8 | use MediaWiki\Specials\SpecialSearch; |
9 | use SearchResult; |
10 | |
11 | /** |
12 | * Renders an enhanced interwiki result |
13 | */ |
14 | class InterwikiSearchResultWidget implements SearchResultWidget { |
15 | /** @var SpecialSearch */ |
16 | protected $specialSearch; |
17 | /** @var LinkRenderer */ |
18 | protected $linkRenderer; |
19 | |
20 | public function __construct( SpecialSearch $specialSearch, LinkRenderer $linkRenderer ) { |
21 | $this->specialSearch = $specialSearch; |
22 | $this->linkRenderer = $linkRenderer; |
23 | } |
24 | |
25 | /** |
26 | * @param SearchResult $result The result to render |
27 | * @param int $position The result position, including offset |
28 | * @return string HTML |
29 | */ |
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 | } |