From e27d3a96e72847a349aaafa979bb4bb1f499f57a Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 3 Apr 2013 15:16:33 -0400 Subject: [PATCH] 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 --- includes/specials/SpecialSearch.php | 20 ++++++++++++++++---- languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 2 ++ maintenance/language/messages.inc | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 380e20e101..a4ab7a8027 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -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( "

\n$1

", array( 'search-nonefound', wfEscapeWikiText( $term ) ) ); - $this->showCreateLink( $t ); + if ( $textStatus ) { + $out->addHTML( '
' . + htmlspecialchars( $textStatus->getWikiText( 'search-error' ) ) . '
' ); + } else { + $out->wrapWikiMsg( "

\n$1

", + array( 'search-nonefound', wfEscapeWikiText( $term ) ) ); + $this->showCreateLink( $t ); + } } $out->addHtml( "" ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index c5dba69dc0..ba5633d2a8 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index d59b87379b..92efbcda31 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -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. diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 33628b6884..a42928e348 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -943,6 +943,7 @@ $wgMessageStructure = array( 'search-external', 'searchdisabled', 'googlesearch', + 'search-error', ), 'opensearch' => array( 'opensearch-desc', -- 2.20.1