* @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;
+
+ /**
+ * A set of extension data.
+ * @var array[]
+ */
+ protected $extensionData;
+
/**
* Return a new SearchResult and initializes it with a title.
*
- * @param Title $title
+ * @param Title $title
+ * @param SearchResultSet $parentSet
* @return SearchResult
*/
- public static function newFromTitle( $title ) {
- $result = new self();
+ public static function newFromTitle( $title, SearchResultSet $parentSet = null ) {
+ $result = new static();
$result->initFromTitle( $title );
+ if ( $parentSet ) {
+ $parentSet->augmentResult( $result );
+ }
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 ) {
function isFileMatch() {
return false;
}
+
+ /**
+ * Get the extension data as:
+ * augmentor name => data
+ * @return array[]
+ */
+ public function getExtensionData() {
+ return $this->extensionData;
+ }
+
+ /**
+ * Set extension data for this result.
+ * The data is:
+ * augmentor name => data
+ * @param array[] $extensionData
+ */
+ public function setExtensionData( array $extensionData ) {
+ $this->extensionData = $extensionData;
+ }
+
}