Allow search backends to return statuses instead of result sets
authorChad Horohoe <chadh@wikimedia.org>
Wed, 3 Apr 2013 19:16:33 +0000 (15:16 -0400)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 9 Apr 2013 00:42:02 +0000 (00:42 +0000)
This will allow a backend to propogate more useful errors up
the stack.

Bug: 43544
Change-Id: I54ab520762381e8f46d5ca17c0bad8820eacb964

includes/specials/SpecialSearch.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 380e20e..a4ab7a8 100644 (file)
@@ -257,8 +257,14 @@ class SpecialSearch extends SpecialPage {
                        $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 @@ class SpecialSearch extends SpecialPage {
                        }
                        $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 @@ class SpecialSearch extends SpecialPage {
                        $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>" );
 
index c5dba69..ba5633d 100644 (file)
@@ -1804,6 +1804,7 @@ Note that their indexes of {{SITENAME}} content may be out of date.',
 
 # 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',
index d59b873..92efbcd 100644 (file)
@@ -2328,6 +2328,8 @@ See also:
 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.
index 33628b6..a42928e 100644 (file)
@@ -943,6 +943,7 @@ $wgMessageStructure = array(
                'search-external',
                'searchdisabled',
                'googlesearch',
+               'search-error',
        ),
        'opensearch' => array(
                'opensearch-desc',