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( $titleMatches->numRows() ) {
258 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
259 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
261 $titleMatches->free();
265 // output appropriate heading
266 if( $textMatches->numRows() ) {
268 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
269 else // if no title matches the heading is redundant
270 $wgOut->addHTML("<hr/>");
271 } elseif( $num == 0 ) {
272 # Don't show the 'no text matches' if we received title matches
273 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
275 // show interwiki results if any
276 if( $textMatches->hasInterwikiResults() )
277 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
279 if( $textMatches->numRows() )
280 $wgOut->addHTML( $this->showMatches( $textMatches ) );
282 $textMatches->free();
286 $wgOut->addWikiMsg( 'search-nonefound' );
289 $wgOut->addHtml( "</div>" );
291 if( $num ||
$this->offset
) {
292 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
294 wfProfileOut( __METHOD__
);
300 protected function setupPage( $term ) {
302 if( !empty( $term ) ) {
303 $wgOut->setPageTitle( wfMsg( 'searchresults') );
304 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
306 $wgOut->setArticleRelated( false );
307 $wgOut->setRobotPolicy( 'noindex,nofollow' );
311 * Extract "power search" namespace settings from the request object,
312 * returning a list of index numbers to search.
314 * @param WebRequest $request
317 protected function powerSearch( &$request ) {
319 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
320 if( $request->getCheck( 'ns' . $ns ) ) {
328 * Reconstruct the 'power search' options for links
331 protected function powerSearchOptions() {
333 foreach( $this->namespaces
as $n ) {
336 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
337 if( $this->searchAdvanced
)
338 $opt['advanced'] = $this->searchAdvanced
;
343 * Show whole set of results
345 * @param SearchResultSet $matches
347 protected function showMatches( &$matches ) {
349 wfProfileIn( __METHOD__
);
351 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
355 $infoLine = $matches->getInfo();
356 if( !is_null($infoLine) )
357 $out .= "\n<!-- {$infoLine} -->\n";
360 $off = $this->offset +
1;
361 $out .= "<ul class='mw-search-results'>\n";
362 while( $result = $matches->next() ) {
363 $out .= $this->showHit( $result, $terms );
367 // convert the whole thing to desired language variant
368 $out = $wgContLang->convert( $out );
369 wfProfileOut( __METHOD__
);
374 * Format a single hit result
375 * @param SearchResult $result
376 * @param array $terms terms to highlight
378 protected function showHit( $result, $terms ) {
379 wfProfileIn( __METHOD__
);
380 global $wgUser, $wgContLang, $wgLang;
382 if( $result->isBrokenTitle() ) {
383 wfProfileOut( __METHOD__
);
384 return "<!-- Broken link in search result -->\n";
387 $t = $result->getTitle();
388 $sk = $wgUser->getSkin();
390 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
392 //If page content is not readable, just return the title.
393 //This is not quite safe, but better than showing excerpts from non-readable pages
394 //Note that hiding the entry entirely would screw up paging.
395 if(!$t->userCanRead()) {
396 wfProfileOut( __METHOD__
);
397 return "<li>{$link}</li>\n";
400 // If the page doesn't *exist*... our search index is out of date.
401 // The least confusing at this point is to drop the result.
402 // You may get less results, but... oh well. :P
403 if( $result->isMissingRevision() ) {
404 wfProfileOut( __METHOD__
);
405 return "<!-- missing page " .
406 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
409 // format redirects / relevant sections
410 $redirectTitle = $result->getRedirectTitle();
411 $redirectText = $result->getRedirectSnippet($terms);
412 $sectionTitle = $result->getSectionTitle();
413 $sectionText = $result->getSectionSnippet($terms);
415 if( !is_null($redirectTitle) )
416 $redirect = "<span class='searchalttitle'>"
417 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
420 if( !is_null($sectionTitle) )
421 $section = "<span class='searchalttitle'>"
422 .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
425 // format text extract
426 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
429 if( is_null( $result->getScore() ) ) {
430 // Search engine doesn't report scoring info
433 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
434 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
438 // format description
439 $byteSize = $result->getByteSize();
440 $wordCount = $result->getWordCount();
441 $timestamp = $result->getTimestamp();
442 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
443 $sk->formatSize( $byteSize ),
445 $date = $wgLang->timeanddate( $timestamp );
447 // link to related articles if supported
449 if( $result->hasRelated() ) {
450 $st = SpecialPage
::getTitleFor( 'Search' );
451 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
452 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
453 'fulltext' => wfMsg('search') ));
455 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
456 wfMsg('search-relatedarticle').'</a>';
459 // Include a thumbnail for media files...
460 if( $t->getNamespace() == NS_IMAGE
) {
461 $img = wfFindFile( $t );
463 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
465 $desc = $img->getShortDesc();
466 wfProfileOut( __METHOD__
);
467 // Float doesn't seem to interact well with the bullets.
468 // Table messes up vertical alignment of the bullets.
469 // Bullets are therefore disabled (didn't look great anyway).
471 '<table class="searchResultImage">' .
473 '<td width="120" align="center" valign="top">' .
474 $thumb->toHtml( array( 'desc-link' => true ) ) .
476 '<td valign="top">' .
479 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
488 wfProfileOut( __METHOD__
);
489 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
490 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
496 * Show results from other wikis
498 * @param SearchResultSet $matches
500 protected function showInterwiki( &$matches, $query ) {
501 wfProfileIn( __METHOD__
);
504 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
506 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
507 wfMsg('search-interwiki-caption')."</div>\n";
508 $off = $this->offset +
1;
509 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
511 // work out custom project captions
512 $customCaptions = array();
513 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
514 foreach($customLines as $line) {
515 $parts = explode(":",$line,2);
516 if(count($parts) == 2) // validate line
517 $customCaptions[$parts[0]] = $parts[1];
522 while( $result = $matches->next() ) {
523 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
524 $prev = $result->getInterwikiPrefix();
526 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
527 $out .= "</ul></div>\n";
529 // convert the whole thing to desired language variant
531 $out = $wgContLang->convert( $out );
532 wfProfileOut( __METHOD__
);
537 * Show single interwiki link
539 * @param SearchResult $result
540 * @param string $lastInterwiki
541 * @param array $terms
542 * @param string $query
543 * @param array $customCaptions iw prefix -> caption
545 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
546 wfProfileIn( __METHOD__
);
547 global $wgUser, $wgContLang, $wgLang;
549 if( $result->isBrokenTitle() ) {
550 wfProfileOut( __METHOD__
);
551 return "<!-- Broken link in search result -->\n";
554 $t = $result->getTitle();
555 $sk = $wgUser->getSkin();
557 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
559 // format redirect if any
560 $redirectTitle = $result->getRedirectTitle();
561 $redirectText = $result->getRedirectSnippet($terms);
563 if( !is_null($redirectTitle) )
564 $redirect = "<span class='searchalttitle'>"
565 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
569 // display project name
570 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
571 if( key_exists($t->getInterwiki(),$customCaptions) )
572 // captions from 'search-interwiki-custom'
573 $caption = $customCaptions[$t->getInterwiki()];
575 // default is to show the hostname of the other wiki which might suck
576 // if there are many wikis on one hostname
577 $parsed = parse_url($t->getFullURL());
578 $caption = wfMsg('search-interwiki-default', $parsed['host']);
580 // "more results" link (special page stuff could be localized, but we might not know target lang)
581 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
582 $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
583 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
584 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
585 {$searchLink}</span>{$caption}</div>\n<ul>";
588 $out .= "<li>{$link} {$redirect}</li>\n";
589 wfProfileOut( __METHOD__
);
595 * Generates the power search box at bottom of [[Special:Search]]
596 * @param $term string: search term
597 * @return $out string: HTML form
599 protected function powerSearchBox( $term ) {
600 global $wgScript, $wgContLang;
602 $namespaces = SearchEngine
::searchableNamespaces();
604 // group namespaces into rows according to subject; try not to make too
605 // many assumptions about namespace numbering
607 foreach( $namespaces as $ns => $name ) {
608 $subj = Namespace::getSubject( $ns );
609 if( !array_key_exists( $subj, $rows ) ) {
612 $name = str_replace( '_', ' ', $name );
614 $name = wfMsg( 'blanknamespace' );
616 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
617 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
618 Xml
::closeElement( 'td' ) . "\n";
620 $rows = array_values( $rows );
621 $numRows = count( $rows );
623 // lay out namespaces in multiple floating two-column tables so they'll
624 // be arranged nicely while still accommodating different screen widths
625 $rowsPerTable = 3; // seems to look nice
627 // float to the right on RTL wikis
628 $tableStyle = ( $wgContLang->isRTL() ?
629 'float: right; margin: 0 0 1em 1em' :
630 'float: left; margin: 0 1em 1em 0' );
633 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
634 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
635 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
636 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
638 $tables .= Xml
::closeElement( 'table' ) . "\n";
641 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
642 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
643 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
644 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
645 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
647 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
648 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
650 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
653 "<hr style=\"clear: both\" />\n" .
655 $redirect . " " . $redirectLabel .
657 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
663 $t = Title
::newFromText( $term );
665 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
667 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
668 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
669 $this->formHeader($term) . $out .
670 Xml
::closeElement( 'fieldset' );
673 protected function powerSearchFocus() {
674 global $wgJsMimeType;
675 return "<script type=\"$wgJsMimeType\">" .
676 "hookEvent(\"load\", function() {" .
677 "document.getElementById('powerSearchText').focus();" .
682 /** Make a search link with some target namespaces */
683 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
685 foreach( $namespaces as $n ) {
688 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
690 $st = SpecialPage
::getTitleFor( 'Search' );
691 $stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt );
693 return Xml
::element( 'a',
694 array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
698 /** Check if query starts with image: prefix */
699 protected function startsWithImage( $term ) {
702 $p = explode( ':', $term );
703 if( count( $p ) > 1 ) {
704 return $wgContLang->getNsIndex( $p[0] ) == NS_IMAGE
;
709 protected function formHeader( $term ) {
710 global $wgContLang, $wgCanonicalNamespaceNames;
712 $sep = ' ';
713 $out = Xml
::openElement('div', array( 'style' => 'padding-bottom:0.5em;' ) );
716 if( $this->startsWithImage( $term ) )
717 $bareterm = substr( $term, strpos( $term, ':' ) +
1 ); // delete all/image prefix
719 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
720 // figure out the active search profile header
721 if( $this->searchAdvanced
)
722 $active = 'advanced';
723 else if( $this->namespaces
=== NS_IMAGE ||
$this->startsWithImage( $term ) )
725 elseif( $this->namespaces
=== $nsAllSet )
727 elseif( $this->namespaces
=== SearchEngine
::defaultNamespaces() )
729 elseif( $this->namespaces
=== SearchEngine
::defaultAndProjectNamespaces() )
730 $active = 'withproject';
731 elseif( $this->namespaces
=== SearchEngine
::projectNamespaces() )
734 $active = 'advanced';
737 // search profiles headers
738 $m = wfMsg( 'searchprofile-articles' );
739 $tt = wfMsg( 'searchprofile-articles-tooltip',
740 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::defaultNamespaces() ) ) );
741 if( $active == 'default' ) {
742 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
744 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::defaultNamespaces(), $m, $tt );
748 $m = wfMsg( 'searchprofile-images' );
749 $tt = wfMsg( 'searchprofile-images-tooltip' );
750 if( $active == 'images' ) {
751 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
753 $imageTextForm = $wgContLang->getFormattedNsText(NS_IMAGE
).':'.$bareterm;
754 $out .= $this->makeSearchLink( $imageTextForm, array( NS_IMAGE
) , $m, $tt );
758 $m = wfMsg( 'searchprofile-articles-and-proj' );
759 $tt = wfMsg( 'searchprofile-project-tooltip',
760 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::defaultAndProjectNamespaces() ) ) );
761 if( $active == 'withproject' ) {
762 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
764 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::defaultAndProjectNamespaces(), $m, $tt );
768 $m = wfMsg( 'searchprofile-project' );
769 $tt = wfMsg( 'searchprofile-project-tooltip',
770 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::projectNamespaces() ) ) );
771 if( $active == 'project' ) {
772 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
774 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::projectNamespaces(), $m, $tt );
778 $m = wfMsg( 'searchprofile-everything' );
779 $tt = wfMsg( 'searchprofile-everything-tooltip' );
780 if( $active == 'all' ) {
781 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
783 $out .= $this->makeSearchLink( $bareterm, $nsAllSet, $m, $tt );
787 $m = wfMsg( 'searchprofile-advanced' );
788 $tt = wfMsg( 'searchprofile-advanced-tooltip' );
789 if( $active == 'advanced' ) {
790 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
792 $out .= $this->makeSearchLink( $bareterm, $this->namespaces
, $m, $tt, array( 'advanced' => '1' ) );
794 $out .= Xml
::closeElement('div') ;
799 protected function shortDialog( $term ) {
801 $out = Xml
::openElement( 'form', array( 'id' => 'search', 'method' => 'get', 'action' => $wgScript ) );
802 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
803 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
804 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
805 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
806 if( in_array( $ns, $this->namespaces
) ) {
807 $out .= Xml
::hidden( "ns{$ns}", '1' );
810 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
811 $out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')';
812 $out .= Xml
::closeElement( 'form' );
813 $t = Title
::newFromText( $term );
815 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
816 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
817 Xml
::element( 'legend', null, wfMsg('searchmenu-legend') ) .
818 $this->formHeader($term) . $out .
819 Xml
::closeElement( 'fieldset' );
824 * implements Special:Search - Run text & title search and display the output
825 * @ingroup SpecialPage
827 class SpecialSearchOld
{
830 * Set up basic search parameters from the request and user settings.
831 * Typically you'll pass $wgRequest and $wgUser.
833 * @param WebRequest $request
837 function __construct( &$request, &$user ) {
838 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
840 $this->namespaces
= $this->powerSearch( $request );
841 if( empty( $this->namespaces
) ) {
842 $this->namespaces
= SearchEngine
::userNamespaces( $user );
845 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
849 * If an exact title match can be found, jump straight ahead to it.
850 * @param string $term
853 function goResult( $term ) {
857 $this->setupPage( $term );
859 # Try to go to page as entered.
860 $t = Title
::newFromText( $term );
862 # If the string cannot be used to create a title
864 return $this->showResults( $term );
867 # If there's an exact or very near match, jump right there.
868 $t = SearchEngine
::getNearMatch( $term );
869 if( !is_null( $t ) ) {
870 $wgOut->redirect( $t->getFullURL() );
874 # No match, generate an edit URL
875 $t = Title
::newFromText( $term );
876 if( ! is_null( $t ) ) {
877 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
878 # If the feature is enabled, go straight to the edit page
880 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
885 $wgOut->wrapWikiMsg( "==$1==\n", 'notitlematches' );
886 if( $t->quickUserCan( 'create' ) && $t->quickUserCan( 'edit' ) ) {
887 $wgOut->addWikiMsg( 'noexactmatch', wfEscapeWikiText( $term ) );
889 $wgOut->addWikiMsg( 'noexactmatch-nocreate', wfEscapeWikiText( $term ) );
892 return $this->showResults( $term );
896 * @param string $term
899 function showResults( $term ) {
900 wfProfileIn( __METHOD__
);
901 global $wgOut, $wgUser;
902 $sk = $wgUser->getSkin();
904 $this->setupPage( $term );
906 $wgOut->addWikiMsg( 'searchresulttext' );
908 if( '' === trim( $term ) ) {
909 // Empty query -- straight view of search form
910 $wgOut->setSubtitle( '' );
911 $wgOut->addHTML( $this->powerSearchBox( $term ) );
912 $wgOut->addHTML( $this->powerSearchFocus() );
913 wfProfileOut( __METHOD__
);
917 global $wgDisableTextSearch;
918 if ( $wgDisableTextSearch ) {
919 global $wgSearchForwardUrl;
920 if( $wgSearchForwardUrl ) {
921 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
922 $wgOut->redirect( $url );
925 global $wgInputEncoding;
927 Xml
::openElement( 'fieldset' ) .
928 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
929 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
930 wfMsg( 'googlesearch',
931 htmlspecialchars( $term ),
932 htmlspecialchars( $wgInputEncoding ),
933 htmlspecialchars( wfMsg( 'searchbutton' ) )
935 Xml
::closeElement( 'fieldset' )
937 wfProfileOut( __METHOD__
);
941 $wgOut->addHTML( $this->shortDialog( $term ) );
943 $search = SearchEngine
::create();
944 $search->setLimitOffset( $this->limit
, $this->offset
);
945 $search->setNamespaces( $this->namespaces
);
946 $search->showRedirects
= $this->searchRedirects
;
947 $rewritten = $search->replacePrefixes($term);
949 $titleMatches = $search->searchTitle( $rewritten );
951 // Sometimes the search engine knows there are too many hits
952 if ($titleMatches instanceof SearchResultTooMany
) {
953 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
954 $wgOut->addHTML( $this->powerSearchBox( $term ) );
955 $wgOut->addHTML( $this->powerSearchFocus() );
956 wfProfileOut( __METHOD__
);
960 $textMatches = $search->searchText( $rewritten );
962 // did you mean... suggestions
963 if($textMatches && $textMatches->hasSuggestion()){
964 $st = SpecialPage
::getTitleFor( 'Search' );
965 $stParams = wfArrayToCGI( array(
966 'search' => $textMatches->getSuggestionQuery(),
967 'fulltext' => wfMsg('search')),
968 $this->powerSearchOptions());
970 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
971 $textMatches->getSuggestionSnippet().'</a>';
973 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
976 // show number of results
977 $num = ( $titleMatches ?
$titleMatches->numRows() : 0 )
978 +
( $textMatches ?
$textMatches->numRows() : 0);
980 if($titleMatches && !is_null($titleMatches->getTotalHits()))
981 $totalNum +
= $titleMatches->getTotalHits();
982 if($textMatches && !is_null($textMatches->getTotalHits()))
983 $totalNum +
= $textMatches->getTotalHits();
985 if ( $totalNum > 0 ){
986 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
987 $this->offset+
1, $this->offset+
$num, $totalNum, $num );
988 } elseif ( $num >= $this->limit
) {
989 $top = wfShowingResults( $this->offset
, $this->limit
);
991 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $num );
993 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
997 if( $num ||
$this->offset
) {
998 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
999 SpecialPage
::getTitleFor( 'Search' ),
1001 $this->powerSearchOptions(),
1002 array( 'search' => $term ) ),
1003 ($num < $this->limit
) );
1004 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
1005 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
1007 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
1010 if( $titleMatches ) {
1011 if( $titleMatches->numRows() ) {
1012 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
1013 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
1015 $titleMatches->free();
1018 if( $textMatches ) {
1019 // output appropriate heading
1020 if( $textMatches->numRows() ) {
1022 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
1023 else // if no title matches the heading is redundant
1024 $wgOut->addHTML("<hr/>");
1025 } elseif( $num == 0 ) {
1026 # Don't show the 'no text matches' if we received title matches
1027 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
1029 // show interwiki results if any
1030 if( $textMatches->hasInterwikiResults() )
1031 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
1033 if( $textMatches->numRows() )
1034 $wgOut->addHTML( $this->showMatches( $textMatches ) );
1036 $textMatches->free();
1040 $wgOut->addWikiMsg( 'nonefound' );
1042 if( $num ||
$this->offset
) {
1043 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
1045 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1046 wfProfileOut( __METHOD__
);
1049 #------------------------------------------------------------------
1050 # Private methods below this line
1055 function setupPage( $term ) {
1057 if( !empty( $term ) ){
1058 $wgOut->setPageTitle( wfMsg( 'searchresults') );
1059 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
1061 $subtitlemsg = ( Title
::newFromText( $term ) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
1062 $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
1063 $wgOut->setArticleRelated( false );
1064 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1068 * Extract "power search" namespace settings from the request object,
1069 * returning a list of index numbers to search.
1071 * @param WebRequest $request
1075 function powerSearch( &$request ) {
1077 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1078 if( $request->getCheck( 'ns' . $ns ) ) {
1086 * Reconstruct the 'power search' options for links
1090 function powerSearchOptions() {
1092 foreach( $this->namespaces
as $n ) {
1093 $opt['ns' . $n] = 1;
1095 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
1100 * Show whole set of results
1102 * @param SearchResultSet $matches
1104 function showMatches( &$matches ) {
1105 wfProfileIn( __METHOD__
);
1108 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1112 $infoLine = $matches->getInfo();
1113 if( !is_null($infoLine) )
1114 $out .= "\n<!-- {$infoLine} -->\n";
1117 $off = $this->offset +
1;
1118 $out .= "<ul class='mw-search-results'>\n";
1120 while( $result = $matches->next() ) {
1121 $out .= $this->showHit( $result, $terms );
1125 // convert the whole thing to desired language variant
1127 $out = $wgContLang->convert( $out );
1128 wfProfileOut( __METHOD__
);
1133 * Format a single hit result
1134 * @param SearchResult $result
1135 * @param array $terms terms to highlight
1137 function showHit( $result, $terms ) {
1138 wfProfileIn( __METHOD__
);
1139 global $wgUser, $wgContLang, $wgLang;
1141 if( $result->isBrokenTitle() ) {
1142 wfProfileOut( __METHOD__
);
1143 return "<!-- Broken link in search result -->\n";
1146 $t = $result->getTitle();
1147 $sk = $wgUser->getSkin();
1149 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1151 //If page content is not readable, just return the title.
1152 //This is not quite safe, but better than showing excerpts from non-readable pages
1153 //Note that hiding the entry entirely would screw up paging.
1154 if (!$t->userCanRead()) {
1155 wfProfileOut( __METHOD__
);
1156 return "<li>{$link}</li>\n";
1159 // If the page doesn't *exist*... our search index is out of date.
1160 // The least confusing at this point is to drop the result.
1161 // You may get less results, but... oh well. :P
1162 if( $result->isMissingRevision() ) {
1163 wfProfileOut( __METHOD__
);
1164 return "<!-- missing page " .
1165 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
1168 // format redirects / relevant sections
1169 $redirectTitle = $result->getRedirectTitle();
1170 $redirectText = $result->getRedirectSnippet($terms);
1171 $sectionTitle = $result->getSectionTitle();
1172 $sectionText = $result->getSectionSnippet($terms);
1174 if( !is_null($redirectTitle) )
1175 $redirect = "<span class='searchalttitle'>"
1176 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1179 if( !is_null($sectionTitle) )
1180 $section = "<span class='searchalttitle'>"
1181 .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
1184 // format text extract
1185 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
1188 if( is_null( $result->getScore() ) ) {
1189 // Search engine doesn't report scoring info
1192 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
1193 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
1197 // format description
1198 $byteSize = $result->getByteSize();
1199 $wordCount = $result->getWordCount();
1200 $timestamp = $result->getTimestamp();
1201 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
1202 $sk->formatSize( $byteSize ),
1204 $date = $wgLang->timeanddate( $timestamp );
1206 // link to related articles if supported
1208 if( $result->hasRelated() ){
1209 $st = SpecialPage
::getTitleFor( 'Search' );
1210 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
1211 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
1212 'fulltext' => wfMsg('search') ));
1214 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
1215 wfMsg('search-relatedarticle').'</a>';
1218 // Include a thumbnail for media files...
1219 if( $t->getNamespace() == NS_IMAGE
) {
1220 $img = wfFindFile( $t );
1222 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
1224 $desc = $img->getShortDesc();
1225 wfProfileOut( __METHOD__
);
1227 // Float doesn't seem to interact well with the bullets.
1228 // Table messes up vertical alignment of the bullet, but I'm
1229 // not sure what more I can do about that. :(
1231 '<table class="searchResultImage">' .
1233 '<td width="120" align="center">' .
1234 $thumb->toHtml( array( 'desc-link' => true ) ) .
1236 '<td valign="top">' .
1239 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
1248 wfProfileOut( __METHOD__
);
1249 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
1250 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
1256 * Show results from other wikis
1258 * @param SearchResultSet $matches
1260 function showInterwiki( &$matches, $query ) {
1261 wfProfileIn( __METHOD__
);
1264 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1266 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
1267 $off = $this->offset +
1;
1268 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
1270 // work out custom project captions
1271 $customCaptions = array();
1272 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
1273 foreach($customLines as $line){
1274 $parts = explode(":",$line,2);
1275 if(count($parts) == 2) // validate line
1276 $customCaptions[$parts[0]] = $parts[1];
1281 while( $result = $matches->next() ) {
1282 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
1283 $prev = $result->getInterwikiPrefix();
1285 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
1286 $out .= "</ul></div>\n";
1288 // convert the whole thing to desired language variant
1290 $out = $wgContLang->convert( $out );
1291 wfProfileOut( __METHOD__
);
1296 * Show single interwiki link
1298 * @param SearchResult $result
1299 * @param string $lastInterwiki
1300 * @param array $terms
1301 * @param string $query
1302 * @param array $customCaptions iw prefix -> caption
1304 function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
1305 wfProfileIn( __METHOD__
);
1306 global $wgUser, $wgContLang, $wgLang;
1308 if( $result->isBrokenTitle() ) {
1309 wfProfileOut( __METHOD__
);
1310 return "<!-- Broken link in search result -->\n";
1313 $t = $result->getTitle();
1314 $sk = $wgUser->getSkin();
1316 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1318 // format redirect if any
1319 $redirectTitle = $result->getRedirectTitle();
1320 $redirectText = $result->getRedirectSnippet($terms);
1322 if( !is_null($redirectTitle) )
1323 $redirect = "<span class='searchalttitle'>"
1324 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1328 // display project name
1329 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()){
1330 if( key_exists($t->getInterwiki(),$customCaptions) )
1331 // captions from 'search-interwiki-custom'
1332 $caption = $customCaptions[$t->getInterwiki()];
1334 // default is to show the hostname of the other wiki which might suck
1335 // if there are many wikis on one hostname
1336 $parsed = parse_url($t->getFullURL());
1337 $caption = wfMsg('search-interwiki-default', $parsed['host']);
1339 // "more results" link (special page stuff could be localized, but we might not know target lang)
1340 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
1341 $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
1342 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
1343 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>{$searchLink}</span>{$caption}</div>\n<ul>";
1346 $out .= "<li>{$link} {$redirect}</li>\n";
1347 wfProfileOut( __METHOD__
);
1353 * Generates the power search box at bottom of [[Special:Search]]
1354 * @param $term string: search term
1355 * @return $out string: HTML form
1357 function powerSearchBox( $term ) {
1358 global $wgScript, $wgContLang;
1360 $namespaces = SearchEngine
::searchableNamespaces();
1362 // group namespaces into rows according to subject; try not to make too
1363 // many assumptions about namespace numbering
1365 foreach( $namespaces as $ns => $name ) {
1366 $subj = Namespace::getSubject( $ns );
1367 if( !array_key_exists( $subj, $rows ) ) {
1370 $name = str_replace( '_', ' ', $name );
1372 $name = wfMsg( 'blanknamespace' );
1374 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
1375 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
1376 Xml
::closeElement( 'td' ) . "\n";
1378 $rows = array_values( $rows );
1379 $numRows = count( $rows );
1381 // lay out namespaces in multiple floating two-column tables so they'll
1382 // be arranged nicely while still accommodating different screen widths
1383 $rowsPerTable = 3; // seems to look nice
1385 // float to the right on RTL wikis
1386 $tableStyle = ( $wgContLang->isRTL() ?
1387 'float: right; margin: 0 0 1em 1em' :
1388 'float: left; margin: 0 1em 1em 0' );
1391 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
1392 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
1393 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
1394 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
1396 $tables .= Xml
::closeElement( 'table' ) . "\n";
1399 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
1400 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
1401 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
1402 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
1403 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1405 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
1406 Xml
::fieldset( wfMsg( 'powersearch-legend' ),
1407 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
1409 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
1412 "<hr style=\"clear: both\" />\n" .
1414 $redirect . " " . $redirectLabel .
1416 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
1426 function powerSearchFocus() {
1427 global $wgJsMimeType;
1428 return "<script type=\"$wgJsMimeType\">" .
1429 "hookEvent(\"load\", function(){" .
1430 "document.getElementById('powerSearchText').focus();" .
1435 function shortDialog($term) {
1438 $out = Xml
::openElement( 'form', array(
1441 'action' => $wgScript
1443 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1444 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() );
1445 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . ' ';
1446 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1447 if( in_array( $ns, $this->namespaces
) ) {
1448 $out .= Xml
::hidden( "ns{$ns}", '1' );
1451 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
1452 $out .= Xml
::closeElement( 'form' );