2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 * Run text & title search and display the output
23 * @ingroup SpecialPage
29 * @param $par String: (default '')
31 function wfSpecialSearch( $par = '' ) {
32 global $wgRequest, $wgUser, $wgUseOldSearchUI;
34 // Strip underscores from title parameter; most of the time we'll want
35 // text form here. But don't strip underscores from actual text params!
36 $titleParam = str_replace( '_', ' ', $par );
38 $search = str_replace( "\n", " ", $wgRequest->getText( 'search', $titleParam ) );
39 $class = $wgUseOldSearchUI ?
'SpecialSearchOld' : 'SpecialSearch';
40 $searchPage = new $class( $wgRequest, $wgUser );
41 if( $wgRequest->getVal( 'fulltext' )
42 ||
!is_null( $wgRequest->getVal( 'offset' ))
43 ||
!is_null( $wgRequest->getVal( 'searchx' )) )
45 $searchPage->showResults( $search, 'search' );
47 $searchPage->goResult( $search );
52 * implements Special:Search - Run text & title search and display the output
53 * @ingroup SpecialPage
58 * Set up basic search parameters from the request and user settings.
59 * Typically you'll pass $wgRequest and $wgUser.
61 * @param WebRequest $request
65 function __construct( &$request, &$user ) {
66 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
68 $this->namespaces
= $this->powerSearch( $request );
69 if( empty( $this->namespaces
) ) {
70 $this->namespaces
= SearchEngine
::userNamespaces( $user );
73 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
74 $this->searchAdvanced
= $request->getVal('advanced');
78 * If an exact title match can be found, jump straight ahead to it.
82 function goResult( $term ) {
83 global $wgOut, $wgGoToEdit;
85 $this->setupPage( $term );
87 # Try to go to page as entered.
88 $t = Title
::newFromText( $term );
90 # If the string cannot be used to create a title
92 return $this->showResults( $term );
95 # If there's an exact or very near match, jump right there.
96 $t = SearchEngine
::getNearMatch( $term );
97 if( !is_null( $t ) ) {
98 $wgOut->redirect( $t->getFullURL() );
102 # No match, generate an edit URL
103 $t = Title
::newFromText( $term );
104 if( ! is_null( $t ) ) {
105 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
106 # If the feature is enabled, go straight to the edit page
108 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
113 return $this->showResults( $term );
117 * @param string $term
120 function showResults( $term ) {
121 wfProfileIn( __METHOD__
);
122 global $wgOut, $wgUser;
123 $sk = $wgUser->getSkin();
125 $this->setupPage( $term );
126 $this->searchEngine
= SearchEngine
::create();
128 $t = Title
::newFromText( $term );
131 Xml
::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
132 Xml
::openElement( 'tr' ) .
133 Xml
::openElement( 'td' ) . "\n"
135 if( $this->searchAdvanced
) {
136 $wgOut->addHTML( $this->powerSearchBox( $term ) );
139 $wgOut->addHTML( $this->shortDialog( $term ) );
143 Xml
::closeElement('td') .
144 Xml
::closeElement('tr') .
145 Xml
::closeElement('table')
148 if( '' === trim( $term ) ) {
149 // Empty query -- straight view of search form
150 wfProfileOut( __METHOD__
);
154 global $wgDisableTextSearch;
155 if( $wgDisableTextSearch ) {
156 global $wgSearchForwardUrl;
157 if( $wgSearchForwardUrl ) {
158 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
159 $wgOut->redirect( $url );
162 global $wgInputEncoding;
164 Xml
::openElement( 'fieldset' ) .
165 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
166 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
167 wfMsg( 'googlesearch',
168 htmlspecialchars( $term ),
169 htmlspecialchars( $wgInputEncoding ),
170 htmlspecialchars( wfMsg( 'searchbutton' ) )
172 Xml
::closeElement( 'fieldset' )
174 wfProfileOut( __METHOD__
);
178 $search =& $this->searchEngine
;
179 $search->setLimitOffset( $this->limit
, $this->offset
);
180 $search->setNamespaces( $this->namespaces
);
181 $search->showRedirects
= $this->searchRedirects
;
182 $rewritten = $search->replacePrefixes($term);
184 $titleMatches = $search->searchTitle( $rewritten );
186 // Sometimes the search engine knows there are too many hits
187 if( $titleMatches instanceof SearchResultTooMany
) {
188 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
189 wfProfileOut( __METHOD__
);
193 $textMatches = $search->searchText( $rewritten );
195 // did you mean... suggestions
196 if( $textMatches && $textMatches->hasSuggestion() ) {
197 $st = SpecialPage
::getTitleFor( 'Search' );
198 $stParams = wfArrayToCGI(
199 array( 'search' => $textMatches->getSuggestionQuery(), 'fulltext' => wfMsg('search') ),
200 $this->powerSearchOptions()
202 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
203 $textMatches->getSuggestionSnippet().'</a>';
205 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
208 // show direct page/create link
210 if( !$t->exists() ) {
211 $wgOut->addWikiMsg( 'searchmenu-new', wfEscapeWikiText( $t->getPrefixedText() ) );
213 $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) );
217 // show number of results
218 $numTitleMatches = $titleMatches ?
$titleMatches->numRows() : 0;
219 $numTextMatches = $textMatches ?
$textMatches->numRows() : 0;
220 $highestNum = max( $numTitleMatches, $numTextMatches );
221 // Total query matches (possible false positives)
222 $num = $numTitleMatches +
$numTextMatches;
223 // Get total actual results
225 if( $titleMatches && !is_null($titleMatches->getTotalHits()) )
226 $totalNum +
= $titleMatches->getTotalHits();
227 if( $textMatches && !is_null($textMatches->getTotalHits()) )
228 $totalNum +
= $textMatches->getTotalHits();
230 if( $totalNum > 0 ) {
231 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
232 $this->offset+
1, $this->offset+
$num, $totalNum, $num );
233 } elseif( $num >= $this->limit
) {
234 $top = wfShowingResults( $this->offset
, $this->limit
);
236 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $num );
238 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
242 if( $num ||
$this->offset
) {
243 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
244 SpecialPage
::getTitleFor( 'Search' ),
245 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
246 ($highestNum < $this->limit
)
248 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
249 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
251 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
254 $wgOut->addHtml( "<div class='searchresults'>" );
256 if( $titleMatches ) {
257 if( $numTitleMatches > 0 ) {
258 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
259 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
261 $titleMatches->free();
265 // output appropriate heading
266 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
267 // if no title matches the heading is redundant
268 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
269 } elseif( $num == 0 ) {
270 # Don't show the 'no text matches' if we received title matches
271 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
273 // show interwiki results if any
274 if( $textMatches->hasInterwikiResults() )
275 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
277 if( $numTextMatches > 0 )
278 $wgOut->addHTML( $this->showMatches( $textMatches ) );
280 $textMatches->free();
284 $wgOut->addWikiMsg( 'search-nonefound' );
287 $wgOut->addHtml( "</div>" );
289 if( $num ||
$this->offset
) {
290 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
292 wfProfileOut( __METHOD__
);
298 protected function setupPage( $term ) {
300 if( !empty( $term ) ) {
301 $wgOut->setPageTitle( wfMsg( 'searchresults') );
302 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
304 $wgOut->setArticleRelated( false );
305 $wgOut->setRobotPolicy( 'noindex,nofollow' );
309 * Extract "power search" namespace settings from the request object,
310 * returning a list of index numbers to search.
312 * @param WebRequest $request
315 protected function powerSearch( &$request ) {
317 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
318 if( $request->getCheck( 'ns' . $ns ) ) {
326 * Reconstruct the 'power search' options for links
329 protected function powerSearchOptions() {
331 foreach( $this->namespaces
as $n ) {
334 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
335 if( $this->searchAdvanced
)
336 $opt['advanced'] = $this->searchAdvanced
;
341 * Show whole set of results
343 * @param SearchResultSet $matches
345 protected function showMatches( &$matches ) {
347 wfProfileIn( __METHOD__
);
349 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
353 $infoLine = $matches->getInfo();
354 if( !is_null($infoLine) )
355 $out .= "\n<!-- {$infoLine} -->\n";
358 $off = $this->offset +
1;
359 $out .= "<ul class='mw-search-results'>\n";
360 while( $result = $matches->next() ) {
361 $out .= $this->showHit( $result, $terms );
365 // convert the whole thing to desired language variant
366 $out = $wgContLang->convert( $out );
367 wfProfileOut( __METHOD__
);
372 * Format a single hit result
373 * @param SearchResult $result
374 * @param array $terms terms to highlight
376 protected function showHit( $result, $terms ) {
377 wfProfileIn( __METHOD__
);
378 global $wgUser, $wgContLang, $wgLang;
380 if( $result->isBrokenTitle() ) {
381 wfProfileOut( __METHOD__
);
382 return "<!-- Broken link in search result -->\n";
385 $t = $result->getTitle();
386 $sk = $wgUser->getSkin();
388 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
390 //If page content is not readable, just return the title.
391 //This is not quite safe, but better than showing excerpts from non-readable pages
392 //Note that hiding the entry entirely would screw up paging.
393 if(!$t->userCanRead()) {
394 wfProfileOut( __METHOD__
);
395 return "<li>{$link}</li>\n";
398 // If the page doesn't *exist*... our search index is out of date.
399 // The least confusing at this point is to drop the result.
400 // You may get less results, but... oh well. :P
401 if( $result->isMissingRevision() ) {
402 wfProfileOut( __METHOD__
);
403 return "<!-- missing page " .
404 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
407 // format redirects / relevant sections
408 $redirectTitle = $result->getRedirectTitle();
409 $redirectText = $result->getRedirectSnippet($terms);
410 $sectionTitle = $result->getSectionTitle();
411 $sectionText = $result->getSectionSnippet($terms);
413 if( !is_null($redirectTitle) )
414 $redirect = "<span class='searchalttitle'>"
415 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
418 if( !is_null($sectionTitle) )
419 $section = "<span class='searchalttitle'>"
420 .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
423 // format text extract
424 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
427 if( is_null( $result->getScore() ) ) {
428 // Search engine doesn't report scoring info
431 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
432 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
436 // format description
437 $byteSize = $result->getByteSize();
438 $wordCount = $result->getWordCount();
439 $timestamp = $result->getTimestamp();
440 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
441 $sk->formatSize( $byteSize ),
443 $date = $wgLang->timeanddate( $timestamp );
445 // link to related articles if supported
447 if( $result->hasRelated() ) {
448 $st = SpecialPage
::getTitleFor( 'Search' );
449 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
450 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
451 'fulltext' => wfMsg('search') ));
453 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
454 wfMsg('search-relatedarticle').'</a>';
457 // Include a thumbnail for media files...
458 if( $t->getNamespace() == NS_IMAGE
) {
459 $img = wfFindFile( $t );
461 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
463 $desc = $img->getShortDesc();
464 wfProfileOut( __METHOD__
);
465 // Float doesn't seem to interact well with the bullets.
466 // Table messes up vertical alignment of the bullets.
467 // Bullets are therefore disabled (didn't look great anyway).
469 '<table class="searchResultImage">' .
471 '<td width="120" align="center" valign="top">' .
472 $thumb->toHtml( array( 'desc-link' => true ) ) .
474 '<td valign="top">' .
477 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
486 wfProfileOut( __METHOD__
);
487 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
488 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
494 * Show results from other wikis
496 * @param SearchResultSet $matches
498 protected function showInterwiki( &$matches, $query ) {
499 wfProfileIn( __METHOD__
);
502 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
504 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
505 wfMsg('search-interwiki-caption')."</div>\n";
506 $off = $this->offset +
1;
507 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
509 // work out custom project captions
510 $customCaptions = array();
511 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
512 foreach($customLines as $line) {
513 $parts = explode(":",$line,2);
514 if(count($parts) == 2) // validate line
515 $customCaptions[$parts[0]] = $parts[1];
520 while( $result = $matches->next() ) {
521 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
522 $prev = $result->getInterwikiPrefix();
524 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
525 $out .= "</ul></div>\n";
527 // convert the whole thing to desired language variant
529 $out = $wgContLang->convert( $out );
530 wfProfileOut( __METHOD__
);
535 * Show single interwiki link
537 * @param SearchResult $result
538 * @param string $lastInterwiki
539 * @param array $terms
540 * @param string $query
541 * @param array $customCaptions iw prefix -> caption
543 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
544 wfProfileIn( __METHOD__
);
545 global $wgUser, $wgContLang, $wgLang;
547 if( $result->isBrokenTitle() ) {
548 wfProfileOut( __METHOD__
);
549 return "<!-- Broken link in search result -->\n";
552 $t = $result->getTitle();
553 $sk = $wgUser->getSkin();
555 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
557 // format redirect if any
558 $redirectTitle = $result->getRedirectTitle();
559 $redirectText = $result->getRedirectSnippet($terms);
561 if( !is_null($redirectTitle) )
562 $redirect = "<span class='searchalttitle'>"
563 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
567 // display project name
568 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
569 if( key_exists($t->getInterwiki(),$customCaptions) )
570 // captions from 'search-interwiki-custom'
571 $caption = $customCaptions[$t->getInterwiki()];
573 // default is to show the hostname of the other wiki which might suck
574 // if there are many wikis on one hostname
575 $parsed = parse_url($t->getFullURL());
576 $caption = wfMsg('search-interwiki-default', $parsed['host']);
578 // "more results" link (special page stuff could be localized, but we might not know target lang)
579 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
580 $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
581 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
582 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
583 {$searchLink}</span>{$caption}</div>\n<ul>";
586 $out .= "<li>{$link} {$redirect}</li>\n";
587 wfProfileOut( __METHOD__
);
593 * Generates the power search box at bottom of [[Special:Search]]
594 * @param $term string: search term
595 * @return $out string: HTML form
597 protected function powerSearchBox( $term ) {
598 global $wgScript, $wgContLang;
600 $namespaces = SearchEngine
::searchableNamespaces();
602 // group namespaces into rows according to subject; try not to make too
603 // many assumptions about namespace numbering
605 foreach( $namespaces as $ns => $name ) {
606 $subj = Namespace::getSubject( $ns );
607 if( !array_key_exists( $subj, $rows ) ) {
610 $name = str_replace( '_', ' ', $name );
612 $name = wfMsg( 'blanknamespace' );
614 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
615 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
616 Xml
::closeElement( 'td' ) . "\n";
618 $rows = array_values( $rows );
619 $numRows = count( $rows );
621 // lay out namespaces in multiple floating two-column tables so they'll
622 // be arranged nicely while still accommodating different screen widths
623 $rowsPerTable = 3; // seems to look nice
625 // float to the right on RTL wikis
626 $tableStyle = ( $wgContLang->isRTL() ?
627 'float: right; margin: 0 0 1em 1em' :
628 'float: left; margin: 0 1em 1em 0' );
631 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
632 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
633 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
634 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
636 $tables .= Xml
::closeElement( 'table' ) . "\n";
639 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
640 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
641 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
642 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
643 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
645 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
646 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
648 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
651 "<hr style=\"clear: both\" />\n" .
653 $redirect . " " . $redirectLabel .
655 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
661 $t = Title
::newFromText( $term );
663 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
665 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
666 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
667 $this->formHeader($term) . $out .
668 Xml
::closeElement( 'fieldset' );
671 protected function powerSearchFocus() {
672 global $wgJsMimeType;
673 return "<script type=\"$wgJsMimeType\">" .
674 "hookEvent(\"load\", function() {" .
675 "document.getElementById('powerSearchText').focus();" .
680 /** Make a search link with some target namespaces */
681 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
683 foreach( $namespaces as $n ) {
686 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
688 $st = SpecialPage
::getTitleFor( 'Search' );
689 $stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt );
691 return Xml
::element( 'a',
692 array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
696 /** Check if query starts with image: prefix */
697 protected function startsWithImage( $term ) {
700 $p = explode( ':', $term );
701 if( count( $p ) > 1 ) {
702 return $wgContLang->getNsIndex( $p[0] ) == NS_IMAGE
;
707 protected function formHeader( $term ) {
708 global $wgContLang, $wgCanonicalNamespaceNames;
710 $sep = ' ';
711 $out = Xml
::openElement('div', array( 'style' => 'padding-bottom:0.5em;' ) );
714 if( $this->startsWithImage( $term ) )
715 $bareterm = substr( $term, strpos( $term, ':' ) +
1 ); // delete all/image prefix
717 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
718 // figure out the active search profile header
719 if( $this->searchAdvanced
)
720 $active = 'advanced';
721 else if( $this->namespaces
=== NS_IMAGE ||
$this->startsWithImage( $term ) )
723 elseif( $this->namespaces
=== $nsAllSet )
725 elseif( $this->namespaces
=== SearchEngine
::defaultNamespaces() )
727 elseif( $this->namespaces
=== SearchEngine
::defaultAndProjectNamespaces() )
728 $active = 'withproject';
729 elseif( $this->namespaces
=== SearchEngine
::projectNamespaces() )
732 $active = 'advanced';
735 // search profiles headers
736 $m = wfMsg( 'searchprofile-articles' );
737 $tt = wfMsg( 'searchprofile-articles-tooltip',
738 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::defaultNamespaces() ) ) );
739 if( $active == 'default' ) {
740 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
742 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::defaultNamespaces(), $m, $tt );
746 $m = wfMsg( 'searchprofile-images' );
747 $tt = wfMsg( 'searchprofile-images-tooltip' );
748 if( $active == 'images' ) {
749 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
751 $imageTextForm = $wgContLang->getFormattedNsText(NS_IMAGE
).':'.$bareterm;
752 $out .= $this->makeSearchLink( $imageTextForm, array( NS_IMAGE
) , $m, $tt );
756 $m = wfMsg( 'searchprofile-articles-and-proj' );
757 $tt = wfMsg( 'searchprofile-project-tooltip',
758 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::defaultAndProjectNamespaces() ) ) );
759 if( $active == 'withproject' ) {
760 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
762 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::defaultAndProjectNamespaces(), $m, $tt );
766 $m = wfMsg( 'searchprofile-project' );
767 $tt = wfMsg( 'searchprofile-project-tooltip',
768 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::projectNamespaces() ) ) );
769 if( $active == 'project' ) {
770 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
772 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::projectNamespaces(), $m, $tt );
776 $m = wfMsg( 'searchprofile-everything' );
777 $tt = wfMsg( 'searchprofile-everything-tooltip' );
778 if( $active == 'all' ) {
779 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
781 $out .= $this->makeSearchLink( $bareterm, $nsAllSet, $m, $tt );
785 $m = wfMsg( 'searchprofile-advanced' );
786 $tt = wfMsg( 'searchprofile-advanced-tooltip' );
787 if( $active == 'advanced' ) {
788 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
790 $out .= $this->makeSearchLink( $bareterm, $this->namespaces
, $m, $tt, array( 'advanced' => '1' ) );
792 $out .= Xml
::closeElement('div') ;
797 protected function shortDialog( $term ) {
799 $out = Xml
::openElement( 'form', array( 'id' => 'search', 'method' => 'get', 'action' => $wgScript ) );
800 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
801 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
802 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
803 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
804 if( in_array( $ns, $this->namespaces
) ) {
805 $out .= Xml
::hidden( "ns{$ns}", '1' );
808 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
809 $out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')';
810 $out .= Xml
::closeElement( 'form' );
811 $t = Title
::newFromText( $term );
813 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
814 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
815 Xml
::element( 'legend', null, wfMsg('searchmenu-legend') ) .
816 $this->formHeader($term) . $out .
817 Xml
::closeElement( 'fieldset' );
822 * implements Special:Search - Run text & title search and display the output
823 * @ingroup SpecialPage
825 class SpecialSearchOld
{
828 * Set up basic search parameters from the request and user settings.
829 * Typically you'll pass $wgRequest and $wgUser.
831 * @param WebRequest $request
835 function __construct( &$request, &$user ) {
836 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
838 $this->namespaces
= $this->powerSearch( $request );
839 if( empty( $this->namespaces
) ) {
840 $this->namespaces
= SearchEngine
::userNamespaces( $user );
843 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
847 * If an exact title match can be found, jump straight ahead to it.
848 * @param string $term
851 function goResult( $term ) {
855 $this->setupPage( $term );
857 # Try to go to page as entered.
858 $t = Title
::newFromText( $term );
860 # If the string cannot be used to create a title
862 return $this->showResults( $term );
865 # If there's an exact or very near match, jump right there.
866 $t = SearchEngine
::getNearMatch( $term );
867 if( !is_null( $t ) ) {
868 $wgOut->redirect( $t->getFullURL() );
872 # No match, generate an edit URL
873 $t = Title
::newFromText( $term );
874 if( ! is_null( $t ) ) {
875 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
876 # If the feature is enabled, go straight to the edit page
878 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
883 $wgOut->wrapWikiMsg( "==$1==\n", 'notitlematches' );
884 if( $t->quickUserCan( 'create' ) && $t->quickUserCan( 'edit' ) ) {
885 $wgOut->addWikiMsg( 'noexactmatch', wfEscapeWikiText( $term ) );
887 $wgOut->addWikiMsg( 'noexactmatch-nocreate', wfEscapeWikiText( $term ) );
890 return $this->showResults( $term );
894 * @param string $term
897 function showResults( $term ) {
898 wfProfileIn( __METHOD__
);
899 global $wgOut, $wgUser;
900 $sk = $wgUser->getSkin();
902 $this->setupPage( $term );
904 $wgOut->addWikiMsg( 'searchresulttext' );
906 if( '' === trim( $term ) ) {
907 // Empty query -- straight view of search form
908 $wgOut->setSubtitle( '' );
909 $wgOut->addHTML( $this->powerSearchBox( $term ) );
910 $wgOut->addHTML( $this->powerSearchFocus() );
911 wfProfileOut( __METHOD__
);
915 global $wgDisableTextSearch;
916 if ( $wgDisableTextSearch ) {
917 global $wgSearchForwardUrl;
918 if( $wgSearchForwardUrl ) {
919 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
920 $wgOut->redirect( $url );
923 global $wgInputEncoding;
925 Xml
::openElement( 'fieldset' ) .
926 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
927 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
928 wfMsg( 'googlesearch',
929 htmlspecialchars( $term ),
930 htmlspecialchars( $wgInputEncoding ),
931 htmlspecialchars( wfMsg( 'searchbutton' ) )
933 Xml
::closeElement( 'fieldset' )
935 wfProfileOut( __METHOD__
);
939 $wgOut->addHTML( $this->shortDialog( $term ) );
941 $search = SearchEngine
::create();
942 $search->setLimitOffset( $this->limit
, $this->offset
);
943 $search->setNamespaces( $this->namespaces
);
944 $search->showRedirects
= $this->searchRedirects
;
945 $rewritten = $search->replacePrefixes($term);
947 $titleMatches = $search->searchTitle( $rewritten );
949 // Sometimes the search engine knows there are too many hits
950 if ($titleMatches instanceof SearchResultTooMany
) {
951 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
952 $wgOut->addHTML( $this->powerSearchBox( $term ) );
953 $wgOut->addHTML( $this->powerSearchFocus() );
954 wfProfileOut( __METHOD__
);
958 $textMatches = $search->searchText( $rewritten );
960 // did you mean... suggestions
961 if($textMatches && $textMatches->hasSuggestion()){
962 $st = SpecialPage
::getTitleFor( 'Search' );
963 $stParams = wfArrayToCGI( array(
964 'search' => $textMatches->getSuggestionQuery(),
965 'fulltext' => wfMsg('search')),
966 $this->powerSearchOptions());
968 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
969 $textMatches->getSuggestionSnippet().'</a>';
971 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
974 // show number of results
975 $num = ( $titleMatches ?
$titleMatches->numRows() : 0 )
976 +
( $textMatches ?
$textMatches->numRows() : 0);
978 if($titleMatches && !is_null($titleMatches->getTotalHits()))
979 $totalNum +
= $titleMatches->getTotalHits();
980 if($textMatches && !is_null($textMatches->getTotalHits()))
981 $totalNum +
= $textMatches->getTotalHits();
983 if ( $totalNum > 0 ){
984 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
985 $this->offset+
1, $this->offset+
$num, $totalNum, $num );
986 } elseif ( $num >= $this->limit
) {
987 $top = wfShowingResults( $this->offset
, $this->limit
);
989 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $num );
991 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
995 if( $num ||
$this->offset
) {
996 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
997 SpecialPage
::getTitleFor( 'Search' ),
999 $this->powerSearchOptions(),
1000 array( 'search' => $term ) ),
1001 ($num < $this->limit
) );
1002 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
1003 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
1005 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
1008 if( $titleMatches ) {
1009 if( $titleMatches->numRows() ) {
1010 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
1011 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
1013 $titleMatches->free();
1016 if( $textMatches ) {
1017 // output appropriate heading
1018 if( $textMatches->numRows() ) {
1020 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
1021 else // if no title matches the heading is redundant
1022 $wgOut->addHTML("<hr/>");
1023 } elseif( $num == 0 ) {
1024 # Don't show the 'no text matches' if we received title matches
1025 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
1027 // show interwiki results if any
1028 if( $textMatches->hasInterwikiResults() )
1029 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
1031 if( $textMatches->numRows() )
1032 $wgOut->addHTML( $this->showMatches( $textMatches ) );
1034 $textMatches->free();
1038 $wgOut->addWikiMsg( 'nonefound' );
1040 if( $num ||
$this->offset
) {
1041 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
1043 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1044 wfProfileOut( __METHOD__
);
1047 #------------------------------------------------------------------
1048 # Private methods below this line
1053 function setupPage( $term ) {
1055 if( !empty( $term ) ){
1056 $wgOut->setPageTitle( wfMsg( 'searchresults') );
1057 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
1059 $subtitlemsg = ( Title
::newFromText( $term ) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
1060 $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
1061 $wgOut->setArticleRelated( false );
1062 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1066 * Extract "power search" namespace settings from the request object,
1067 * returning a list of index numbers to search.
1069 * @param WebRequest $request
1073 function powerSearch( &$request ) {
1075 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1076 if( $request->getCheck( 'ns' . $ns ) ) {
1084 * Reconstruct the 'power search' options for links
1088 function powerSearchOptions() {
1090 foreach( $this->namespaces
as $n ) {
1091 $opt['ns' . $n] = 1;
1093 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
1098 * Show whole set of results
1100 * @param SearchResultSet $matches
1102 function showMatches( &$matches ) {
1103 wfProfileIn( __METHOD__
);
1106 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1110 $infoLine = $matches->getInfo();
1111 if( !is_null($infoLine) )
1112 $out .= "\n<!-- {$infoLine} -->\n";
1115 $off = $this->offset +
1;
1116 $out .= "<ul class='mw-search-results'>\n";
1118 while( $result = $matches->next() ) {
1119 $out .= $this->showHit( $result, $terms );
1123 // convert the whole thing to desired language variant
1125 $out = $wgContLang->convert( $out );
1126 wfProfileOut( __METHOD__
);
1131 * Format a single hit result
1132 * @param SearchResult $result
1133 * @param array $terms terms to highlight
1135 function showHit( $result, $terms ) {
1136 wfProfileIn( __METHOD__
);
1137 global $wgUser, $wgContLang, $wgLang;
1139 if( $result->isBrokenTitle() ) {
1140 wfProfileOut( __METHOD__
);
1141 return "<!-- Broken link in search result -->\n";
1144 $t = $result->getTitle();
1145 $sk = $wgUser->getSkin();
1147 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1149 //If page content is not readable, just return the title.
1150 //This is not quite safe, but better than showing excerpts from non-readable pages
1151 //Note that hiding the entry entirely would screw up paging.
1152 if (!$t->userCanRead()) {
1153 wfProfileOut( __METHOD__
);
1154 return "<li>{$link}</li>\n";
1157 // If the page doesn't *exist*... our search index is out of date.
1158 // The least confusing at this point is to drop the result.
1159 // You may get less results, but... oh well. :P
1160 if( $result->isMissingRevision() ) {
1161 wfProfileOut( __METHOD__
);
1162 return "<!-- missing page " .
1163 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
1166 // format redirects / relevant sections
1167 $redirectTitle = $result->getRedirectTitle();
1168 $redirectText = $result->getRedirectSnippet($terms);
1169 $sectionTitle = $result->getSectionTitle();
1170 $sectionText = $result->getSectionSnippet($terms);
1172 if( !is_null($redirectTitle) )
1173 $redirect = "<span class='searchalttitle'>"
1174 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1177 if( !is_null($sectionTitle) )
1178 $section = "<span class='searchalttitle'>"
1179 .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
1182 // format text extract
1183 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
1186 if( is_null( $result->getScore() ) ) {
1187 // Search engine doesn't report scoring info
1190 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
1191 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
1195 // format description
1196 $byteSize = $result->getByteSize();
1197 $wordCount = $result->getWordCount();
1198 $timestamp = $result->getTimestamp();
1199 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
1200 $sk->formatSize( $byteSize ),
1202 $date = $wgLang->timeanddate( $timestamp );
1204 // link to related articles if supported
1206 if( $result->hasRelated() ){
1207 $st = SpecialPage
::getTitleFor( 'Search' );
1208 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
1209 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
1210 'fulltext' => wfMsg('search') ));
1212 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
1213 wfMsg('search-relatedarticle').'</a>';
1216 // Include a thumbnail for media files...
1217 if( $t->getNamespace() == NS_IMAGE
) {
1218 $img = wfFindFile( $t );
1220 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
1222 $desc = $img->getShortDesc();
1223 wfProfileOut( __METHOD__
);
1225 // Float doesn't seem to interact well with the bullets.
1226 // Table messes up vertical alignment of the bullet, but I'm
1227 // not sure what more I can do about that. :(
1229 '<table class="searchResultImage">' .
1231 '<td width="120" align="center">' .
1232 $thumb->toHtml( array( 'desc-link' => true ) ) .
1234 '<td valign="top">' .
1237 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
1246 wfProfileOut( __METHOD__
);
1247 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
1248 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
1254 * Show results from other wikis
1256 * @param SearchResultSet $matches
1258 function showInterwiki( &$matches, $query ) {
1259 wfProfileIn( __METHOD__
);
1262 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1264 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
1265 $off = $this->offset +
1;
1266 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
1268 // work out custom project captions
1269 $customCaptions = array();
1270 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
1271 foreach($customLines as $line){
1272 $parts = explode(":",$line,2);
1273 if(count($parts) == 2) // validate line
1274 $customCaptions[$parts[0]] = $parts[1];
1279 while( $result = $matches->next() ) {
1280 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
1281 $prev = $result->getInterwikiPrefix();
1283 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
1284 $out .= "</ul></div>\n";
1286 // convert the whole thing to desired language variant
1288 $out = $wgContLang->convert( $out );
1289 wfProfileOut( __METHOD__
);
1294 * Show single interwiki link
1296 * @param SearchResult $result
1297 * @param string $lastInterwiki
1298 * @param array $terms
1299 * @param string $query
1300 * @param array $customCaptions iw prefix -> caption
1302 function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
1303 wfProfileIn( __METHOD__
);
1304 global $wgUser, $wgContLang, $wgLang;
1306 if( $result->isBrokenTitle() ) {
1307 wfProfileOut( __METHOD__
);
1308 return "<!-- Broken link in search result -->\n";
1311 $t = $result->getTitle();
1312 $sk = $wgUser->getSkin();
1314 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1316 // format redirect if any
1317 $redirectTitle = $result->getRedirectTitle();
1318 $redirectText = $result->getRedirectSnippet($terms);
1320 if( !is_null($redirectTitle) )
1321 $redirect = "<span class='searchalttitle'>"
1322 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1326 // display project name
1327 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()){
1328 if( key_exists($t->getInterwiki(),$customCaptions) )
1329 // captions from 'search-interwiki-custom'
1330 $caption = $customCaptions[$t->getInterwiki()];
1332 // default is to show the hostname of the other wiki which might suck
1333 // if there are many wikis on one hostname
1334 $parsed = parse_url($t->getFullURL());
1335 $caption = wfMsg('search-interwiki-default', $parsed['host']);
1337 // "more results" link (special page stuff could be localized, but we might not know target lang)
1338 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
1339 $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
1340 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
1341 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>{$searchLink}</span>{$caption}</div>\n<ul>";
1344 $out .= "<li>{$link} {$redirect}</li>\n";
1345 wfProfileOut( __METHOD__
);
1351 * Generates the power search box at bottom of [[Special:Search]]
1352 * @param $term string: search term
1353 * @return $out string: HTML form
1355 function powerSearchBox( $term ) {
1356 global $wgScript, $wgContLang;
1358 $namespaces = SearchEngine
::searchableNamespaces();
1360 // group namespaces into rows according to subject; try not to make too
1361 // many assumptions about namespace numbering
1363 foreach( $namespaces as $ns => $name ) {
1364 $subj = Namespace::getSubject( $ns );
1365 if( !array_key_exists( $subj, $rows ) ) {
1368 $name = str_replace( '_', ' ', $name );
1370 $name = wfMsg( 'blanknamespace' );
1372 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
1373 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
1374 Xml
::closeElement( 'td' ) . "\n";
1376 $rows = array_values( $rows );
1377 $numRows = count( $rows );
1379 // lay out namespaces in multiple floating two-column tables so they'll
1380 // be arranged nicely while still accommodating different screen widths
1381 $rowsPerTable = 3; // seems to look nice
1383 // float to the right on RTL wikis
1384 $tableStyle = ( $wgContLang->isRTL() ?
1385 'float: right; margin: 0 0 1em 1em' :
1386 'float: left; margin: 0 1em 1em 0' );
1389 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
1390 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
1391 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
1392 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
1394 $tables .= Xml
::closeElement( 'table' ) . "\n";
1397 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
1398 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
1399 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
1400 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
1401 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1403 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
1404 Xml
::fieldset( wfMsg( 'powersearch-legend' ),
1405 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
1407 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
1410 "<hr style=\"clear: both\" />\n" .
1412 $redirect . " " . $redirectLabel .
1414 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
1424 function powerSearchFocus() {
1425 global $wgJsMimeType;
1426 return "<script type=\"$wgJsMimeType\">" .
1427 "hookEvent(\"load\", function(){" .
1428 "document.getElementById('powerSearchText').focus();" .
1433 function shortDialog($term) {
1436 $out = Xml
::openElement( 'form', array(
1439 'action' => $wgScript
1441 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1442 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() );
1443 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . ' ';
1444 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1445 if( in_array( $ns, $this->namespaces
) ) {
1446 $out .= Xml
::hidden( "ns{$ns}", '1' );
1449 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
1450 $out .= Xml
::closeElement( 'form' );