Add explicit visibility to SearchResult methods
[lhc/web/wiklou.git] / includes / search / SearchResult.php
index f85c58f..1d71c87 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();
        }
 
        /**
@@ -103,7 +104,7 @@ class SearchResult {
         *
         * @return bool
         */
-       function isBrokenTitle() {
+       public function isBrokenTitle() {
                return is_null( $this->mTitle );
        }
 
@@ -112,14 +113,14 @@ class SearchResult {
         *
         * @return bool
         */
-       function isMissingRevision() {
+       public function isMissingRevision() {
                return !$this->mRevision && !$this->mImage;
        }
 
        /**
         * @return Title
         */
-       function getTitle() {
+       public function getTitle() {
                return $this->mTitle;
        }
 
@@ -127,7 +128,7 @@ class SearchResult {
         * Get the file for this page, if one exists
         * @return File|null
         */
-       function getFile() {
+       public function getFile() {
                return $this->mImage;
        }
 
@@ -146,53 +147,38 @@ class SearchResult {
        }
 
        /**
-        * @param array $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 );
-               }
+       public function getTextSnippet( $terms = [] ) {
+               return '';
        }
 
        /**
         * @return string Highlighted title, '' if not supported
         */
-       function getTitleSnippet() {
+       public function getTitleSnippet() {
                return '';
        }
 
        /**
         * @return string Highlighted redirect name (redirect to this page), '' if none or not supported
         */
-       function getRedirectSnippet() {
+       public function getRedirectSnippet() {
                return '';
        }
 
        /**
         * @return Title|null Title object for the redirect to this page, null if none or not supported
         */
-       function getRedirectTitle() {
+       public function getRedirectTitle() {
                return null;
        }
 
        /**
         * @return string Highlighted relevant section name, null if none or not supported
         */
-       function getSectionSnippet() {
+       public function getSectionSnippet() {
                return '';
        }
 
@@ -200,7 +186,7 @@ class SearchResult {
         * @return Title|null Title object (pagename+fragment) for the section,
         *  null if none or not supported
         */
-       function getSectionTitle() {
+       public function getSectionTitle() {
                return null;
        }
 
@@ -214,7 +200,7 @@ class SearchResult {
        /**
         * @return string Timestamp
         */
-       function getTimestamp() {
+       public function getTimestamp() {
                if ( $this->mRevision ) {
                        return $this->mRevision->getTimestamp();
                } elseif ( $this->mImage ) {
@@ -226,7 +212,7 @@ class SearchResult {
        /**
         * @return int Number of words
         */
-       function getWordCount() {
+       public function getWordCount() {
                $this->initText();
                return str_word_count( $this->mText );
        }
@@ -234,7 +220,7 @@ class SearchResult {
        /**
         * @return int Size in bytes
         */
-       function getByteSize() {
+       public function getByteSize() {
                $this->initText();
                return strlen( $this->mText );
        }
@@ -242,14 +228,14 @@ class SearchResult {
        /**
         * @return string Interwiki prefix of the title (return iw even if title is broken)
         */
-       function getInterwikiPrefix() {
+       public function getInterwikiPrefix() {
                return '';
        }
 
        /**
         * @return string Interwiki namespace of the title (since we likely can't resolve it locally)
         */
-       function getInterwikiNamespaceText() {
+       public function getInterwikiNamespaceText() {
                return '';
        }
 
@@ -257,7 +243,7 @@ class SearchResult {
         * Did this match file contents (eg: PDF/DJVU)?
         * @return bool
         */
-       function isFileMatch() {
+       public function isFileMatch() {
                return false;
        }