Merge "mw.htmlform: Fields hidden with 'hide-if' should be disabled"
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index 9280b04..727179a 100644 (file)
@@ -295,12 +295,12 @@ class SpecialSearch extends SpecialPage {
                $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() ) {
@@ -360,6 +360,25 @@ class SpecialSearch extends SpecialPage {
 
                $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 ) {
@@ -388,7 +407,8 @@ class SpecialSearch extends SpecialPage {
                        }
                        $titleMatches->free();
                }
-               if ( $textMatches && !$textStatus ) {
+
+               if ( $textMatches ) {
                        // output appropriate heading
                        if ( $numTextMatches > 0 && $numTitleMatches > 0 ) {
                                $out->addHTML( '<div class="mw-search-visualclear"></div>' );
@@ -412,22 +432,18 @@ class SpecialSearch extends SpecialPage {
                $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 ) {
@@ -483,9 +499,16 @@ class SpecialSearch extends SpecialPage {
                }
                $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
                );
@@ -519,18 +542,25 @@ class SpecialSearch extends SpecialPage {
                }
                $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
                );
@@ -750,7 +780,13 @@ class SpecialSearch extends SpecialPage {
                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
@@ -784,9 +820,13 @@ class SpecialSearch extends SpecialPage {
                                $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>";
                }
 
@@ -796,9 +836,13 @@ class SpecialSearch extends SpecialPage {
                                $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>";
                }
 
@@ -955,6 +999,8 @@ class SpecialSearch extends SpecialPage {
                        return '';
                }
 
+               $linkRenderer = $this->getLinkRenderer();
+
                $title = $result->getTitle();
 
                $titleSnippet = $result->getTitleSnippet();
@@ -963,7 +1009,11 @@ class SpecialSearch extends SpecialPage {
                        $titleSnippet = null;
                }
 
-               $link = Linker::linkKnown(
+               if ( $titleSnippet !== null ) {
+                       $titleSnippet = new HtmlArmor( $titleSnippet );
+               }
+
+               $link = $linkRenderer->makeKnownLink(
                        $title,
                        $titleSnippet
                );
@@ -977,9 +1027,13 @@ class SpecialSearch extends SpecialPage {
                                $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>";
                }
 
@@ -997,7 +1051,7 @@ class SpecialSearch extends SpecialPage {
                        }
                        // "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(),
                                [],