SimpleSearchResultWidget.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace MediaWiki\Widget\Search;
  3. use HtmlArmor;
  4. use MediaWiki\Linker\LinkRenderer;
  5. use SearchResult;
  6. use SpecialSearch;
  7. /**
  8. * Renders a simple one-line result
  9. *
  10. * @deprecated since 1.31. Use other result widgets.
  11. */
  12. class SimpleSearchResultWidget implements SearchResultWidget {
  13. /** @var SpecialSearch */
  14. protected $specialSearch;
  15. /** @var LinkRenderer */
  16. protected $linkRenderer;
  17. public function __construct( SpecialSearch $specialSearch, LinkRenderer $linkRenderer ) {
  18. wfDeprecated( __METHOD__, '1.31' );
  19. $this->specialSearch = $specialSearch;
  20. $this->linkRenderer = $linkRenderer;
  21. }
  22. /**
  23. * @param SearchResult $result The result to render
  24. * @param int $position The result position, including offset
  25. * @return string HTML
  26. */
  27. public function render( SearchResult $result, $position ) {
  28. $title = $result->getTitle();
  29. $titleSnippet = $result->getTitleSnippet();
  30. if ( $titleSnippet ) {
  31. $titleSnippet = new HtmlArmor( $titleSnippet );
  32. } else {
  33. $titleSnippet = null;
  34. }
  35. $link = $this->linkRenderer->makeLink( $title, $titleSnippet );
  36. $redirectTitle = $result->getRedirectTitle();
  37. $redirect = '';
  38. if ( $redirectTitle !== null ) {
  39. $redirectText = $result->getRedirectSnippet();
  40. if ( $redirectText ) {
  41. $redirectText = new HtmlArmor( $redirectText );
  42. } else {
  43. $redirectText = null;
  44. }
  45. $redirect =
  46. "<span class='searchalttitle'>" .
  47. $this->specialSearch->msg( 'search-redirect' )->rawParams(
  48. $this->linkRenderer->makeLink( $redirectTitle, $redirectText )
  49. )->parse() .
  50. "</span>";
  51. }
  52. return "<li>{$link} {$redirect}</li>";
  53. }
  54. }