Index: trunk/phase3/includes/specials/SpecialSearch.php |
— | — | @@ -208,19 +208,26 @@ |
209 | 209 | |
210 | 210 | |
211 | 211 | // Get number of results |
212 | | - $titleMatchesSQL = $titleMatches ? $titleMatches->numRows() : 0; |
213 | | - $textMatchesSQL = $textMatches ? $textMatches->numRows() : 0; |
| 212 | + $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0; |
| 213 | + $textMatchesNum = $textMatches ? $textMatches->numRows() : 0; |
214 | 214 | // Total initial query matches (possible false positives) |
215 | | - $numSQL = $titleMatchesSQL + $textMatchesSQL; |
| 215 | + $num = $titleMatchesNum + $textMatchesNum; |
| 216 | + |
216 | 217 | // Get total actual results (after second filtering, if any) |
217 | 218 | $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ? |
218 | | - $titleMatches->getTotalHits() : $titleMatchesSQL; |
| 219 | + $titleMatches->getTotalHits() : $titleMatchesNum; |
219 | 220 | $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ? |
220 | | - $textMatches->getTotalHits() : $textMatchesSQL; |
221 | | - $totalRes = $numTitleMatches + $numTextMatches; |
| 221 | + $textMatches->getTotalHits() : $textMatchesNum; |
222 | 222 | |
| 223 | + // get total number of results if backend can calculate it |
| 224 | + $totalRes = 0; |
| 225 | + if($titleMatches && !is_null( $titleMatches->getTotalHits() ) ) |
| 226 | + $totalRes += $titleMatches->getTotalHits(); |
| 227 | + if($textMatches && !is_null( $textMatches->getTotalHits() )) |
| 228 | + $totalRes += $textMatches->getTotalHits(); |
| 229 | + |
223 | 230 | // show number of results and current offset |
224 | | - $wgOut->addHTML( $this->formHeader($term, $numSQL, $totalRes)); |
| 231 | + $wgOut->addHTML( $this->formHeader($term, $num, $totalRes)); |
225 | 232 | |
226 | 233 | $wgOut->addHtml( "<div class='searchresults'>" ); |
227 | 234 | |
— | — | @@ -234,11 +241,11 @@ |
235 | 242 | } |
236 | 243 | |
237 | 244 | // prev/next links |
238 | | - if( $numSQL || $this->offset ) { |
| 245 | + if( $num || $this->offset ) { |
239 | 246 | $prevnext = wfViewPrevNext( $this->offset, $this->limit, |
240 | 247 | SpecialPage::getTitleFor( 'Search' ), |
241 | 248 | wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ), |
242 | | - max( $titleMatchesSQL, $textMatchesSQL ) < $this->limit |
| 249 | + max( $titleMatchesNum, $textMatchesNum ) < $this->limit |
243 | 250 | ); |
244 | 251 | //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" ); |
245 | 252 | wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) ); |
— | — | @@ -274,15 +281,15 @@ |
275 | 282 | |
276 | 283 | $textMatches->free(); |
277 | 284 | } |
278 | | - if( $totalRes === 0 ) { |
| 285 | + if( $num === 0 ) { |
279 | 286 | $wgOut->addWikiMsg( 'search-nonefound' ); |
280 | 287 | } |
281 | 288 | $wgOut->addHtml( "</div>" ); |
282 | | - if( $totalRes === 0 ) { |
| 289 | + if( $num === 0 ) { |
283 | 290 | $wgOut->addHTML( $this->searchAdvanced ? $this->powerSearchFocus() : $this->searchFocus() ); |
284 | 291 | } |
285 | 292 | |
286 | | - if( $numSQL || $this->offset ) { |
| 293 | + if( $num || $this->offset ) { |
287 | 294 | $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" ); |
288 | 295 | } |
289 | 296 | wfProfileOut( __METHOD__ ); |
— | — | @@ -663,7 +670,7 @@ |
664 | 671 | "</script>"; |
665 | 672 | } |
666 | 673 | |
667 | | - protected function formHeader( $term, $resultsShown, $totalRes ) { |
| 674 | + protected function formHeader( $term, $resultsShown, $totalNum ) { |
668 | 675 | global $wgContLang, $wgCanonicalNamespaceNames, $wgLang; |
669 | 676 | |
670 | 677 | $sep = ' '; |
— | — | @@ -726,14 +733,19 @@ |
727 | 734 | } |
728 | 735 | $out .= Xml::closeElement('div') ; |
729 | 736 | |
730 | | - if( $totalRes > 0){ |
731 | | - $countHtml = wfMsgExt('showingresultsheader', array( 'parseinline' ), |
732 | | - $this->offset+1, $this->offset+$resultsShown, $totalRes, $term, $resultsShown ); |
733 | | - $out .= "<p>{$countHtml}</p>\n" ; |
734 | | - } else{ |
| 737 | + if ( $resultsShown > 0 ) { |
| 738 | + if ( $totalNum > 0 ){ |
| 739 | + $top = wfMsgExt('showingresultsheader', array( 'parseinline' ), |
| 740 | + $this->offset+1, $this->offset+$resultsShown, $totalNum, $term, $resultsShown ); |
| 741 | + } elseif ( $resultsShown >= $this->limit ) { |
| 742 | + $top = wfShowingResults( $this->offset, $this->limit ); |
| 743 | + } else { |
| 744 | + $top = wfShowingResultsNum( $this->offset, $this->limit, $resultsShown ); |
| 745 | + } |
| 746 | + $out .= "<p>{$top}</p>\n"; |
| 747 | + } else |
735 | 748 | $out .= "<p> </p>\n"; |
736 | | - } |
737 | | - |
| 749 | + |
738 | 750 | $out .= Xml::closeElement('div') ; |
739 | 751 | |
740 | 752 | return $out; |