protected function formHeader($term, $resultsShown, $totalNum) { global $wgContLang, $wgLang; $out = Xml::openElement('div', array('class' => 'mw-search-formheader')); $bareterm = $term; if ($this->startsWithImage($term)) { // Deletes prefixes $bareterm = substr($term, strpos($term, ':') + 1); } $profiles = $this->getSearchProfiles(); // Outputs XML for Search Types $out .= Xml::openElement('div', array('class' => 'search-types')); $out .= Xml::openElement('ul'); foreach ($profiles as $id => $profile) { $tooltipParam = isset($profile['namespace-messages']) ? $wgLang->commaList($profile['namespace-messages']) : null; $out .= Xml::tags('li', array('class' => $this->active == $id ? 'current' : 'normal'), $this->makeSearchLink($bareterm, $profile['namespaces'], wfMsg($profile['message']), wfMsg($profile['tooltip'], $tooltipParam), isset($profile['parameters']) ? $profile['parameters'] : array())); } $out .= Xml::closeElement('ul'); $out .= Xml::closeElement('div'); // Results-info if ($resultsShown > 0) { if ($totalNum > 0) { $top = wfMsgExt('showingresultsheader', array('parseinline'), $wgLang->formatNum($this->offset + 1), $wgLang->formatNum($this->offset + $resultsShown), $wgLang->formatNum($totalNum), wfEscapeWikiText($term), $wgLang->formatNum($resultsShown)); } elseif ($resultsShown >= $this->limit) { $top = wfShowingResults($this->offset, $this->limit); } else { $top = wfShowingResultsNum($this->offset, $this->limit, $resultsShown); } $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'); // Adds hidden namespace fields if (!$this->searchAdvanced) { foreach ($this->namespaces as $ns) { $out .= Xml::hidden("ns{$ns}", '1'); } } return $out; }
protected function formHeader($resultsShown, $totalNum) { global $wgLang; $out = Xml::openElement('div', array('class' => 'mw-search-formheader')); // Results-info if ($resultsShown > 0) { if ($totalNum > 0) { $top = wfMsgExt('showingresultsheader', array('parseinline'), $wgLang->formatNum($this->offset + 1), $wgLang->formatNum($this->offset + $resultsShown), $wgLang->formatNum($totalNum), $wgLang->formatNum($resultsShown)); } elseif ($resultsShown >= $this->limit) { $top = wfShowingResults($this->offset, $this->limit); } else { $top = wfShowingResultsNum($this->offset, $this->limit, $resultsShown); } $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'); return $out; }
/** * @param string $term * @public */ function showResults($term) { $fname = 'SpecialSearch::showResults'; wfProfileIn($fname); $this->setupPage($term); global $wgOut; $wgOut->addWikiMsg('searchresulttext'); if ('' === trim($term)) { // Empty query -- straight view of search form $wgOut->setSubtitle(''); $wgOut->addHTML($this->powerSearchBox($term)); $wgOut->addHTML($this->powerSearchFocus()); wfProfileOut($fname); return; } global $wgDisableTextSearch; if ($wgDisableTextSearch) { global $wgForwardSearchUrl; if ($wgForwardSearchUrl) { $url = str_replace('$1', urlencode($term), $wgForwardSearchUrl); $wgOut->redirect($url); return; } global $wgInputEncoding; $wgOut->addHTML(wfMsg('searchdisabled')); $wgOut->addHTML(wfMsg('googlesearch', htmlspecialchars($term), htmlspecialchars($wgInputEncoding), htmlspecialchars(wfMsg('searchbutton')))); wfProfileOut($fname); return; } $search = SearchEngine::create(); $search->setLimitOffset($this->limit, $this->offset); $search->setNamespaces($this->namespaces); $search->showRedirects = $this->searchRedirects; $titleMatches = $search->searchTitle($term); // Sometimes the search engine knows there are too many hits if ($titleMatches instanceof SearchResultTooMany) { $wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n"); $wgOut->addHTML($this->powerSearchBox($term)); $wgOut->addHTML($this->powerSearchFocus()); wfProfileOut($fname); return; } $textMatches = $search->searchText($term); $num = ($titleMatches ? $titleMatches->numRows() : 0) + ($textMatches ? $textMatches->numRows() : 0); if ($num > 0) { if ($num >= $this->limit) { $top = wfShowingResults($this->offset, $this->limit); } else { $top = wfShowingResultsNum($this->offset, $this->limit, $num); } $wgOut->addHTML("<p>{$top}</p>\n"); } if ($num || $this->offset) { $prevnext = wfViewPrevNext($this->offset, $this->limit, SpecialPage::getTitleFor('Search'), wfArrayToCGI($this->powerSearchOptions(), array('search' => $term)), $num < $this->limit); $wgOut->addHTML("<br />{$prevnext}\n"); } if ($titleMatches) { if ($titleMatches->numRows()) { $wgOut->wrapWikiMsg("==\$1==\n", 'titlematches'); $wgOut->addHTML($this->showMatches($titleMatches)); } else { $wgOut->wrapWikiMsg("==\$1==\n", 'notitlematches'); } $titleMatches->free(); } if ($textMatches) { if ($textMatches->numRows()) { $wgOut->wrapWikiMsg("==\$1==\n", 'textmatches'); $wgOut->addHTML($this->showMatches($textMatches)); } elseif ($num == 0) { # Don't show the 'no text matches' if we received title matches $wgOut->wrapWikiMsg("==\$1==\n", 'notextmatches'); } $textMatches->free(); } if ($num == 0) { $wgOut->addWikiMsg('nonefound'); } if ($num || $this->offset) { $wgOut->addHTML("<p>{$prevnext}</p>\n"); } $wgOut->addHTML($this->powerSearchBox($term)); wfProfileOut($fname); }
/** * @param string $term * @access public */ function showResults($term) { $fname = 'SpecialSearch::showResults'; wfProfileIn($fname); $this->setupPage($term); global $wgUser, $wgOut; $sk = $wgUser->getSkin(); $wgOut->addWikiText(wfMsg('searchresulttext')); #if ( !$this->parseQuery() ) { if ('' === trim($term)) { $wgOut->setSubtitle(''); $wgOut->addHTML($this->powerSearchBox($term)); wfProfileOut($fname); return; } global $wgDisableTextSearch; if ($wgDisableTextSearch) { global $wgForwardSearchUrl; if ($wgForwardSearchUrl) { $url = str_replace('$1', urlencode($term), $wgForwardSearchUrl); $wgOut->redirect($url); return; } global $wgInputEncoding; $wgOut->addHTML(wfMsg('searchdisabled')); $wgOut->addHTML(wfMsg('googlesearch', htmlspecialchars($term), htmlspecialchars($wgInputEncoding), htmlspecialchars(wfMsg('search')))); wfProfileOut($fname); return; } $search =& SearchEngine::create(); $search->setLimitOffset($this->limit, $this->offset); $search->setNamespaces($this->namespaces); $titleMatches = $search->searchTitle($term); $textMatches = $search->searchText($term); $num = ($titleMatches ? $titleMatches->numRows() : 0) + ($textMatches ? $textMatches->numRows() : 0); if ($num >= $this->limit) { $top = wfShowingResults($this->offset, $this->limit); } else { $top = wfShowingResultsNum($this->offset, $this->limit, $num); } $wgOut->addHTML("<p>{$top}</p>\n"); if ($num || $this->offset) { $prevnext = wfViewPrevNext($this->offset, $this->limit, 'Special:Search', wfArrayToCGI($this->powerSearchOptions(), array('search' => $term))); $wgOut->addHTML("<br />{$prevnext}\n"); } if ($titleMatches) { if ($titleMatches->numRows()) { $wgOut->addWikiText('==' . wfMsg('titlematches') . "==\n"); $wgOut->addHTML($this->showMatches($titleMatches)); } else { $wgOut->addWikiText('==' . wfMsg('notitlematches') . "==\n"); } } if ($textMatches) { if ($textMatches->numRows()) { $wgOut->addWikiText('==' . wfMsg('textmatches') . "==\n"); $wgOut->addHTML($this->showMatches($textMatches)); } elseif ($num == 0) { # Don't show the 'no text matches' if we received title matches $wgOut->addWikiText('==' . wfMsg('notextmatches') . "==\n"); } } if ($num == 0) { $wgOut->addWikiText(wfMsg('nonefound')); } if ($num || $this->offset) { $wgOut->addHTML("<p>{$prevnext}</p>\n"); } $wgOut->addHTML($this->powerSearchBox($term)); wfProfileOut($fname); }
/** * @param string $term * @public */ function showResults($term) { wfProfileIn(__METHOD__); global $wgOut, $wgUser; $sk = $wgUser->getSkin(); $search = SearchEngine::create(); $search->setLimitOffset($this->limit, $this->offset); $search->setNamespaces($this->namespaces); $search->showRedirects = $this->searchRedirects; $search->prefix = $this->mPrefix; $term = $search->transformSearchTerm($term); $this->setupPage($term); $rewritten = $search->replacePrefixes($term); $titleMatches = $search->searchTitle($rewritten); $textMatches = $search->searchText($rewritten); // did you mean... suggestions if ($textMatches && $textMatches->hasSuggestion()) { $st = SpecialPage::getTitleFor('Search'); $stParams = wfArrayToCGI(array('search' => $textMatches->getSuggestionQuery(), 'fulltext' => wfMsg('search')), $this->powerSearchOptions()); $suggestLink = $sk->makeKnownLinkObj($st, $textMatches->getSuggestionSnippet(), $stParams); $wgOut->addHTML('<div class="searchdidyoumean">' . wfMsg('search-suggest', $suggestLink) . '</div>'); } $wgOut->addWikiMsg('searchresulttext'); if ('' === trim($term)) { // Empty query -- straight view of search form $wgOut->setSubtitle(''); $wgOut->addHTML($this->powerSearchBox($term)); $wgOut->addHTML($this->powerSearchFocus()); wfProfileOut(__METHOD__); return; } global $wgDisableTextSearch; if ($wgDisableTextSearch) { global $wgSearchForwardUrl; if ($wgSearchForwardUrl) { $url = str_replace('$1', urlencode($term), $wgSearchForwardUrl); $wgOut->redirect($url); wfProfileOut(__METHOD__); return; } global $wgInputEncoding; $wgOut->addHTML(Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('search-external')) . Xml::element('p', array('class' => 'mw-searchdisabled'), wfMsg('searchdisabled')) . wfMsg('googlesearch', htmlspecialchars($term), htmlspecialchars($wgInputEncoding), htmlspecialchars(wfMsg('searchbutton'))) . Xml::closeElement('fieldset')); wfProfileOut(__METHOD__); return; } $wgOut->addHTML($this->shortDialog($term)); // Sometimes the search engine knows there are too many hits if ($titleMatches instanceof SearchResultTooMany) { $wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n"); $wgOut->addHTML($this->powerSearchBox($term)); $wgOut->addHTML($this->powerSearchFocus()); wfProfileOut(__METHOD__); return; } // show number of results $num = ($titleMatches ? $titleMatches->numRows() : 0) + ($textMatches ? $textMatches->numRows() : 0); $totalNum = 0; if ($titleMatches && !is_null($titleMatches->getTotalHits())) { $totalNum += $titleMatches->getTotalHits(); } if ($textMatches && !is_null($textMatches->getTotalHits())) { $totalNum += $textMatches->getTotalHits(); } if ($num > 0) { if ($totalNum > 0) { $top = wfMsgExt('showingresultstotal', array('parseinline'), $this->offset + 1, $this->offset + $num, $totalNum, $num); } elseif ($num >= $this->limit) { $top = wfShowingResults($this->offset, $this->limit); } else { $top = wfShowingResultsNum($this->offset, $this->limit, $num); } $wgOut->addHTML("<p class='mw-search-numberresults'>{$top}</p>\n"); } // prev/next links if ($num || $this->offset) { $prevnext = wfViewPrevNext($this->offset, $this->limit, SpecialPage::getTitleFor('Search'), wfArrayToCGI($this->powerSearchOptions(), array('search' => $term)), $num < $this->limit); $wgOut->addHTML("<p class='mw-search-pager-top'>{$prevnext}</p>\n"); wfRunHooks('SpecialSearchResults', array($term, &$titleMatches, &$textMatches)); } else { wfRunHooks('SpecialSearchNoResults', array($term)); } if ($titleMatches) { if ($titleMatches->numRows()) { $wgOut->wrapWikiMsg("==\$1==\n", 'titlematches'); $wgOut->addHTML($this->showMatches($titleMatches)); } $titleMatches->free(); } if ($textMatches) { // output appropriate heading if ($textMatches->numRows()) { if ($titleMatches) { $wgOut->wrapWikiMsg("==\$1==\n", 'textmatches'); } else { // if no title matches the heading is redundant $wgOut->addHTML("<hr/>"); } } elseif ($num == 0) { # Don't show the 'no text matches' if we received title matches $wgOut->wrapWikiMsg("==\$1==\n", 'notextmatches'); } // show interwiki results if any if ($textMatches->hasInterwikiResults()) { $wgOut->addHTML($this->showInterwiki($textMatches->getInterwikiResults(), $term)); } // show results if ($textMatches->numRows()) { $wgOut->addHTML($this->showMatches($textMatches)); } $textMatches->free(); } if ($num == 0) { $wgOut->addWikiMsg('nonefound'); } if ($num || $this->offset) { $wgOut->addHTML("<p class='mw-search-pager-bottom'>{$prevnext}</p>\n"); } $wgOut->addHTML($this->powerSearchBox($term)); wfProfileOut(__METHOD__); }