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;
33 // Strip underscores from title parameter; most of the time we'll want
34 // text form here. But don't strip underscores from actual text params!
35 $titleParam = str_replace( '_', ' ', $par );
36 // Fetch the search term
37 $search = str_replace( "\n", " ", $wgRequest->getText( 'search', $titleParam ) );
38 $class = $wgUseOldSearchUI ?
'SpecialSearchOld' : 'SpecialSearch';
39 $searchPage = new $class( $wgRequest, $wgUser );
40 if( $wgRequest->getVal( 'fulltext' )
41 ||
!is_null( $wgRequest->getVal( 'offset' ))
42 ||
!is_null( $wgRequest->getVal( 'searchx' )) )
44 $searchPage->showResults( $search );
46 $searchPage->goResult( $search );
51 * implements Special:Search - Run text & title search and display the output
52 * @ingroup SpecialPage
57 * Set up basic search parameters from the request and user settings.
58 * Typically you'll pass $wgRequest and $wgUser.
60 * @param WebRequest $request
64 function __construct( &$request, &$user ) {
65 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
66 $this->mPrefix
= $request->getVal('prefix', '');
67 # Extract requested namespaces
68 $this->namespaces
= $this->powerSearch( $request );
69 if( empty( $this->namespaces
) ) {
70 $this->namespaces
= SearchEngine
::userNamespaces( $user );
72 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
73 $this->searchAdvanced
= $request->getVal( 'advanced' );
74 $this->active
= 'advanced';
75 $this->sk
= $user->getSkin();
76 $this->didYouMeanHtml
= ''; # html of did you mean... link
80 * If an exact title match can be found, jump straight ahead to it.
83 public function goResult( $term ) {
85 $this->setupPage( $term );
86 # Try to go to page as entered.
87 $t = Title
::newFromText( $term );
88 # If the string cannot be used to create a title
90 return $this->showResults( $term );
92 # If there's an exact or very near match, jump right there.
93 $t = SearchEngine
::getNearMatch( $term );
94 if( !is_null( $t ) ) {
95 $wgOut->redirect( $t->getFullURL() );
98 # No match, generate an edit URL
99 $t = Title
::newFromText( $term );
100 if( !is_null( $t ) ) {
102 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
103 # If the feature is enabled, go straight to the edit page
105 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
109 return $this->showResults( $term );
113 * @param string $term
115 public function showResults( $term ) {
116 global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang;
117 wfProfileIn( __METHOD__
);
119 $sk = $wgUser->getSkin();
121 $this->searchEngine
= SearchEngine
::create();
122 $search =& $this->searchEngine
;
123 $search->setLimitOffset( $this->limit
, $this->offset
);
124 $search->setNamespaces( $this->namespaces
);
125 $search->showRedirects
= $this->searchRedirects
;
126 $search->prefix
= $this->mPrefix
;
127 $term = $search->transformSearchTerm($term);
129 $this->setupPage( $term );
131 if( $wgDisableTextSearch ) {
132 global $wgSearchForwardUrl;
133 if( $wgSearchForwardUrl ) {
134 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
135 $wgOut->redirect( $url );
136 wfProfileOut( __METHOD__
);
139 global $wgInputEncoding;
141 Xml
::openElement( 'fieldset' ) .
142 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
143 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
144 wfMsg( 'googlesearch',
145 htmlspecialchars( $term ),
146 htmlspecialchars( $wgInputEncoding ),
147 htmlspecialchars( wfMsg( 'searchbutton' ) )
149 Xml
::closeElement( 'fieldset' )
151 wfProfileOut( __METHOD__
);
155 $t = Title
::newFromText( $term );
157 // fetch search results
158 $rewritten = $search->replacePrefixes($term);
160 $titleMatches = $search->searchTitle( $rewritten );
161 if( !($titleMatches instanceof SearchResultTooMany
))
162 $textMatches = $search->searchText( $rewritten );
164 // did you mean... suggestions
165 if( $textMatches && $textMatches->hasSuggestion() ) {
166 $st = SpecialPage
::getTitleFor( 'Search' );
167 $stParams = wfArrayToCGI(
168 array( 'search' => $textMatches->getSuggestionQuery(), 'fulltext' => wfMsg('search') ),
169 $this->powerSearchOptions()
171 $suggestLink = $sk->makeKnownLinkObj( $st,
172 $textMatches->getSuggestionSnippet(),
175 $this->didYouMeanHtml
= '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
178 // start rendering the page
180 Xml
::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
181 Xml
::openElement( 'tr' ) .
182 Xml
::openElement( 'td' ) . "\n" .
183 ( $this->searchAdvanced ?
$this->powerSearchBox( $term ) : $this->shortDialog( $term ) ) .
184 Xml
::closeElement('td') .
185 Xml
::closeElement('tr') .
186 Xml
::closeElement('table')
189 // Sometimes the search engine knows there are too many hits
190 if( $titleMatches instanceof SearchResultTooMany
) {
191 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
192 wfProfileOut( __METHOD__
);
196 $filePrefix = $wgContLang->getFormattedNsText(NS_FILE
).':';
197 if( '' === trim( $term ) ||
$filePrefix === trim( $term ) ) {
198 $wgOut->addHTML( $this->searchAdvanced ?
$this->powerSearchFocus() : $this->searchFocus() );
199 // Empty query -- straight view of search form
200 wfProfileOut( __METHOD__
);
204 // show direct page/create link
206 if( !$t->exists() ) {
207 $wgOut->addWikiMsg( 'searchmenu-new', wfEscapeWikiText( $t->getPrefixedText() ) );
209 $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) );
213 // Get number of results
214 $titleMatchesSQL = $titleMatches ?
$titleMatches->numRows() : 0;
215 $textMatchesSQL = $textMatches ?
$textMatches->numRows() : 0;
216 // Total initial query matches (possible false positives)
217 $numSQL = $titleMatchesSQL +
$textMatchesSQL;
218 // Get total actual results (after second filtering, if any)
219 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
220 $titleMatches->getTotalHits() : $titleMatchesSQL;
221 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
222 $textMatches->getTotalHits() : $textMatchesSQL;
223 $totalRes = $numTitleMatches +
$numTextMatches;
225 // show number of results and current offset
228 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
229 $this->offset+
1, $this->offset+
$numSQL, $totalRes, $numSQL );
230 } elseif( $numSQL >= $this->limit
) {
231 $top = wfShowingResults( $this->offset
, $this->limit
);
233 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $numSQL );
235 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
239 if( $numSQL ||
$this->offset
) {
240 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
241 SpecialPage
::getTitleFor( 'Search' ),
242 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
243 max( $titleMatchesSQL, $textMatchesSQL ) < $this->limit
245 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
246 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
248 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
251 $wgOut->addHtml( "<div class='searchresults'>" );
252 if( $titleMatches ) {
253 if( $numTitleMatches > 0 ) {
254 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
255 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
257 $titleMatches->free();
260 // output appropriate heading
261 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
262 // if no title matches the heading is redundant
263 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
264 } elseif( $totalRes == 0 ) {
265 # Don't show the 'no text matches' if we received title matches
266 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
268 // show interwiki results if any
269 if( $textMatches->hasInterwikiResults() ) {
270 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
273 if( $numTextMatches > 0 ) {
274 $wgOut->addHTML( $this->showMatches( $textMatches ) );
277 $textMatches->free();
279 if( $totalRes === 0 ) {
280 $wgOut->addWikiMsg( 'search-nonefound' );
282 $wgOut->addHtml( "</div>" );
283 if( $totalRes === 0 ) {
284 $wgOut->addHTML( $this->searchAdvanced ?
$this->powerSearchFocus() : $this->searchFocus() );
287 if( $numSQL ||
$this->offset
) {
288 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
290 wfProfileOut( __METHOD__
);
296 protected function setupPage( $term ) {
298 // Figure out the active search profile header
299 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
300 if( $this->searchAdvanced
)
301 $this->active
= 'advanced';
302 else if( $this->namespaces
=== NS_FILE ||
$this->startsWithImage( $term ) )
303 $this->active
= 'images';
304 elseif( $this->namespaces
=== $nsAllSet )
305 $this->active
= 'all';
306 elseif( $this->namespaces
=== SearchEngine
::defaultNamespaces() )
307 $this->active
= 'default';
308 elseif( $this->namespaces
=== SearchEngine
::projectNamespaces() )
309 $this->active
= 'project';
311 $this->active
= 'advanced';
312 # Should advanced UI be used?
313 $this->searchAdvanced
= ($this->active
=== 'advanced');
314 if( !empty( $term ) ) {
315 $wgOut->setPageTitle( wfMsg( 'searchresults') );
316 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
318 $wgOut->setArticleRelated( false );
319 $wgOut->setRobotPolicy( 'noindex,nofollow' );
323 * Extract "power search" namespace settings from the request object,
324 * returning a list of index numbers to search.
326 * @param WebRequest $request
329 protected function powerSearch( &$request ) {
331 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
332 if( $request->getCheck( 'ns' . $ns ) ) {
340 * Reconstruct the 'power search' options for links
343 protected function powerSearchOptions() {
345 foreach( $this->namespaces
as $n ) {
348 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
349 if( $this->searchAdvanced
) {
350 $opt['advanced'] = $this->searchAdvanced
;
356 * Show whole set of results
358 * @param SearchResultSet $matches
360 protected function showMatches( &$matches ) {
362 wfProfileIn( __METHOD__
);
364 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
367 $infoLine = $matches->getInfo();
368 if( !is_null($infoLine) ) {
369 $out .= "\n<!-- {$infoLine} -->\n";
371 $off = $this->offset +
1;
372 $out .= "<ul class='mw-search-results'>\n";
373 while( $result = $matches->next() ) {
374 $out .= $this->showHit( $result, $terms );
378 // convert the whole thing to desired language variant
379 $out = $wgContLang->convert( $out );
380 wfProfileOut( __METHOD__
);
385 * Format a single hit result
386 * @param SearchResult $result
387 * @param array $terms terms to highlight
389 protected function showHit( $result, $terms ) {
390 global $wgContLang, $wgLang, $wgUser;
391 wfProfileIn( __METHOD__
);
393 if( $result->isBrokenTitle() ) {
394 wfProfileOut( __METHOD__
);
395 return "<!-- Broken link in search result -->\n";
398 $sk = $wgUser->getSkin();
399 $t = $result->getTitle();
401 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
403 //If page content is not readable, just return the title.
404 //This is not quite safe, but better than showing excerpts from non-readable pages
405 //Note that hiding the entry entirely would screw up paging.
406 if( !$t->userCanRead() ) {
407 wfProfileOut( __METHOD__
);
408 return "<li>{$link}</li>\n";
411 // If the page doesn't *exist*... our search index is out of date.
412 // The least confusing at this point is to drop the result.
413 // You may get less results, but... oh well. :P
414 if( $result->isMissingRevision() ) {
415 wfProfileOut( __METHOD__
);
416 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
419 // format redirects / relevant sections
420 $redirectTitle = $result->getRedirectTitle();
421 $redirectText = $result->getRedirectSnippet($terms);
422 $sectionTitle = $result->getSectionTitle();
423 $sectionText = $result->getSectionSnippet($terms);
425 if( !is_null($redirectTitle) )
426 $redirect = "<span class='searchalttitle'>"
427 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
430 if( !is_null($sectionTitle) )
431 $section = "<span class='searchalttitle'>"
432 .wfMsg('search-section', $this->sk
->makeKnownLinkObj( $sectionTitle, $sectionText))
435 // format text extract
436 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
439 if( is_null( $result->getScore() ) ) {
440 // Search engine doesn't report scoring info
443 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
444 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
448 // format description
449 $byteSize = $result->getByteSize();
450 $wordCount = $result->getWordCount();
451 $timestamp = $result->getTimestamp();
452 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
453 $this->sk
->formatSize( $byteSize ), $wordCount );
454 $date = $wgLang->timeanddate( $timestamp );
456 // link to related articles if supported
458 if( $result->hasRelated() ) {
459 $st = SpecialPage
::getTitleFor( 'Search' );
460 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
461 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
462 'fulltext' => wfMsg('search') ));
464 $related = ' -- ' . $sk->makeKnownLinkObj( $st,
465 wfMsg('search-relatedarticle'), $stParams );
468 // Include a thumbnail for media files...
469 if( $t->getNamespace() == NS_FILE
) {
470 $img = wfFindFile( $t );
472 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
474 $desc = $img->getShortDesc();
475 wfProfileOut( __METHOD__
);
476 // Float doesn't seem to interact well with the bullets.
477 // Table messes up vertical alignment of the bullets.
478 // Bullets are therefore disabled (didn't look great anyway).
480 '<table class="searchResultImage">' .
482 '<td width="120" align="center" valign="top">' .
483 $thumb->toHtml( array( 'desc-link' => true ) ) .
485 '<td valign="top">' .
488 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
497 wfProfileOut( __METHOD__
);
498 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
499 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
505 * Show results from other wikis
507 * @param SearchResultSet $matches
509 protected function showInterwiki( &$matches, $query ) {
511 wfProfileIn( __METHOD__
);
512 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
514 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
515 wfMsg('search-interwiki-caption')."</div>\n";
516 $off = $this->offset +
1;
517 $out .= "<ul class='mw-search-iwresults'>\n";
519 // work out custom project captions
520 $customCaptions = array();
521 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
522 foreach($customLines as $line) {
523 $parts = explode(":",$line,2);
524 if(count($parts) == 2) // validate line
525 $customCaptions[$parts[0]] = $parts[1];
529 while( $result = $matches->next() ) {
530 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
531 $prev = $result->getInterwikiPrefix();
533 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
534 $out .= "</ul></div>\n";
536 // convert the whole thing to desired language variant
537 $out = $wgContLang->convert( $out );
538 wfProfileOut( __METHOD__
);
543 * Show single interwiki link
545 * @param SearchResult $result
546 * @param string $lastInterwiki
547 * @param array $terms
548 * @param string $query
549 * @param array $customCaptions iw prefix -> caption
551 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
552 wfProfileIn( __METHOD__
);
553 global $wgContLang, $wgLang;
555 if( $result->isBrokenTitle() ) {
556 wfProfileOut( __METHOD__
);
557 return "<!-- Broken link in search result -->\n";
560 $t = $result->getTitle();
562 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
564 // format redirect if any
565 $redirectTitle = $result->getRedirectTitle();
566 $redirectText = $result->getRedirectSnippet($terms);
568 if( !is_null($redirectTitle) )
569 $redirect = "<span class='searchalttitle'>"
570 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
574 // display project name
575 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
576 if( key_exists($t->getInterwiki(),$customCaptions) )
577 // captions from 'search-interwiki-custom'
578 $caption = $customCaptions[$t->getInterwiki()];
580 // default is to show the hostname of the other wiki which might suck
581 // if there are many wikis on one hostname
582 $parsed = parse_url($t->getFullURL());
583 $caption = wfMsg('search-interwiki-default', $parsed['host']);
585 // "more results" link (special page stuff could be localized, but we might not know target lang)
586 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
587 $searchLink = $this->sk
->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
588 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
589 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
590 {$searchLink}</span>{$caption}</div>\n<ul>";
593 $out .= "<li>{$link} {$redirect}</li>\n";
594 wfProfileOut( __METHOD__
);
600 * Generates the power search box at bottom of [[Special:Search]]
601 * @param $term string: search term
602 * @return $out string: HTML form
604 protected function powerSearchBox( $term ) {
607 $namespaces = SearchEngine
::searchableNamespaces();
609 $tables = $this->namespaceTables( $namespaces );
611 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
612 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
613 $searchField = Xml
::inputLabel( wfMsg('powersearch-field'), 'search', 'powerSearchText', 50, $term,
614 array( 'type' => 'text') );
615 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' )) . "\n";
616 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
619 // show redirects check only if backend supports it
620 if( $this->searchEngine
->acceptListRedirects() ) {
621 $redirectText = "<p>". $redirect . " " . $redirectLabel ."</p>";
624 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
625 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
627 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
629 '<input type="hidden" name="advanced" value="'.$this->searchAdvanced
."\"/>\n".
631 "<hr style=\"clear: both;\" />\n".
633 "<div style=\"padding-top:2px;padding-bottom:2px;\">".
636 Xml
::hidden( 'fulltext', 'Advanced search' ) . "\n" .
640 $t = Title
::newFromText( $term );
641 /* if( $t != null && count($this->namespaces) === 1 ) {
642 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
644 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
645 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
646 $this->formHeader($term) . $out . $this->didYouMeanHtml
.
647 Xml
::closeElement( 'fieldset' );
650 protected function searchFocus() {
651 global $wgJsMimeType;
652 return "<script type=\"$wgJsMimeType\">" .
653 "hookEvent(\"load\", function() {" .
654 "document.getElementById('searchText').focus();" .
659 protected function powerSearchFocus() {
660 global $wgJsMimeType;
661 return "<script type=\"$wgJsMimeType\">" .
662 "hookEvent(\"load\", function() {" .
663 "document.getElementById('powerSearchText').focus();" .
668 protected function formHeader( $term ) {
669 global $wgContLang, $wgCanonicalNamespaceNames;
671 $sep = ' ';
672 $out = Xml
::openElement('div', array( 'style' => 'padding-bottom:0.5em;' ) );
675 if( $this->startsWithImage( $term ) )
676 $bareterm = substr( $term, strpos( $term, ':' ) +
1 ); // delete all/image prefix
678 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
680 // search profiles headers
681 $m = wfMsg( 'searchprofile-articles' );
682 $tt = wfMsg( 'searchprofile-articles-tooltip',
683 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::defaultNamespaces() ) ) );
684 if( $this->active
== 'default' ) {
685 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
687 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::defaultNamespaces(), $m, $tt );
691 $m = wfMsg( 'searchprofile-images' );
692 $tt = wfMsg( 'searchprofile-images-tooltip' );
693 if( $this->active
== 'images' ) {
694 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
696 $imageTextForm = $wgContLang->getFormattedNsText(NS_FILE
).':'.$bareterm;
697 $out .= $this->makeSearchLink( $imageTextForm, array( NS_FILE
) , $m, $tt );
702 $m = wfMsg( 'searchprofile-articles-and-proj' );
703 $tt = wfMsg( 'searchprofile-project-tooltip',
704 implode( ', ', SearchEngine::namespacesAsText( SearchEngine::defaultAndProjectNamespaces() ) ) );
705 if( $this->active == 'withproject' ) {
706 $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
708 $out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultAndProjectNamespaces(), $m, $tt );
713 $m = wfMsg( 'searchprofile-project' );
714 $tt = wfMsg( 'searchprofile-project-tooltip',
715 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::projectNamespaces() ) ) );
716 if( $this->active
== 'project' ) {
717 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
719 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::projectNamespaces(), $m, $tt );
723 $m = wfMsg( 'searchprofile-everything' );
724 $tt = wfMsg( 'searchprofile-everything-tooltip' );
725 if( $this->active
== 'all' ) {
726 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
728 $out .= $this->makeSearchLink( $bareterm, $nsAllSet, $m, $tt );
732 $m = wfMsg( 'searchprofile-advanced' );
733 $tt = wfMsg( 'searchprofile-advanced-tooltip' );
734 if( $this->active
== 'advanced' ) {
735 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
737 $out .= $this->makeSearchLink( $bareterm, $this->namespaces
, $m, $tt, array( 'advanced' => '1' ) );
739 $out .= Xml
::closeElement('div') ;
744 protected function shortDialog( $term ) {
746 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
747 $searchable = SearchEngine
::searchableNamespaces();
748 $out = Xml
::openElement( 'form', array( 'id' => 'search', 'method' => 'get', 'action' => $wgScript ) );
749 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
750 // show namespaces only for advanced search
751 if( $this->active
== 'advanced' ) {
753 foreach( $this->namespaces
as $ns ) {
754 $active[$ns] = $searchable[$ns];
756 $out .= wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) . "<br/>\n";
757 $out .= $this->namespaceTables( $active, 1 )."<br/>\n";
758 // Still keep namespace settings otherwise, but don't show them
760 foreach( $this->namespaces
as $ns ) {
761 $out .= Xml
::hidden( "ns{$ns}", '1' );
764 // Keep redirect setting
765 $out .= Xml
::hidden( "redirs", (int)$this->searchRedirects
);
767 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
768 $out .= Xml
::hidden( 'fulltext', 'Search' );
769 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
770 $out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')';
771 $out .= Xml
::closeElement( 'form' );
772 // Add prefix link for single-namespace searches
773 $t = Title
::newFromText( $term );
774 /*if( $t != null && count($this->namespaces) === 1 ) {
775 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
777 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
778 Xml
::element( 'legend', null, wfMsg('searchmenu-legend') ) .
779 $this->formHeader($term) . $out . $this->didYouMeanHtml
.
780 Xml
::closeElement( 'fieldset' );
783 /** Make a search link with some target namespaces */
784 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
786 foreach( $namespaces as $n ) {
789 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
791 $st = SpecialPage
::getTitleFor( 'Search' );
792 $stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt );
794 return Xml
::element( 'a',
795 array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
799 /** Check if query starts with image: prefix */
800 protected function startsWithImage( $term ) {
803 $p = explode( ':', $term );
804 if( count( $p ) > 1 ) {
805 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
810 protected function namespaceTables( $namespaces, $rowsPerTable = 3 ) {
812 // Group namespaces into rows according to subject.
813 // Try not to make too many assumptions about namespace numbering.
816 foreach( $namespaces as $ns => $name ) {
817 $subj = MWNamespace
::getSubject( $ns );
818 if( !array_key_exists( $subj, $rows ) ) {
821 $name = str_replace( '_', ' ', $name );
823 $name = wfMsg( 'blanknamespace' );
825 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
826 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
827 Xml
::closeElement( 'td' ) . "\n";
829 $rows = array_values( $rows );
830 $numRows = count( $rows );
831 // Lay out namespaces in multiple floating two-column tables so they'll
832 // be arranged nicely while still accommodating different screen widths
833 // Float to the right on RTL wikis
834 $tableStyle = $wgContLang->isRTL() ?
835 'float: right; margin: 0 0 0em 1em' : 'float: left; margin: 0 1em 0em 0';
836 // Build the final HTML table...
837 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
838 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
839 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
840 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
842 $tables .= Xml
::closeElement( 'table' ) . "\n";
849 * implements Special:Search - Run text & title search and display the output
850 * @ingroup SpecialPage
852 class SpecialSearchOld
{
855 * Set up basic search parameters from the request and user settings.
856 * Typically you'll pass $wgRequest and $wgUser.
858 * @param WebRequest $request
862 function __construct( &$request, &$user ) {
863 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
864 $this->mPrefix
= $request->getVal('prefix', '');
865 $this->namespaces
= $this->powerSearch( $request );
866 if( empty( $this->namespaces
) ) {
867 $this->namespaces
= SearchEngine
::userNamespaces( $user );
870 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
874 * If an exact title match can be found, jump straight ahead to it.
875 * @param string $term
878 function goResult( $term ) {
882 $this->setupPage( $term );
884 # Try to go to page as entered.
885 $t = Title
::newFromText( $term );
887 # If the string cannot be used to create a title
889 return $this->showResults( $term );
892 # If there's an exact or very near match, jump right there.
893 $t = SearchEngine
::getNearMatch( $term );
894 if( !is_null( $t ) ) {
895 $wgOut->redirect( $t->getFullURL() );
899 # No match, generate an edit URL
900 $t = Title
::newFromText( $term );
901 if( ! is_null( $t ) ) {
902 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
903 # If the feature is enabled, go straight to the edit page
905 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
910 $extra = $wgOut->parse( '=='.wfMsgNoTrans( 'notitlematches' )."==\n" );
911 if( $t->quickUserCan( 'create' ) && $t->quickUserCan( 'edit' ) ) {
912 $extra .= wfMsgExt( 'noexactmatch', 'parse', wfEscapeWikiText( $term ) );
914 $extra .= wfMsgExt( 'noexactmatch-nocreate', 'parse', wfEscapeWikiText( $term ) );
917 $this->showResults( $term, $extra );
921 * @param string $term
922 * @param string $extra Extra HTML to add after "did you mean"
924 public function showResults( $term, $extra = '' ) {
925 wfProfileIn( __METHOD__
);
926 global $wgOut, $wgUser;
927 $sk = $wgUser->getSkin();
929 $search = SearchEngine
::create();
930 $search->setLimitOffset( $this->limit
, $this->offset
);
931 $search->setNamespaces( $this->namespaces
);
932 $search->showRedirects
= $this->searchRedirects
;
933 $search->prefix
= $this->mPrefix
;
934 $term = $search->transformSearchTerm($term);
936 $this->setupPage( $term );
938 $rewritten = $search->replacePrefixes($term);
939 $titleMatches = $search->searchTitle( $rewritten );
940 $textMatches = $search->searchText( $rewritten );
942 // did you mean... suggestions
943 if($textMatches && $textMatches->hasSuggestion()){
944 $st = SpecialPage
::getTitleFor( 'Search' );
945 $stParams = wfArrayToCGI( array(
946 'search' => $textMatches->getSuggestionQuery(),
947 'fulltext' => wfMsg('search')),
948 $this->powerSearchOptions());
950 $suggestLink = $sk->makeKnownLinkObj( $st,
951 $textMatches->getSuggestionSnippet(),
954 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
957 $wgOut->addHTML( $extra );
959 $wgOut->wrapWikiMsg( "<div class='mw-searchresult'>\n$1</div>", 'searchresulttext' );
961 if( '' === trim( $term ) ) {
962 // Empty query -- straight view of search form
963 $wgOut->setSubtitle( '' );
964 $wgOut->addHTML( $this->powerSearchBox( $term ) );
965 $wgOut->addHTML( $this->powerSearchFocus() );
966 wfProfileOut( __METHOD__
);
970 global $wgDisableTextSearch;
971 if ( $wgDisableTextSearch ) {
972 global $wgSearchForwardUrl;
973 if( $wgSearchForwardUrl ) {
974 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
975 $wgOut->redirect( $url );
976 wfProfileOut( __METHOD__
);
979 global $wgInputEncoding;
981 Xml
::openElement( 'fieldset' ) .
982 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
983 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
984 wfMsg( 'googlesearch',
985 htmlspecialchars( $term ),
986 htmlspecialchars( $wgInputEncoding ),
987 htmlspecialchars( wfMsg( 'searchbutton' ) )
989 Xml
::closeElement( 'fieldset' )
991 wfProfileOut( __METHOD__
);
995 $wgOut->addHTML( $this->shortDialog( $term ) );
997 // Sometimes the search engine knows there are too many hits
998 if ($titleMatches instanceof SearchResultTooMany
) {
999 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
1000 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1001 $wgOut->addHTML( $this->powerSearchFocus() );
1002 wfProfileOut( __METHOD__
);
1006 // show number of results
1007 $num = ( $titleMatches ?
$titleMatches->numRows() : 0 )
1008 +
( $textMatches ?
$textMatches->numRows() : 0);
1010 if($titleMatches && !is_null($titleMatches->getTotalHits()))
1011 $totalNum +
= $titleMatches->getTotalHits();
1012 if($textMatches && !is_null($textMatches->getTotalHits()))
1013 $totalNum +
= $textMatches->getTotalHits();
1015 if ( $totalNum > 0 ){
1016 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
1017 $this->offset+
1, $this->offset+
$num, $totalNum, $num );
1018 } elseif ( $num >= $this->limit
) {
1019 $top = wfShowingResults( $this->offset
, $this->limit
);
1021 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $num );
1023 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
1027 if( $num ||
$this->offset
) {
1028 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
1029 SpecialPage
::getTitleFor( 'Search' ),
1031 $this->powerSearchOptions(),
1032 array( 'search' => $term ) ),
1033 ($num < $this->limit
) );
1034 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
1035 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
1037 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
1040 if( $titleMatches ) {
1041 if( $titleMatches->numRows() ) {
1042 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
1043 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
1045 $titleMatches->free();
1048 if( $textMatches ) {
1049 // output appropriate heading
1050 if( $textMatches->numRows() ) {
1052 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
1053 else // if no title matches the heading is redundant
1054 $wgOut->addHTML("<hr/>");
1055 } elseif( $num == 0 ) {
1056 # Don't show the 'no text matches' if we received title matches
1057 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
1059 // show interwiki results if any
1060 if( $textMatches->hasInterwikiResults() )
1061 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
1063 if( $textMatches->numRows() )
1064 $wgOut->addHTML( $this->showMatches( $textMatches ) );
1066 $textMatches->free();
1070 $wgOut->addWikiMsg( 'nonefound' );
1072 if( $num ||
$this->offset
) {
1073 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
1075 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1076 wfProfileOut( __METHOD__
);
1079 #------------------------------------------------------------------
1080 # Private methods below this line
1085 function setupPage( $term ) {
1087 if( !empty( $term ) ){
1088 $wgOut->setPageTitle( wfMsg( 'searchresults') );
1089 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
1091 $subtitlemsg = ( Title
::newFromText( $term ) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
1092 $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
1093 $wgOut->setArticleRelated( false );
1094 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1098 * Extract "power search" namespace settings from the request object,
1099 * returning a list of index numbers to search.
1101 * @param WebRequest $request
1105 function powerSearch( &$request ) {
1107 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1108 if( $request->getCheck( 'ns' . $ns ) ) {
1116 * Reconstruct the 'power search' options for links
1120 function powerSearchOptions() {
1122 foreach( $this->namespaces
as $n ) {
1123 $opt['ns' . $n] = 1;
1125 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
1130 * Show whole set of results
1132 * @param SearchResultSet $matches
1134 function showMatches( &$matches ) {
1135 wfProfileIn( __METHOD__
);
1138 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1142 $infoLine = $matches->getInfo();
1143 if( !is_null($infoLine) )
1144 $out .= "\n<!-- {$infoLine} -->\n";
1147 $off = $this->offset +
1;
1148 $out .= "<ul class='mw-search-results'>\n";
1150 while( $result = $matches->next() ) {
1151 $out .= $this->showHit( $result, $terms );
1155 // convert the whole thing to desired language variant
1157 $out = $wgContLang->convert( $out );
1158 wfProfileOut( __METHOD__
);
1163 * Format a single hit result
1164 * @param SearchResult $result
1165 * @param array $terms terms to highlight
1167 function showHit( $result, $terms ) {
1168 wfProfileIn( __METHOD__
);
1169 global $wgUser, $wgContLang, $wgLang;
1171 if( $result->isBrokenTitle() ) {
1172 wfProfileOut( __METHOD__
);
1173 return "<!-- Broken link in search result -->\n";
1176 $t = $result->getTitle();
1177 $sk = $wgUser->getSkin();
1179 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1181 //If page content is not readable, just return the title.
1182 //This is not quite safe, but better than showing excerpts from non-readable pages
1183 //Note that hiding the entry entirely would screw up paging.
1184 if (!$t->userCanRead()) {
1185 wfProfileOut( __METHOD__
);
1186 return "<li>{$link}</li>\n";
1189 // If the page doesn't *exist*... our search index is out of date.
1190 // The least confusing at this point is to drop the result.
1191 // You may get less results, but... oh well. :P
1192 if( $result->isMissingRevision() ) {
1193 wfProfileOut( __METHOD__
);
1194 return "<!-- missing page " .
1195 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
1198 // format redirects / relevant sections
1199 $redirectTitle = $result->getRedirectTitle();
1200 $redirectText = $result->getRedirectSnippet($terms);
1201 $sectionTitle = $result->getSectionTitle();
1202 $sectionText = $result->getSectionSnippet($terms);
1204 if( !is_null($redirectTitle) )
1205 $redirect = "<span class='searchalttitle'>"
1206 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1209 if( !is_null($sectionTitle) )
1210 $section = "<span class='searchalttitle'>"
1211 .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
1214 // format text extract
1215 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
1218 if( is_null( $result->getScore() ) ) {
1219 // Search engine doesn't report scoring info
1222 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
1223 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
1227 // format description
1228 $byteSize = $result->getByteSize();
1229 $wordCount = $result->getWordCount();
1230 $timestamp = $result->getTimestamp();
1231 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
1232 $sk->formatSize( $byteSize ),
1234 $date = $wgLang->timeanddate( $timestamp );
1236 // link to related articles if supported
1238 if( $result->hasRelated() ){
1239 $st = SpecialPage
::getTitleFor( 'Search' );
1240 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
1241 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
1242 'fulltext' => wfMsg('search') ));
1244 $related = ' -- ' . $sk->makeKnownLinkObj( $st,
1245 wfMsg('search-relatedarticle'), $stParams );
1248 // Include a thumbnail for media files...
1249 if( $t->getNamespace() == NS_FILE
) {
1250 $img = wfFindFile( $t );
1252 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
1254 $desc = $img->getShortDesc();
1255 wfProfileOut( __METHOD__
);
1257 // Float doesn't seem to interact well with the bullets.
1258 // Table messes up vertical alignment of the bullet, but I'm
1259 // not sure what more I can do about that. :(
1261 '<table class="searchResultImage">' .
1263 '<td width="120" align="center">' .
1264 $thumb->toHtml( array( 'desc-link' => true ) ) .
1266 '<td valign="top">' .
1269 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
1278 wfProfileOut( __METHOD__
);
1279 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
1280 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
1286 * Show results from other wikis
1288 * @param SearchResultSet $matches
1290 function showInterwiki( &$matches, $query ) {
1291 wfProfileIn( __METHOD__
);
1294 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1296 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
1297 $off = $this->offset +
1;
1298 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
1300 // work out custom project captions
1301 $customCaptions = array();
1302 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
1303 foreach($customLines as $line){
1304 $parts = explode(":",$line,2);
1305 if(count($parts) == 2) // validate line
1306 $customCaptions[$parts[0]] = $parts[1];
1311 while( $result = $matches->next() ) {
1312 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
1313 $prev = $result->getInterwikiPrefix();
1315 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
1316 $out .= "</ul></div>\n";
1318 // convert the whole thing to desired language variant
1320 $out = $wgContLang->convert( $out );
1321 wfProfileOut( __METHOD__
);
1326 * Show single interwiki link
1328 * @param SearchResult $result
1329 * @param string $lastInterwiki
1330 * @param array $terms
1331 * @param string $query
1332 * @param array $customCaptions iw prefix -> caption
1334 function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
1335 wfProfileIn( __METHOD__
);
1336 global $wgUser, $wgContLang, $wgLang;
1338 if( $result->isBrokenTitle() ) {
1339 wfProfileOut( __METHOD__
);
1340 return "<!-- Broken link in search result -->\n";
1343 $t = $result->getTitle();
1344 $sk = $wgUser->getSkin();
1346 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1348 // format redirect if any
1349 $redirectTitle = $result->getRedirectTitle();
1350 $redirectText = $result->getRedirectSnippet($terms);
1352 if( !is_null($redirectTitle) )
1353 $redirect = "<span class='searchalttitle'>"
1354 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1358 // display project name
1359 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()){
1360 if( key_exists($t->getInterwiki(),$customCaptions) )
1361 // captions from 'search-interwiki-custom'
1362 $caption = $customCaptions[$t->getInterwiki()];
1364 // default is to show the hostname of the other wiki which might suck
1365 // if there are many wikis on one hostname
1366 $parsed = parse_url($t->getFullURL());
1367 $caption = wfMsg('search-interwiki-default', $parsed['host']);
1369 // "more results" link (special page stuff could be localized, but we might not know target lang)
1370 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
1371 $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
1372 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
1373 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>{$searchLink}</span>{$caption}</div>\n<ul>";
1376 $out .= "<li>{$link} {$redirect}</li>\n";
1377 wfProfileOut( __METHOD__
);
1383 * Generates the power search box at bottom of [[Special:Search]]
1384 * @param $term string: search term
1385 * @return $out string: HTML form
1387 function powerSearchBox( $term ) {
1388 global $wgScript, $wgContLang;
1390 $namespaces = SearchEngine
::searchableNamespaces();
1392 // group namespaces into rows according to subject; try not to make too
1393 // many assumptions about namespace numbering
1395 foreach( $namespaces as $ns => $name ) {
1396 $subj = MWNamespace
::getSubject( $ns );
1397 if( !array_key_exists( $subj, $rows ) ) {
1400 $name = str_replace( '_', ' ', $name );
1402 $name = wfMsg( 'blanknamespace' );
1404 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
1405 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
1406 Xml
::closeElement( 'td' ) . "\n";
1408 $rows = array_values( $rows );
1409 $numRows = count( $rows );
1411 // lay out namespaces in multiple floating two-column tables so they'll
1412 // be arranged nicely while still accommodating different screen widths
1413 $rowsPerTable = 3; // seems to look nice
1415 // float to the right on RTL wikis
1416 $tableStyle = ( $wgContLang->isRTL() ?
1417 'float: right; margin: 0 0 1em 1em' :
1418 'float: left; margin: 0 1em 1em 0' );
1421 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
1422 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
1423 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
1424 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
1426 $tables .= Xml
::closeElement( 'table' ) . "\n";
1429 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
1430 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
1431 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
1432 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
1433 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1434 $searchHiddens = Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
1435 $searchHiddens .= Xml
::hidden( 'fulltext', 'Advanced search' ) . "\n";
1437 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
1438 Xml
::fieldset( wfMsg( 'powersearch-legend' ),
1440 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
1443 "<hr style=\"clear: both\" />\n" .
1445 $redirect . " " . $redirectLabel .
1447 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
1458 function powerSearchFocus() {
1459 global $wgJsMimeType;
1460 return "<script type=\"$wgJsMimeType\">" .
1461 "hookEvent(\"load\", function(){" .
1462 "document.getElementById('powerSearchText').focus();" .
1467 function shortDialog($term) {
1470 $out = Xml
::openElement( 'form', array(
1473 'action' => $wgScript
1475 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1476 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . ' ';
1477 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1478 if( in_array( $ns, $this->namespaces
) ) {
1479 $out .= Xml
::hidden( "ns{$ns}", '1' );
1482 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() );
1483 $out .= Xml
::hidden( 'fulltext', 'Search' );
1484 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
1485 $out .= Xml
::closeElement( 'form' );