Merge "Revert actor changes to populateLogSearch.php"
[lhc/web/wiklou.git] / includes / search / SearchResultSet.php
index 84f8bcf..73e33a2 100644 (file)
@@ -24,7 +24,8 @@
 /**
  * @ingroup Search
  */
-class SearchResultSet implements ISearchResultSet {
+class SearchResultSet extends BaseSearchResultSet {
+       use SearchResultSetTrait;
 
        protected $containedSyntax = false;
 
@@ -42,25 +43,11 @@ class SearchResultSet implements ISearchResultSet {
         */
        protected $results;
 
-       /**
-        * Set of result's extra data, indexed per result id
-        * and then per data item name.
-        * The structure is:
-        * PAGE_ID => [ augmentor name => data, ... ]
-        * @var array[]
-        */
-       protected $extraData = [];
-
        /**
         * @var boolean True when there are more pages of search results available.
         */
        private $hasMoreResults;
 
-       /**
-        * @var ArrayIterator|null Iterator supporting BC iteration methods
-        */
-       private $bcIterator;
-
        /**
         * @param bool $containedSyntax True when query is not requesting a simple
         *  term match
@@ -78,19 +65,7 @@ class SearchResultSet implements ISearchResultSet {
                $this->hasMoreResults = $hasMoreResults;
        }
 
-       /**
-        * Fetch an array of regular expression fragments for matching
-        * the search terms as parsed by this engine in a text extract.
-        * STUB
-        *
-        * @return string[]
-        * @deprecated since 1.34 (use SqlSearchResult)
-        */
-       function termMatches() {
-               return [];
-       }
-
-       function numRows() {
+       public function numRows() {
                return $this->count();
        }
 
@@ -108,7 +83,7 @@ class SearchResultSet implements ISearchResultSet {
         *
         * @return int
         */
-       function getTotalHits() {
+       public function getTotalHits() {
                return null;
        }
 
@@ -119,7 +94,7 @@ class SearchResultSet implements ISearchResultSet {
         *
         * @return bool
         */
-       function hasRewrittenQuery() {
+       public function hasRewrittenQuery() {
                return false;
        }
 
@@ -127,7 +102,7 @@ class SearchResultSet implements ISearchResultSet {
         * @return string|null The search the query was internally rewritten to,
         *  or null when the result of the original query was returned.
         */
-       function getQueryAfterRewrite() {
+       public function getQueryAfterRewrite() {
                return null;
        }
 
@@ -135,7 +110,7 @@ class SearchResultSet implements ISearchResultSet {
         * @return string|null Same as self::getQueryAfterRewrite(), but in HTML
         *  and with changes highlighted. Null when the query was not rewritten.
         */
-       function getQueryAfterRewriteSnippet() {
+       public function getQueryAfterRewriteSnippet() {
                return null;
        }
 
@@ -145,21 +120,21 @@ class SearchResultSet implements ISearchResultSet {
         *
         * @return bool
         */
-       function hasSuggestion() {
+       public function hasSuggestion() {
                return false;
        }
 
        /**
         * @return string|null Suggested query, null if none
         */
-       function getSuggestionQuery() {
+       public function getSuggestionQuery() {
                return null;
        }
 
        /**
         * @return string HTML highlighted suggested query, '' if none
         */
-       function getSuggestionSnippet() {
+       public function getSuggestionSnippet() {
                return '';
        }
 
@@ -169,7 +144,7 @@ class SearchResultSet implements ISearchResultSet {
         * @param int $type
         * @return ISearchResultSet[]
         */
-       function getInterwikiResults( $type = self::SECONDARY_RESULTS ) {
+       public function getInterwikiResults( $type = self::SECONDARY_RESULTS ) {
                return null;
        }
 
@@ -179,54 +154,10 @@ class SearchResultSet implements ISearchResultSet {
         * @param int $type
         * @return bool
         */
-       function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) {
+       public function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) {
                return false;
        }
 
-       /**
-        * Fetches next search result, or false.
-        * @deprecated since 1.32; Use self::extractResults() or foreach
-        * @return SearchResult|false
-        */
-       public function next() {
-               wfDeprecated( __METHOD__, '1.32' );
-               $it = $this->bcIterator();
-               $searchResult = $it->current();
-               $it->next();
-               return $searchResult ?? false;
-       }
-
-       /**
-        * Rewind result set back to beginning
-        * @deprecated since 1.32; Use self::extractResults() or foreach
-        */
-       public function rewind() {
-               wfDeprecated( __METHOD__, '1.32' );
-               $this->bcIterator()->rewind();
-       }
-
-       private function bcIterator() {
-               if ( $this->bcIterator === null ) {
-                       $this->bcIterator = 'RECURSION';
-                       $this->bcIterator = $this->getIterator();
-               } elseif ( $this->bcIterator === 'RECURSION' ) {
-                       // Either next/rewind or extractResults must be implemented.  This
-                       // class was potentially instantiated directly. It should be
-                       // abstract with abstract methods to enforce this but that's a
-                       // breaking change...
-                       wfDeprecated( static::class . ' without implementing extractResults', '1.32' );
-                       $this->bcIterator = new ArrayIterator( [] );
-               }
-               return $this->bcIterator;
-       }
-
-       /**
-        * Frees the result set, if applicable.
-        * @deprecated noop since 1.34
-        */
-       function free() {
-       }
-
        /**
         * Did the search contain search syntax?  If so, Special:Search won't offer
         * the user a link to a create a page named by the search string because the
@@ -304,43 +235,4 @@ class SearchResultSet implements ISearchResultSet {
                }
                return $this->titles;
        }
-
-       /**
-        * Sets augmented data for result set.
-        * @param string $name Extra data item name
-        * @param array[] $data Extra data as PAGEID => data
-        */
-       public function setAugmentedData( $name, $data ) {
-               foreach ( $data as $id => $resultData ) {
-                       $this->extraData[$id][$name] = $resultData;
-               }
-       }
-
-       /**
-        * Returns extra data for specific result and store it in SearchResult object.
-        * @param SearchResult $result
-        */
-       public function augmentResult( SearchResult $result ) {
-               $id = $result->getTitle()->getArticleID();
-               if ( $id === -1 ) {
-                       return;
-               }
-               $result->setExtensionData( function () use ( $id ) {
-                       return $this->extraData[$id] ?? [];
-               } );
-       }
-
-       /**
-        * @return int|null The offset the current page starts at. Typically
-        *  this should be null to allow the UI to decide on its own, but in
-        *  special cases like interleaved AB tests specifying explicitly is
-        *  necessary.
-        */
-       public function getOffset() {
-               return null;
-       }
-
-       final public function getIterator() {
-               return new ArrayIterator( $this->extractResults() );
-       }
 }