Merge "xhprof: Guard against division by 0 when computing percentages"
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index c922fbd..448b802 100644 (file)
@@ -330,8 +330,9 @@ class SpecialSearch extends SpecialPage {
                        Xml::openElement( 'div', array( 'id' => 'mw-search-top-table' ) ) .
                        $this->shortDialog( $term, $num, $totalRes ) .
                        Xml::closeElement( 'div' ) .
-                       $this->formHeader( $term ) .
-                       Xml::closeElement( 'form' )
+                       Xml::closeElement( 'form' ) .
+                       $this->didYouMeanHtml .
+                       $this->searchProfileTabs( $term )
                );
 
                $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
@@ -426,15 +427,18 @@ class SpecialSearch extends SpecialPage {
                        return;
                }
 
+               $messageName = 'searchmenu-new-nocreate';
                $linkClass = 'mw-search-createlink';
-               if ( $title->isKnown() ) {
-                       $messageName = 'searchmenu-exists';
-                       $linkClass = 'mw-search-exists';
-               } elseif ( $title->quickUserCan( 'create', $this->getUser() ) ) {
-                       $messageName = 'searchmenu-new';
-               } else {
-                       $messageName = 'searchmenu-new-nocreate';
+
+               if ( !$title->isExternal() ) {
+                       if ( $title->isKnown() ) {
+                               $messageName = 'searchmenu-exists';
+                               $linkClass = 'mw-search-exists';
+                       } elseif ( $title->quickUserCan( 'create', $this->getUser() ) ) {
+                               $messageName = 'searchmenu-new';
+                       }
                }
+
                $params = array(
                        $messageName,
                        wfEscapeWikiText( $title->getPrefixedText() ),
@@ -618,8 +622,9 @@ class SpecialSearch extends SpecialPage {
                $redirectText = $result->getRedirectSnippet();
                $sectionTitle = $result->getSectionTitle();
                $sectionText = $result->getSectionSnippet();
-               $redirect = '';
+               $categorySnippet = $result->getCategorySnippet();
 
+               $redirect = '';
                if ( !is_null( $redirectTitle ) ) {
                        if ( $redirectText == '' ) {
                                $redirectText = null;
@@ -632,7 +637,6 @@ class SpecialSearch extends SpecialPage {
                }
 
                $section = '';
-
                if ( !is_null( $sectionTitle ) ) {
                        if ( $sectionText == '' ) {
                                $sectionText = null;
@@ -644,6 +648,13 @@ class SpecialSearch extends SpecialPage {
                                "</span>";
                }
 
+               $category = '';
+               if ( $categorySnippet ) {
+                       $category = "<span class='searchalttitle'>" .
+                               $this->msg( 'search-category' )->rawParams( $categorySnippet )->text() .
+                               "</span>";
+               }
+
                // format text extract
                $extract = "<div class='searchresult'>" . $result->getTextSnippet( $terms ) . "</div>";
 
@@ -688,7 +699,7 @@ class SpecialSearch extends SpecialPage {
                                                $thumb->toHtml( array( 'desc-link' => true ) ) .
                                                '</td>' .
                                                '<td style="vertical-align: top;">' .
-                                               "{$link} {$redirect} {$section} {$fileMatch}" .
+                                               "{$link} {$redirect} {$category} {$section} {$fileMatch}" .
                                                $extract .
                                                "<div class='mw-search-result-data'>{$desc} - {$date}</div>" .
                                                '</td>' .
@@ -709,7 +720,7 @@ class SpecialSearch extends SpecialPage {
                        &$html
                ) ) ) {
                        $html = "<li><div class='mw-search-result-heading'>" .
-                               "{$link} {$redirect} {$section} {$fileMatch}</div> {$extract}\n" .
+                               "{$link} {$redirect} {$category} {$section} {$fileMatch}</div> {$extract}\n" .
                                "<div class='mw-search-result-data'>{$size} - {$date}</div>" .
                                "</li>\n";
                }
@@ -885,10 +896,7 @@ class SpecialSearch extends SpecialPage {
                // be arranged nicely while still accommodating different screen widths
                $namespaceTables = '';
                for ( $i = 0; $i < $numRows; $i += 4 ) {
-                       $namespaceTables .= Xml::openElement(
-                               'table',
-                               array( 'cellpadding' => 0, 'cellspacing' => 0 )
-                       );
+                       $namespaceTables .= Xml::openElement( 'table' );
 
                        for ( $j = $i; $j < $i + 4 && $j < $numRows; $j++ ) {
                                $namespaceTables .= Xml::tags( 'tr', null, $rows[$j] );
@@ -986,8 +994,8 @@ class SpecialSearch extends SpecialPage {
         * @param string $term
         * @return string
         */
-       protected function formHeader( $term ) {
-               $out = Xml::openElement( 'div', array( 'class' => 'mw-search-formheader' ) );
+       protected function searchProfileTabs( $term ) {
+               $out = Xml::openElement( 'div', array( 'class' => 'mw-search-profile-tabs' ) );
 
                $bareterm = $term;
                if ( $this->startsWithImage( $term ) ) {
@@ -1062,7 +1070,8 @@ class SpecialSearch extends SpecialPage {
                $out .= Html::hidden( 'fulltext', 'Search' ) . "\n";
                $out .= Html::submitButton(
                        $this->msg( 'searchbutton' )->text(),
-                       array(), array( 'mw-ui-progressive' )
+                       array( 'class' => 'mw-ui-button mw-ui-progressive' ),
+                       array( 'mw-ui-progressive' )
                ) . "\n";
 
                // Results-info
@@ -1075,7 +1084,7 @@ class SpecialSearch extends SpecialPage {
                                Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
                }
 
-               return $out . $this->didYouMeanHtml;
+               return $out;
        }
 
        /**