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;
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 if( '' === trim( $term ) ) {
133 // Empty query -- straight view of search form
134 wfProfileOut( __METHOD__
);
138 if( $wgDisableTextSearch ) {
139 global $wgSearchForwardUrl;
140 if( $wgSearchForwardUrl ) {
141 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
142 $wgOut->redirect( $url );
143 wfProfileOut( __METHOD__
);
146 global $wgInputEncoding;
148 Xml
::openElement( 'fieldset' ) .
149 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
150 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
151 wfMsg( 'googlesearch',
152 htmlspecialchars( $term ),
153 htmlspecialchars( $wgInputEncoding ),
154 htmlspecialchars( wfMsg( 'searchbutton' ) )
156 Xml
::closeElement( 'fieldset' )
158 wfProfileOut( __METHOD__
);
162 $search =& $this->searchEngine
;
163 $search->setLimitOffset( $this->limit
, $this->offset
);
164 $search->setNamespaces( $this->namespaces
);
165 $search->showRedirects
= $this->searchRedirects
;
166 $rewritten = $search->replacePrefixes($term);
168 $titleMatches = $search->searchTitle( $rewritten );
170 // Sometimes the search engine knows there are too many hits
171 if( $titleMatches instanceof SearchResultTooMany
) {
172 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
173 wfProfileOut( __METHOD__
);
177 $textMatches = $search->searchText( $rewritten );
179 // did you mean... suggestions
180 if( $textMatches && $textMatches->hasSuggestion() ) {
181 $st = SpecialPage
::getTitleFor( 'Search' );
182 $stParams = wfArrayToCGI(
183 array( 'search' => $textMatches->getSuggestionQuery(), 'fulltext' => wfMsg('search') ),
184 $this->powerSearchOptions()
186 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
187 $textMatches->getSuggestionSnippet().'</a>';
189 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
192 // show direct page/create link
194 if( !$t->exists() ) {
195 $wgOut->addWikiMsg( 'searchmenu-new', wfEscapeWikiText( $t->getPrefixedText() ) );
197 $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) );
201 // Get number of results
202 $titleMatchesSQL = $titleMatches ?
$titleMatches->numRows() : 0;
203 $textMatchesSQL = $textMatches ?
$textMatches->numRows() : 0;
204 // Total initial query matches (possible false positives)
205 $numSQL = $titleMatchesSQL +
$textMatchesSQL;
206 // Get total actual results (after second filtering, if any)
207 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
208 $titleMatches->getTotalHits() : $titleMatchesSQL;
209 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
210 $textMatches->getTotalHits() : $textMatchesSQL;
211 $totalRes = $numTitleMatches +
$numTextMatches;
213 // show number of results and current offset
216 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
217 $this->offset+
1, $this->offset+
$numSQL, $totalRes, $numSQL );
218 } elseif( $numSQL >= $this->limit
) {
219 $top = wfShowingResults( $this->offset
, $this->limit
);
221 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $numSQL );
223 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
227 if( $numSQL ||
$this->offset
) {
228 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
229 SpecialPage
::getTitleFor( 'Search' ),
230 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
231 max( $titleMatchesSQL, $textMatchesSQL ) < $this->limit
233 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
234 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
236 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
239 $wgOut->addHtml( "<div class='searchresults'>" );
240 if( $titleMatches ) {
241 if( $numTitleMatches > 0 ) {
242 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
243 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
245 $titleMatches->free();
248 // output appropriate heading
249 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
250 // if no title matches the heading is redundant
251 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
252 } elseif( $totalRes == 0 ) {
253 # Don't show the 'no text matches' if we received title matches
254 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
256 // show interwiki results if any
257 if( $textMatches->hasInterwikiResults() ) {
258 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
261 if( $numTextMatches > 0 ) {
262 $wgOut->addHTML( $this->showMatches( $textMatches ) );
265 $textMatches->free();
267 if( $totalRes === 0 ) {
268 $wgOut->addWikiMsg( 'search-nonefound' );
270 $wgOut->addHtml( "</div>" );
272 if( $numSQL ||
$this->offset
) {
273 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
275 wfProfileOut( __METHOD__
);
281 protected function setupPage( $term ) {
283 // Figure out the active search profile header
284 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
285 if( $this->searchAdvanced
)
286 $this->active
= 'advanced';
287 else if( $this->namespaces
=== NS_FILE ||
$this->startsWithImage( $term ) )
288 $this->active
= 'images';
289 elseif( $this->namespaces
=== $nsAllSet )
290 $this->active
= 'all';
291 elseif( $this->namespaces
=== SearchEngine
::defaultNamespaces() )
292 $this->active
= 'default';
293 elseif( $this->namespaces
=== SearchEngine
::projectNamespaces() )
294 $this->active
= 'project';
296 $this->active
= 'advanced';
297 # Should advanced UI be used?
298 $this->searchAdvanced
= ($this->active
=== 'advanced');
299 if( !empty( $term ) ) {
300 $wgOut->setPageTitle( wfMsg( 'searchresults') );
301 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
303 $wgOut->setArticleRelated( false );
304 $wgOut->setRobotPolicy( 'noindex,nofollow' );
308 * Extract "power search" namespace settings from the request object,
309 * returning a list of index numbers to search.
311 * @param WebRequest $request
314 protected function powerSearch( &$request ) {
316 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
317 if( $request->getCheck( 'ns' . $ns ) ) {
325 * Reconstruct the 'power search' options for links
328 protected function powerSearchOptions() {
330 foreach( $this->namespaces
as $n ) {
333 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
334 if( $this->searchAdvanced
) {
335 $opt['advanced'] = $this->searchAdvanced
;
341 * Show whole set of results
343 * @param SearchResultSet $matches
345 protected function showMatches( &$matches ) {
347 wfProfileIn( __METHOD__
);
349 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
352 $infoLine = $matches->getInfo();
353 if( !is_null($infoLine) ) {
354 $out .= "\n<!-- {$infoLine} -->\n";
356 $off = $this->offset +
1;
357 $out .= "<ul class='mw-search-results'>\n";
358 while( $result = $matches->next() ) {
359 $out .= $this->showHit( $result, $terms );
363 // convert the whole thing to desired language variant
364 $out = $wgContLang->convert( $out );
365 wfProfileOut( __METHOD__
);
370 * Format a single hit result
371 * @param SearchResult $result
372 * @param array $terms terms to highlight
374 protected function showHit( $result, $terms ) {
375 global $wgContLang, $wgLang;
376 wfProfileIn( __METHOD__
);
378 if( $result->isBrokenTitle() ) {
379 wfProfileOut( __METHOD__
);
380 return "<!-- Broken link in search result -->\n";
383 $t = $result->getTitle();
385 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
387 //If page content is not readable, just return the title.
388 //This is not quite safe, but better than showing excerpts from non-readable pages
389 //Note that hiding the entry entirely would screw up paging.
390 if( !$t->userCanRead() ) {
391 wfProfileOut( __METHOD__
);
392 return "<li>{$link}</li>\n";
395 // If the page doesn't *exist*... our search index is out of date.
396 // The least confusing at this point is to drop the result.
397 // You may get less results, but... oh well. :P
398 if( $result->isMissingRevision() ) {
399 wfProfileOut( __METHOD__
);
400 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
403 // format redirects / relevant sections
404 $redirectTitle = $result->getRedirectTitle();
405 $redirectText = $result->getRedirectSnippet($terms);
406 $sectionTitle = $result->getSectionTitle();
407 $sectionText = $result->getSectionSnippet($terms);
409 if( !is_null($redirectTitle) )
410 $redirect = "<span class='searchalttitle'>"
411 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
414 if( !is_null($sectionTitle) )
415 $section = "<span class='searchalttitle'>"
416 .wfMsg('search-section', $this->sk
->makeKnownLinkObj( $sectionTitle, $sectionText))
419 // format text extract
420 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
423 if( is_null( $result->getScore() ) ) {
424 // Search engine doesn't report scoring info
427 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
428 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
432 // format description
433 $byteSize = $result->getByteSize();
434 $wordCount = $result->getWordCount();
435 $timestamp = $result->getTimestamp();
436 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
437 $this->sk
->formatSize( $byteSize ), $wordCount );
438 $date = $wgLang->timeanddate( $timestamp );
440 // link to related articles if supported
442 if( $result->hasRelated() ) {
443 $st = SpecialPage
::getTitleFor( 'Search' );
444 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
445 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
446 'fulltext' => wfMsg('search') ));
448 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
449 wfMsg('search-relatedarticle').'</a>';
452 // Include a thumbnail for media files...
453 if( $t->getNamespace() == NS_FILE
) {
454 $img = wfFindFile( $t );
456 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
458 $desc = $img->getShortDesc();
459 wfProfileOut( __METHOD__
);
460 // Float doesn't seem to interact well with the bullets.
461 // Table messes up vertical alignment of the bullets.
462 // Bullets are therefore disabled (didn't look great anyway).
464 '<table class="searchResultImage">' .
466 '<td width="120" align="center" valign="top">' .
467 $thumb->toHtml( array( 'desc-link' => true ) ) .
469 '<td valign="top">' .
472 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
481 wfProfileOut( __METHOD__
);
482 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
483 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
489 * Show results from other wikis
491 * @param SearchResultSet $matches
493 protected function showInterwiki( &$matches, $query ) {
495 wfProfileIn( __METHOD__
);
496 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
498 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
499 wfMsg('search-interwiki-caption')."</div>\n";
500 $off = $this->offset +
1;
501 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
503 // work out custom project captions
504 $customCaptions = array();
505 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
506 foreach($customLines as $line) {
507 $parts = explode(":",$line,2);
508 if(count($parts) == 2) // validate line
509 $customCaptions[$parts[0]] = $parts[1];
513 while( $result = $matches->next() ) {
514 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
515 $prev = $result->getInterwikiPrefix();
517 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
518 $out .= "</ul></div>\n";
520 // convert the whole thing to desired language variant
521 $out = $wgContLang->convert( $out );
522 wfProfileOut( __METHOD__
);
527 * Show single interwiki link
529 * @param SearchResult $result
530 * @param string $lastInterwiki
531 * @param array $terms
532 * @param string $query
533 * @param array $customCaptions iw prefix -> caption
535 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
536 wfProfileIn( __METHOD__
);
537 global $wgContLang, $wgLang;
539 if( $result->isBrokenTitle() ) {
540 wfProfileOut( __METHOD__
);
541 return "<!-- Broken link in search result -->\n";
544 $t = $result->getTitle();
546 $link = $this->sk
->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
548 // format redirect if any
549 $redirectTitle = $result->getRedirectTitle();
550 $redirectText = $result->getRedirectSnippet($terms);
552 if( !is_null($redirectTitle) )
553 $redirect = "<span class='searchalttitle'>"
554 .wfMsg('search-redirect',$this->sk
->makeKnownLinkObj( $redirectTitle, $redirectText))
558 // display project name
559 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
560 if( key_exists($t->getInterwiki(),$customCaptions) )
561 // captions from 'search-interwiki-custom'
562 $caption = $customCaptions[$t->getInterwiki()];
564 // default is to show the hostname of the other wiki which might suck
565 // if there are many wikis on one hostname
566 $parsed = parse_url($t->getFullURL());
567 $caption = wfMsg('search-interwiki-default', $parsed['host']);
569 // "more results" link (special page stuff could be localized, but we might not know target lang)
570 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
571 $searchLink = $this->sk
->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
572 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
573 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
574 {$searchLink}</span>{$caption}</div>\n<ul>";
577 $out .= "<li>{$link} {$redirect}</li>\n";
578 wfProfileOut( __METHOD__
);
584 * Generates the power search box at bottom of [[Special:Search]]
585 * @param $term string: search term
586 * @return $out string: HTML form
588 protected function powerSearchBox( $term ) {
591 $namespaces = SearchEngine
::searchableNamespaces();
593 $tables = $this->namespaceTables( $namespaces );
595 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
596 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
597 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
598 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
599 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
601 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
602 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
604 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
607 "<hr style=\"clear: both\" />\n" .
609 $redirect . " " . $redirectLabel .
611 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
617 $t = Title
::newFromText( $term );
618 if( $t != null && count($this->namespaces
) === 1 ) {
619 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
621 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
622 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
623 $this->formHeader($term) . $out .
624 Xml
::closeElement( 'fieldset' );
627 protected function powerSearchFocus() {
628 global $wgJsMimeType;
629 return "<script type=\"$wgJsMimeType\">" .
630 "hookEvent(\"load\", function() {" .
631 "document.getElementById('powerSearchText').focus();" .
636 protected function formHeader( $term ) {
637 global $wgContLang, $wgCanonicalNamespaceNames;
639 $sep = ' ';
640 $out = Xml
::openElement('div', array( 'style' => 'padding-bottom:0.5em;' ) );
643 if( $this->startsWithImage( $term ) )
644 $bareterm = substr( $term, strpos( $term, ':' ) +
1 ); // delete all/image prefix
646 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
648 // search profiles headers
649 $m = wfMsg( 'searchprofile-articles' );
650 $tt = wfMsg( 'searchprofile-articles-tooltip',
651 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::defaultNamespaces() ) ) );
652 if( $this->active
== 'default' ) {
653 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
655 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::defaultNamespaces(), $m, $tt );
659 $m = wfMsg( 'searchprofile-images' );
660 $tt = wfMsg( 'searchprofile-images-tooltip' );
661 if( $this->active
== 'images' ) {
662 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
664 $imageTextForm = $wgContLang->getFormattedNsText(NS_FILE
).':'.$bareterm;
665 $out .= $this->makeSearchLink( $imageTextForm, array( NS_FILE
) , $m, $tt );
670 $m = wfMsg( 'searchprofile-articles-and-proj' );
671 $tt = wfMsg( 'searchprofile-project-tooltip',
672 implode( ', ', SearchEngine::namespacesAsText( SearchEngine::defaultAndProjectNamespaces() ) ) );
673 if( $this->active == 'withproject' ) {
674 $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
676 $out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultAndProjectNamespaces(), $m, $tt );
681 $m = wfMsg( 'searchprofile-project' );
682 $tt = wfMsg( 'searchprofile-project-tooltip',
683 implode( ', ', SearchEngine
::namespacesAsText( SearchEngine
::projectNamespaces() ) ) );
684 if( $this->active
== 'project' ) {
685 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
687 $out .= $this->makeSearchLink( $bareterm, SearchEngine
::projectNamespaces(), $m, $tt );
691 $m = wfMsg( 'searchprofile-everything' );
692 $tt = wfMsg( 'searchprofile-everything-tooltip' );
693 if( $this->active
== 'all' ) {
694 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
696 $out .= $this->makeSearchLink( $bareterm, $nsAllSet, $m, $tt );
700 $m = wfMsg( 'searchprofile-advanced' );
701 $tt = wfMsg( 'searchprofile-advanced-tooltip' );
702 if( $this->active
== 'advanced' ) {
703 $out .= Xml
::element( 'strong', array( 'title'=>$tt ), $m );
705 $out .= $this->makeSearchLink( $bareterm, $this->namespaces
, $m, $tt, array( 'advanced' => '1' ) );
707 $out .= Xml
::closeElement('div') ;
712 protected function shortDialog( $term ) {
714 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
715 $searchable = SearchEngine
::searchableNamespaces();
716 $out = Xml
::openElement( 'form', array( 'id' => 'search', 'method' => 'get', 'action' => $wgScript ) );
717 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
718 // If searching several, but not all namespaces, show what we are searching.
719 if( count($this->namespaces
) > 1 && $this->namespaces
!== array_keys($searchable) ) {
721 foreach( $this->namespaces
as $ns ) {
722 $active[$ns] = $searchable[$ns];
724 $out .= wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) . "<br/>\n";
725 $out .= $this->namespaceTables( $active, 1 )."<br/>\n";
726 // Still keep namespace settings otherwise, but don't show them
728 foreach( $this->namespaces
as $ns ) {
729 $out .= Xml
::hidden( "ns{$ns}", '1' );
732 // Keep redirect setting
733 $out .= Xml
::hidden( "redirs", (int)$this->searchRedirects
);
735 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
736 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
737 $out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')';
738 $out .= Xml
::closeElement( 'form' );
739 // Add prefix link for single-namespace searches
740 $t = Title
::newFromText( $term );
741 if( $t != null && count($this->namespaces
) === 1 ) {
742 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
744 return Xml
::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
745 Xml
::element( 'legend', null, wfMsg('searchmenu-legend') ) .
746 $this->formHeader($term) . $out .
747 Xml
::closeElement( 'fieldset' );
750 /** Make a search link with some target namespaces */
751 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
753 foreach( $namespaces as $n ) {
756 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
758 $st = SpecialPage
::getTitleFor( 'Search' );
759 $stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt );
761 return Xml
::element( 'a',
762 array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
766 /** Check if query starts with image: prefix */
767 protected function startsWithImage( $term ) {
770 $p = explode( ':', $term );
771 if( count( $p ) > 1 ) {
772 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
777 protected function namespaceTables( $namespaces, $rowsPerTable = 3 ) {
779 // Group namespaces into rows according to subject.
780 // Try not to make too many assumptions about namespace numbering.
783 foreach( $namespaces as $ns => $name ) {
784 $subj = Namespace::getSubject( $ns );
785 if( !array_key_exists( $subj, $rows ) ) {
788 $name = str_replace( '_', ' ', $name );
790 $name = wfMsg( 'blanknamespace' );
792 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
793 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
794 Xml
::closeElement( 'td' ) . "\n";
796 $rows = array_values( $rows );
797 $numRows = count( $rows );
798 // Lay out namespaces in multiple floating two-column tables so they'll
799 // be arranged nicely while still accommodating different screen widths
800 // Float to the right on RTL wikis
801 $tableStyle = $wgContLang->isRTL() ?
802 'float: right; margin: 0 0 0em 1em' : 'float: left; margin: 0 1em 0em 0';
803 // Build the final HTML table...
804 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
805 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
806 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
807 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
809 $tables .= Xml
::closeElement( 'table' ) . "\n";
816 * implements Special:Search - Run text & title search and display the output
817 * @ingroup SpecialPage
819 class SpecialSearchOld
{
822 * Set up basic search parameters from the request and user settings.
823 * Typically you'll pass $wgRequest and $wgUser.
825 * @param WebRequest $request
829 function __construct( &$request, &$user ) {
830 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
832 $this->namespaces
= $this->powerSearch( $request );
833 if( empty( $this->namespaces
) ) {
834 $this->namespaces
= SearchEngine
::userNamespaces( $user );
837 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
841 * If an exact title match can be found, jump straight ahead to it.
842 * @param string $term
845 function goResult( $term ) {
849 $this->setupPage( $term );
851 # Try to go to page as entered.
852 $t = Title
::newFromText( $term );
854 # If the string cannot be used to create a title
856 return $this->showResults( $term );
859 # If there's an exact or very near match, jump right there.
860 $t = SearchEngine
::getNearMatch( $term );
861 if( !is_null( $t ) ) {
862 $wgOut->redirect( $t->getFullURL() );
866 # No match, generate an edit URL
867 $t = Title
::newFromText( $term );
868 if( ! is_null( $t ) ) {
869 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
870 # If the feature is enabled, go straight to the edit page
872 $wgOut->redirect( $t->getFullURL( 'action=edit' ) );
877 $wgOut->wrapWikiMsg( "==$1==\n", 'notitlematches' );
878 if( $t->quickUserCan( 'create' ) && $t->quickUserCan( 'edit' ) ) {
879 $wgOut->addWikiMsg( 'noexactmatch', wfEscapeWikiText( $term ) );
881 $wgOut->addWikiMsg( 'noexactmatch-nocreate', wfEscapeWikiText( $term ) );
884 return $this->showResults( $term );
888 * @param string $term
891 function showResults( $term ) {
892 wfProfileIn( __METHOD__
);
893 global $wgOut, $wgUser;
894 $sk = $wgUser->getSkin();
896 $this->setupPage( $term );
898 $wgOut->addWikiMsg( 'searchresulttext' );
900 if( '' === trim( $term ) ) {
901 // Empty query -- straight view of search form
902 $wgOut->setSubtitle( '' );
903 $wgOut->addHTML( $this->powerSearchBox( $term ) );
904 $wgOut->addHTML( $this->powerSearchFocus() );
905 wfProfileOut( __METHOD__
);
909 global $wgDisableTextSearch;
910 if ( $wgDisableTextSearch ) {
911 global $wgSearchForwardUrl;
912 if( $wgSearchForwardUrl ) {
913 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
914 $wgOut->redirect( $url );
915 wfProfileOut( __METHOD__
);
918 global $wgInputEncoding;
920 Xml
::openElement( 'fieldset' ) .
921 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
922 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
923 wfMsg( 'googlesearch',
924 htmlspecialchars( $term ),
925 htmlspecialchars( $wgInputEncoding ),
926 htmlspecialchars( wfMsg( 'searchbutton' ) )
928 Xml
::closeElement( 'fieldset' )
930 wfProfileOut( __METHOD__
);
934 $wgOut->addHTML( $this->shortDialog( $term ) );
936 $search = SearchEngine
::create();
937 $search->setLimitOffset( $this->limit
, $this->offset
);
938 $search->setNamespaces( $this->namespaces
);
939 $search->showRedirects
= $this->searchRedirects
;
940 $rewritten = $search->replacePrefixes($term);
942 $titleMatches = $search->searchTitle( $rewritten );
944 // Sometimes the search engine knows there are too many hits
945 if ($titleMatches instanceof SearchResultTooMany
) {
946 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
947 $wgOut->addHTML( $this->powerSearchBox( $term ) );
948 $wgOut->addHTML( $this->powerSearchFocus() );
949 wfProfileOut( __METHOD__
);
953 $textMatches = $search->searchText( $rewritten );
955 // did you mean... suggestions
956 if($textMatches && $textMatches->hasSuggestion()){
957 $st = SpecialPage
::getTitleFor( 'Search' );
958 $stParams = wfArrayToCGI( array(
959 'search' => $textMatches->getSuggestionQuery(),
960 'fulltext' => wfMsg('search')),
961 $this->powerSearchOptions());
963 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
964 $textMatches->getSuggestionSnippet().'</a>';
966 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
969 // show number of results
970 $num = ( $titleMatches ?
$titleMatches->numRows() : 0 )
971 +
( $textMatches ?
$textMatches->numRows() : 0);
973 if($titleMatches && !is_null($titleMatches->getTotalHits()))
974 $totalNum +
= $titleMatches->getTotalHits();
975 if($textMatches && !is_null($textMatches->getTotalHits()))
976 $totalNum +
= $textMatches->getTotalHits();
978 if ( $totalNum > 0 ){
979 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
980 $this->offset+
1, $this->offset+
$num, $totalNum, $num );
981 } elseif ( $num >= $this->limit
) {
982 $top = wfShowingResults( $this->offset
, $this->limit
);
984 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $num );
986 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
990 if( $num ||
$this->offset
) {
991 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
992 SpecialPage
::getTitleFor( 'Search' ),
994 $this->powerSearchOptions(),
995 array( 'search' => $term ) ),
996 ($num < $this->limit
) );
997 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
998 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
1000 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
1003 if( $titleMatches ) {
1004 if( $titleMatches->numRows() ) {
1005 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
1006 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
1008 $titleMatches->free();
1011 if( $textMatches ) {
1012 // output appropriate heading
1013 if( $textMatches->numRows() ) {
1015 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
1016 else // if no title matches the heading is redundant
1017 $wgOut->addHTML("<hr/>");
1018 } elseif( $num == 0 ) {
1019 # Don't show the 'no text matches' if we received title matches
1020 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
1022 // show interwiki results if any
1023 if( $textMatches->hasInterwikiResults() )
1024 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
1026 if( $textMatches->numRows() )
1027 $wgOut->addHTML( $this->showMatches( $textMatches ) );
1029 $textMatches->free();
1033 $wgOut->addWikiMsg( 'nonefound' );
1035 if( $num ||
$this->offset
) {
1036 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
1038 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1039 wfProfileOut( __METHOD__
);
1042 #------------------------------------------------------------------
1043 # Private methods below this line
1048 function setupPage( $term ) {
1050 if( !empty( $term ) ){
1051 $wgOut->setPageTitle( wfMsg( 'searchresults') );
1052 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
1054 $subtitlemsg = ( Title
::newFromText( $term ) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
1055 $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
1056 $wgOut->setArticleRelated( false );
1057 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1061 * Extract "power search" namespace settings from the request object,
1062 * returning a list of index numbers to search.
1064 * @param WebRequest $request
1068 function powerSearch( &$request ) {
1070 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1071 if( $request->getCheck( 'ns' . $ns ) ) {
1079 * Reconstruct the 'power search' options for links
1083 function powerSearchOptions() {
1085 foreach( $this->namespaces
as $n ) {
1086 $opt['ns' . $n] = 1;
1088 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
1093 * Show whole set of results
1095 * @param SearchResultSet $matches
1097 function showMatches( &$matches ) {
1098 wfProfileIn( __METHOD__
);
1101 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1105 $infoLine = $matches->getInfo();
1106 if( !is_null($infoLine) )
1107 $out .= "\n<!-- {$infoLine} -->\n";
1110 $off = $this->offset +
1;
1111 $out .= "<ul class='mw-search-results'>\n";
1113 while( $result = $matches->next() ) {
1114 $out .= $this->showHit( $result, $terms );
1118 // convert the whole thing to desired language variant
1120 $out = $wgContLang->convert( $out );
1121 wfProfileOut( __METHOD__
);
1126 * Format a single hit result
1127 * @param SearchResult $result
1128 * @param array $terms terms to highlight
1130 function showHit( $result, $terms ) {
1131 wfProfileIn( __METHOD__
);
1132 global $wgUser, $wgContLang, $wgLang;
1134 if( $result->isBrokenTitle() ) {
1135 wfProfileOut( __METHOD__
);
1136 return "<!-- Broken link in search result -->\n";
1139 $t = $result->getTitle();
1140 $sk = $wgUser->getSkin();
1142 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1144 //If page content is not readable, just return the title.
1145 //This is not quite safe, but better than showing excerpts from non-readable pages
1146 //Note that hiding the entry entirely would screw up paging.
1147 if (!$t->userCanRead()) {
1148 wfProfileOut( __METHOD__
);
1149 return "<li>{$link}</li>\n";
1152 // If the page doesn't *exist*... our search index is out of date.
1153 // The least confusing at this point is to drop the result.
1154 // You may get less results, but... oh well. :P
1155 if( $result->isMissingRevision() ) {
1156 wfProfileOut( __METHOD__
);
1157 return "<!-- missing page " .
1158 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
1161 // format redirects / relevant sections
1162 $redirectTitle = $result->getRedirectTitle();
1163 $redirectText = $result->getRedirectSnippet($terms);
1164 $sectionTitle = $result->getSectionTitle();
1165 $sectionText = $result->getSectionSnippet($terms);
1167 if( !is_null($redirectTitle) )
1168 $redirect = "<span class='searchalttitle'>"
1169 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1172 if( !is_null($sectionTitle) )
1173 $section = "<span class='searchalttitle'>"
1174 .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
1177 // format text extract
1178 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
1181 if( is_null( $result->getScore() ) ) {
1182 // Search engine doesn't report scoring info
1185 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
1186 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
1190 // format description
1191 $byteSize = $result->getByteSize();
1192 $wordCount = $result->getWordCount();
1193 $timestamp = $result->getTimestamp();
1194 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
1195 $sk->formatSize( $byteSize ),
1197 $date = $wgLang->timeanddate( $timestamp );
1199 // link to related articles if supported
1201 if( $result->hasRelated() ){
1202 $st = SpecialPage
::getTitleFor( 'Search' );
1203 $stParams = wfArrayToCGI( $this->powerSearchOptions(),
1204 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
1205 'fulltext' => wfMsg('search') ));
1207 $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
1208 wfMsg('search-relatedarticle').'</a>';
1211 // Include a thumbnail for media files...
1212 if( $t->getNamespace() == NS_FILE
) {
1213 $img = wfFindFile( $t );
1215 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
1217 $desc = $img->getShortDesc();
1218 wfProfileOut( __METHOD__
);
1220 // Float doesn't seem to interact well with the bullets.
1221 // Table messes up vertical alignment of the bullet, but I'm
1222 // not sure what more I can do about that. :(
1224 '<table class="searchResultImage">' .
1226 '<td width="120" align="center">' .
1227 $thumb->toHtml( array( 'desc-link' => true ) ) .
1229 '<td valign="top">' .
1232 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
1241 wfProfileOut( __METHOD__
);
1242 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
1243 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
1249 * Show results from other wikis
1251 * @param SearchResultSet $matches
1253 function showInterwiki( &$matches, $query ) {
1254 wfProfileIn( __METHOD__
);
1257 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1259 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
1260 $off = $this->offset +
1;
1261 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
1263 // work out custom project captions
1264 $customCaptions = array();
1265 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
1266 foreach($customLines as $line){
1267 $parts = explode(":",$line,2);
1268 if(count($parts) == 2) // validate line
1269 $customCaptions[$parts[0]] = $parts[1];
1274 while( $result = $matches->next() ) {
1275 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
1276 $prev = $result->getInterwikiPrefix();
1278 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
1279 $out .= "</ul></div>\n";
1281 // convert the whole thing to desired language variant
1283 $out = $wgContLang->convert( $out );
1284 wfProfileOut( __METHOD__
);
1289 * Show single interwiki link
1291 * @param SearchResult $result
1292 * @param string $lastInterwiki
1293 * @param array $terms
1294 * @param string $query
1295 * @param array $customCaptions iw prefix -> caption
1297 function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
1298 wfProfileIn( __METHOD__
);
1299 global $wgUser, $wgContLang, $wgLang;
1301 if( $result->isBrokenTitle() ) {
1302 wfProfileOut( __METHOD__
);
1303 return "<!-- Broken link in search result -->\n";
1306 $t = $result->getTitle();
1307 $sk = $wgUser->getSkin();
1309 $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
1311 // format redirect if any
1312 $redirectTitle = $result->getRedirectTitle();
1313 $redirectText = $result->getRedirectSnippet($terms);
1315 if( !is_null($redirectTitle) )
1316 $redirect = "<span class='searchalttitle'>"
1317 .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
1321 // display project name
1322 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()){
1323 if( key_exists($t->getInterwiki(),$customCaptions) )
1324 // captions from 'search-interwiki-custom'
1325 $caption = $customCaptions[$t->getInterwiki()];
1327 // default is to show the hostname of the other wiki which might suck
1328 // if there are many wikis on one hostname
1329 $parsed = parse_url($t->getFullURL());
1330 $caption = wfMsg('search-interwiki-default', $parsed['host']);
1332 // "more results" link (special page stuff could be localized, but we might not know target lang)
1333 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
1334 $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'),
1335 wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search')));
1336 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>{$searchLink}</span>{$caption}</div>\n<ul>";
1339 $out .= "<li>{$link} {$redirect}</li>\n";
1340 wfProfileOut( __METHOD__
);
1346 * Generates the power search box at bottom of [[Special:Search]]
1347 * @param $term string: search term
1348 * @return $out string: HTML form
1350 function powerSearchBox( $term ) {
1351 global $wgScript, $wgContLang;
1353 $namespaces = SearchEngine
::searchableNamespaces();
1355 // group namespaces into rows according to subject; try not to make too
1356 // many assumptions about namespace numbering
1358 foreach( $namespaces as $ns => $name ) {
1359 $subj = Namespace::getSubject( $ns );
1360 if( !array_key_exists( $subj, $rows ) ) {
1363 $name = str_replace( '_', ' ', $name );
1365 $name = wfMsg( 'blanknamespace' );
1367 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
1368 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
1369 Xml
::closeElement( 'td' ) . "\n";
1371 $rows = array_values( $rows );
1372 $numRows = count( $rows );
1374 // lay out namespaces in multiple floating two-column tables so they'll
1375 // be arranged nicely while still accommodating different screen widths
1376 $rowsPerTable = 3; // seems to look nice
1378 // float to the right on RTL wikis
1379 $tableStyle = ( $wgContLang->isRTL() ?
1380 'float: right; margin: 0 0 1em 1em' :
1381 'float: left; margin: 0 1em 1em 0' );
1384 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
1385 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
1386 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
1387 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
1389 $tables .= Xml
::closeElement( 'table' ) . "\n";
1392 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
1393 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
1394 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
1395 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
1396 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1398 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
1399 Xml
::fieldset( wfMsg( 'powersearch-legend' ),
1400 Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
1402 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
1405 "<hr style=\"clear: both\" />\n" .
1407 $redirect . " " . $redirectLabel .
1409 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
1419 function powerSearchFocus() {
1420 global $wgJsMimeType;
1421 return "<script type=\"$wgJsMimeType\">" .
1422 "hookEvent(\"load\", function(){" .
1423 "document.getElementById('powerSearchText').focus();" .
1428 function shortDialog($term) {
1431 $out = Xml
::openElement( 'form', array(
1434 'action' => $wgScript
1436 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1437 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() );
1438 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . ' ';
1439 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1440 if( in_array( $ns, $this->namespaces
) ) {
1441 $out .= Xml
::hidden( "ns{$ns}", '1' );
1444 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ), array( 'name' => 'fulltext' ) );
1445 $out .= Xml
::closeElement( 'form' );