jenkins-bot has submitted this change and it was merged.

Change subject: Allow search backends to return statuses instead of result sets
......................................................................


Allow search backends to return statuses instead of result sets

This will allow a backend to propogate more useful errors up
the stack.

Bug: 43544
Change-Id: I54ab520762381e8f46d5ca17c0bad8820eacb964
---
M includes/specials/SpecialSearch.php
M languages/messages/MessagesEn.php
M languages/messages/MessagesQqq.php
M maintenance/language/messages.inc
4 files changed, 20 insertions(+), 4 deletions(-)

Approvals:
  Tim Starling: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/specials/SpecialSearch.php 
b/includes/specials/SpecialSearch.php
index 380e20e..a4ab7a8 100644
--- a/includes/specials/SpecialSearch.php
+++ b/includes/specials/SpecialSearch.php
@@ -257,8 +257,14 @@
                        $textMatches = $search->searchText( $rewritten );
                }
 
+               $textStatus = null;
+               if( $textMatches instanceof Status ) {
+                       $textStatus = $textMatches;
+                       $textMatches = null;
+               }
+
                // did you mean... suggestions
-               if( $textMatches && $textMatches->hasSuggestion() ) {
+               if( $textMatches && !$textStatus && 
$textMatches->hasSuggestion() ) {
                        $st = SpecialPage::getTitleFor( 'Search' );
 
                        # mirror Go/Search behavior of original request ..
@@ -381,7 +387,7 @@
                        }
                        $titleMatches->free();
                }
-               if( $textMatches ) {
+               if( $textMatches && !$textStatus ) {
                        // output appropriate heading
                        if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
                                // if no title matches the heading is redundant
@@ -402,8 +408,14 @@
                        $textMatches->free();
                }
                if( $num === 0 ) {
-                       $out->wrapWikiMsg( "<p 
class=\"mw-search-nonefound\">\n$1</p>", array( 'search-nonefound', 
wfEscapeWikiText( $term ) ) );
-                       $this->showCreateLink( $t );
+                       if ( $textStatus ) {
+                               $out->addHTML( '<div class="error">' .
+                                       htmlspecialchars( 
$textStatus->getWikiText( 'search-error' ) ) . '</div>' );
+                       } else {
+                               $out->wrapWikiMsg( "<p 
class=\"mw-search-nonefound\">\n$1</p>",
+                                       array( 'search-nonefound', 
wfEscapeWikiText( $term ) ) );
+                               $this->showCreateLink( $t );
+                       }
                }
                $out->addHtml( "</div>" );
 
diff --git a/languages/messages/MessagesEn.php 
b/languages/messages/MessagesEn.php
index c5dba69..ba5633d 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -1804,6 +1804,7 @@
 
 # OpenSearch description
 'opensearch-desc' => '{{SITENAME}} ({{CONTENTLANGUAGE}})', # do not translate 
or duplicate this message to other languages
+'search-error' => 'An error has occurred while searching: $1',
 
 # Preferences page
 'preferences'                   => 'Preferences',
diff --git a/languages/messages/MessagesQqq.php 
b/languages/messages/MessagesQqq.php
index d59b873..92efbcd 100644
--- a/languages/messages/MessagesQqq.php
+++ b/languages/messages/MessagesQqq.php
@@ -2328,6 +2328,8 @@
 In this sentence, "their indexes" refers to "Google\'s indexes".
 
 Shown on [[Special:Search]] when the internal search is disabled.',
+'search-error' => 'Shown when an error has occurred when performing a search
+* $1 is the localized error that was returned',
 
 # Preferences page
 'preferences' => 'Title of the [[Special:Preferences]] page.
diff --git a/maintenance/language/messages.inc 
b/maintenance/language/messages.inc
index 33628b6..a42928e 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -943,6 +943,7 @@
                'search-external',
                'searchdisabled',
                'googlesearch',
+               'search-error',
        ),
        'opensearch' => array(
                'opensearch-desc',

-- 
To view, visit https://gerrit.wikimedia.org/r/57336
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I54ab520762381e8f46d5ca17c0bad8820eacb964
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Demon <[email protected]>
Gerrit-Reviewer: Ram <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to