|| !is_null( $wgRequest->getVal( 'offset' ))
|| !is_null( $wgRequest->getVal( 'searchx' )) )
{
- $searchPage->showResults( $search, 'search' );
+ $searchPage->showResults( $search );
} else {
$searchPage->goResult( $search );
}
*/
function __construct( &$request, &$user ) {
list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' );
+ $this->mPrefix = $request->getVal('prefix', '');
# Extract requested namespaces
$this->namespaces = $this->powerSearch( $request );
if( empty( $this->namespaces ) ) {
$this->searchAdvanced = $request->getVal( 'advanced' );
$this->active = 'advanced';
$this->sk = $user->getSkin();
+ $this->didYouMeanHtml = ''; # html of did you mean... link
}
/**
* @param string $term
*/
public function showResults( $term ) {
- global $wgOut, $wgDisableTextSearch;
+ global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang;
wfProfileIn( __METHOD__ );
-
- $this->setupPage( $term );
+
+ $sk = $wgUser->getSkin();
+
$this->searchEngine = SearchEngine::create();
+ $search =& $this->searchEngine;
+ $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 );
- $t = Title::newFromText( $term );
-
- $wgOut->addHtml(
- Xml::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
- Xml::openElement( 'tr' ) .
- Xml::openElement( 'td' ) . "\n" .
- ( $this->searchAdvanced ? $this->powerSearchBox( $term ) : $this->shortDialog( $term ) ) .
- Xml::closeElement('td') .
- Xml::closeElement('tr') .
- Xml::closeElement('table')
- );
-
- if( '' === trim( $term ) ) {
- // Empty query -- straight view of search form
- wfProfileOut( __METHOD__ );
- return;
- }
-
if( $wgDisableTextSearch ) {
global $wgSearchForwardUrl;
if( $wgSearchForwardUrl ) {
wfProfileOut( __METHOD__ );
return;
}
-
- $search =& $this->searchEngine;
- $search->setLimitOffset( $this->limit, $this->offset );
- $search->setNamespaces( $this->namespaces );
- $search->showRedirects = $this->searchRedirects;
+
+ $t = Title::newFromText( $term );
+
+ // fetch search results
$rewritten = $search->replacePrefixes($term);
$titleMatches = $search->searchTitle( $rewritten );
-
- // Sometimes the search engine knows there are too many hits
- if( $titleMatches instanceof SearchResultTooMany ) {
- $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
- wfProfileOut( __METHOD__ );
- return;
- }
-
- $textMatches = $search->searchText( $rewritten );
+ if( !($titleMatches instanceof SearchResultTooMany))
+ $textMatches = $search->searchText( $rewritten );
// did you mean... suggestions
if( $textMatches && $textMatches->hasSuggestion() ) {
array( 'search' => $textMatches->getSuggestionQuery(), 'fulltext' => wfMsg('search') ),
$this->powerSearchOptions()
);
- $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
- $textMatches->getSuggestionSnippet().'</a>';
+ $suggestLink = $sk->makeKnownLinkObj( $st,
+ $textMatches->getSuggestionSnippet(),
+ $stParams );
- $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
+ $this->didYouMeanHtml = '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
+ }
+
+ // start rendering the page
+ $wgOut->addHtml(
+ Xml::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
+ Xml::openElement( 'tr' ) .
+ Xml::openElement( 'td' ) . "\n" .
+ ( $this->searchAdvanced ? $this->powerSearchBox( $term ) : $this->shortDialog( $term ) ) .
+ Xml::closeElement('td') .
+ 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() );
+ // Empty query -- straight view of search form
+ wfProfileOut( __METHOD__ );
+ return;
}
// show direct page/create link
$wgOut->addWikiMsg( 'search-nonefound' );
}
$wgOut->addHtml( "</div>" );
+ if( $totalRes === 0 ) {
+ $wgOut->addHTML( $this->searchAdvanced ? $this->powerSearchFocus() : $this->searchFocus() );
+ }
if( $numSQL || $this->offset ) {
$wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
* @param array $terms terms to highlight
*/
protected function showHit( $result, $terms ) {
- global $wgContLang, $wgLang;
+ global $wgContLang, $wgLang, $wgUser;
wfProfileIn( __METHOD__ );
if( $result->isBrokenTitle() ) {
return "<!-- Broken link in search result -->\n";
}
+ $sk = $wgUser->getSkin();
$t = $result->getTitle();
$link = $this->sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
'fulltext' => wfMsg('search') ));
- $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
- wfMsg('search-relatedarticle').'</a>';
+ $related = ' -- ' . $sk->makeKnownLinkObj( $st,
+ wfMsg('search-relatedarticle'), $stParams );
}
// Include a thumbnail for media files...
$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";
+ $out .= "<ul class='mw-search-iwresults'>\n";
// work out custom project captions
$customCaptions = array();
$redirect = Xml::check( 'redirs', $this->searchRedirects, array( 'value' => '1', 'id' => 'redirs' ) );
$redirectLabel = Xml::label( wfMsg( 'powersearch-redir' ), 'redirs' );
- $searchField = Xml::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
- $searchButton = Xml::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
+ $searchField = Xml::inputLabel( wfMsg('powersearch-field'), 'search', 'powerSearchText', 50, $term,
+ array( 'type' => 'text') );
+ $searchButton = Xml::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' )) . "\n";
$searchTitle = SpecialPage::getTitleFor( 'Search' );
+ $redirectText = '';
+ // 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>" .
wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
"</p>\n" .
+ '<input type="hidden" name="advanced" value="'.$this->searchAdvanced."\"/>\n".
$tables .
- "<hr style=\"clear: both\" />\n" .
- "<p>" .
- $redirect . " " . $redirectLabel .
- "</p>\n" .
- wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
- " " .
+ "<hr style=\"clear: both;\" />\n".
+ $redirectText ."\n".
+ "<div style=\"padding-top:2px;padding-bottom:2px;\">".
$searchField .
" " .
+ Xml::hidden( 'fulltext', 'Advanced search' ) . "\n" .
$searchButton .
+ "</div>".
"</form>";
$t = Title::newFromText( $term );
- if( $t != null && count($this->namespaces) === 1 ) {
+ /* if( $t != null && count($this->namespaces) === 1 ) {
$out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
- }
+ } */
return Xml::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
Xml::element( 'legend', null, wfMsg('powersearch-legend') ) .
- $this->formHeader($term) . $out .
+ $this->formHeader($term) . $out . $this->didYouMeanHtml .
Xml::closeElement( 'fieldset' );
}
+
+ protected function searchFocus() {
+ global $wgJsMimeType;
+ return "<script type=\"$wgJsMimeType\">" .
+ "hookEvent(\"load\", function() {" .
+ "document.getElementById('searchText').focus();" .
+ "});" .
+ "</script>";
+ }
protected function powerSearchFocus() {
global $wgJsMimeType;
$searchable = SearchEngine::searchableNamespaces();
$out = Xml::openElement( 'form', array( 'id' => 'search', 'method' => 'get', 'action' => $wgScript ) );
$out .= Xml::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
- // If searching several, but not all namespaces, show what we are searching.
- if( count($this->namespaces) > 1 && $this->namespaces !== array_keys($searchable) ) {
+ // show namespaces only for advanced search
+ if( $this->active == 'advanced' ) {
$active = array();
foreach( $this->namespaces as $ns ) {
$active[$ns] = $searchable[$ns];
$out .= Xml::hidden( "redirs", (int)$this->searchRedirects );
// Term box
$out .= Xml::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
+ $out .= Xml::hidden( 'fulltext', 'Search' );
$out .= Xml::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
$out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')';
$out .= Xml::closeElement( 'form' );
// Add prefix link for single-namespace searches
$t = Title::newFromText( $term );
- if( $t != null && count($this->namespaces) === 1 ) {
+ /*if( $t != null && count($this->namespaces) === 1 ) {
$out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
- }
+ }*/
return Xml::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
Xml::element( 'legend', null, wfMsg('searchmenu-legend') ) .
- $this->formHeader($term) . $out .
+ $this->formHeader($term) . $out . $this->didYouMeanHtml .
Xml::closeElement( 'fieldset' );
}
$rows = array();
$tables = "";
foreach( $namespaces as $ns => $name ) {
- $subj = Namespace::getSubject( $ns );
+ $subj = MWNamespace::getSubject( $ns );
if( !array_key_exists( $subj, $rows ) ) {
$rows[$subj] = "";
}
*/
function __construct( &$request, &$user ) {
list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' );
-
+ $this->mPrefix = $request->getVal('prefix', '');
$this->namespaces = $this->powerSearch( $request );
if( empty( $this->namespaces ) ) {
$this->namespaces = SearchEngine::userNamespaces( $user );
}
}
- $wgOut->wrapWikiMsg( "==$1==\n", 'notitlematches' );
+ $extra = $wgOut->parse( '=='.wfMsgNoTrans( 'notitlematches' )."==\n" );
if( $t->quickUserCan( 'create' ) && $t->quickUserCan( 'edit' ) ) {
- $wgOut->addWikiMsg( 'noexactmatch', wfEscapeWikiText( $term ) );
+ $extra .= wfMsgExt( 'noexactmatch', 'parse', wfEscapeWikiText( $term ) );
} else {
- $wgOut->addWikiMsg( 'noexactmatch-nocreate', wfEscapeWikiText( $term ) );
+ $extra .= wfMsgExt( 'noexactmatch-nocreate', 'parse', wfEscapeWikiText( $term ) );
}
- return $this->showResults( $term );
+ $this->showResults( $term, $extra );
}
/**
* @param string $term
- * @public
+ * @param string $extra Extra HTML to add after "did you mean"
*/
- function showResults( $term ) {
+ public function showResults( $term, $extra = '' ) {
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 );
- $wgOut->addWikiMsg( 'searchresulttext' );
+ $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->addHTML( $extra );
+
+ $wgOut->wrapWikiMsg( "<div class='mw-searchresult'>\n$1</div>", 'searchresulttext' );
if( '' === trim( $term ) ) {
// Empty query -- straight view of search form
return;
}
- $wgOut->addHTML( $this->shortDialog( $term ) );
-
- $search = SearchEngine::create();
- $search->setLimitOffset( $this->limit, $this->offset );
- $search->setNamespaces( $this->namespaces );
- $search->showRedirects = $this->searchRedirects;
- $rewritten = $search->replacePrefixes($term);
-
- $titleMatches = $search->searchTitle( $rewritten );
+ $wgOut->addHTML( $this->shortDialog( $term ) );
// Sometimes the search engine knows there are too many hits
if ($titleMatches instanceof SearchResultTooMany) {
return;
}
- $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 = '<a href="'.$st->escapeLocalURL($stParams).'">'.
- $textMatches->getSuggestionSnippet().'</a>';
-
- $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
- }
-
// show number of results
$num = ( $titleMatches ? $titleMatches->numRows() : 0 )
+ ( $textMatches ? $textMatches->numRows() : 0);
array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
'fulltext' => wfMsg('search') ));
- $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
- wfMsg('search-relatedarticle').'</a>';
+ $related = ' -- ' . $sk->makeKnownLinkObj( $st,
+ wfMsg('search-relatedarticle'), $stParams );
}
// Include a thumbnail for media files...
// many assumptions about namespace numbering
$rows = array();
foreach( $namespaces as $ns => $name ) {
- $subj = Namespace::getSubject( $ns );
+ $subj = MWNamespace::getSubject( $ns );
if( !array_key_exists( $subj, $rows ) ) {
$rows[$subj] = "";
}
$searchField = Xml::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
$searchButton = Xml::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
$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::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
+ Xml::fieldset( wfMsg( 'powersearch-legend' ),
"<p>" .
wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
"</p>\n" .
" " .
$searchField .
" " .
+ $searchHiddens .
$searchButton ) .
"</form>";
'action' => $wgScript
));
$searchTitle = SpecialPage::getTitleFor( 'Search' );
- $out .= Xml::hidden( 'title', $searchTitle->getPrefixedText() );
$out .= Xml::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . ' ';
foreach( SearchEngine::searchableNamespaces() as $ns => $name ) {
if( in_array( $ns, $this->namespaces ) ) {
$out .= Xml::hidden( "ns{$ns}", '1' );
}
}
+ $out .= Xml::hidden( 'title', $searchTitle->getPrefixedText() );
+ $out .= Xml::hidden( 'fulltext', 'Search' );
$out .= Xml::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
$out .= Xml::closeElement( 'form' );