Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / search / SearchResult.php
index 30d7be7..a862e17 100644 (file)
@@ -66,10 +66,10 @@ class SearchResult {
         * Return a new SearchResult and initializes it with a title.
         *
         * @param Title $title
-        * @param SearchResultSet|null $parentSet
+        * @param ISearchResultSet|null $parentSet
         * @return SearchResult
         */
-       public static function newFromTitle( $title, SearchResultSet $parentSet = null ) {
+       public static function newFromTitle( $title, ISearchResultSet $parentSet = null ) {
                $result = new static();
                $result->initFromTitle( $title );
                if ( $parentSet ) {
@@ -86,16 +86,17 @@ class SearchResult {
         */
        protected function initFromTitle( $title ) {
                $this->mTitle = $title;
+               $services = MediaWikiServices::getInstance();
                if ( !is_null( $this->mTitle ) ) {
                        $id = false;
                        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->mImage = $services->getRepoGroup()->findFile( $this->mTitle );
                        }
                }
-               $this->searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
+               $this->searchEngine = $services->newSearchEngine();
        }
 
        /**
@@ -146,26 +147,11 @@ class SearchResult {
        }
 
        /**
-        * @param string[] $terms Terms to highlight
+        * @param string[] $terms Terms to highlight (this parameter is deprecated and ignored)
         * @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( $terms ) > 0 ) {
-                       if ( $wgAdvancedSearchHighlighting ) {
-                               return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars );
-                       } else {
-                               return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars );
-                       }
-               } else {
-                       return $h->highlightNone( $this->mText, $contextlines, $contextchars );
-               }
+       function getTextSnippet( $terms = [] ) {
+               return '';
        }
 
        /**