And start indicating that hooks relying on this data might become unreliable as this data is only populated by SearchDatabase search engines. This information was only populated by SearchDatabase implementations and due to bad initial design of SearchResult[Set] (now fixed) it forced users of these classes to carry this information for the sole purpose of highlighting. Because SearchEngine can now own their SearchResult[Set] implementations nothing that is engine specific should be exposed outside of these specific implementations. If there are some logic that still requires access to such list of terms they should be made engine specific by guarding their code against instanceof SqlSearchResult. Change-Id: I38b82c5e4c35309ee447edc3ded60ca6a18b247a Depends-On: I53fe37c65c7940f696c1e184125e01e592a976e4
62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Widget\Search;
|
|
|
|
use HtmlArmor;
|
|
use MediaWiki\Linker\LinkRenderer;
|
|
use SearchResult;
|
|
use SpecialSearch;
|
|
|
|
/**
|
|
* Renders a simple one-line result
|
|
*
|
|
* @deprecated since 1.31. Use other result widgets.
|
|
*/
|
|
class SimpleSearchResultWidget implements SearchResultWidget {
|
|
/** @var SpecialSearch */
|
|
protected $specialSearch;
|
|
/** @var LinkRenderer */
|
|
protected $linkRenderer;
|
|
|
|
public function __construct( SpecialSearch $specialSearch, LinkRenderer $linkRenderer ) {
|
|
wfDeprecated( __METHOD__, '1.31' );
|
|
$this->specialSearch = $specialSearch;
|
|
$this->linkRenderer = $linkRenderer;
|
|
}
|
|
|
|
/**
|
|
* @param SearchResult $result The result to render
|
|
* @param int $position The result position, including offset
|
|
* @return string HTML
|
|
*/
|
|
public function render( SearchResult $result, $position ) {
|
|
$title = $result->getTitle();
|
|
$titleSnippet = $result->getTitleSnippet();
|
|
if ( $titleSnippet ) {
|
|
$titleSnippet = new HtmlArmor( $titleSnippet );
|
|
} else {
|
|
$titleSnippet = null;
|
|
}
|
|
|
|
$link = $this->linkRenderer->makeLink( $title, $titleSnippet );
|
|
|
|
$redirectTitle = $result->getRedirectTitle();
|
|
$redirect = '';
|
|
if ( $redirectTitle !== null ) {
|
|
$redirectText = $result->getRedirectSnippet();
|
|
if ( $redirectText ) {
|
|
$redirectText = new HtmlArmor( $redirectText );
|
|
} else {
|
|
$redirectText = null;
|
|
}
|
|
$redirect =
|
|
"<span class='searchalttitle'>" .
|
|
$this->specialSearch->msg( 'search-redirect' )->rawParams(
|
|
$this->linkRenderer->makeLink( $redirectTitle, $redirectText )
|
|
)->parse() .
|
|
"</span>";
|
|
}
|
|
|
|
return "<li>{$link} {$redirect}</li>";
|
|
}
|
|
}
|