From 46a13941f98d14a49103a49fb1a586b6c69eca66 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Fri, 18 Sep 2015 12:30:30 -0700 Subject: [PATCH] Displaying search results for multiple wikis Uses fully translated string like search-interwiki-results-abwiki which should be present in WikimediaMessages. Requires Ic4bdd9462f844febea2e402e4b89d9dcc4c836b6 Supports I0d0efacf3066b3b5fe0bfcb058dd0b0f9988ccae Bug: T112349 Change-Id: Ib6524bc79e1648ccf6adc5745f0dbc4c26dcb0d2 --- includes/search/SearchResultSet.php | 21 +++++- includes/specials/SpecialSearch.php | 101 +++++++++++++++++++++------- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 4 files changed, 97 insertions(+), 27 deletions(-) diff --git a/includes/search/SearchResultSet.php b/includes/search/SearchResultSet.php index 6178756218..8fb04e4a91 100644 --- a/includes/search/SearchResultSet.php +++ b/includes/search/SearchResultSet.php @@ -25,6 +25,21 @@ * @ingroup Search */ class SearchResultSet { + + /** + * Types of interwiki results + */ + /** + * Results that are displayed only together with existing main wiki results + * @var int + */ + const SECONDARY_RESULTS = 0; + /** + * Results that can displayed even if no existing main wiki results exist + * @var int + */ + const INLINE_RESULTS = 1; + protected $containedSyntax = false; public function __construct( $containedSyntax = false ) { @@ -116,7 +131,7 @@ class SearchResultSet { * * @return SearchResultSet */ - function getInterwikiResults() { + function getInterwikiResults( $type = self::SECONDARY_RESULTS ) { return null; } @@ -125,8 +140,8 @@ class SearchResultSet { * * @return bool */ - function hasInterwikiResults() { - return $this->getInterwikiResults() != null; + function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) { + return false; } /** diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index fc7eeb17d5..d6ce6a4be7 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -73,6 +73,12 @@ class SpecialSearch extends SpecialPage { */ protected $runSuggestion = true; + /** + * Names of the wikis, in format: Interwiki prefix -> caption + * @var array + */ + protected $customCaptions; + const NAMESPACES_CURRENT = 'sense'; public function __construct() { @@ -371,25 +377,45 @@ class SpecialSearch extends SpecialPage { if ( $numTextMatches > 0 ) { $out->addHTML( $this->showMatches( $textMatches ) ); } - // show interwiki results if any - if ( $textMatches->hasInterwikiResults() ) { - $out->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) ); + + // show secondary interwiki results if any + if ( $textMatches->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS ) ) { + $out->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults( + SearchResultSet::SECONDARY_RESULTS ), $term ) ); } $textMatches->free(); } + + $hasOtherResults = $textMatches->hasInterwikiResults( SearchResultSet::INLINE_RESULTS ); + if ( $num === 0 ) { if ( $textStatus ) { $out->addHTML( '
' . $textStatus->getMessage( 'search-error' ) . '
' ); } else { - $out->wrapWikiMsg( "

\n$1

", - array( 'search-nonefound', wfEscapeWikiText( $term ) ) ); $this->showCreateLink( $title, $num, $titleMatches, $textMatches ); + $out->wrapWikiMsg( "

\n$1

", + array( $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound', + wfEscapeWikiText( $term ) + ) ); + } + } + + if ( $hasOtherResults ) { + foreach ( $textMatches->getInterwikiResults( SearchResultSet::INLINE_RESULTS ) + as $interwiki => $interwikiResult ) { + if ( $interwikiResult instanceof Status || $interwikiResult->numRows() == 0 ) { + // ignore bad interwikis for now + continue; + } + // TODO: wiki header + $out->addHTML( $this->showMatches( $interwikiResult, $interwiki ) ); } } $out->addHTML( '
' ); + if ( $prevnext ) { $out->addHTML( "

{$prevnext}

\n" ); } @@ -400,6 +426,17 @@ class SpecialSearch extends SpecialPage { } + /** + * Produce wiki header for interwiki results + * @param string $interwiki Interwiki name + * @param SearchResultSet $interwikiResult The result set + */ + protected function interwikiHeader( $interwiki, $interwikiResult ) { + // TODO: we need to figure out how to name wikis correctly + $wikiMsg = $this->msg( 'search-interwiki-results-' . $interwiki )->parse(); + return "

\n$wikiMsg

"; + } + /** * Decide if the suggested query should be run, and it's results returned * instead of the provided $textMatches @@ -636,17 +673,23 @@ class SpecialSearch extends SpecialPage { * Show whole set of results * * @param SearchResultSet $matches + * @param string $interwiki Interwiki name * * @return string */ - protected function showMatches( &$matches ) { + protected function showMatches( &$matches, $interwiki = null ) { global $wgContLang; $terms = $wgContLang->convertForSearchResult( $matches->termMatches() ); - - $out = "