$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 ) {
}
$stParams = array_merge( $params, $this->powerSearchOptions() );
- $suggest = Linker::linkKnown(
+ $linkRenderer = $this->getLinkRenderer();
+
+ $snippet = $textMatches->getSuggestionSnippet() ?: null;
+ if ( $snippet !== null ) {
+ $snippet = new HtmlArmor( $snippet );
+ }
+
+ $suggest = $linkRenderer->makeKnownLink(
$this->getPageTitle(),
- $textMatches->getSuggestionSnippet() ?: null,
+ $snippet,
[ 'id' => 'mw-search-DYM-suggestion' ],
$stParams
);
}
$stParams = array_merge( $params, $this->powerSearchOptions() );
- $rewritten = Linker::linkKnown(
+ $linkRenderer = $this->getLinkRenderer();
+
+ $snippet = $textMatches->getQueryAfterRewriteSnippet() ?: null;
+ if ( $snippet !== null ) {
+ $snippet = new HtmlArmor( $snippet );
+ }
+
+ $rewritten = $linkRenderer->makeKnownLink(
$this->getPageTitle(),
- $textMatches->getQueryAfterRewriteSnippet() ?: null,
+ $snippet,
[ 'id' => 'mw-search-DYM-rewritten' ],
$stParams
);
$stParams['search'] = $term;
$stParams['runsuggestion'] = 0;
- $original = Linker::linkKnown(
+ $original = $linkRenderer->makeKnownLink(
$this->getPageTitle(),
- htmlspecialchars( $term ),
+ $term,
[ 'id' => 'mw-search-DYM-original' ],
$stParams
);
Hooks::run( 'ShowSearchHitTitle',
[ &$link_t, &$titleSnippet, $result, $terms, $this, &$query ] );
- $link = Linker::linkKnown(
+ $linkRenderer = $this->getLinkRenderer();
+
+ if ( $titleSnippet !== null ) {
+ $titleSnippet = new HtmlArmor( $titleSnippet );
+ }
+
+ $link = $linkRenderer->makeKnownLink(
$link_t,
$titleSnippet,
[ 'data-serp-pos' => $position ], // HTML attributes
$redirectText = null;
}
+ if ( $redirectText !== null ) {
+ $redirectText = new HtmlArmor( $redirectText );
+ }
+
$redirect = "<span class='searchalttitle'>" .
$this->msg( 'search-redirect' )->rawParams(
- Linker::linkKnown( $redirectTitle, $redirectText ) )->text() .
+ $linkRenderer->makeKnownLink( $redirectTitle, $redirectText ) )->text() .
"</span>";
}
$sectionText = null;
}
+ if ( $sectionText !== null ) {
+ $sectionText = new HtmlArmor( $sectionText );
+ }
+
$section = "<span class='searchalttitle'>" .
$this->msg( 'search-section' )->rawParams(
- Linker::linkKnown( $sectionTitle, $sectionText ) )->text() .
+ $linkRenderer->makeKnownLink( $sectionTitle, $sectionText ) )->text() .
"</span>";
}
return '';
}
+ $linkRenderer = $this->getLinkRenderer();
+
$title = $result->getTitle();
$titleSnippet = $result->getTitleSnippet();
$titleSnippet = null;
}
- $link = Linker::linkKnown(
+ if ( $titleSnippet !== null ) {
+ $titleSnippet = new HtmlArmor( $titleSnippet );
+ }
+
+ $link = $linkRenderer->makeKnownLink(
$title,
$titleSnippet
);
$redirectText = null;
}
+ if ( $redirectText !== null ) {
+ $redirectText = new HtmlArmor( $redirectText );
+ }
+
$redirect = "<span class='searchalttitle'>" .
$this->msg( 'search-redirect' )->rawParams(
- Linker::linkKnown( $redirectTitle, $redirectText ) )->text() .
+ $linkRenderer->makeKnownLink( $redirectTitle, $redirectText ) )->text() .
"</span>";
}
}
// "more results" link (special page stuff could be localized, but we might not know target lang)
$searchTitle = Title::newFromText( $title->getInterwiki() . ":Special:Search" );
- $searchLink = Linker::linkKnown(
+ $searchLink = $linkRenderer->makeKnownLink(
$searchTitle,
$this->msg( 'search-interwiki-more' )->text(),
[],