MediaWiki  master
SimpleSearchResultWidget.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use HtmlArmor;
7 use SearchResult;
8 use SpecialSearch;
9 
17  protected $specialSearch;
19  protected $linkRenderer;
20 
22  wfDeprecated( __METHOD__, '1.31' );
23  $this->specialSearch = $specialSearch;
24  $this->linkRenderer = $linkRenderer;
25  }
26 
32  public function render( SearchResult $result, $position ) {
33  $title = $result->getTitle();
34  $titleSnippet = $result->getTitleSnippet();
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  if ( $redirectText ) {
48  $redirectText = new HtmlArmor( $redirectText );
49  } else {
50  $redirectText = null;
51  }
52  $redirect =
53  "<span class='searchalttitle'>" .
54  $this->specialSearch->msg( 'search-redirect' )->rawParams(
55  $this->linkRenderer->makeLink( $redirectTitle, $redirectText )
56  )->parse() .
57  "</span>";
58  }
59 
60  return "<li>{$link} {$redirect}</li>";
61  }
62 }
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
MediaWiki\Search\SearchWidgets\SimpleSearchResultWidget\render
render(SearchResult $result, $position)
Definition: SimpleSearchResultWidget.php:32
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:41
SearchResult
NOTE: this class is being refactored into an abstract base class.
Definition: SearchResult.php:38
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1026
MediaWiki\Search\SearchWidgets\SimpleSearchResultWidget\$linkRenderer
LinkRenderer $linkRenderer
Definition: SimpleSearchResultWidget.php:19
$title
$title
Definition: testCompression.php:38
MediaWiki\Search\SearchWidgets\SimpleSearchResultWidget\__construct
__construct(SpecialSearch $specialSearch, LinkRenderer $linkRenderer)
Definition: SimpleSearchResultWidget.php:21
MediaWiki\Search\SearchWidgets\SimpleSearchResultWidget\$specialSearch
SpecialSearch $specialSearch
Definition: SimpleSearchResultWidget.php:17
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\SimpleSearchResultWidget
Renders a simple one-line result.
Definition: SimpleSearchResultWidget.php:15
MediaWiki\Search\SearchWidgets
Definition: BasicSearchResultSetWidget.php:3