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
77 $this->fulltext
= $request->getVal('fulltext');
81 * If an exact title match can be found, jump straight ahead to it.
84 public function goResult( $term ) {
86 $this->setupPage( $term );
87 # Try to go to page as entered.
88 $t = Title
::newFromText( $term );
89 # If the string cannot be used to create a title
91 return $this->showResults( $term );
93 # If there's an exact or very near match, jump right there.
94 $t = SearchEngine
::getNearMatch( $term );
95 if( !is_null( $t ) ) {
96 $wgOut->redirect( $t->getFullURL() );
99 # No match, generate an edit URL
100 $t = Title
::newFromText( $term );
101 if( !is_null( $t ) ) {
103 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
104 # If the feature is enabled, go straight to the edit page
106 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
110 return $this->showResults( $term );
114 * @param string $term
116 public function showResults( $term ) {
117 global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang;
118 wfProfileIn( __METHOD__
);
120 $sk = $wgUser->getSkin();
122 $this->searchEngine
= SearchEngine
::create();
123 $search =& $this->searchEngine
;
124 $search->setLimitOffset( $this->limit
, $this->offset
);
125 $search->setNamespaces( $this->namespaces
);
126 $search->showRedirects
= $this->searchRedirects
;
127 $search->prefix
= $this->mPrefix
;
128 $term = $search->transformSearchTerm($term);
130 $this->setupPage( $term );
132 if( $wgDisableTextSearch ) {
133 global $wgSearchForwardUrl;
134 if( $wgSearchForwardUrl ) {
135 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
136 $wgOut->redirect( $url );
137 wfProfileOut( __METHOD__
);
140 global $wgInputEncoding;
142 Xml
::openElement( 'fieldset' ) .
143 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
144 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
145 wfMsg( 'googlesearch',
146 htmlspecialchars( $term ),
147 htmlspecialchars( $wgInputEncoding ),
148 htmlspecialchars( wfMsg( 'searchbutton' ) )
150 Xml
::closeElement( 'fieldset' )
152 wfProfileOut( __METHOD__
);
156 $t = Title
::newFromText( $term );
158 // fetch search results
159 $rewritten = $search->replacePrefixes($term);
161 $titleMatches = $search->searchTitle( $rewritten );
162 if( !($titleMatches instanceof SearchResultTooMany
))
163 $textMatches = $search->searchText( $rewritten );
165 // did you mean... suggestions
166 if( $textMatches && $textMatches->hasSuggestion() ) {
167 $st = SpecialPage
::getTitleFor( 'Search' );
168 # mirror Go/Search behaviour of original request ..
169 $didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
170 if($this->fulltext
!= NULL)
171 $didYouMeanParams['fulltext'] = $this->fulltext
;
172 $stParams = wfArrayToCGI(
174 $this->powerSearchOptions()
176 $suggestLink = $sk->makeKnownLinkObj( $st,
177 $textMatches->getSuggestionSnippet(),
180 $this->didYouMeanHtml
= '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
183 // start rendering the page
185 Xml
::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
186 Xml
::openElement( 'tr' ) .
187 Xml
::openElement( 'td' ) . "\n" .
188 ( $this->searchAdvanced ?
$this->powerSearchBox( $term ) : $this->shortDialog( $term ) ) .
189 Xml
::closeElement('td') .
190 Xml
::closeElement('tr') .
191 Xml
::closeElement('table')
194 // Sometimes the search engine knows there are too many hits
195 if( $titleMatches instanceof SearchResultTooMany
) {
196 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
197 wfProfileOut( __METHOD__
);
201 $filePrefix = $wgContLang->getFormattedNsText(NS_FILE
).':';
202 if( '' === trim( $term ) ||
$filePrefix === trim( $term ) ) {
203 $wgOut->addHTML( $this->searchAdvanced ?
$this->powerSearchFocus() : $this->searchFocus() );
204 // Empty query -- straight view of search form
205 wfProfileOut( __METHOD__
);
209 // show direct page/create link
211 if( !$t->exists() ) {
212 $wgOut->addWikiMsg( 'searchmenu-new', wfEscapeWikiText( $t->getPrefixedText() ) );
214 $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) );
218 // Get number of results
219 $titleMatchesSQL = $titleMatches ?
$titleMatches->numRows() : 0;
220 $textMatchesSQL = $textMatches ?
$textMatches->numRows() : 0;
221 // Total initial query matches (possible false positives)
222 $numSQL = $titleMatchesSQL +
$textMatchesSQL;
223 // Get total actual results (after second filtering, if any)
224 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
225 $titleMatches->getTotalHits() : $titleMatchesSQL;
226 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
227 $textMatches->getTotalHits() : $textMatchesSQL;
228 $totalRes = $numTitleMatches +
$numTextMatches;
230 // show number of results and current offset
233 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
234 $this->offset+
1, $this->offset+
$numSQL, $totalRes, $numSQL );
235 } elseif( $numSQL >= $this->limit
) {
236 $top = wfShowingResults( $this->offset
, $this->limit
);
238 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $numSQL );
240 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
244 if( $numSQL ||
$this->offset
) {
245 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
246 SpecialPage
::getTitleFor( 'Search' ),
247 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
248 max( $titleMatchesSQL, $textMatchesSQL ) < $this->limit
250 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
251 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
253 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
256 $wgOut->addHtml( "<div class='searchresults'>" );
257 if( $titleMatches ) {
258 if( $numTitleMatches > 0 ) {
259 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
260 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
262 $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( $totalRes == 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 ) );
278 if( $numTextMatches > 0 ) {
279 $wgOut->addHTML( $this->showMatches( $textMatches ) );
282 $textMatches->free();
284 if( $totalRes === 0 ) {
285 $wgOut->addWikiMsg( 'search-nonefound' );
287 $wgOut->addHtml( "</div>" );
288 if( $totalRes === 0 ) {
289 $wgOut->addHTML( $this->searchAdvanced ?
$this->powerSearchFocus() : $this->searchFocus() );
292 if( $numSQL ||
$this->offset
) {
293 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
295 wfProfileOut( __METHOD__
);
301 protected function setupPage( $term ) {
303 // Figure out the active search profile header
304 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
305 if( $this->searchAdvanced
)
306 $this->active
= 'advanced';
307 else if( $this->namespaces
=== NS_FILE ||
$this->startsWithImage( $term ) )
308 $this->active
= 'images';
309 elseif( $this->namespaces
=== $nsAllSet )
310 $this->active
= 'all';
311 elseif( $this->namespaces
=== SearchEngine
::defaultNamespaces() )
312 $this->active
= 'default';
313 elseif( $this->namespaces
=== SearchEngine
::projectNamespaces() )
314 $this->active
= 'project';
316 $this->active
= 'advanced';
317 # Should advanced UI be used?
318 $this->searchAdvanced
= ($this->active
=== 'advanced');
319 if( !empty( $term ) ) {
320 $wgOut->setPageTitle( wfMsg( 'searchresults') );
321 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
323 $wgOut->setArticleRelated( false );
324 $wgOut->setRobotPolicy( 'noindex,nofollow' );
328 * Extract "power search" namespace settings from the request object,
329 * returning a list of index numbers to search.
331 * @param WebRequest $request
334 protected function powerSearch( &$request ) {
336 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
337 if( $request->getCheck( 'ns' . $ns ) ) {
345 * Reconstruct the 'power search' options for links
348 protected function powerSearchOptions() {
350 foreach( $this->namespaces
as $n ) {
353 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
354 if( $this->searchAdvanced
) {
355 $opt['advanced'] = $this->searchAdvanced
;
361 * Show whole set of results
363 * @param SearchResultSet $matches
365 protected function showMatches( &$matches ) {
367 wfProfileIn( __METHOD__
);
369 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
372 $infoLine = $matches->getInfo();
373 if( !is_null($infoLine) ) {
374 $out .= "\n<!-- {$infoLine} -->\n";
376 $off = $this->offset +
1;
377 $out .= "<ul class='mw-search-results'>\n";
378 while( $result = $matches->next() ) {
379 $out .= $this->showHit( $result, $terms );
383 // convert the whole thing to desired language variant
384 $out = $wgContLang->convert( $out );
385 wfProfileOut( __METHOD__
);
390 * Format a single hit result
391 * @param SearchResult $result
392 * @param array $terms terms to highlight
394 protected function showHit( $result, $terms ) {
395 global $wgContLang, $wgLang, $wgUser;
396 wfProfileIn( __METHOD__
);
398 if( $result->isBrokenTitle() ) {
399 wfProfileOut( __METHOD__
);
400 return "<!-- Broken link in search result -->\n";
403 $sk = $wgUser->getSkin();
404 $t = $result->getTitle();
406 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
408 //If page content is not readable, just return the title.
409 //This is not quite safe, but better than showing excerpts from non-readable pages
410 //Note that hiding the entry entirely would screw up paging.
411 if( !$t->userCanRead() ) {
412 wfProfileOut( __METHOD__
);
413 return "<li>{$link}</li>\n";
416 // If the page doesn't *exist*... our search index is out of date.
417 // The least confusing at this point is to drop the result.
418 // You may get less results, but... oh well. :P
419 if( $result->isMissingRevision() ) {
420 wfProfileOut( __METHOD__
);
421 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
424 // format redirects / relevant sections
425 $redirectTitle = $result->getRedirectTitle();
426 $redirectText = $result->getRedirectSnippet($terms);
427 $sectionTitle = $result->getSectionTitle();
428 $sectionText = $result->getSectionSnippet($terms);
430 if( !is_null($redirectTitle) )
431 $redirect = "<span class='searchalttitle'>"
432 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
435 if( !is_null($sectionTitle) )
436 $section = "<span class='searchalttitle'>"
437 .wfMsg('search-section', $this->sk
->makeKnownLinkObj( $sectionTitle, $sectionText))
440 // format text extract
441 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
444 if( is_null( $result->getScore() ) ) {
445 // Search engine doesn't report scoring info
448 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
449 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
453 // format description
454 $byteSize = $result->getByteSize();
455 $wordCount = $result->getWordCount();
456 $timestamp = $result->getTimestamp();
457 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
458 $this->sk
->formatSize( $byteSize ), $wordCount );
459 $date = $wgLang->timeanddate( $timestamp );
461 // link to related articles if supported
463 if( $result->hasRelated() ) {
464 $st = SpecialPage
::getTitleFor( 'Search' );
465 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
466 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
467 'fulltext' => wfMsg('search') ));
469 $related = ' -- ' . $sk->makeKnownLinkObj( $st,
470 wfMsg('search-relatedarticle'), $stParams );
473 // Include a thumbnail for media files...
474 if( $t->getNamespace() == NS_FILE
) {
475 $img = wfFindFile( $t );
477 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
479 $desc = $img->getShortDesc();
480 wfProfileOut( __METHOD__
);
481 // Float doesn't seem to interact well with the bullets.
482 // Table messes up vertical alignment of the bullets.
483 // Bullets are therefore disabled (didn't look great anyway).
485 '<table class="searchResultImage">' .
487 '<td width="120" align="center" valign="top">' .
488 $thumb->toHtml( array( 'desc-link' => true ) ) .
490 '<td valign="top">' .
493 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
502 wfProfileOut( __METHOD__
);
503 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
504 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
510 * Show results from other wikis
512 * @param SearchResultSet $matches
514 protected function showInterwiki( &$matches, $query ) {
516 wfProfileIn( __METHOD__
);
517 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
519 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
520 wfMsg('search-interwiki-caption')."</div>\n";
521 $off = $this->offset +
1;
522 $out .= "<ul class='mw-search-iwresults'>\n";
524 // work out custom project captions
525 $customCaptions = array();
526 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
527 foreach($customLines as $line) {
528 $parts = explode(":",$line,2);
529 if(count($parts) == 2) // validate line
530 $customCaptions[$parts[0]] = $parts[1];
534 while( $result = $matches->next() ) {
535 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
536 $prev = $result->getInterwikiPrefix();
538 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
539 $out .= "</ul></div>\n";
541 // convert the whole thing to desired language variant
542 $out = $wgContLang->convert( $out );
543 wfProfileOut( __METHOD__
);
548 * Show single interwiki link
550 * @param SearchResult $result
551 * @param string $lastInterwiki
552 * @param array $terms
553 * @param string $query
554 * @param array $customCaptions iw prefix -> caption
556 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
557 wfProfileIn( __METHOD__
);
558 global $wgContLang, $wgLang;
560 if( $result->isBrokenTitle() ) {
561 wfProfileOut( __METHOD__
);
562 return "<!-- Broken link in search result -->\n";
565 $t = $result->getTitle();
567 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
569 // format redirect if any
570 $redirectTitle = $result->getRedirectTitle();
571 $redirectText = $result->getRedirectSnippet($terms);
573 if( !is_null($redirectTitle) )
574 $redirect = "<span class='searchalttitle'>"
575 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
579 // display project name
580 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
581 if( key_exists($t->getInterwiki(),$customCaptions) )
582 // captions from 'search-interwiki-custom'
583 $caption = $customCaptions[$t->getInterwiki()];
585 // default is to show the hostname of the other wiki which might suck
586 // if there are many wikis on one hostname
587 $parsed = parse_url($t->getFullURL());
588 $caption = wfMsg('search-interwiki-default', $parsed['host']);
590 // "more results" link (special page stuff could be localized, but we might not know target lang)
591 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
592 $searchLink = $this->sk
->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
593 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
594 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
595 {$searchLink}</span>{$caption}</div>\n<ul>";
598 $out .= "<li>{$link} {$redirect}</li>\n";
599 wfProfileOut( __METHOD__
);
605 * Generates the power search box at bottom of [[Special:Search]]
606 * @param $term string: search term
607 * @return $out string: HTML form
609 protected function powerSearchBox( $term ) {
612 $namespaces = SearchEngine
::searchableNamespaces();
614 $tables = $this->namespaceTables( $namespaces );
616 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
617 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
618 $searchField = Xml
::inputLabel( wfMsg('powersearch-field'), 'search', 'powerSearchText', 50, $term,
619 array( 'type' => 'text') );
620 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ) ) . "\n";
621 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
624 // show redirects check only if backend supports it
625 if( $this->searchEngine
->acceptListRedirects() ) {
626 $redirectText = "<p>". $redirect . " " . $redirectLabel ."</p>";
629 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
630 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
632 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
634 '<input type="hidden" name="advanced" value="'.$this->searchAdvanced
."\"/>\n".
636 "<hr style=\"clear: both;\" />\n".
638 "<div style=\"padding-top:2px;padding-bottom:2px;\">".
641 Xml
::hidden( 'fulltext', 'Advanced search' ) . "\n" .
645 $t = Title
::newFromText( $term );
646 /* if( $t != null && count($this->namespaces) === 1 ) {
647 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
649 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
650 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
651 $this->formHeader($term) . $out . $this->didYouMeanHtml
.
652 Xml
::closeElement( 'fieldset' );
655 protected function searchFocus() {
656 global $wgJsMimeType;
657 return "<script type=\"$wgJsMimeType\">" .
658 "hookEvent(\"load\", function() {" .
659 "document.getElementById('searchText').focus();" .
664 protected function powerSearchFocus() {
665 global $wgJsMimeType;
666 return "<script type=\"$wgJsMimeType\">" .
667 "hookEvent(\"load\", function() {" .
668 "document.getElementById('powerSearchText').focus();" .
673 protected function formHeader( $term ) {
674 global $wgContLang, $wgCanonicalNamespaceNames, $wgLang;
676 $sep = ' ';
677 $out = Xml
::openElement('div', array( 'style' => 'padding-bottom:0.5em;' ) );
680 if( $this->startsWithImage( $term ) )
681 $bareterm = substr( $term, strpos( $term, ':' ) +
1 ); // delete all/image prefix
683 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
685 // search profiles headers
686 $m = wfMsg( 'searchprofile-articles' );
687 $tt = wfMsg( 'searchprofile-articles-tooltip',
688 $wgLang->commaList( SearchEngine
::namespacesAsText( SearchEngine
::defaultNamespaces() ) ) );
689 $tt = Sanitizer
::decodeCharReferences( $tt ); // need to allow entities
690 if( $this->active
== 'default' ) {
691 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
693 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::defaultNamespaces(), $m, $tt );
697 $m = wfMsg( 'searchprofile-images' );
698 $tt = wfMsg( 'searchprofile-images-tooltip' );
699 if( $this->active
== 'images' ) {
700 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
702 $imageTextForm = $wgContLang->getFormattedNsText(NS_FILE
).':'.$bareterm;
703 $out .= $this->makeSearchLink( $imageTextForm, array( NS_FILE
) , $m, $tt );
707 $m = wfMsg( 'searchprofile-project' );
708 $tt = wfMsg( 'searchprofile-project-tooltip',
709 $wgLang->commaList( SearchEngine
::namespacesAsText( SearchEngine
::projectNamespaces() ) ) );
710 $tt = Sanitizer
::decodeCharReferences( $tt ); // need to allow entities
711 if( $this->active
== 'project' ) {
712 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
714 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::projectNamespaces(), $m, $tt );
718 $m = wfMsg( 'searchprofile-everything' );
719 $tt = wfMsg( 'searchprofile-everything-tooltip' );
720 if( $this->active
== 'all' ) {
721 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
723 $out .= $this->makeSearchLink( $bareterm, $nsAllSet, $m, $tt );
727 $m = wfMsg( 'searchprofile-advanced' );
728 $tt = wfMsg( 'searchprofile-advanced-tooltip' );
729 if( $this->active
== 'advanced' ) {
730 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
732 $out .= $this->makeSearchLink( $bareterm, $this->namespaces
, $m, $tt, array( 'advanced' => '1' ) );
734 $out .= Xml
::closeElement('div') ;
739 protected function shortDialog( $term ) {
741 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
742 $searchable = SearchEngine
::searchableNamespaces();
743 $out = Xml
::openElement( 'form', array( 'id' => 'search', 'method' => 'get', 'action' => $wgScript ) );
744 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
745 // show namespaces only for advanced search
746 if( $this->active
== 'advanced' ) {
748 foreach( $this->namespaces
as $ns ) {
749 $active[$ns] = $searchable[$ns];
751 $out .= wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) . "<br/>\n";
752 $out .= $this->namespaceTables( $active, 1 )."<br/>\n";
753 // Still keep namespace settings otherwise, but don't show them
755 foreach( $this->namespaces
as $ns ) {
756 $out .= Xml
::hidden( "ns{$ns}", '1' );
759 // Keep redirect setting
760 $out .= Xml
::hidden( "redirs", (int)$this->searchRedirects
);
762 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
763 $out .= Xml
::hidden( 'fulltext', 'Search' );
764 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ) );
765 $out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')';
766 $out .= Xml
::closeElement( 'form' );
767 // Add prefix link for single-namespace searches
768 $t = Title
::newFromText( $term );
769 /*if( $t != null && count($this->namespaces) === 1 ) {
770 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
772 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
773 Xml
::element( 'legend', null, wfMsg('searchmenu-legend') ) .
774 $this->formHeader($term) . $out . $this->didYouMeanHtml
.
775 Xml
::closeElement( 'fieldset' );
778 /** Make a search link with some target namespaces */
779 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
781 foreach( $namespaces as $n ) {
784 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
786 $st = SpecialPage
::getTitleFor( 'Search' );
787 $stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt );
789 return Xml
::element( 'a',
790 array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
794 /** Check if query starts with image: prefix */
795 protected function startsWithImage( $term ) {
798 $p = explode( ':', $term );
799 if( count( $p ) > 1 ) {
800 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
805 protected function namespaceTables( $namespaces, $rowsPerTable = 3 ) {
807 // Group namespaces into rows according to subject.
808 // Try not to make too many assumptions about namespace numbering.
811 foreach( $namespaces as $ns => $name ) {
812 $subj = MWNamespace
::getSubject( $ns );
813 if( !array_key_exists( $subj, $rows ) ) {
816 $name = str_replace( '_', ' ', $name );
818 $name = wfMsg( 'blanknamespace' );
820 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
821 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
822 Xml
::closeElement( 'td' ) . "\n";
824 $rows = array_values( $rows );
825 $numRows = count( $rows );
826 // Lay out namespaces in multiple floating two-column tables so they'll
827 // be arranged nicely while still accommodating different screen widths
828 // Float to the right on RTL wikis
829 $tableStyle = $wgContLang->isRTL() ?
830 'float: right; margin: 0 0 0em 1em' : 'float: left; margin: 0 1em 0em 0';
831 // Build the final HTML table...
832 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
833 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
834 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
835 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
837 $tables .= Xml
::closeElement( 'table' ) . "\n";
844 * implements Special:Search - Run text & title search and display the output
845 * @ingroup SpecialPage
847 class SpecialSearchOld
{
850 * Set up basic search parameters from the request and user settings.
851 * Typically you'll pass $wgRequest and $wgUser.
853 * @param WebRequest $request
857 function __construct( &$request, &$user ) {
858 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
859 $this->mPrefix
= $request->getVal('prefix', '');
860 $this->namespaces
= $this->powerSearch( $request );
861 if( empty( $this->namespaces
) ) {
862 $this->namespaces
= SearchEngine
::userNamespaces( $user );
865 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
866 $this->fulltext
= $request->getVal('fulltext');
870 * If an exact title match can be found, jump straight ahead to it.
871 * @param string $term
874 function goResult( $term ) {
878 $this->setupPage( $term );
880 # Try to go to page as entered.
881 $t = Title
::newFromText( $term );
883 # If the string cannot be used to create a title
885 return $this->showResults( $term );
888 # If there's an exact or very near match, jump right there.
889 $t = SearchEngine
::getNearMatch( $term );
890 if( !is_null( $t ) ) {
891 $wgOut->redirect( $t->getFullURL() );
895 # No match, generate an edit URL
896 $t = Title
::newFromText( $term );
897 if( ! is_null( $t ) ) {
898 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
899 # If the feature is enabled, go straight to the edit page
901 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
906 $extra = $wgOut->parse( '=='.wfMsgNoTrans( 'notitlematches' )."==\n" );
907 if( $t->quickUserCan( 'create' ) && $t->quickUserCan( 'edit' ) ) {
908 $extra .= wfMsgExt( 'noexactmatch', 'parse', wfEscapeWikiText( $term ) );
910 $extra .= wfMsgExt( 'noexactmatch-nocreate', 'parse', wfEscapeWikiText( $term ) );
913 $this->showResults( $term, $extra );
917 * @param string $term
918 * @param string $extra Extra HTML to add after "did you mean"
920 public function showResults( $term, $extra = '' ) {
921 wfProfileIn( __METHOD__
);
922 global $wgOut, $wgUser;
923 $sk = $wgUser->getSkin();
925 $search = SearchEngine
::create();
926 $search->setLimitOffset( $this->limit
, $this->offset
);
927 $search->setNamespaces( $this->namespaces
);
928 $search->showRedirects
= $this->searchRedirects
;
929 $search->prefix
= $this->mPrefix
;
930 $term = $search->transformSearchTerm($term);
932 $this->setupPage( $term );
934 $rewritten = $search->replacePrefixes($term);
935 $titleMatches = $search->searchTitle( $rewritten );
936 $textMatches = $search->searchText( $rewritten );
938 // did you mean... suggestions
939 if($textMatches && $textMatches->hasSuggestion()){
940 $st = SpecialPage
::getTitleFor( 'Search' );
942 # mirror Go/Search behaviour of original request
943 $didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
944 if($this->fulltext
!= NULL)
945 $didYouMeanParams['fulltext'] = $this->fulltext
;
946 $stParams = wfArrayToCGI(
948 $this->powerSearchOptions()
951 $suggestLink = $sk->makeKnownLinkObj( $st,
952 $textMatches->getSuggestionSnippet(),
955 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
958 $wgOut->addHTML( $extra );
960 $wgOut->wrapWikiMsg( "<div class='mw-searchresult'>\n$1</div>", 'searchresulttext' );
962 if( '' === trim( $term ) ) {
963 // Empty query -- straight view of search form
964 $wgOut->setSubtitle( '' );
965 $wgOut->addHTML( $this->powerSearchBox( $term ) );
966 $wgOut->addHTML( $this->powerSearchFocus() );
967 wfProfileOut( __METHOD__
);
971 global $wgDisableTextSearch;
972 if ( $wgDisableTextSearch ) {
973 global $wgSearchForwardUrl;
974 if( $wgSearchForwardUrl ) {
975 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
976 $wgOut->redirect( $url );
977 wfProfileOut( __METHOD__
);
980 global $wgInputEncoding;
982 Xml
::openElement( 'fieldset' ) .
983 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
984 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
985 wfMsg( 'googlesearch',
986 htmlspecialchars( $term ),
987 htmlspecialchars( $wgInputEncoding ),
988 htmlspecialchars( wfMsg( 'searchbutton' ) )
990 Xml
::closeElement( 'fieldset' )
992 wfProfileOut( __METHOD__
);
996 $wgOut->addHTML( $this->shortDialog( $term ) );
998 // Sometimes the search engine knows there are too many hits
999 if ($titleMatches instanceof SearchResultTooMany
) {
1000 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
1001 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1002 $wgOut->addHTML( $this->powerSearchFocus() );
1003 wfProfileOut( __METHOD__
);
1007 // show number of results
1008 $num = ( $titleMatches ?
$titleMatches->numRows() : 0 )
1009 +
( $textMatches ?
$textMatches->numRows() : 0);
1011 if($titleMatches && !is_null($titleMatches->getTotalHits()))
1012 $totalNum +
= $titleMatches->getTotalHits();
1013 if($textMatches && !is_null($textMatches->getTotalHits()))
1014 $totalNum +
= $textMatches->getTotalHits();
1016 if ( $totalNum > 0 ){
1017 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
1018 $this->offset+
1, $this->offset+
$num, $totalNum, $num );
1019 } elseif ( $num >= $this->limit
) {
1020 $top = wfShowingResults( $this->offset
, $this->limit
);
1022 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $num );
1024 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
1028 if( $num ||
$this->offset
) {
1029 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
1030 SpecialPage
::getTitleFor( 'Search' ),
1032 $this->powerSearchOptions(),
1033 array( 'search' => $term ) ),
1034 ($num < $this->limit
) );
1035 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
1036 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
1038 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
1041 if( $titleMatches ) {
1042 if( $titleMatches->numRows() ) {
1043 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
1044 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
1046 $titleMatches->free();
1049 if( $textMatches ) {
1050 // output appropriate heading
1051 if( $textMatches->numRows() ) {
1053 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
1054 else // if no title matches the heading is redundant
1055 $wgOut->addHTML("<hr/>");
1056 } elseif( $num == 0 ) {
1057 # Don't show the 'no text matches' if we received title matches
1058 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
1060 // show interwiki results if any
1061 if( $textMatches->hasInterwikiResults() )
1062 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
1064 if( $textMatches->numRows() )
1065 $wgOut->addHTML( $this->showMatches( $textMatches ) );
1067 $textMatches->free();
1071 $wgOut->addWikiMsg( 'nonefound' );
1073 if( $num ||
$this->offset
) {
1074 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
1076 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1077 wfProfileOut( __METHOD__
);
1080 #------------------------------------------------------------------
1081 # Private methods below this line
1086 function setupPage( $term ) {
1088 if( !empty( $term ) ){
1089 $wgOut->setPageTitle( wfMsg( 'searchresults') );
1090 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
1092 $subtitlemsg = ( Title
::newFromText( $term ) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
1093 $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
1094 $wgOut->setArticleRelated( false );
1095 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1099 * Extract "power search" namespace settings from the request object,
1100 * returning a list of index numbers to search.
1102 * @param WebRequest $request
1106 function powerSearch( &$request ) {
1108 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1109 if( $request->getCheck( 'ns' . $ns ) ) {
1117 * Reconstruct the 'power search' options for links
1121 function powerSearchOptions() {
1123 foreach( $this->namespaces
as $n ) {
1124 $opt['ns' . $n] = 1;
1126 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
1131 * Show whole set of results
1133 * @param SearchResultSet $matches
1135 function showMatches( &$matches ) {
1136 wfProfileIn( __METHOD__
);
1139 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1143 $infoLine = $matches->getInfo();
1144 if( !is_null($infoLine) )
1145 $out .= "\n<!-- {$infoLine} -->\n";
1148 $off = $this->offset +
1;
1149 $out .= "<ul class='mw-search-results'>\n";
1151 while( $result = $matches->next() ) {
1152 $out .= $this->showHit( $result, $terms );
1156 // convert the whole thing to desired language variant
1158 $out = $wgContLang->convert( $out );
1159 wfProfileOut( __METHOD__
);
1164 * Format a single hit result
1165 * @param SearchResult $result
1166 * @param array $terms terms to highlight
1168 function showHit( $result, $terms ) {
1169 wfProfileIn( __METHOD__
);
1170 global $wgUser, $wgContLang, $wgLang;
1172 if( $result->isBrokenTitle() ) {
1173 wfProfileOut( __METHOD__
);
1174 return "<!-- Broken link in search result -->\n";
1177 $t = $result->getTitle();
1178 $sk = $wgUser->getSkin();
1180 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1182 //If page content is not readable, just return the title.
1183 //This is not quite safe, but better than showing excerpts from non-readable pages
1184 //Note that hiding the entry entirely would screw up paging.
1185 if (!$t->userCanRead()) {
1186 wfProfileOut( __METHOD__
);
1187 return "<li>{$link}</li>\n";
1190 // If the page doesn't *exist*... our search index is out of date.
1191 // The least confusing at this point is to drop the result.
1192 // You may get less results, but... oh well. :P
1193 if( $result->isMissingRevision() ) {
1194 wfProfileOut( __METHOD__
);
1195 return "<!-- missing page " .
1196 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
1199 // format redirects / relevant sections
1200 $redirectTitle = $result->getRedirectTitle();
1201 $redirectText = $result->getRedirectSnippet($terms);
1202 $sectionTitle = $result->getSectionTitle();
1203 $sectionText = $result->getSectionSnippet($terms);
1205 if( !is_null($redirectTitle) )
1206 $redirect = "<span class='searchalttitle'>"
1207 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1210 if( !is_null($sectionTitle) )
1211 $section = "<span class='searchalttitle'>"
1212 .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
1215 // format text extract
1216 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
1219 if( is_null( $result->getScore() ) ) {
1220 // Search engine doesn't report scoring info
1223 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
1224 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
1228 // format description
1229 $byteSize = $result->getByteSize();
1230 $wordCount = $result->getWordCount();
1231 $timestamp = $result->getTimestamp();
1232 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
1233 $sk->formatSize( $byteSize ),
1235 $date = $wgLang->timeanddate( $timestamp );
1237 // link to related articles if supported
1239 if( $result->hasRelated() ){
1240 $st = SpecialPage
::getTitleFor( 'Search' );
1241 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
1242 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
1243 'fulltext' => wfMsg('search') ));
1245 $related = ' -- ' . $sk->makeKnownLinkObj( $st,
1246 wfMsg('search-relatedarticle'), $stParams );
1249 // Include a thumbnail for media files...
1250 if( $t->getNamespace() == NS_FILE
) {
1251 $img = wfFindFile( $t );
1253 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
1255 $desc = $img->getShortDesc();
1256 wfProfileOut( __METHOD__
);
1258 // Float doesn't seem to interact well with the bullets.
1259 // Table messes up vertical alignment of the bullet, but I'm
1260 // not sure what more I can do about that. :(
1262 '<table class="searchResultImage">' .
1264 '<td width="120" align="center">' .
1265 $thumb->toHtml( array( 'desc-link' => true ) ) .
1267 '<td valign="top">' .
1270 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
1279 wfProfileOut( __METHOD__
);
1280 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
1281 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
1287 * Show results from other wikis
1289 * @param SearchResultSet $matches
1291 function showInterwiki( &$matches, $query ) {
1292 wfProfileIn( __METHOD__
);
1295 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1297 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
1298 $off = $this->offset +
1;
1299 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
1301 // work out custom project captions
1302 $customCaptions = array();
1303 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
1304 foreach($customLines as $line){
1305 $parts = explode(":",$line,2);
1306 if(count($parts) == 2) // validate line
1307 $customCaptions[$parts[0]] = $parts[1];
1312 while( $result = $matches->next() ) {
1313 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
1314 $prev = $result->getInterwikiPrefix();
1316 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
1317 $out .= "</ul></div>\n";
1319 // convert the whole thing to desired language variant
1321 $out = $wgContLang->convert( $out );
1322 wfProfileOut( __METHOD__
);
1327 * Show single interwiki link
1329 * @param SearchResult $result
1330 * @param string $lastInterwiki
1331 * @param array $terms
1332 * @param string $query
1333 * @param array $customCaptions iw prefix -> caption
1335 function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
1336 wfProfileIn( __METHOD__
);
1337 global $wgUser, $wgContLang, $wgLang;
1339 if( $result->isBrokenTitle() ) {
1340 wfProfileOut( __METHOD__
);
1341 return "<!-- Broken link in search result -->\n";
1344 $t = $result->getTitle();
1345 $sk = $wgUser->getSkin();
1347 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1349 // format redirect if any
1350 $redirectTitle = $result->getRedirectTitle();
1351 $redirectText = $result->getRedirectSnippet($terms);
1353 if( !is_null($redirectTitle) )
1354 $redirect = "<span class='searchalttitle'>"
1355 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1359 // display project name
1360 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()){
1361 if( key_exists($t->getInterwiki(),$customCaptions) )
1362 // captions from 'search-interwiki-custom'
1363 $caption = $customCaptions[$t->getInterwiki()];
1365 // default is to show the hostname of the other wiki which might suck
1366 // if there are many wikis on one hostname
1367 $parsed = parse_url($t->getFullURL());
1368 $caption = wfMsg('search-interwiki-default', $parsed['host']);
1370 // "more results" link (special page stuff could be localized, but we might not know target lang)
1371 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
1372 $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
1373 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
1374 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>{$searchLink}</span>{$caption}</div>\n<ul>";
1377 $out .= "<li>{$link} {$redirect}</li>\n";
1378 wfProfileOut( __METHOD__
);
1384 * Generates the power search box at bottom of [[Special:Search]]
1385 * @param $term string: search term
1386 * @return $out string: HTML form
1388 function powerSearchBox( $term ) {
1389 global $wgScript, $wgContLang;
1391 $namespaces = SearchEngine
::searchableNamespaces();
1393 // group namespaces into rows according to subject; try not to make too
1394 // many assumptions about namespace numbering
1396 foreach( $namespaces as $ns => $name ) {
1397 $subj = MWNamespace
::getSubject( $ns );
1398 if( !array_key_exists( $subj, $rows ) ) {
1401 $name = str_replace( '_', ' ', $name );
1403 $name = wfMsg( 'blanknamespace' );
1405 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
1406 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
1407 Xml
::closeElement( 'td' ) . "\n";
1409 $rows = array_values( $rows );
1410 $numRows = count( $rows );
1412 // lay out namespaces in multiple floating two-column tables so they'll
1413 // be arranged nicely while still accommodating different screen widths
1414 $rowsPerTable = 3; // seems to look nice
1416 // float to the right on RTL wikis
1417 $tableStyle = ( $wgContLang->isRTL() ?
1418 'float: right; margin: 0 0 1em 1em' :
1419 'float: left; margin: 0 1em 1em 0' );
1422 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
1423 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
1424 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
1425 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
1427 $tables .= Xml
::closeElement( 'table' ) . "\n";
1430 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
1431 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
1432 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
1433 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ) ) . "\n";
1434 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1435 $searchHiddens = Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
1436 $searchHiddens .= Xml
::hidden( 'fulltext', 'Advanced search' ) . "\n";
1438 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
1439 Xml
::fieldset( wfMsg( 'powersearch-legend' ),
1441 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
1444 "<hr style=\"clear: both\" />\n" .
1446 $redirect . " " . $redirectLabel .
1448 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
1459 function powerSearchFocus() {
1460 global $wgJsMimeType;
1461 return "<script type=\"$wgJsMimeType\">" .
1462 "hookEvent(\"load\", function(){" .
1463 "document.getElementById('powerSearchText').focus();" .
1468 function shortDialog($term) {
1471 $out = Xml
::openElement( 'form', array(
1474 'action' => $wgScript
1476 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1477 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . ' ';
1478 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1479 if( in_array( $ns, $this->namespaces
) ) {
1480 $out .= Xml
::hidden( "ns{$ns}", '1' );
1483 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() );
1484 $out .= Xml
::hidden( 'fulltext', 'Search' );
1485 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ) );
1486 $out .= Xml
::closeElement( 'form' );