Merge "Fix param type of search terms in search related classes"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 17 Jun 2019 07:54:27 +0000 (07:54 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 17 Jun 2019 07:54:27 +0000 (07:54 +0000)
1  2 
includes/search/SearchEngine.php
includes/search/SearchResult.php
includes/search/SqlSearchResultSet.php
includes/widget/search/FullSearchResultWidget.php

@@@ -46,7 -46,7 +46,7 @@@ abstract class SearchEngine 
        /** @var int */
        protected $offset = 0;
  
-       /** @var array|string */
+       /** @var string[] */
        protected $searchTerms = [];
  
        /** @var bool */
         * be converted to final in 1.34. Override self::doSearchArchiveTitle().
         *
         * @param string $term Raw search term
 -       * @return Status<Title[]>
 +       * @return Status
         * @since 1.29
         */
        public function searchArchiveTitle( $term ) {
         * Perform a title search in the article archive.
         *
         * @param string $term Raw search term
 -       * @return Status<Title[]>
 +       * @return Status
         * @since 1.32
         */
        protected function doSearchArchiveTitle( $term ) {
@@@ -86,17 -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();
        }
  
        /**
        }
  
        /**
-        * @param array $terms Terms to highlight
+        * @param string[] $terms Terms to highlight
         * @return string Highlighted text snippet, null (and not '') if not supported
         */
        function getTextSnippet( $terms ) {
@@@ -1,22 -1,20 +1,22 @@@
  <?php
  
 -use Wikimedia\Rdbms\ResultWrapper;
 +use Wikimedia\Rdbms\IResultWrapper;
  
  /**
   * This class is used for different SQL-based search engines shipped with MediaWiki
   * @ingroup Search
   */
  class SqlSearchResultSet extends SearchResultSet {
 -      /** @var ResultWrapper Result object from database */
 +      /** @noinspection PhpMissingParentConstructorInspection */
 +
 +      /** @var IResultWrapper Result object from database */
        protected $resultSet;
-       /** @var string Requested search query */
+       /** @var string[] Requested search query */
        protected $terms;
        /** @var int|null Total number of hits for $terms */
        protected $totalHits;
  
 -      function __construct( ResultWrapper $resultSet, $terms, $total = null ) {
 +      function __construct( IResultWrapper $resultSet, $terms, $total = null ) {
                $this->resultSet = $resultSet;
                $this->terms = $terms;
                $this->totalHits = $total;
@@@ -53,7 -51,7 +53,7 @@@
  
        function free() {
                if ( $this->resultSet === false ) {
 -                      return false;
 +                      return;
                }
  
                $this->resultSet->free();
@@@ -6,7 -6,6 +6,7 @@@ use Category
  use Hooks;
  use HtmlArmor;
  use MediaWiki\Linker\LinkRenderer;
 +use MediaWiki\MediaWikiServices;
  use SearchResult;
  use SpecialSearch;
  use Title;
@@@ -31,7 -30,7 +31,7 @@@ class FullSearchResultWidget implement
  
        /**
         * @param SearchResult $result The result to render
-        * @param string $terms Terms to be highlighted (@see SearchResult::getTextSnippet)
+        * @param string[] $terms Terms to be highlighted (@see SearchResult::getTextSnippet)
         * @param int $position The result position, including offset
         * @return string HTML
         */
                // This is not quite safe, but better than showing excerpts from
                // non-readable pages. Note that hiding the entry entirely would
                // screw up paging (really?).
 -              if ( !$result->getTitle()->userCan( 'read', $this->specialPage->getUser() ) ) {
 +              $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 +              if ( !$permissionManager->userCan(
 +                      'read', $this->specialPage->getUser(), $result->getTitle()
 +              ) ) {
                        return "<li>{$link}</li>";
                }
  
         * title with highlighted words).
         *
         * @param SearchResult $result
-        * @param string $terms
+        * @param string[] $terms
         * @param int $position
         * @return string HTML
         */
                $descHtml = null;
                $thumbHtml = null;
  
 -              $img = $result->getFile() ?: wfFindFile( $title );
 +              $img = $result->getFile() ?: MediaWikiServices::getInstance()->getRepoGroup()
 +                      ->findFile( $title );
                if ( $img ) {
                        $thumb = $img->transform( [ 'width' => 120, 'height' => 120 ] );
                        if ( $thumb ) {