* @ingroup Search
*/
+use MediaWiki\MediaWikiServices;
+
/**
* @todo FIXME: This class is horribly factored. It would probably be better to
* have a useful base class to which you pass some standard information, then
*/
protected $mText;
+ /**
+ * @var SearchEngine
+ */
+ protected $searchEngine;
+
/**
* Return a new SearchResult and initializes it with a title.
*
* @return SearchResult
*/
public static function newFromTitle( $title ) {
- $result = new self();
+ $result = new static();
$result->initFromTitle( $title );
return $result;
}
$this->mTitle = $title;
if ( !is_null( $this->mTitle ) ) {
$id = false;
- Hooks::run( 'SearchResultInitFromTitle', array( $title, &$id ) );
+ Hooks::run( 'SearchResultInitFromTitle', [ $title, &$id ] );
$this->mRevision = Revision::newFromTitle(
$this->mTitle, $id, Revision::READ_NORMAL );
if ( $this->mTitle->getNamespace() === NS_FILE ) {
$this->mImage = wfFindFile( $this->mTitle );
}
}
+ $this->searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
}
/**
protected function initText() {
if ( !isset( $this->mText ) ) {
if ( $this->mRevision != null ) {
- $this->mText = SearchEngine::create()
- ->getTextFromContent( $this->mTitle, $this->mRevision->getContent() );
+ $this->mText = $this->searchEngine->getTextFromContent(
+ $this->mTitle, $this->mRevision->getContent() );
} else { // TODO: can we fetch raw wikitext for commons images?
$this->mText = '';
}
$this->initText();
// TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter.
- list( $contextlines, $contextchars ) = SearchEngine::userHighlightPrefs();
+ list( $contextlines, $contextchars ) = $this->searchEngine->userHighlightPrefs();
$h = new SearchHighlighter();
if ( count( $terms ) > 0 ) {
}
/**
- * @return Title|null Title object (pagename+fragment) for the section, null if none or not supported
+ * @return Title|null Title object (pagename+fragment) for the section,
+ * null if none or not supported
*/
function getSectionTitle() {
return null;