SpecialSearch: Simplify result info
authorChad Horohoe <chadh@wikimedia.org>
Fri, 20 Jun 2014 17:07:01 +0000 (10:07 -0700)
committerChad Horohoe <chadh@wikimedia.org>
Mon, 23 Jun 2014 17:59:45 +0000 (10:59 -0700)
- Removes two message cases we never actually hit, moves remaining
  case up to the short dialog instead of in the form header area.
- Remove superfluous <ul> with a single item.
- Tweak styling a tad, smaller font, etc.
- Simplify counting and some presentation logic while we're here.

Change-Id: Ib04f08231ea4138116f31f60910df61bd8445043

includes/specials/SpecialSearch.php
languages/i18n/en.json
resources/src/mediawiki.special/mediawiki.special.css

index 15b93ae..5c3b390 100644 (file)
@@ -308,51 +308,37 @@ class SpecialSearch extends SpecialPage {
                                )
                        )
                );
+
+               // Get number of results
+               $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
+               if ( $titleMatches ) {
+                       $titleMatchesNum = $titleMatches->numRows();
+                       $numTitleMatches = $titleMatches->getTotalHits();
+               }
+               if ( $textMatches ) {
+                       $textMatchesNum = $textMatches->numRows();
+                       $numTextMatches = $textMatches->getTotalHits();
+               }
+               $num = $titleMatchesNum + $textMatchesNum;
+               $totalRes = $numTitleMatches + $numTextMatches;
+
                $out->addHtml(
                        # This is an awful awful ID name. It's not a table, but we
                        # named it poorly from when this was a table so now we're
                        # stuck with it
                        Xml::openElement( 'div', array( 'id' => 'mw-search-top-table' ) ) .
-                       $this->shortDialog( $term ) .
-                       Xml::closeElement( 'div' )
+                       $this->shortDialog( $term, $num, $totalRes ) .
+                       Xml::closeElement( 'div' ) .
+                       $this->formHeader( $term ) .
+                       Xml::closeElement( 'form' )
                );
 
                $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
                if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
-                       $out->addHTML( $this->formHeader( $term, 0, 0 ) );
-                       $out->addHtml( $this->getProfileForm( $this->profile, $term ) );
-                       $out->addHTML( '</form>' );
-
                        // Empty query -- straight view of search form
                        return;
                }
 
-               // Get number of results
-               $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
-               $textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
-               // Total initial query matches (possible false positives)
-               $num = $titleMatchesNum + $textMatchesNum;
-
-               // Get total actual results (after second filtering, if any)
-               $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
-                       $titleMatches->getTotalHits() : $titleMatchesNum;
-               $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
-                       $textMatches->getTotalHits() : $textMatchesNum;
-
-               // get total number of results if backend can calculate it
-               $totalRes = 0;
-               if ( $titleMatches && !is_null( $titleMatches->getTotalHits() ) ) {
-                       $totalRes += $titleMatches->getTotalHits();
-               }
-               if ( $textMatches && !is_null( $textMatches->getTotalHits() ) ) {
-                       $totalRes += $textMatches->getTotalHits();
-               }
-
-               // show number of results and current offset
-               $out->addHTML( $this->formHeader( $term, $num, $totalRes ) );
-               $out->addHtml( $this->getProfileForm( $this->profile, $term ) );
-
-               $out->addHtml( Xml::closeElement( 'form' ) );
                $out->addHtml( "<div class='searchresults'>" );
 
                // prev/next links
@@ -882,26 +868,6 @@ class SpecialSearch extends SpecialPage {
                return $out;
        }
 
-       /**
-        * @param string $profile
-        * @param string $term
-        * @return string
-        */
-       protected function getProfileForm( $profile, $term ) {
-               // Hidden stuff
-               $opts = array();
-               $opts['profile'] = $this->profile;
-
-               if ( $profile === 'advanced' ) {
-                       return $this->powerSearchBox( $term, $opts );
-               } else {
-                       $form = '';
-                       wfRunHooks( 'SpecialSearchProfileForm', array( $this, &$form, $profile, $term, $opts ) );
-
-                       return $form;
-               }
-       }
-
        /**
         * Generates the power search box at [[Special:Search]]
         *
@@ -1042,11 +1008,9 @@ class SpecialSearch extends SpecialPage {
 
        /**
         * @param string $term
-        * @param int $resultsShown
-        * @param int $totalNum
         * @return string
         */
