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();
75 $this->didYouMeanHtml
= ''; # html of did you mean... link
79 * If an exact title match can be found, jump straight ahead to it.
82 public function goResult( $term ) {
84 $this->setupPage( $term );
85 # Try to go to page as entered.
86 $t = Title
::newFromText( $term );
87 # If the string cannot be used to create a title
89 return $this->showResults( $term );
91 # If there's an exact or very near match, jump right there.
92 $t = SearchEngine
::getNearMatch( $term );
93 if( !is_null( $t ) ) {
94 $wgOut->redirect( $t->getFullURL() );
97 # No match, generate an edit URL
98 $t = Title
::newFromText( $term );
99 if( !is_null( $t ) ) {
101 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
102 # If the feature is enabled, go straight to the edit page
104 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
108 return $this->showResults( $term );
112 * @param string $term
114 public function showResults( $term ) {
115 global $wgOut, $wgDisableTextSearch, $wgContLang;
116 wfProfileIn( __METHOD__
);
118 $this->setupPage( $term );
119 $this->searchEngine
= SearchEngine
::create();
121 if( $wgDisableTextSearch ) {
122 global $wgSearchForwardUrl;
123 if( $wgSearchForwardUrl ) {
124 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
125 $wgOut->redirect( $url );
126 wfProfileOut( __METHOD__
);
129 global $wgInputEncoding;
131 Xml
::openElement( 'fieldset' ) .
132 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
133 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
134 wfMsg( 'googlesearch',
135 htmlspecialchars( $term ),
136 htmlspecialchars( $wgInputEncoding ),
137 htmlspecialchars( wfMsg( 'searchbutton' ) )
139 Xml
::closeElement( 'fieldset' )
141 wfProfileOut( __METHOD__
);
145 $t = Title
::newFromText( $term );
146 // fetch search results
147 $search =& $this->searchEngine
;
148 $search->setLimitOffset( $this->limit
, $this->offset
);
149 $search->setNamespaces( $this->namespaces
);
150 $search->showRedirects
= $this->searchRedirects
;
151 $rewritten = $search->replacePrefixes($term);
153 $titleMatches = $search->searchTitle( $rewritten );
154 if( !($titleMatches instanceof SearchResultTooMany
))
155 $textMatches = $search->searchText( $rewritten );
157 // did you mean... suggestions
158 if( $textMatches && $textMatches->hasSuggestion() ) {
159 $st = SpecialPage
::getTitleFor( 'Search' );
160 $stParams = wfArrayToCGI(
161 array( 'search' => $textMatches->getSuggestionQuery(), 'fulltext' => wfMsg('search') ),
162 $this->powerSearchOptions()
164 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
165 $textMatches->getSuggestionSnippet().'</a>';
167 $this->didYouMeanHtml
= '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
170 // start rendering the page
172 Xml
::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
173 Xml
::openElement( 'tr' ) .
174 Xml
::openElement( 'td' ) . "\n" .
175 ( $this->searchAdvanced ?
$this->powerSearchBox( $term ) : $this->shortDialog( $term ) ) .
176 Xml
::closeElement('td') .
177 Xml
::closeElement('tr') .
178 Xml
::closeElement('table')
181 // Sometimes the search engine knows there are too many hits
182 if( $titleMatches instanceof SearchResultTooMany
) {
183 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
184 wfProfileOut( __METHOD__
);
188 $filePrefix = $wgContLang->getFormattedNsText(NS_FILE
).':';
189 if( '' === trim( $term ) ||
$filePrefix === trim( $term ) ) {
190 $wgOut->addHTML( $this->searchAdvanced ?
$this->powerSearchFocus() : $this->searchFocus() );
191 // Empty query -- straight view of search form
192 wfProfileOut( __METHOD__
);
196 // show direct page/create link
198 if( !$t->exists() ) {
199 $wgOut->addWikiMsg( 'searchmenu-new', wfEscapeWikiText( $t->getPrefixedText() ) );
201 $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) );
205 // Get number of results
206 $titleMatchesSQL = $titleMatches ?
$titleMatches->numRows() : 0;
207 $textMatchesSQL = $textMatches ?
$textMatches->numRows() : 0;
208 // Total initial query matches (possible false positives)
209 $numSQL = $titleMatchesSQL +
$textMatchesSQL;
210 // Get total actual results (after second filtering, if any)
211 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
212 $titleMatches->getTotalHits() : $titleMatchesSQL;
213 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
214 $textMatches->getTotalHits() : $textMatchesSQL;
215 $totalRes = $numTitleMatches +
$numTextMatches;
217 // show number of results and current offset
220 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
221 $this->offset+
1, $this->offset+
$numSQL, $totalRes, $numSQL );
222 } elseif( $numSQL >= $this->limit
) {
223 $top = wfShowingResults( $this->offset
, $this->limit
);
225 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $numSQL );
227 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
231 if( $numSQL ||
$this->offset
) {
232 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
233 SpecialPage
::getTitleFor( 'Search' ),
234 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
235 max( $titleMatchesSQL, $textMatchesSQL ) < $this->limit
237 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
238 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
240 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
243 $wgOut->addHtml( "<div class='searchresults'>" );
244 if( $titleMatches ) {
245 if( $numTitleMatches > 0 ) {
246 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
247 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
249 $titleMatches->free();
252 // output appropriate heading
253 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
254 // if no title matches the heading is redundant
255 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
256 } elseif( $totalRes == 0 ) {
257 # Don't show the 'no text matches' if we received title matches
258 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
260 // show interwiki results if any
261 if( $textMatches->hasInterwikiResults() ) {
262 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
265 if( $numTextMatches > 0 ) {
266 $wgOut->addHTML( $this->showMatches( $textMatches ) );
269 $textMatches->free();
271 if( $totalRes === 0 ) {
272 $wgOut->addWikiMsg( 'search-nonefound' );
274 $wgOut->addHtml( "</div>" );
275 if( $totalRes === 0 ) {
276 $wgOut->addHTML( $this->searchAdvanced ?
$this->powerSearchFocus() : $this->searchFocus() );
279 if( $numSQL ||
$this->offset
) {
280 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
282 wfProfileOut( __METHOD__
);
288 protected function setupPage( $term ) {
290 // Figure out the active search profile header
291 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
292 if( $this->searchAdvanced
)
293 $this->active
= 'advanced';
294 else if( $this->namespaces
=== NS_FILE ||
$this->startsWithImage( $term ) )
295 $this->active
= 'images';
296 elseif( $this->namespaces
=== $nsAllSet )
297 $this->active
= 'all';
298 elseif( $this->namespaces
=== SearchEngine
::defaultNamespaces() )
299 $this->active
= 'default';
300 elseif( $this->namespaces
=== SearchEngine
::projectNamespaces() )
301 $this->active
= 'project';
303 $this->active
= 'advanced';
304 # Should advanced UI be used?
305 $this->searchAdvanced
= ($this->active
=== 'advanced');
306 if( !empty( $term ) ) {
307 $wgOut->setPageTitle( wfMsg( 'searchresults') );
308 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
310 $wgOut->setArticleRelated( false );
311 $wgOut->setRobotPolicy( 'noindex,nofollow' );
315 * Extract "power search" namespace settings from the request object,
316 * returning a list of index numbers to search.
318 * @param WebRequest $request
321 protected function powerSearch( &$request ) {
323 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
324 if( $request->getCheck( 'ns' . $ns ) ) {
332 * Reconstruct the 'power search' options for links
335 protected function powerSearchOptions() {
337 foreach( $this->namespaces
as $n ) {
340 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
341 if( $this->searchAdvanced
) {
342 $opt['advanced'] = $this->searchAdvanced
;
348 * Show whole set of results
350 * @param SearchResultSet $matches
352 protected function showMatches( &$matches ) {
354 wfProfileIn( __METHOD__
);
356 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
359 $infoLine = $matches->getInfo();
360 if( !is_null($infoLine) ) {
361 $out .= "\n<!-- {$infoLine} -->\n";
363 $off = $this->offset +
1;
364 $out .= "<ul class='mw-search-results'>\n";
365 while( $result = $matches->next() ) {
366 $out .= $this->showHit( $result, $terms );
370 // convert the whole thing to desired language variant
371 $out = $wgContLang->convert( $out );
372 wfProfileOut( __METHOD__
);
377 * Format a single hit result
378 * @param SearchResult $result
379 * @param array $terms terms to highlight
381 protected function showHit( $result, $terms ) {
382 global $wgContLang, $wgLang;
383 wfProfileIn( __METHOD__
);
385 if( $result->isBrokenTitle() ) {
386 wfProfileOut( __METHOD__
);
387 return "<!-- Broken link in search result -->\n";
390 $t = $result->getTitle();
392 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
394 //If page content is not readable, just return the title.
395 //This is not quite safe, but better than showing excerpts from non-readable pages
396 //Note that hiding the entry entirely would screw up paging.
397 if( !$t->userCanRead() ) {
398 wfProfileOut( __METHOD__
);
399 return "<li>{$link}</li>\n";
402 // If the page doesn't *exist*... our search index is out of date.
403 // The least confusing at this point is to drop the result.
404 // You may get less results, but... oh well. :P
405 if( $result->isMissingRevision() ) {
406 wfProfileOut( __METHOD__
);
407 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
410 // format redirects / relevant sections
411 $redirectTitle = $result->getRedirectTitle();
412 $redirectText = $result->getRedirectSnippet($terms);
413 $sectionTitle = $result->getSectionTitle();
414 $sectionText = $result->getSectionSnippet($terms);
416 if( !is_null($redirectTitle) )
417 $redirect = "<span class='searchalttitle'>"
418 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
421 if( !is_null($sectionTitle) )
422 $section = "<span class='searchalttitle'>"
423 .wfMsg('search-section', $this->sk
->makeKnownLinkObj( $sectionTitle, $sectionText))
426 // format text extract
427 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
430 if( is_null( $result->getScore() ) ) {
431 // Search engine doesn't report scoring info
434 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
435 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
439 // format description
440 $byteSize = $result->getByteSize();
441 $wordCount = $result->getWordCount();
442 $timestamp = $result->getTimestamp();
443 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
444 $this->sk
->formatSize( $byteSize ), $wordCount );
445 $date = $wgLang->timeanddate( $timestamp );
447 // link to related articles if supported
449 if( $result->hasRelated() ) {
450 $st = SpecialPage
::getTitleFor( 'Search' );
451 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
452 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
453 'fulltext' => wfMsg('search') ));
455 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
456 wfMsg('search-relatedarticle').'</a>';
459 // Include a thumbnail for media files...
460 if( $t->getNamespace() == NS_FILE
) {
461 $img = wfFindFile( $t );
463 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
465 $desc = $img->getShortDesc();
466 wfProfileOut( __METHOD__
);
467 // Float doesn't seem to interact well with the bullets.
468 // Table messes up vertical alignment of the bullets.
469 // Bullets are therefore disabled (didn't look great anyway).
471 '<table class="searchResultImage">' .
473 '<td width="120" align="center" valign="top">' .
474 $thumb->toHtml( array( 'desc-link' => true ) ) .
476 '<td valign="top">' .
479 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
488 wfProfileOut( __METHOD__
);
489 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
490 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
496 * Show results from other wikis
498 * @param SearchResultSet $matches
500 protected function showInterwiki( &$matches, $query ) {
502 wfProfileIn( __METHOD__
);
503 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
505 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
506 wfMsg('search-interwiki-caption')."</div>\n";
507 $off = $this->offset +
1;
508 $out .= "<ul class='mw-search-iwresults'>\n";
510 // work out custom project captions
511 $customCaptions = array();
512 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
513 foreach($customLines as $line) {
514 $parts = explode(":",$line,2);
515 if(count($parts) == 2) // validate line
516 $customCaptions[$parts[0]] = $parts[1];
520 while( $result = $matches->next() ) {
521 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
522 $prev = $result->getInterwikiPrefix();
524 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
525 $out .= "</ul></div>\n";
527 // convert the whole thing to desired language variant
528 $out = $wgContLang->convert( $out );
529 wfProfileOut( __METHOD__
);
534 * Show single interwiki link
536 * @param SearchResult $result
537 * @param string $lastInterwiki
538 * @param array $terms
539 * @param string $query
540 * @param array $customCaptions iw prefix -> caption
542 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
543 wfProfileIn( __METHOD__
);
544 global $wgContLang, $wgLang;
546 if( $result->isBrokenTitle() ) {
547 wfProfileOut( __METHOD__
);
548 return "<!-- Broken link in search result -->\n";
551 $t = $result->getTitle();
553 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
555 // format redirect if any
556 $redirectTitle = $result->getRedirectTitle();
557 $redirectText = $result->getRedirectSnippet($terms);
559 if( !is_null($redirectTitle) )
560 $redirect = "<span class='searchalttitle'>"
561 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
565 // display project name
566 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
567 if( key_exists($t->getInterwiki(),$customCaptions) )
568 // captions from 'search-interwiki-custom'
569 $caption = $customCaptions[$t->getInterwiki()];
571 // default is to show the hostname of the other wiki which might suck
572 // if there are many wikis on one hostname
573 $parsed = parse_url($t->getFullURL());
574 $caption = wfMsg('search-interwiki-default', $parsed['host']);
576 // "more results" link (special page stuff could be localized, but we might not know target lang)
577 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
578 $searchLink = $this->sk
->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
579 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
580 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
581 {$searchLink}</span>{$caption}</div>\n<ul>";
584 $out .= "<li>{$link} {$redirect}</li>\n";
585 wfProfileOut( __METHOD__
);
591 * Generates the power search box at bottom of [[Special:Search]]
592 * @param $term string: search term
593 * @return $out string: HTML form
595 protected function powerSearchBox( $term ) {
598 $namespaces = SearchEngine
::searchableNamespaces();
600 $tables = $this->namespaceTables( $namespaces );
602 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
603 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
604 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
605 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' )) . "\n";
606 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
609 // show redirects check only if backend supports it
610 if( $this->searchEngine
->acceptListRedirects() ) {
611 $redirectText = "<p>". $redirect . " " . $redirectLabel ."</p>";
614 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
615 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
617 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
619 '<input type="hidden" name="advanced" value="'.$this->searchAdvanced
."\"/>\n".
621 "<hr style=\"clear: both;\" />\n".
623 "<div style=\"padding-top:2px;padding-bottom:2px;\">".
624 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
631 $t = Title
::newFromText( $term );
632 /* if( $t != null && count($this->namespaces) === 1 ) {
633 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
635 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
636 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
637 $this->formHeader($term) . $out . $this->didYouMeanHtml
.
638 Xml
::closeElement( 'fieldset' );
641 protected function searchFocus() {
642 global $wgJsMimeType;
643 return "<script type=\"$wgJsMimeType\">" .
644 "hookEvent(\"load\", function() {" .
645 "document.getElementById('searchText').focus();" .
650 protected function powerSearchFocus() {
651 global $wgJsMimeType;
652 return "<script type=\"$wgJsMimeType\">" .
653 "hookEvent(\"load\", function() {" .
654 "document.getElementById('powerSearchText').focus();" .
659 protected function formHeader( $term ) {
660 global $wgContLang, $wgCanonicalNamespaceNames;
662 $sep = ' ';
663 $out = Xml
::openElement('div', array( 'style' => 'padding-bottom:0.5em;' ) );
666 if( $this->startsWithImage( $term ) )
667 $bareterm = substr( $term, strpos( $term, ':' ) +
1 ); // delete all/image prefix
669 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
671 // search profiles headers
672 $m = wfMsg( 'searchprofile-articles' );
673 $tt = wfMsg( 'searchprofile-articles-tooltip',
674 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::defaultNamespaces() ) ) );
675 if( $this->active
== 'default' ) {
676 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
678 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::defaultNamespaces(), $m, $tt );
682 $m = wfMsg( 'searchprofile-images' );
683 $tt = wfMsg( 'searchprofile-images-tooltip' );
684 if( $this->active
== 'images' ) {
685 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
687 $imageTextForm = $wgContLang->getFormattedNsText(NS_FILE
).':'.$bareterm;
688 $out .= $this->makeSearchLink( $imageTextForm, array( NS_FILE
) , $m, $tt );
693 $m = wfMsg( 'searchprofile-articles-and-proj' );
694 $tt = wfMsg( 'searchprofile-project-tooltip',
695 implode( ', ', SearchEngine::namespacesAsText( SearchEngine::defaultAndProjectNamespaces() ) ) );
696 if( $this->active == 'withproject' ) {
697 $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
699 $out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultAndProjectNamespaces(), $m, $tt );
704 $m = wfMsg( 'searchprofile-project' );
705 $tt = wfMsg( 'searchprofile-project-tooltip',
706 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::projectNamespaces() ) ) );
707 if( $this->active
== 'project' ) {
708 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
710 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::projectNamespaces(), $m, $tt );
714 $m = wfMsg( 'searchprofile-everything' );
715 $tt = wfMsg( 'searchprofile-everything-tooltip' );
716 if( $this->active
== 'all' ) {
717 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
719 $out .= $this->makeSearchLink( $bareterm, $nsAllSet, $m, $tt );
723 $m = wfMsg( 'searchprofile-advanced' );
724 $tt = wfMsg( 'searchprofile-advanced-tooltip' );
725 if( $this->active
== 'advanced' ) {
726 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
728 $out .= $this->makeSearchLink( $bareterm, $this->namespaces
, $m, $tt, array( 'advanced' => '1' ) );
730 $out .= Xml
::closeElement('div') ;
735 protected function shortDialog( $term ) {
737 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
738 $searchable = SearchEngine
::searchableNamespaces();
739 $out = Xml
::openElement( 'form', array( 'id' => 'search', 'method' => 'get', 'action' => $wgScript ) );
740 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
741 // show namespaces only for advanced search
742 if( $this->active
== 'advanced' ) {
744 foreach( $this->namespaces
as $ns ) {
745 $active[$ns] = $searchable[$ns];
747 $out .= wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) . "<br/>\n";
748 $out .= $this->namespaceTables( $active, 1 )."<br/>\n";
749 // Still keep namespace settings otherwise, but don't show them
751 foreach( $this->namespaces
as $ns ) {
752 $out .= Xml
::hidden( "ns{$ns}", '1' );
755 // Keep redirect setting
756 $out .= Xml
::hidden( "redirs", (int)$this->searchRedirects
);
758 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
759 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
760 $out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')';
761 $out .= Xml
::closeElement( 'form' );
762 // Add prefix link for single-namespace searches
763 $t = Title
::newFromText( $term );
764 /*if( $t != null && count($this->namespaces) === 1 ) {
765 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
767 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
768 Xml
::element( 'legend', null, wfMsg('searchmenu-legend') ) .
769 $this->formHeader($term) . $out . $this->didYouMeanHtml
.
770 Xml
::closeElement( 'fieldset' );
773 /** Make a search link with some target namespaces */
774 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
776 foreach( $namespaces as $n ) {
779 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
781 $st = SpecialPage
::getTitleFor( 'Search' );
782 $stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt );
784 return Xml
::element( 'a',
785 array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
789 /** Check if query starts with image: prefix */
790 protected function startsWithImage( $term ) {
793 $p = explode( ':', $term );
794 if( count( $p ) > 1 ) {
795 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
800 protected function namespaceTables( $namespaces, $rowsPerTable = 3 ) {
802 // Group namespaces into rows according to subject.
803 // Try not to make too many assumptions about namespace numbering.
806 foreach( $namespaces as $ns => $name ) {
807 $subj = MWNamespace
::getSubject( $ns );
808 if( !array_key_exists( $subj, $rows ) ) {
811 $name = str_replace( '_', ' ', $name );
813 $name = wfMsg( 'blanknamespace' );
815 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
816 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
817 Xml
::closeElement( 'td' ) . "\n";
819 $rows = array_values( $rows );
820 $numRows = count( $rows );
821 // Lay out namespaces in multiple floating two-column tables so they'll
822 // be arranged nicely while still accommodating different screen widths
823 // Float to the right on RTL wikis
824 $tableStyle = $wgContLang->isRTL() ?
825 'float: right; margin: 0 0 0em 1em' : 'float: left; margin: 0 1em 0em 0';
826 // Build the final HTML table...
827 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
828 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
829 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
830 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
832 $tables .= Xml
::closeElement( 'table' ) . "\n";
839 * implements Special:Search - Run text & title search and display the output
840 * @ingroup SpecialPage
842 class SpecialSearchOld
{
845 * Set up basic search parameters from the request and user settings.
846 * Typically you'll pass $wgRequest and $wgUser.
848 * @param WebRequest $request
852 function __construct( &$request, &$user ) {
853 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
855 $this->namespaces
= $this->powerSearch( $request );
856 if( empty( $this->namespaces
) ) {
857 $this->namespaces
= SearchEngine
::userNamespaces( $user );
860 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
864 * If an exact title match can be found, jump straight ahead to it.
865 * @param string $term
868 function goResult( $term ) {
872 $this->setupPage( $term );
874 # Try to go to page as entered.
875 $t = Title
::newFromText( $term );
877 # If the string cannot be used to create a title
879 return $this->showResults( $term );
882 # If there's an exact or very near match, jump right there.
883 $t = SearchEngine
::getNearMatch( $term );
884 if( !is_null( $t ) ) {
885 $wgOut->redirect( $t->getFullURL() );
889 # No match, generate an edit URL
890 $t = Title
::newFromText( $term );
891 if( ! is_null( $t ) ) {
892 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
893 # If the feature is enabled, go straight to the edit page
895 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
900 $wgOut->wrapWikiMsg( "==$1==\n", 'notitlematches' );
901 if( $t->quickUserCan( 'create' ) && $t->quickUserCan( 'edit' ) ) {
902 $wgOut->addWikiMsg( 'noexactmatch', wfEscapeWikiText( $term ) );
904 $wgOut->addWikiMsg( 'noexactmatch-nocreate', wfEscapeWikiText( $term ) );
907 return $this->showResults( $term );
911 * @param string $term
914 function showResults( $term ) {
915 wfProfileIn( __METHOD__
);
916 global $wgOut, $wgUser;
917 $sk = $wgUser->getSkin();
919 $this->setupPage( $term );
921 $wgOut->addWikiMsg( 'searchresulttext' );
923 if( '' === trim( $term ) ) {
924 // Empty query -- straight view of search form
925 $wgOut->setSubtitle( '' );
926 $wgOut->addHTML( $this->powerSearchBox( $term ) );
927 $wgOut->addHTML( $this->powerSearchFocus() );
928 wfProfileOut( __METHOD__
);
932 global $wgDisableTextSearch;
933 if ( $wgDisableTextSearch ) {
934 global $wgSearchForwardUrl;
935 if( $wgSearchForwardUrl ) {
936 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
937 $wgOut->redirect( $url );
938 wfProfileOut( __METHOD__
);
941 global $wgInputEncoding;
943 Xml
::openElement( 'fieldset' ) .
944 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
945 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
946 wfMsg( 'googlesearch',
947 htmlspecialchars( $term ),
948 htmlspecialchars( $wgInputEncoding ),
949 htmlspecialchars( wfMsg( 'searchbutton' ) )
951 Xml
::closeElement( 'fieldset' )
953 wfProfileOut( __METHOD__
);
957 $wgOut->addHTML( $this->shortDialog( $term ) );
959 $search = SearchEngine
::create();
960 $search->setLimitOffset( $this->limit
, $this->offset
);
961 $search->setNamespaces( $this->namespaces
);
962 $search->showRedirects
= $this->searchRedirects
;
963 $rewritten = $search->replacePrefixes($term);
965 $titleMatches = $search->searchTitle( $rewritten );
967 // Sometimes the search engine knows there are too many hits
968 if ($titleMatches instanceof SearchResultTooMany
) {
969 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
970 $wgOut->addHTML( $this->powerSearchBox( $term ) );
971 $wgOut->addHTML( $this->powerSearchFocus() );
972 wfProfileOut( __METHOD__
);
976 $textMatches = $search->searchText( $rewritten );
978 // did you mean... suggestions
979 if($textMatches && $textMatches->hasSuggestion()){
980 $st = SpecialPage
::getTitleFor( 'Search' );
981 $stParams = wfArrayToCGI( array(
982 'search' => $textMatches->getSuggestionQuery(),
983 'fulltext' => wfMsg('search')),
984 $this->powerSearchOptions());
986 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
987 $textMatches->getSuggestionSnippet().'</a>';
989 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
992 // show number of results
993 $num = ( $titleMatches ?
$titleMatches->numRows() : 0 )
994 +
( $textMatches ?
$textMatches->numRows() : 0);
996 if($titleMatches && !is_null($titleMatches->getTotalHits()))
997 $totalNum +
= $titleMatches->getTotalHits();
998 if($textMatches && !is_null($textMatches->getTotalHits()))
999 $totalNum +
= $textMatches->getTotalHits();
1001 if ( $totalNum > 0 ){
1002 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
1003 $this->offset+
1, $this->offset+
$num, $totalNum, $num );
1004 } elseif ( $num >= $this->limit
) {
1005 $top = wfShowingResults( $this->offset
, $this->limit
);
1007 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $num );
1009 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
1013 if( $num ||
$this->offset
) {
1014 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
1015 SpecialPage
::getTitleFor( 'Search' ),
1017 $this->powerSearchOptions(),
1018 array( 'search' => $term ) ),
1019 ($num < $this->limit
) );
1020 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
1021 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
1023 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
1026 if( $titleMatches ) {
1027 if( $titleMatches->numRows() ) {
1028 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
1029 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
1031 $titleMatches->free();
1034 if( $textMatches ) {
1035 // output appropriate heading
1036 if( $textMatches->numRows() ) {
1038 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
1039 else // if no title matches the heading is redundant
1040 $wgOut->addHTML("<hr/>");
1041 } elseif( $num == 0 ) {
1042 # Don't show the 'no text matches' if we received title matches
1043 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
1045 // show interwiki results if any
1046 if( $textMatches->hasInterwikiResults() )
1047 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
1049 if( $textMatches->numRows() )
1050 $wgOut->addHTML( $this->showMatches( $textMatches ) );
1052 $textMatches->free();
1056 $wgOut->addWikiMsg( 'nonefound' );
1058 if( $num ||
$this->offset
) {
1059 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
1061 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1062 wfProfileOut( __METHOD__
);
1065 #------------------------------------------------------------------
1066 # Private methods below this line
1071 function setupPage( $term ) {
1073 if( !empty( $term ) ){
1074 $wgOut->setPageTitle( wfMsg( 'searchresults') );
1075 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
1077 $subtitlemsg = ( Title
::newFromText( $term ) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
1078 $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
1079 $wgOut->setArticleRelated( false );
1080 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1084 * Extract "power search" namespace settings from the request object,
1085 * returning a list of index numbers to search.
1087 * @param WebRequest $request
1091 function powerSearch( &$request ) {
1093 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1094 if( $request->getCheck( 'ns' . $ns ) ) {
1102 * Reconstruct the 'power search' options for links
1106 function powerSearchOptions() {
1108 foreach( $this->namespaces
as $n ) {
1109 $opt['ns' . $n] = 1;
1111 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
1116 * Show whole set of results
1118 * @param SearchResultSet $matches
1120 function showMatches( &$matches ) {
1121 wfProfileIn( __METHOD__
);
1124 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1128 $infoLine = $matches->getInfo();
1129 if( !is_null($infoLine) )
1130 $out .= "\n<!-- {$infoLine} -->\n";
1133 $off = $this->offset +
1;
1134 $out .= "<ul class='mw-search-results'>\n";
1136 while( $result = $matches->next() ) {
1137 $out .= $this->showHit( $result, $terms );
1141 // convert the whole thing to desired language variant
1143 $out = $wgContLang->convert( $out );
1144 wfProfileOut( __METHOD__
);
1149 * Format a single hit result
1150 * @param SearchResult $result
1151 * @param array $terms terms to highlight
1153 function showHit( $result, $terms ) {
1154 wfProfileIn( __METHOD__
);
1155 global $wgUser, $wgContLang, $wgLang;
1157 if( $result->isBrokenTitle() ) {
1158 wfProfileOut( __METHOD__
);
1159 return "<!-- Broken link in search result -->\n";
1162 $t = $result->getTitle();
1163 $sk = $wgUser->getSkin();
1165 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1167 //If page content is not readable, just return the title.
1168 //This is not quite safe, but better than showing excerpts from non-readable pages
1169 //Note that hiding the entry entirely would screw up paging.
1170 if (!$t->userCanRead()) {
1171 wfProfileOut( __METHOD__
);
1172 return "<li>{$link}</li>\n";
1175 // If the page doesn't *exist*... our search index is out of date.
1176 // The least confusing at this point is to drop the result.
1177 // You may get less results, but... oh well. :P
1178 if( $result->isMissingRevision() ) {
1179 wfProfileOut( __METHOD__
);
1180 return "<!-- missing page " .
1181 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
1184 // format redirects / relevant sections
1185 $redirectTitle = $result->getRedirectTitle();
1186 $redirectText = $result->getRedirectSnippet($terms);
1187 $sectionTitle = $result->getSectionTitle();
1188 $sectionText = $result->getSectionSnippet($terms);
1190 if( !is_null($redirectTitle) )
1191 $redirect = "<span class='searchalttitle'>"
1192 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1195 if( !is_null($sectionTitle) )
1196 $section = "<span class='searchalttitle'>"
1197 .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
1200 // format text extract
1201 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
1204 if( is_null( $result->getScore() ) ) {
1205 // Search engine doesn't report scoring info
1208 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
1209 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
1213 // format description
1214 $byteSize = $result->getByteSize();
1215 $wordCount = $result->getWordCount();
1216 $timestamp = $result->getTimestamp();
1217 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
1218 $sk->formatSize( $byteSize ),
1220 $date = $wgLang->timeanddate( $timestamp );
1222 // link to related articles if supported
1224 if( $result->hasRelated() ){
1225 $st = SpecialPage
::getTitleFor( 'Search' );
1226 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
1227 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
1228 'fulltext' => wfMsg('search') ));
1230 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
1231 wfMsg('search-relatedarticle').'</a>';
1234 // Include a thumbnail for media files...
1235 if( $t->getNamespace() == NS_FILE
) {
1236 $img = wfFindFile( $t );
1238 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
1240 $desc = $img->getShortDesc();
1241 wfProfileOut( __METHOD__
);
1243 // Float doesn't seem to interact well with the bullets.
1244 // Table messes up vertical alignment of the bullet, but I'm
1245 // not sure what more I can do about that. :(
1247 '<table class="searchResultImage">' .
1249 '<td width="120" align="center">' .
1250 $thumb->toHtml( array( 'desc-link' => true ) ) .
1252 '<td valign="top">' .
1255 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
1264 wfProfileOut( __METHOD__
);
1265 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
1266 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
1272 * Show results from other wikis
1274 * @param SearchResultSet $matches
1276 function showInterwiki( &$matches, $query ) {
1277 wfProfileIn( __METHOD__
);
1280 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1282 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
1283 $off = $this->offset +
1;
1284 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
1286 // work out custom project captions
1287 $customCaptions = array();
1288 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
1289 foreach($customLines as $line){
1290 $parts = explode(":",$line,2);
1291 if(count($parts) == 2) // validate line
1292 $customCaptions[$parts[0]] = $parts[1];
1297 while( $result = $matches->next() ) {
1298 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
1299 $prev = $result->getInterwikiPrefix();
1301 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
1302 $out .= "</ul></div>\n";
1304 // convert the whole thing to desired language variant
1306 $out = $wgContLang->convert( $out );
1307 wfProfileOut( __METHOD__
);
1312 * Show single interwiki link
1314 * @param SearchResult $result
1315 * @param string $lastInterwiki
1316 * @param array $terms
1317 * @param string $query
1318 * @param array $customCaptions iw prefix -> caption
1320 function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
1321 wfProfileIn( __METHOD__
);
1322 global $wgUser, $wgContLang, $wgLang;
1324 if( $result->isBrokenTitle() ) {
1325 wfProfileOut( __METHOD__
);
1326 return "<!-- Broken link in search result -->\n";
1329 $t = $result->getTitle();
1330 $sk = $wgUser->getSkin();
1332 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1334 // format redirect if any
1335 $redirectTitle = $result->getRedirectTitle();
1336 $redirectText = $result->getRedirectSnippet($terms);
1338 if( !is_null($redirectTitle) )
1339 $redirect = "<span class='searchalttitle'>"
1340 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1344 // display project name
1345 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()){
1346 if( key_exists($t->getInterwiki(),$customCaptions) )
1347 // captions from 'search-interwiki-custom'
1348 $caption = $customCaptions[$t->getInterwiki()];
1350 // default is to show the hostname of the other wiki which might suck
1351 // if there are many wikis on one hostname
1352 $parsed = parse_url($t->getFullURL());
1353 $caption = wfMsg('search-interwiki-default', $parsed['host']);
1355 // "more results" link (special page stuff could be localized, but we might not know target lang)
1356 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
1357 $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
1358 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
1359 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>{$searchLink}</span>{$caption}</div>\n<ul>";
1362 $out .= "<li>{$link} {$redirect}</li>\n";
1363 wfProfileOut( __METHOD__
);
1369 * Generates the power search box at bottom of [[Special:Search]]
1370 * @param $term string: search term
1371 * @return $out string: HTML form
1373 function powerSearchBox( $term ) {
1374 global $wgScript, $wgContLang;
1376 $namespaces = SearchEngine
::searchableNamespaces();
1378 // group namespaces into rows according to subject; try not to make too
1379 // many assumptions about namespace numbering
1381 foreach( $namespaces as $ns => $name ) {
1382 $subj = MWNamespace
::getSubject( $ns );
1383 if( !array_key_exists( $subj, $rows ) ) {
1386 $name = str_replace( '_', ' ', $name );
1388 $name = wfMsg( 'blanknamespace' );
1390 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
1391 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
1392 Xml
::closeElement( 'td' ) . "\n";
1394 $rows = array_values( $rows );
1395 $numRows = count( $rows );
1397 // lay out namespaces in multiple floating two-column tables so they'll
1398 // be arranged nicely while still accommodating different screen widths
1399 $rowsPerTable = 3; // seems to look nice
1401 // float to the right on RTL wikis
1402 $tableStyle = ( $wgContLang->isRTL() ?
1403 'float: right; margin: 0 0 1em 1em' :
1404 'float: left; margin: 0 1em 1em 0' );
1407 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
1408 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
1409 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
1410 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
1412 $tables .= Xml
::closeElement( 'table' ) . "\n";
1415 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
1416 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
1417 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
1418 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
1419 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1421 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
1422 Xml
::fieldset( wfMsg( 'powersearch-legend' ),
1423 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
1425 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
1428 "<hr style=\"clear: both\" />\n" .
1430 $redirect . " " . $redirectLabel .
1432 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
1442 function powerSearchFocus() {
1443 global $wgJsMimeType;
1444 return "<script type=\"$wgJsMimeType\">" .
1445 "hookEvent(\"load\", function(){" .
1446 "document.getElementById('powerSearchText').focus();" .
1451 function shortDialog($term) {
1454 $out = Xml
::openElement( 'form', array(
1457 'action' => $wgScript
1459 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1460 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() );
1461 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . ' ';
1462 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1463 if( in_array( $ns, $this->namespaces
) ) {
1464 $out .= Xml
::hidden( "ns{$ns}", '1' );
1467 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
1468 $out .= Xml
::closeElement( 'form' );