initFromTitle( $title ); $this->terms = $terms; } /** * return string[] */ public function getTermMatches(): array { return $this->terms; } /** * @param array $terms Terms to highlight (this parameter is deprecated) * @return string Highlighted text snippet, null (and not '') if not supported */ function getTextSnippet( $terms = [] ) { global $wgAdvancedSearchHighlighting; $this->initText(); // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter. list( $contextlines, $contextchars ) = $this->searchEngine->userHighlightPrefs(); $h = new SearchHighlighter(); if ( count( $this->terms ) > 0 ) { if ( $wgAdvancedSearchHighlighting ) { return $h->highlightText( $this->mText, $this->terms, $contextlines, $contextchars ); } else { return $h->highlightSimple( $this->mText, $this->terms, $contextlines, $contextchars ); } } else { return $h->highlightNone( $this->mText, $contextlines, $contextchars ); } } }