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, '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 # Extract requested namespaces
67 $this->namespaces
= $this->powerSearch( $request );
68 if( empty( $this->namespaces
) ) {
69 $this->namespaces
= SearchEngine
::userNamespaces( $user );
71 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
72 $this->searchAdvanced
= $request->getVal( 'advanced' );
73 $this->active
= 'advanced';
74 $this->sk
= $user->getSkin();
78 * If an exact title match can be found, jump straight ahead to it.
81 public function goResult( $term ) {
83 $this->setupPage( $term );
84 # Try to go to page as entered.
85 $t = Title
::newFromText( $term );
86 # If the string cannot be used to create a title
88 return $this->showResults( $term );
90 # If there's an exact or very near match, jump right there.
91 $t = SearchEngine
::getNearMatch( $term );
92 if( !is_null( $t ) ) {
93 $wgOut->redirect( $t->getFullURL() );
96 # No match, generate an edit URL
97 $t = Title
::newFromText( $term );
98 if( !is_null( $t ) ) {
100 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
101 # If the feature is enabled, go straight to the edit page
103 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
107 return $this->showResults( $term );
111 * @param string $term
113 public function showResults( $term ) {
114 global $wgOut, $wgDisableTextSearch, $wgContLang;
115 wfProfileIn( __METHOD__
);
117 $this->setupPage( $term );
118 $this->searchEngine
= SearchEngine
::create();
120 $t = Title
::newFromText( $term );
123 Xml
::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
124 Xml
::openElement( 'tr' ) .
125 Xml
::openElement( 'td' ) . "\n" .
126 ( $this->searchAdvanced ?
$this->powerSearchBox( $term ) : $this->shortDialog( $term ) ) .
127 Xml
::closeElement('td') .
128 Xml
::closeElement('tr') .
129 Xml
::closeElement('table')
132 $filePrefix = $wgContLang->getFormattedNsText(NS_FILE
).':';
133 if( '' === trim( $term ) ||
$filePrefix === trim( $term ) ) {
134 $wgOut->addHTML( $this->searchAdvanced ?
$this->powerSearchFocus() : $this->searchFocus() );
135 // Empty query -- straight view of search form
136 wfProfileOut( __METHOD__
);
140 if( $wgDisableTextSearch ) {
141 global $wgSearchForwardUrl;
142 if( $wgSearchForwardUrl ) {
143 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
144 $wgOut->redirect( $url );
145 wfProfileOut( __METHOD__
);
148 global $wgInputEncoding;
150 Xml
::openElement( 'fieldset' ) .
151 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
152 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
153 wfMsg( 'googlesearch',
154 htmlspecialchars( $term ),
155 htmlspecialchars( $wgInputEncoding ),
156 htmlspecialchars( wfMsg( 'searchbutton' ) )
158 Xml
::closeElement( 'fieldset' )
160 wfProfileOut( __METHOD__
);
164 $search =& $this->searchEngine
;
165 $search->setLimitOffset( $this->limit
, $this->offset
);
166 $search->setNamespaces( $this->namespaces
);
167 $search->showRedirects
= $this->searchRedirects
;
168 $rewritten = $search->replacePrefixes($term);
170 $titleMatches = $search->searchTitle( $rewritten );
172 // Sometimes the search engine knows there are too many hits
173 if( $titleMatches instanceof SearchResultTooMany
) {
174 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
175 wfProfileOut( __METHOD__
);
179 $textMatches = $search->searchText( $rewritten );
181 // did you mean... suggestions
182 if( $textMatches && $textMatches->hasSuggestion() ) {
183 $st = SpecialPage
::getTitleFor( 'Search' );
184 $stParams = wfArrayToCGI(
185 array( 'search' => $textMatches->getSuggestionQuery(), 'fulltext' => wfMsg('search') ),
186 $this->powerSearchOptions()
188 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
189 $textMatches->getSuggestionSnippet().'</a>';
191 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
194 // show direct page/create link
196 if( !$t->exists() ) {
197 $wgOut->addWikiMsg( 'searchmenu-new', wfEscapeWikiText( $t->getPrefixedText() ) );
199 $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) );
203 // Get number of results
204 $titleMatchesSQL = $titleMatches ?
$titleMatches->numRows() : 0;
205 $textMatchesSQL = $textMatches ?
$textMatches->numRows() : 0;
206 // Total initial query matches (possible false positives)
207 $numSQL = $titleMatchesSQL +
$textMatchesSQL;
208 // Get total actual results (after second filtering, if any)
209 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
210 $titleMatches->getTotalHits() : $titleMatchesSQL;
211 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
212 $textMatches->getTotalHits() : $textMatchesSQL;
213 $totalRes = $numTitleMatches +
$numTextMatches;
215 // show number of results and current offset
218 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
219 $this->offset+
1, $this->offset+
$numSQL, $totalRes, $numSQL );
220 } elseif( $numSQL >= $this->limit
) {
221 $top = wfShowingResults( $this->offset
, $this->limit
);
223 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $numSQL );
225 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
229 if( $numSQL ||
$this->offset
) {
230 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
231 SpecialPage
::getTitleFor( 'Search' ),
232 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
233 max( $titleMatchesSQL, $textMatchesSQL ) < $this->limit
235 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
236 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
238 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
241 $wgOut->addHtml( "<div class='searchresults'>" );
242 if( $titleMatches ) {
243 if( $numTitleMatches > 0 ) {
244 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
245 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
247 $titleMatches->free();
250 // output appropriate heading
251 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
252 // if no title matches the heading is redundant
253 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
254 } elseif( $totalRes == 0 ) {
255 # Don't show the 'no text matches' if we received title matches
256 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
258 // show interwiki results if any
259 if( $textMatches->hasInterwikiResults() ) {
260 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
263 if( $numTextMatches > 0 ) {
264 $wgOut->addHTML( $this->showMatches( $textMatches ) );
267 $textMatches->free();
269 if( $totalRes === 0 ) {
270 $wgOut->addWikiMsg( 'search-nonefound' );
272 $wgOut->addHtml( "</div>" );
273 if( $totalRes === 0 ) {
274 $wgOut->addHTML( $this->searchAdvanced ?
$this->powerSearchFocus() : $this->searchFocus() );
277 if( $numSQL ||
$this->offset
) {
278 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
280 wfProfileOut( __METHOD__
);
286 protected function setupPage( $term ) {
288 // Figure out the active search profile header
289 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
290 if( $this->searchAdvanced
)
291 $this->active
= 'advanced';
292 else if( $this->namespaces
=== NS_FILE ||
$this->startsWithImage( $term ) )
293 $this->active
= 'images';
294 elseif( $this->namespaces
=== $nsAllSet )
295 $this->active
= 'all';
296 elseif( $this->namespaces
=== SearchEngine
::defaultNamespaces() )
297 $this->active
= 'default';
298 elseif( $this->namespaces
=== SearchEngine
::projectNamespaces() )
299 $this->active
= 'project';
301 $this->active
= 'advanced';
302 # Should advanced UI be used?
303 $this->searchAdvanced
= ($this->active
=== 'advanced');
304 if( !empty( $term ) ) {
305 $wgOut->setPageTitle( wfMsg( 'searchresults') );
306 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
308 $wgOut->setArticleRelated( false );
309 $wgOut->setRobotPolicy( 'noindex,nofollow' );
313 * Extract "power search" namespace settings from the request object,
314 * returning a list of index numbers to search.
316 * @param WebRequest $request
319 protected function powerSearch( &$request ) {
321 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
322 if( $request->getCheck( 'ns' . $ns ) ) {
330 * Reconstruct the 'power search' options for links
333 protected function powerSearchOptions() {
335 foreach( $this->namespaces
as $n ) {
338 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
339 if( $this->searchAdvanced
) {
340 $opt['advanced'] = $this->searchAdvanced
;
346 * Show whole set of results
348 * @param SearchResultSet $matches
350 protected function showMatches( &$matches ) {
352 wfProfileIn( __METHOD__
);
354 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
357 $infoLine = $matches->getInfo();
358 if( !is_null($infoLine) ) {
359 $out .= "\n<!-- {$infoLine} -->\n";
361 $off = $this->offset +
1;
362 $out .= "<ul class='mw-search-results'>\n";
363 while( $result = $matches->next() ) {
364 $out .= $this->showHit( $result, $terms );
368 // convert the whole thing to desired language variant
369 $out = $wgContLang->convert( $out );
370 wfProfileOut( __METHOD__
);
375 * Format a single hit result
376 * @param SearchResult $result
377 * @param array $terms terms to highlight
379 protected function showHit( $result, $terms ) {
380 global $wgContLang, $wgLang;
381 wfProfileIn( __METHOD__
);
383 if( $result->isBrokenTitle() ) {
384 wfProfileOut( __METHOD__
);
385 return "<!-- Broken link in search result -->\n";
388 $t = $result->getTitle();
390 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
392 //If page content is not readable, just return the title.
393 //This is not quite safe, but better than showing excerpts from non-readable pages
394 //Note that hiding the entry entirely would screw up paging.
395 if( !$t->userCanRead() ) {
396 wfProfileOut( __METHOD__
);
397 return "<li>{$link}</li>\n";
400 // If the page doesn't *exist*... our search index is out of date.
401 // The least confusing at this point is to drop the result.
402 // You may get less results, but... oh well. :P
403 if( $result->isMissingRevision() ) {
404 wfProfileOut( __METHOD__
);
405 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
408 // format redirects / relevant sections
409 $redirectTitle = $result->getRedirectTitle();
410 $redirectText = $result->getRedirectSnippet($terms);
411 $sectionTitle = $result->getSectionTitle();
412 $sectionText = $result->getSectionSnippet($terms);
414 if( !is_null($redirectTitle) )
415 $redirect = "<span class='searchalttitle'>"
416 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
419 if( !is_null($sectionTitle) )
420 $section = "<span class='searchalttitle'>"
421 .wfMsg('search-section', $this->sk
->makeKnownLinkObj( $sectionTitle, $sectionText))
424 // format text extract
425 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
428 if( is_null( $result->getScore() ) ) {
429 // Search engine doesn't report scoring info
432 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
433 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
437 // format description
438 $byteSize = $result->getByteSize();
439 $wordCount = $result->getWordCount();
440 $timestamp = $result->getTimestamp();
441 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
442 $this->sk
->formatSize( $byteSize ), $wordCount );
443 $date = $wgLang->timeanddate( $timestamp );
445 // link to related articles if supported
447 if( $result->hasRelated() ) {
448 $st = SpecialPage
::getTitleFor( 'Search' );
449 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
450 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
451 'fulltext' => wfMsg('search') ));
453 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
454 wfMsg('search-relatedarticle').'</a>';
457 // Include a thumbnail for media files...
458 if( $t->getNamespace() == NS_FILE
) {
459 $img = wfFindFile( $t );
461 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
463 $desc = $img->getShortDesc();
464 wfProfileOut( __METHOD__
);
465 // Float doesn't seem to interact well with the bullets.
466 // Table messes up vertical alignment of the bullets.
467 // Bullets are therefore disabled (didn't look great anyway).
469 '<table class="searchResultImage">' .
471 '<td width="120" align="center" valign="top">' .
472 $thumb->toHtml( array( 'desc-link' => true ) ) .
474 '<td valign="top">' .
477 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
486 wfProfileOut( __METHOD__
);
487 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
488 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
494 * Show results from other wikis
496 * @param SearchResultSet $matches
498 protected function showInterwiki( &$matches, $query ) {
500 wfProfileIn( __METHOD__
);
501 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
503 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
504 wfMsg('search-interwiki-caption')."</div>\n";
505 $off = $this->offset +
1;
506 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
508 // work out custom project captions
509 $customCaptions = array();
510 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
511 foreach($customLines as $line) {
512 $parts = explode(":",$line,2);
513 if(count($parts) == 2) // validate line
514 $customCaptions[$parts[0]] = $parts[1];
518 while( $result = $matches->next() ) {
519 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
520 $prev = $result->getInterwikiPrefix();
522 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
523 $out .= "</ul></div>\n";
525 // convert the whole thing to desired language variant
526 $out = $wgContLang->convert( $out );
527 wfProfileOut( __METHOD__
);
532 * Show single interwiki link
534 * @param SearchResult $result
535 * @param string $lastInterwiki
536 * @param array $terms
537 * @param string $query
538 * @param array $customCaptions iw prefix -> caption
540 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
541 wfProfileIn( __METHOD__
);
542 global $wgContLang, $wgLang;
544 if( $result->isBrokenTitle() ) {
545 wfProfileOut( __METHOD__
);
546 return "<!-- Broken link in search result -->\n";
549 $t = $result->getTitle();
551 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
553 // format redirect if any
554 $redirectTitle = $result->getRedirectTitle();
555 $redirectText = $result->getRedirectSnippet($terms);
557 if( !is_null($redirectTitle) )
558 $redirect = "<span class='searchalttitle'>"
559 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
563 // display project name
564 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
565 if( key_exists($t->getInterwiki(),$customCaptions) )
566 // captions from 'search-interwiki-custom'
567 $caption = $customCaptions[$t->getInterwiki()];
569 // default is to show the hostname of the other wiki which might suck
570 // if there are many wikis on one hostname
571 $parsed = parse_url($t->getFullURL());
572 $caption = wfMsg('search-interwiki-default', $parsed['host']);
574 // "more results" link (special page stuff could be localized, but we might not know target lang)
575 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
576 $searchLink = $this->sk
->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
577 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
578 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
579 {$searchLink}</span>{$caption}</div>\n<ul>";
582 $out .= "<li>{$link} {$redirect}</li>\n";
583 wfProfileOut( __METHOD__
);
589 * Generates the power search box at bottom of [[Special:Search]]
590 * @param $term string: search term
591 * @return $out string: HTML form
593 protected function powerSearchBox( $term ) {
596 $namespaces = SearchEngine
::searchableNamespaces();
598 $tables = $this->namespaceTables( $namespaces );
600 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
601 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
602 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
603 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
604 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
606 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
607 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
609 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
612 "<hr style=\"clear: both\" />\n" .
614 $redirect . " " . $redirectLabel .
616 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
622 $t = Title
::newFromText( $term );
623 if( $t != null && count($this->namespaces
) === 1 ) {
624 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
626 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
627 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
628 $this->formHeader($term) . $out .
629 Xml
::closeElement( 'fieldset' );
632 protected function searchFocus() {
633 global $wgJsMimeType;
634 return "<script type=\"$wgJsMimeType\">" .
635 "hookEvent(\"load\", function() {" .
636 "document.getElementById('searchText').focus();" .
641 protected function powerSearchFocus() {
642 global $wgJsMimeType;
643 return "<script type=\"$wgJsMimeType\">" .
644 "hookEvent(\"load\", function() {" .
645 "document.getElementById('powerSearchText').focus();" .
650 protected function formHeader( $term ) {
651 global $wgContLang, $wgCanonicalNamespaceNames;
653 $sep = ' ';
654 $out = Xml
::openElement('div', array( 'style' => 'padding-bottom:0.5em;' ) );
657 if( $this->startsWithImage( $term ) )
658 $bareterm = substr( $term, strpos( $term, ':' ) +
1 ); // delete all/image prefix
660 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
662 // search profiles headers
663 $m = wfMsg( 'searchprofile-articles' );
664 $tt = wfMsg( 'searchprofile-articles-tooltip',
665 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::defaultNamespaces() ) ) );
666 if( $this->active
== 'default' ) {
667 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
669 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::defaultNamespaces(), $m, $tt );
673 $m = wfMsg( 'searchprofile-images' );
674 $tt = wfMsg( 'searchprofile-images-tooltip' );
675 if( $this->active
== 'images' ) {
676 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
678 $imageTextForm = $wgContLang->getFormattedNsText(NS_FILE
).':'.$bareterm;
679 $out .= $this->makeSearchLink( $imageTextForm, array( NS_FILE
) , $m, $tt );
684 $m = wfMsg( 'searchprofile-articles-and-proj' );
685 $tt = wfMsg( 'searchprofile-project-tooltip',
686 implode( ', ', SearchEngine::namespacesAsText( SearchEngine::defaultAndProjectNamespaces() ) ) );
687 if( $this->active == 'withproject' ) {
688 $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
690 $out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultAndProjectNamespaces(), $m, $tt );
695 $m = wfMsg( 'searchprofile-project' );
696 $tt = wfMsg( 'searchprofile-project-tooltip',
697 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::projectNamespaces() ) ) );
698 if( $this->active
== 'project' ) {
699 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
701 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::projectNamespaces(), $m, $tt );
705 $m = wfMsg( 'searchprofile-everything' );
706 $tt = wfMsg( 'searchprofile-everything-tooltip' );
707 if( $this->active
== 'all' ) {
708 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
710 $out .= $this->makeSearchLink( $bareterm, $nsAllSet, $m, $tt );
714 $m = wfMsg( 'searchprofile-advanced' );
715 $tt = wfMsg( 'searchprofile-advanced-tooltip' );
716 if( $this->active
== 'advanced' ) {
717 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
719 $out .= $this->makeSearchLink( $bareterm, $this->namespaces
, $m, $tt, array( 'advanced' => '1' ) );
721 $out .= Xml
::closeElement('div') ;
726 protected function shortDialog( $term ) {
728 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
729 $searchable = SearchEngine
::searchableNamespaces();
730 $out = Xml
::openElement( 'form', array( 'id' => 'search', 'method' => 'get', 'action' => $wgScript ) );
731 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
732 // If searching several, but not all namespaces, show what we are searching.
733 if( count($this->namespaces
) > 1 && $this->namespaces
!== array_keys($searchable) ) {
735 foreach( $this->namespaces
as $ns ) {
736 $active[$ns] = $searchable[$ns];
738 $out .= wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) . "<br/>\n";
739 $out .= $this->namespaceTables( $active, 1 )."<br/>\n";
740 // Still keep namespace settings otherwise, but don't show them
742 foreach( $this->namespaces
as $ns ) {
743 $out .= Xml
::hidden( "ns{$ns}", '1' );
746 // Keep redirect setting
747 $out .= Xml
::hidden( "redirs", (int)$this->searchRedirects
);
749 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
750 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
751 $out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')';
752 $out .= Xml
::closeElement( 'form' );
753 // Add prefix link for single-namespace searches
754 $t = Title
::newFromText( $term );
755 if( $t != null && count($this->namespaces
) === 1 ) {
756 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
758 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
759 Xml
::element( 'legend', null, wfMsg('searchmenu-legend') ) .
760 $this->formHeader($term) . $out .
761 Xml
::closeElement( 'fieldset' );
764 /** Make a search link with some target namespaces */
765 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
767 foreach( $namespaces as $n ) {
770 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
772 $st = SpecialPage
::getTitleFor( 'Search' );
773 $stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt );
775 return Xml
::element( 'a',
776 array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
780 /** Check if query starts with image: prefix */
781 protected function startsWithImage( $term ) {
784 $p = explode( ':', $term );
785 if( count( $p ) > 1 ) {
786 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
791 protected function namespaceTables( $namespaces, $rowsPerTable = 3 ) {
793 // Group namespaces into rows according to subject.
794 // Try not to make too many assumptions about namespace numbering.
797 foreach( $namespaces as $ns => $name ) {
798 $subj = Namespace::getSubject( $ns );
799 if( !array_key_exists( $subj, $rows ) ) {
802 $name = str_replace( '_', ' ', $name );
804 $name = wfMsg( 'blanknamespace' );
806 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
807 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
808 Xml
::closeElement( 'td' ) . "\n";
810 $rows = array_values( $rows );
811 $numRows = count( $rows );
812 // Lay out namespaces in multiple floating two-column tables so they'll
813 // be arranged nicely while still accommodating different screen widths
814 // Float to the right on RTL wikis
815 $tableStyle = $wgContLang->isRTL() ?
816 'float: right; margin: 0 0 0em 1em' : 'float: left; margin: 0 1em 0em 0';
817 // Build the final HTML table...
818 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
819 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
820 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
821 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
823 $tables .= Xml
::closeElement( 'table' ) . "\n";
830 * implements Special:Search - Run text & title search and display the output
831 * @ingroup SpecialPage
833 class SpecialSearchOld
{
836 * Set up basic search parameters from the request and user settings.
837 * Typically you'll pass $wgRequest and $wgUser.
839 * @param WebRequest $request
843 function __construct( &$request, &$user ) {
844 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
846 $this->namespaces
= $this->powerSearch( $request );
847 if( empty( $this->namespaces
) ) {
848 $this->namespaces
= SearchEngine
::userNamespaces( $user );
851 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
855 * If an exact title match can be found, jump straight ahead to it.
856 * @param string $term
859 function goResult( $term ) {
863 $this->setupPage( $term );
865 # Try to go to page as entered.
866 $t = Title
::newFromText( $term );
868 # If the string cannot be used to create a title
870 return $this->showResults( $term );
873 # If there's an exact or very near match, jump right there.
874 $t = SearchEngine
::getNearMatch( $term );
875 if( !is_null( $t ) ) {
876 $wgOut->redirect( $t->getFullURL() );
880 # No match, generate an edit URL
881 $t = Title
::newFromText( $term );
882 if( ! is_null( $t ) ) {
883 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
884 # If the feature is enabled, go straight to the edit page
886 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
891 $wgOut->wrapWikiMsg( "==$1==\n", 'notitlematches' );
892 if( $t->quickUserCan( 'create' ) && $t->quickUserCan( 'edit' ) ) {
893 $wgOut->addWikiMsg( 'noexactmatch', wfEscapeWikiText( $term ) );
895 $wgOut->addWikiMsg( 'noexactmatch-nocreate', wfEscapeWikiText( $term ) );
898 return $this->showResults( $term );
902 * @param string $term
905 function showResults( $term ) {
906 wfProfileIn( __METHOD__
);
907 global $wgOut, $wgUser;
908 $sk = $wgUser->getSkin();
910 $this->setupPage( $term );
912 $wgOut->addWikiMsg( 'searchresulttext' );
914 if( '' === trim( $term ) ) {
915 // Empty query -- straight view of search form
916 $wgOut->setSubtitle( '' );
917 $wgOut->addHTML( $this->powerSearchBox( $term ) );
918 $wgOut->addHTML( $this->powerSearchFocus() );
919 wfProfileOut( __METHOD__
);
923 global $wgDisableTextSearch;
924 if ( $wgDisableTextSearch ) {
925 global $wgSearchForwardUrl;
926 if( $wgSearchForwardUrl ) {
927 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
928 $wgOut->redirect( $url );
929 wfProfileOut( __METHOD__
);
932 global $wgInputEncoding;
934 Xml
::openElement( 'fieldset' ) .
935 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
936 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
937 wfMsg( 'googlesearch',
938 htmlspecialchars( $term ),
939 htmlspecialchars( $wgInputEncoding ),
940 htmlspecialchars( wfMsg( 'searchbutton' ) )
942 Xml
::closeElement( 'fieldset' )
944 wfProfileOut( __METHOD__
);
948 $wgOut->addHTML( $this->shortDialog( $term ) );
950 $search = SearchEngine
::create();
951 $search->setLimitOffset( $this->limit
, $this->offset
);
952 $search->setNamespaces( $this->namespaces
);
953 $search->showRedirects
= $this->searchRedirects
;
954 $rewritten = $search->replacePrefixes($term);
956 $titleMatches = $search->searchTitle( $rewritten );
958 // Sometimes the search engine knows there are too many hits
959 if ($titleMatches instanceof SearchResultTooMany
) {
960 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
961 $wgOut->addHTML( $this->powerSearchBox( $term ) );
962 $wgOut->addHTML( $this->powerSearchFocus() );
963 wfProfileOut( __METHOD__
);
967 $textMatches = $search->searchText( $rewritten );
969 // did you mean... suggestions
970 if($textMatches && $textMatches->hasSuggestion()){
971 $st = SpecialPage
::getTitleFor( 'Search' );
972 $stParams = wfArrayToCGI( array(
973 'search' => $textMatches->getSuggestionQuery(),
974 'fulltext' => wfMsg('search')),
975 $this->powerSearchOptions());
977 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
978 $textMatches->getSuggestionSnippet().'</a>';
980 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
983 // show number of results
984 $num = ( $titleMatches ?
$titleMatches->numRows() : 0 )
985 +
( $textMatches ?
$textMatches->numRows() : 0);
987 if($titleMatches && !is_null($titleMatches->getTotalHits()))
988 $totalNum +
= $titleMatches->getTotalHits();
989 if($textMatches && !is_null($textMatches->getTotalHits()))
990 $totalNum +
= $textMatches->getTotalHits();
992 if ( $totalNum > 0 ){
993 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
994 $this->offset+
1, $this->offset+
$num, $totalNum, $num );
995 } elseif ( $num >= $this->limit
) {
996 $top = wfShowingResults( $this->offset
, $this->limit
);
998 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $num );
1000 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
1004 if( $num ||
$this->offset
) {
1005 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
1006 SpecialPage
::getTitleFor( 'Search' ),
1008 $this->powerSearchOptions(),
1009 array( 'search' => $term ) ),
1010 ($num < $this->limit
) );
1011 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
1012 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
1014 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
1017 if( $titleMatches ) {
1018 if( $titleMatches->numRows() ) {
1019 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
1020 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
1022 $titleMatches->free();
1025 if( $textMatches ) {
1026 // output appropriate heading
1027 if( $textMatches->numRows() ) {
1029 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
1030 else // if no title matches the heading is redundant
1031 $wgOut->addHTML("<hr/>");
1032 } elseif( $num == 0 ) {
1033 # Don't show the 'no text matches' if we received title matches
1034 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
1036 // show interwiki results if any
1037 if( $textMatches->hasInterwikiResults() )
1038 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
1040 if( $textMatches->numRows() )
1041 $wgOut->addHTML( $this->showMatches( $textMatches ) );
1043 $textMatches->free();
1047 $wgOut->addWikiMsg( 'nonefound' );
1049 if( $num ||
$this->offset
) {
1050 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
1052 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1053 wfProfileOut( __METHOD__
);
1056 #------------------------------------------------------------------
1057 # Private methods below this line
1062 function setupPage( $term ) {
1064 if( !empty( $term ) ){
1065 $wgOut->setPageTitle( wfMsg( 'searchresults') );
1066 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
1068 $subtitlemsg = ( Title
::newFromText( $term ) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
1069 $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
1070 $wgOut->setArticleRelated( false );
1071 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1075 * Extract "power search" namespace settings from the request object,
1076 * returning a list of index numbers to search.
1078 * @param WebRequest $request
1082 function powerSearch( &$request ) {
1084 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1085 if( $request->getCheck( 'ns' . $ns ) ) {
1093 * Reconstruct the 'power search' options for links
1097 function powerSearchOptions() {
1099 foreach( $this->namespaces
as $n ) {
1100 $opt['ns' . $n] = 1;
1102 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
1107 * Show whole set of results
1109 * @param SearchResultSet $matches
1111 function showMatches( &$matches ) {
1112 wfProfileIn( __METHOD__
);
1115 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1119 $infoLine = $matches->getInfo();
1120 if( !is_null($infoLine) )
1121 $out .= "\n<!-- {$infoLine} -->\n";
1124 $off = $this->offset +
1;
1125 $out .= "<ul class='mw-search-results'>\n";
1127 while( $result = $matches->next() ) {
1128 $out .= $this->showHit( $result, $terms );
1132 // convert the whole thing to desired language variant
1134 $out = $wgContLang->convert( $out );
1135 wfProfileOut( __METHOD__
);
1140 * Format a single hit result
1141 * @param SearchResult $result
1142 * @param array $terms terms to highlight
1144 function showHit( $result, $terms ) {
1145 wfProfileIn( __METHOD__
);
1146 global $wgUser, $wgContLang, $wgLang;
1148 if( $result->isBrokenTitle() ) {
1149 wfProfileOut( __METHOD__
);
1150 return "<!-- Broken link in search result -->\n";
1153 $t = $result->getTitle();
1154 $sk = $wgUser->getSkin();
1156 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1158 //If page content is not readable, just return the title.
1159 //This is not quite safe, but better than showing excerpts from non-readable pages
1160 //Note that hiding the entry entirely would screw up paging.
1161 if (!$t->userCanRead()) {
1162 wfProfileOut( __METHOD__
);
1163 return "<li>{$link}</li>\n";
1166 // If the page doesn't *exist*... our search index is out of date.
1167 // The least confusing at this point is to drop the result.
1168 // You may get less results, but... oh well. :P
1169 if( $result->isMissingRevision() ) {
1170 wfProfileOut( __METHOD__
);
1171 return "<!-- missing page " .
1172 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
1175 // format redirects / relevant sections
1176 $redirectTitle = $result->getRedirectTitle();
1177 $redirectText = $result->getRedirectSnippet($terms);
1178 $sectionTitle = $result->getSectionTitle();
1179 $sectionText = $result->getSectionSnippet($terms);
1181 if( !is_null($redirectTitle) )
1182 $redirect = "<span class='searchalttitle'>"
1183 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1186 if( !is_null($sectionTitle) )
1187 $section = "<span class='searchalttitle'>"
1188 .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
1191 // format text extract
1192 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
1195 if( is_null( $result->getScore() ) ) {
1196 // Search engine doesn't report scoring info
1199 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
1200 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
1204 // format description
1205 $byteSize = $result->getByteSize();
1206 $wordCount = $result->getWordCount();
1207 $timestamp = $result->getTimestamp();
1208 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
1209 $sk->formatSize( $byteSize ),
1211 $date = $wgLang->timeanddate( $timestamp );
1213 // link to related articles if supported
1215 if( $result->hasRelated() ){
1216 $st = SpecialPage
::getTitleFor( 'Search' );
1217 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
1218 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
1219 'fulltext' => wfMsg('search') ));
1221 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
1222 wfMsg('search-relatedarticle').'</a>';
1225 // Include a thumbnail for media files...
1226 if( $t->getNamespace() == NS_FILE
) {
1227 $img = wfFindFile( $t );
1229 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
1231 $desc = $img->getShortDesc();
1232 wfProfileOut( __METHOD__
);
1234 // Float doesn't seem to interact well with the bullets.
1235 // Table messes up vertical alignment of the bullet, but I'm
1236 // not sure what more I can do about that. :(
1238 '<table class="searchResultImage">' .
1240 '<td width="120" align="center">' .
1241 $thumb->toHtml( array( 'desc-link' => true ) ) .
1243 '<td valign="top">' .
1246 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
1255 wfProfileOut( __METHOD__
);
1256 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
1257 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
1263 * Show results from other wikis
1265 * @param SearchResultSet $matches
1267 function showInterwiki( &$matches, $query ) {
1268 wfProfileIn( __METHOD__
);
1271 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1273 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
1274 $off = $this->offset +
1;
1275 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
1277 // work out custom project captions
1278 $customCaptions = array();
1279 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
1280 foreach($customLines as $line){
1281 $parts = explode(":",$line,2);
1282 if(count($parts) == 2) // validate line
1283 $customCaptions[$parts[0]] = $parts[1];
1288 while( $result = $matches->next() ) {
1289 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
1290 $prev = $result->getInterwikiPrefix();
1292 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
1293 $out .= "</ul></div>\n";
1295 // convert the whole thing to desired language variant
1297 $out = $wgContLang->convert( $out );
1298 wfProfileOut( __METHOD__
);
1303 * Show single interwiki link
1305 * @param SearchResult $result
1306 * @param string $lastInterwiki
1307 * @param array $terms
1308 * @param string $query
1309 * @param array $customCaptions iw prefix -> caption
1311 function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
1312 wfProfileIn( __METHOD__
);
1313 global $wgUser, $wgContLang, $wgLang;
1315 if( $result->isBrokenTitle() ) {
1316 wfProfileOut( __METHOD__
);
1317 return "<!-- Broken link in search result -->\n";
1320 $t = $result->getTitle();
1321 $sk = $wgUser->getSkin();
1323 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1325 // format redirect if any
1326 $redirectTitle = $result->getRedirectTitle();
1327 $redirectText = $result->getRedirectSnippet($terms);
1329 if( !is_null($redirectTitle) )
1330 $redirect = "<span class='searchalttitle'>"
1331 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1335 // display project name
1336 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()){
1337 if( key_exists($t->getInterwiki(),$customCaptions) )
1338 // captions from 'search-interwiki-custom'
1339 $caption = $customCaptions[$t->getInterwiki()];
1341 // default is to show the hostname of the other wiki which might suck
1342 // if there are many wikis on one hostname
1343 $parsed = parse_url($t->getFullURL());
1344 $caption = wfMsg('search-interwiki-default', $parsed['host']);
1346 // "more results" link (special page stuff could be localized, but we might not know target lang)
1347 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
1348 $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
1349 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
1350 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>{$searchLink}</span>{$caption}</div>\n<ul>";
1353 $out .= "<li>{$link} {$redirect}</li>\n";
1354 wfProfileOut( __METHOD__
);
1360 * Generates the power search box at bottom of [[Special:Search]]
1361 * @param $term string: search term
1362 * @return $out string: HTML form
1364 function powerSearchBox( $term ) {
1365 global $wgScript, $wgContLang;
1367 $namespaces = SearchEngine
::searchableNamespaces();
1369 // group namespaces into rows according to subject; try not to make too
1370 // many assumptions about namespace numbering
1372 foreach( $namespaces as $ns => $name ) {
1373 $subj = Namespace::getSubject( $ns );
1374 if( !array_key_exists( $subj, $rows ) ) {
1377 $name = str_replace( '_', ' ', $name );
1379 $name = wfMsg( 'blanknamespace' );
1381 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
1382 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
1383 Xml
::closeElement( 'td' ) . "\n";
1385 $rows = array_values( $rows );
1386 $numRows = count( $rows );
1388 // lay out namespaces in multiple floating two-column tables so they'll
1389 // be arranged nicely while still accommodating different screen widths
1390 $rowsPerTable = 3; // seems to look nice
1392 // float to the right on RTL wikis
1393 $tableStyle = ( $wgContLang->isRTL() ?
1394 'float: right; margin: 0 0 1em 1em' :
1395 'float: left; margin: 0 1em 1em 0' );
1398 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
1399 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
1400 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
1401 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
1403 $tables .= Xml
::closeElement( 'table' ) . "\n";
1406 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
1407 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
1408 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
1409 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
1410 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1412 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
1413 Xml
::fieldset( wfMsg( 'powersearch-legend' ),
1414 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
1416 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
1419 "<hr style=\"clear: both\" />\n" .
1421 $redirect . " " . $redirectLabel .
1423 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
1433 function powerSearchFocus() {
1434 global $wgJsMimeType;
1435 return "<script type=\"$wgJsMimeType\">" .
1436 "hookEvent(\"load\", function(){" .
1437 "document.getElementById('powerSearchText').focus();" .
1442 function shortDialog($term) {
1445 $out = Xml
::openElement( 'form', array(
1448 'action' => $wgScript
1450 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1451 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() );
1452 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . ' ';
1453 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1454 if( in_array( $ns, $this->namespaces
) ) {
1455 $out .= Xml
::hidden( "ns{$ns}", '1' );
1458 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
1459 $out .= Xml
::closeElement( 'form' );