$matches = $search->searchText( $query );
}
}
- if ( is_null( $matches ) ) {
+
+ if ( $matches instanceof Status ) {
+ $status = $matches;
+ $matches = $status->getValue();
+ } else {
+ $status = null;
+ }
+
+ if ( $status ) {
+ if ( $status->isOK() ) {
+ $this->getMain()->getErrorFormatter()->addMessagesFromStatus(
+ $this->getModuleName(),
+ $status
+ );
+ } else {
+ $this->dieUsage( $status->getWikiText( false, false, 'en' ), 'search-error' );
+ }
+ } elseif ( is_null( $matches ) ) {
$this->dieUsage( "{$what} search is disabled", "search-{$what}-disabled" );
- } elseif ( $matches instanceof Status && !$matches->isGood() ) {
- $this->dieUsage( $matches->getWikiText( false, false, 'en' ), 'search-error' );
}
if ( $resultPageSet === null ) {
$textStatus = null;
if ( $textMatches instanceof Status ) {
$textStatus = $textMatches;
- $textMatches = null;
+ $textMatches = $textStatus->getValue();
}
// did you mean... suggestions
$didYouMeanHtml = '';
- if ( $showSuggestion && $textMatches && !$textStatus ) {
+ if ( $showSuggestion && $textMatches ) {
if ( $textMatches->hasRewrittenQuery() ) {
$didYouMeanHtml = $this->getDidYouMeanRewrittenHtml( $term, $textMatches );
} elseif ( $textMatches->hasSuggestion() ) {
$out->addHTML( "<div class='searchresults'>" );
+ $hasErrors = $textStatus && $textStatus->getErrors();
+ if ( $hasErrors ) {
+ list( $error, $warning ) = $textStatus->splitByErrorType();
+ if ( $error->getErrors() ) {
+ $out->addHTML( Html::rawElement(
+ 'div',
+ [ 'class' => 'errorbox' ],
+ $error->getHTML( 'search-error' )
+ ) );
+ }
+ if ( $warning->getErrors() ) {
+ $out->addHTML( Html::rawElement(
+ 'div',
+ [ 'class' => 'warningbox' ],
+ $warning->getHTML( 'search-warning' )
+ ) );
+ }
+ }
+
// prev/next links
$prevnext = null;
if ( $num || $this->offset ) {
}
$titleMatches->free();
}
- if ( $textMatches && !$textStatus ) {
+
+ if ( $textMatches ) {
// output appropriate heading
if ( $numTextMatches > 0 && $numTitleMatches > 0 ) {
$out->addHTML( '<div class="mw-search-visualclear"></div>' );
$hasOtherResults = $textMatches &&
$textMatches->hasInterwikiResults( SearchResultSet::INLINE_RESULTS );
- if ( $num === 0 ) {
- if ( $textStatus ) {
- $out->addHTML( '<div class="error">' .
- $textStatus->getMessage( 'search-error' ) . '</div>' );
- } else {
- if ( !$this->offset ) {
- // If we have an offset the create link was rendered earlier in this function.
- // This class needs a good de-spaghettification, but for now this will
- // do the job.
- $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
- }
- $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>",
- [ $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
- wfEscapeWikiText( $term )
- ] );
+ // If we have no results and we have not already displayed an error message
+ if ( $num === 0 && !$hasErrors ) {
+ if ( !$this->offset ) {
+ // If we have an offset the create link was rendered earlier in this function.
+ // This class needs a good de-spaghettification, but for now this will
+ // do the job.
+ $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
}
+ $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>", [
+ $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
+ wfEscapeWikiText( $term )
+ ] );
}
if ( $hasOtherResults ) {
"searchdisabled": "{{SITENAME}} search is disabled.\nYou can search via Google in the meantime.\nNote that their indexes of {{SITENAME}} content may be out of date.",
"googlesearch": "<form method=\"get\" action=\"//www.google.com/search\" id=\"googlesearch\">\n\t<input type=\"hidden\" name=\"domains\" value=\"{{SERVER}}\" />\n\t<input type=\"hidden\" name=\"num\" value=\"50\" />\n\t<input type=\"hidden\" name=\"ie\" value=\"$2\" />\n\t<input type=\"hidden\" name=\"oe\" value=\"$2\" />\n\n\t<input type=\"text\" name=\"q\" size=\"31\" maxlength=\"255\" value=\"$1\" />\n\t<input type=\"submit\" name=\"btnG\" value=\"$3\" />\n <div>\n\t<input type=\"radio\" name=\"sitesearch\" id=\"gwiki\" value=\"{{SERVER}}\" checked=\"checked\" /><label for=\"gwiki\">{{SITENAME}}</label>\n\t<input type=\"radio\" name=\"sitesearch\" id=\"gWWW\" value=\"\" /><label for=\"gWWW\">WWW</label>\n </div>\n</form>",
"search-error": "An error has occurred while searching: $1",
+ "search-warning": "A warning has occured while searching: $1",
"opensearch-desc": "{{SITENAME}} ({{CONTENTLANGUAGE}})",
"preferences": "Preferences",
"preferences-summary": "",
"search-external": "Legend of the fieldset for the input form when the internal search is disabled. Inside the fieldset [[MediaWiki:Searchdisabled]] and [[MediaWiki:Googlesearch]] is shown.",
"searchdisabled": "{{doc-singularthey}}\nIn this sentence, \"their indexes\" refers to \"Google's indexes\".\n\nShown on [[Special:Search]] when the internal search is disabled.",
"googlesearch": "{{notranslate}}\nShown when [[mw:Manual:$wgDisableTextSearch|$wgDisableTextSearch]] is set to true and no [[mw:Manual:$wgSearchForwardUrl|$wgSearchForwardUrl]] is set.\n\nParameters:\n* $1 - the search term\n* $2 - \"UTF-8\" (hard-coded)\n* $3 - the message {{msg-mw|Searchbutton}}",
- "search-error": "Shown when an error has occurred when performing a search. Parameters:\n* $1 - the localized error that was returned",
+ "search-error": "Shown when an error has occurred when performing a search. Parameters:\n* $1 - the localized error that was returned.",
+ "search-warning": "Shown when a warning has occured when performing a search. Parameters:\n* $1 - the localized warning that was returned.",
"opensearch-desc": "{{ignored}}Link description of the [www.opensearch.org/ OpenSearch] link in the HTML head of pages.",
"preferences": "Title of the [[Special:Preferences]] page.\n{{Identical|Preferences}}",
"preferences-summary": "{{doc-specialpagesummary|preferences}}",