$search = str_replace( "\n", " ", $wgRequest->getText( 'search', $titleParam ) );
$class = $wgUseOldSearchUI ? 'SpecialSearchOld' : 'SpecialSearch';
$searchPage = new $class( $wgRequest, $wgUser );
- if( $wgRequest->getVal( 'fulltext' )
- || !is_null( $wgRequest->getVal( 'offset' ))
+ if( $wgRequest->getVal( 'fulltext' )
+ || !is_null( $wgRequest->getVal( 'offset' ))
|| !is_null( $wgRequest->getVal( 'searchx' )) )
{
$searchPage->showResults( $search );
$this->active = 'advanced';
$this->sk = $user->getSkin();
$this->didYouMeanHtml = ''; # html of did you mean... link
- $this->fulltext = $request->getVal('fulltext');
+ $this->fulltext = $request->getVal('fulltext');
}
/**
public function showResults( $term ) {
global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang;
wfProfileIn( __METHOD__ );
-
+
$sk = $wgUser->getSkin();
-
+
$this->searchEngine = SearchEngine::create();
$search =& $this->searchEngine;
$search->setLimitOffset( $this->limit, $this->offset );
$search->showRedirects = $this->searchRedirects;
$search->prefix = $this->mPrefix;
$term = $search->transformSearchTerm($term);
-
+
$this->setupPage( $term );
-
+
if( $wgDisableTextSearch ) {
global $wgSearchForwardUrl;
if( $wgSearchForwardUrl ) {
wfProfileOut( __METHOD__ );
return;
}
-
+
$t = Title::newFromText( $term );
-
- // fetch search results
+
+ // fetch search results
$rewritten = $search->replacePrefixes($term);
$titleMatches = $search->searchTitle( $rewritten );
# mirror Go/Search behaviour of original request ..
$didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
if($this->fulltext != NULL)
- $didYouMeanParams['fulltext'] = $this->fulltext;
- $stParams = wfArrayToCGI(
+ $didYouMeanParams['fulltext'] = $this->fulltext;
+ $stParams = wfArrayToCGI(
$didYouMeanParams,
$this->powerSearchOptions()
);
$this->didYouMeanHtml = '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
}
-
- // start rendering the page
- $wgOut->addHtml(
+
+ // start rendering the page
+ $wgOut->addHtml(
Xml::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
Xml::openElement( 'tr' ) .
Xml::openElement( 'td' ) . "\n" .
Xml::closeElement('tr') .
Xml::closeElement('table')
);
-
+
// Sometimes the search engine knows there are too many hits
if( $titleMatches instanceof SearchResultTooMany ) {
$wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
wfProfileOut( __METHOD__ );
return;
}
-
+
$filePrefix = $wgContLang->getFormattedNsText(NS_FILE).':';
if( '' === trim( $term ) || $filePrefix === trim( $term ) ) {
$wgOut->addHTML( $this->searchAdvanced ? $this->powerSearchFocus() : $this->searchFocus() );
// show number of results and current offset
if( $numSQL > 0 ) {
if( $numSQL > 0 ) {
- $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
+ $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
$this->offset+1, $this->offset+$numSQL, $totalRes, $numSQL );
} elseif( $numSQL >= $this->limit ) {
$top = wfShowingResults( $this->offset, $this->limit );
// output appropriate heading
if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
// if no title matches the heading is redundant
- $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
+ $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
} elseif( $totalRes == 0 ) {
# Don't show the 'no text matches' if we received title matches
$wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
}
wfProfileOut( __METHOD__ );
}
-
+
/**
*
*/
if( !empty( $term ) ) {
$wgOut->setPageTitle( wfMsg( 'searchresults') );
$wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
- }
+ }
$wgOut->setArticleRelated( false );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
}
}
/**
- * Show whole set of results
- *
+ * Show whole set of results
+ *
* @param SearchResultSet $matches
*/
protected function showMatches( &$matches ) {
."</span>";
$section = '';
if( !is_null($sectionTitle) )
- $section = "<span class='searchalttitle'>"
+ $section = "<span class='searchalttitle'>"
.wfMsg('search-section', $this->sk->makeKnownLinkObj( $sectionTitle, $sectionText))
."</span>";
// format text extract
$extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
-
+
// format score
if( is_null( $result->getScore() ) ) {
// Search engine doesn't report scoring info
$stParams = wfArrayToCGI( $this->powerSearchOptions(),
array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
'fulltext' => wfMsg('search') ));
-
+
$related = ' -- ' . $sk->makeKnownLinkObj( $st,
wfMsg('search-relatedarticle'), $stParams );
}
/**
* Show results from other wikis
- *
+ *
* @param SearchResultSet $matches
*/
protected function showInterwiki( &$matches, $query ) {
$terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
$out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
- wfMsg('search-interwiki-caption')."</div>\n";
+ wfMsg('search-interwiki-caption')."</div>\n";
$off = $this->offset + 1;
$out .= "<ul class='mw-search-iwresults'>\n";
foreach($customLines as $line) {
$parts = explode(":",$line,2);
if(count($parts) == 2) // validate line
- $customCaptions[$parts[0]] = $parts[1];
+ $customCaptions[$parts[0]] = $parts[1];
}
-
+
$prev = null;
while( $result = $matches->next() ) {
$out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
wfProfileOut( __METHOD__ );
return $out;
}
-
+
/**
* Show single interwiki link
*
* @param SearchResult $result
* @param string $lastInterwiki
* @param array $terms
- * @param string $query
+ * @param string $query
* @param array $customCaptions iw prefix -> caption
*/
protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
wfProfileIn( __METHOD__ );
global $wgContLang, $wgLang;
-
+
if( $result->isBrokenTitle() ) {
wfProfileOut( __METHOD__ );
return "<!-- Broken link in search result -->\n";
}
-
+
$t = $result->getTitle();
$link = $this->sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
."</span>";
$out = "";
- // display project name
+ // display project name
if(is_null($lastInterwiki) || $lastInterwiki != $t->getInterwiki()) {
if( key_exists($t->getInterwiki(),$customCaptions) )
// captions from 'search-interwiki-custom'
$caption = $customCaptions[$t->getInterwiki()];
else{
- // default is to show the hostname of the other wiki which might suck
+ // default is to show the hostname of the other wiki which might suck
// if there are many wikis on one hostname
$parsed = parse_url($t->getFullURL());
- $caption = wfMsg('search-interwiki-default', $parsed['host']);
- }
+ $caption = wfMsg('search-interwiki-default', $parsed['host']);
+ }
// "more results" link (special page stuff could be localized, but we might not know target lang)
- $searchTitle = Title::newFromText($t->getInterwiki().":Special:Search");
+ $searchTitle = Title::newFromText($t->getInterwiki().":Special:Search");
$searchLink = $this->sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
- wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
+ wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
$out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
{$searchLink}</span>{$caption}</div>\n<ul>";
}
- $out .= "<li>{$link} {$redirect}</li>\n";
+ $out .= "<li>{$link} {$redirect}</li>\n";
wfProfileOut( __METHOD__ );
return $out;
}
-
+
/**
* Generates the power search box at bottom of [[Special:Search]]
array( 'type' => 'text') );
$searchButton = Xml::submitButton( wfMsg( 'powersearch' ) ) . "\n";
$searchTitle = SpecialPage::getTitleFor( 'Search' );
-
+
$redirectText = '';
- // show redirects check only if backend supports it
+ // show redirects check only if backend supports it
if( $this->searchEngine->acceptListRedirects() ) {
$redirectText = "<p>". $redirect . " " . $redirectLabel ."</p>";
}
-
+
$out = Xml::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
Xml::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
"<p>" .
"</p>\n" .
'<input type="hidden" name="advanced" value="'.$this->searchAdvanced."\"/>\n".
$tables .
- "<hr style=\"clear: both;\" />\n".
+ "<hr style=\"clear: both;\" />\n".
$redirectText ."\n".
"<div style=\"padding-top:2px;padding-bottom:2px;\">".
$searchField .
} */
return Xml::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
Xml::element( 'legend', null, wfMsg('powersearch-legend') ) .
- $this->formHeader($term) . $out . $this->didYouMeanHtml .
+ $this->formHeader($term) . $out . $this->didYouMeanHtml .
Xml::closeElement( 'fieldset' );
}
-
+
protected function searchFocus() {
global $wgJsMimeType;
return "<script type=\"$wgJsMimeType\">" .
$bareterm = $term;
if( $this->startsWithImage( $term ) )
$bareterm = substr( $term, strpos( $term, ':' ) + 1 ); // delete all/image prefix
-
+
$nsAllSet = array_keys( SearchEngine::searchableNamespaces() );
// search profiles headers
$m = wfMsg( 'searchprofile-articles' );
- $tt = wfMsg( 'searchprofile-articles-tooltip',
+ $tt = wfMsg( 'searchprofile-articles-tooltip',
$wgLang->commaList( SearchEngine::namespacesAsText( SearchEngine::defaultNamespaces() ) ) );
$tt = Sanitizer::decodeCharReferences( $tt ); // need to allow entities
if( $this->active == 'default' ) {
- $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
+ $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
} else {
$out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultNamespaces(), $m, $tt );
}
$out .= $sep;
-
+
$m = wfMsg( 'searchprofile-images' );
$tt = wfMsg( 'searchprofile-images-tooltip' );
if( $this->active == 'images' ) {
- $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
+ $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
} else {
$imageTextForm = $wgContLang->getFormattedNsText(NS_FILE).':'.$bareterm;
$out .= $this->makeSearchLink( $imageTextForm, array( NS_FILE ) , $m, $tt );
$out .= $sep;
$m = wfMsg( 'searchprofile-project' );
- $tt = wfMsg( 'searchprofile-project-tooltip',
+ $tt = wfMsg( 'searchprofile-project-tooltip',
$wgLang->commaList( SearchEngine::namespacesAsText( SearchEngine::projectNamespaces() ) ) );
$tt = Sanitizer::decodeCharReferences( $tt ); // need to allow entities
if( $this->active == 'project' ) {
- $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
+ $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
} else {
$out .= $this->makeSearchLink( $bareterm, SearchEngine::projectNamespaces(), $m, $tt );
}
$out .= $sep;
-
+
$m = wfMsg( 'searchprofile-everything' );
$tt = wfMsg( 'searchprofile-everything-tooltip' );
if( $this->active == 'all' ) {
- $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
+ $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
} else {
$out .= $this->makeSearchLink( $bareterm, $nsAllSet, $m, $tt );
}
$out .= $sep;
-
+
$m = wfMsg( 'searchprofile-advanced' );
$tt = wfMsg( 'searchprofile-advanced-tooltip' );
if( $this->active == 'advanced' ) {
- $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
+ $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
} else {
$out .= $this->makeSearchLink( $bareterm, $this->namespaces, $m, $tt, array( 'advanced' => '1' ) );
}
$out .= Xml::closeElement('div') ;
-
+
return $out;
}
-
+
protected function shortDialog( $term ) {
global $wgScript;
$searchTitle = SpecialPage::getTitleFor( 'Search' );
$this->formHeader($term) . $out . $this->didYouMeanHtml .
Xml::closeElement( 'fieldset' );
}
-
+
/** Make a search link with some target namespaces */
protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
$opt = $params;
}
$opt['redirs'] = $this->searchRedirects ? 1 : 0;
- $st = SpecialPage::getTitleFor( 'Search' );
+ $st = SpecialPage::getTitleFor( 'Search' );
$stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt );
- return Xml::element( 'a',
- array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
- $label );
+ return Xml::element( 'a',
+ array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
+ $label );
}
-
+
/** Check if query starts with image: prefix */
protected function startsWithImage( $term ) {
global $wgContLang;
-
+
$p = explode( ':', $term );
if( count( $p ) > 1 ) {
return $wgContLang->getNsIndex( $p[0] ) == NS_FILE;
}
return false;
}
-
+
protected function namespaceTables( $namespaces, $rowsPerTable = 3 ) {
global $wgContLang;
// Group namespaces into rows according to subject.
}
$this->searchRedirects = $request->getcheck( 'redirs' ) ? true : false;
- $this->fulltext = $request->getVal('fulltext');
+ $this->fulltext = $request->getVal('fulltext');
}
/**
// did you mean... suggestions
if($textMatches && $textMatches->hasSuggestion()){
$st = SpecialPage::getTitleFor( 'Search' );
-
- # mirror Go/Search behaviour of original request
+
+ # mirror Go/Search behaviour of original request
$didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
if($this->fulltext != NULL)
- $didYouMeanParams['fulltext'] = $this->fulltext;
- $stParams = wfArrayToCGI(
+ $didYouMeanParams['fulltext'] = $this->fulltext;
+ $stParams = wfArrayToCGI(
$didYouMeanParams,
$this->powerSearchOptions()
- );
+ );
$suggestLink = $sk->makeKnownLinkObj( $st,
$textMatches->getSuggestionSnippet(),
return;
}
- $wgOut->addHTML( $this->shortDialog( $term ) );
+ $wgOut->addHTML( $this->shortDialog( $term ) );
// Sometimes the search engine knows there are too many hits
if ($titleMatches instanceof SearchResultTooMany) {
wfProfileOut( __METHOD__ );
return;
}
-
+
// show number of results
$num = ( $titleMatches ? $titleMatches->numRows() : 0 )
+ ( $textMatches ? $textMatches->numRows() : 0);
$totalNum += $textMatches->getTotalHits();
if ( $num > 0 ) {
if ( $totalNum > 0 ){
- $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
+ $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
$this->offset+1, $this->offset+$num, $totalNum, $num );
} elseif ( $num >= $this->limit ) {
$top = wfShowingResults( $this->offset, $this->limit );
if($titleMatches)
$wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
else // if no title matches the heading is redundant
- $wgOut->addHTML("<hr/>");
+ $wgOut->addHTML("<hr/>");
} elseif( $num == 0 ) {
# Don't show the 'no text matches' if we received title matches
$wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
#------------------------------------------------------------------
# Private methods below this line
-
+
/**
*
*/
if( !empty( $term ) ){
$wgOut->setPageTitle( wfMsg( 'searchresults') );
$wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
- }
+ }
$subtitlemsg = ( Title::newFromText( $term ) ? 'searchsubtitle' : 'searchsubtitleinvalid' );
$wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
$wgOut->setArticleRelated( false );
}
/**
- * Show whole set of results
- *
+ * Show whole set of results
+ *
* @param SearchResultSet $matches
*/
function showMatches( &$matches ) {
$terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
$out = "";
-
+
$infoLine = $matches->getInfo();
if( !is_null($infoLine) )
$out .= "\n<!-- {$infoLine} -->\n";
-
-
+
+
$off = $this->offset + 1;
$out .= "<ul class='mw-search-results'>\n";
function showHit( $result, $terms ) {
wfProfileIn( __METHOD__ );
global $wgUser, $wgContLang, $wgLang;
-
+
if( $result->isBrokenTitle() ) {
wfProfileOut( __METHOD__ );
return "<!-- Broken link in search result -->\n";
}
-
+
$t = $result->getTitle();
$sk = $wgUser->getSkin();
."</span>";
$section = '';
if( !is_null($sectionTitle) )
- $section = "<span class='searchalttitle'>"
+ $section = "<span class='searchalttitle'>"
.wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
."</span>";
// format text extract
$extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
-
+
// format score
if( is_null( $result->getScore() ) ) {
// Search engine doesn't report scoring info
$stParams = wfArrayToCGI( $this->powerSearchOptions(),
array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
'fulltext' => wfMsg('search') ));
-
+
$related = ' -- ' . $sk->makeKnownLinkObj( $st,
wfMsg('search-relatedarticle'), $stParams );
}
-
+
// Include a thumbnail for media files...
if( $t->getNamespace() == NS_FILE ) {
$img = wfFindFile( $t );
/**
* Show results from other wikis
- *
+ *
* @param SearchResultSet $matches
*/
function showInterwiki( &$matches, $query ) {
global $wgContLang;
$terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
- $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
+ $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
$off = $this->offset + 1;
$out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
foreach($customLines as $line){
$parts = explode(":",$line,2);
if(count($parts) == 2) // validate line
- $customCaptions[$parts[0]] = $parts[1];
+ $customCaptions[$parts[0]] = $parts[1];
}
-
-
+
+
$prev = null;
while( $result = $matches->next() ) {
$out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
wfProfileOut( __METHOD__ );
return $out;
}
-
+
/**
* Show single interwiki link
*
* @param SearchResult $result
* @param string $lastInterwiki
* @param array $terms
- * @param string $query
+ * @param string $query
* @param array $customCaptions iw prefix -> caption
*/
function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
wfProfileIn( __METHOD__ );
global $wgUser, $wgContLang, $wgLang;
-
+
if( $result->isBrokenTitle() ) {
wfProfileOut( __METHOD__ );
return "<!-- Broken link in search result -->\n";
}
-
+
$t = $result->getTitle();
$sk = $wgUser->getSkin();
-
+
$link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
-
+
// format redirect if any
$redirectTitle = $result->getRedirectTitle();
$redirectText = $result->getRedirectSnippet($terms);
."</span>";
$out = "";
- // display project name
+ // display project name
if(is_null($lastInterwiki) || $lastInterwiki != $t->getInterwiki()){
if( key_exists($t->getInterwiki(),$customCaptions) )
// captions from 'search-interwiki-custom'
$caption = $customCaptions[$t->getInterwiki()];
else{
- // default is to show the hostname of the other wiki which might suck
+ // default is to show the hostname of the other wiki which might suck
// if there are many wikis on one hostname
$parsed = parse_url($t->getFullURL());
- $caption = wfMsg('search-interwiki-default', $parsed['host']);
- }
+ $caption = wfMsg('search-interwiki-default', $parsed['host']);
+ }
// "more results" link (special page stuff could be localized, but we might not know target lang)
- $searchTitle = Title::newFromText($t->getInterwiki().":Special:Search");
+ $searchTitle = Title::newFromText($t->getInterwiki().":Special:Search");
$searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
- wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
+ wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
$out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>{$searchLink}</span>{$caption}</div>\n<ul>";
}
- $out .= "<li>{$link} {$redirect}</li>\n";
+ $out .= "<li>{$link} {$redirect}</li>\n";
wfProfileOut( __METHOD__ );
return $out;
}
-
+
/**
* Generates the power search box at bottom of [[Special:Search]]
$searchTitle = SpecialPage::getTitleFor( 'Search' );
$searchHiddens = Xml::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
$searchHiddens .= Xml::hidden( 'fulltext', 'Advanced search' ) . "\n";
-
+
$out = Xml::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
- Xml::fieldset( wfMsg( 'powersearch-legend' ),
+ Xml::fieldset( wfMsg( 'powersearch-legend' ),
"<p>" .
wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
"</p>\n" .
" " .
$searchField .
" " .
- $searchHiddens .
+ $searchHiddens .
$searchButton ) .
"</form>";