-       protected function formHeader( $term, $resultsShown, $totalNum ) {
+       protected function formHeader( $term ) {
                $out = Xml::openElement( 'div', array( 'class' => 'mw-search-formheader' ) );
 
                $bareterm = $term;
@@ -1085,32 +1049,21 @@ class SpecialSearch extends SpecialPage {
                }
                $out .= Xml::closeElement( 'ul' );
                $out .= Xml::closeElement( 'div' );
-
-               // Results-info
-               if ( $resultsShown > 0 ) {
-                       if ( $totalNum > 0 ) {
-                               $top = $this->msg( 'showingresultsheader' )
-                                       ->numParams( $this->offset + 1, $this->offset + $resultsShown, $totalNum )
-                                       ->params( wfEscapeWikiText( $term ) )
-                                       ->numParams( $resultsShown )
-                                       ->parse();
-                       } elseif ( $resultsShown >= $this->limit ) {
-                               $top = $this->msg( 'showingresults' )
-                                       ->numParams( $this->limit, $this->offset + 1 )
-                                       ->parse();
-                       } else {
-                               $top = $this->msg( 'showingresultsnum' )
-                                       ->numParams( $this->limit, $this->offset + 1, $resultsShown )
-                                       ->parse();
-                       }
-                       $out .= Xml::tags( 'div', array( 'class' => 'results-info' ),
-                               Xml::tags( 'ul', null, Xml::tags( 'li', null, $top ) )
-                       );
-               }
-
                $out .= Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
                $out .= Xml::closeElement( 'div' );
 
+               // Hidden stuff
+               $opts = array();
+               $opts['profile'] = $this->profile;
+
+               if ( $this->profile === 'advanced' ) {
+                       $out .= $this->powerSearchBox( $term, $opts );
+               } else {
+                       $form = '';
+                       wfRunHooks( 'SpecialSearchProfileForm', array( $this, &$form, $this->profile, $term, $opts ) );
+                       $out .= $form;
+               }
+
                return $out;
        }
 
@@ -1118,7 +1071,7 @@ class SpecialSearch extends SpecialPage {
         * @param string $term
         * @return string
         */
-       protected function shortDialog( $term ) {
+       protected function shortDialog( $term, $resultsShown, $totalNum ) {
                $out = Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
                $out .= Html::hidden( 'profile', $this->profile ) . "\n";
                // Term box
@@ -1134,6 +1087,16 @@ class SpecialSearch extends SpecialPage {
                        array( 'class' => array( 'mw-ui-button', 'mw-ui-progressive' ) )
                ) . "\n";
 
+               // Results-info
+               if ( $totalNum > 0 ) {
+                       $top = $this->msg( 'showingresultsheader' )
+                               ->numParams( $this->offset + 1, $this->offset + $resultsShown, $totalNum )
+                               ->params( wfEscapeWikiText( $term ) )
+                               ->numParams( $resultsShown )
+                               ->parse();
+                       $out .= Xml::tags( 'div', array( 'class' => 'results-info' ), $top );
+               }
+
                return $out . $this->didYouMeanHtml;
        }
 
index 667b6f7..0e26205 100644 (file)
        "searchall": "all",
        "showingresults": "Showing below up to {{PLURAL:$1|<strong>1</strong> result|<strong>$1</strong> results}} starting with #<strong>$2</strong>.",
        "showingresultsinrange": "Showing below up to {{PLURAL:$1|<strong>1</strong> result|<strong>$1</strong> results}} in range #<strong>$2</strong> to #<strong>$3</strong>.",
-       "showingresultsnum": "Showing below {{PLURAL:$3|<strong>1</strong> result|<strong>$3</strong> results}} starting with #<strong>$2</strong>.",
        "showingresultsheader": "{{PLURAL:$5|Result <strong>$1</strong> of <strong>$3</strong>|Results <strong>$1 - $2</strong> of <strong>$3</strong>}} for <strong>$4</strong>",
        "search-nonefound": "There were no results matching the query.",
        "powersearch-legend": "Advanced search",
index eb7072c..5860adf 100644 (file)
@@ -130,21 +130,14 @@ div.searchresult {
 .mw-search-formheader div.search-types ul li.current a:hover {
        text-decoration: none;
 }
-.mw-search-formheader div.results-info {
+#mw-search-top-table div.results-info {
        float: right;
        padding: 0.5em;
        padding-right: 0.75em;
+       color: #666;
+       font-size: 95%;
 }
-.mw-search-formheader div.results-info ul {
-       margin: 0 !important;
-       padding: 0 !important;
-       list-style: none !important;
-}
-.mw-search-formheader div.results-info ul li {
-       float: right;
-       margin: 0;
-       padding: 0;
-}
+
 fieldset#mw-searchoptions {
        margin: 0;
        padding: 0.5em 0.75em 0.75em 0.75em !important;