2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 * Run text & title search and display the output
23 * @ingroup SpecialPage
29 * @param $par String: (default '')
31 function wfSpecialSearch( $par = '' ) {
32 global $wgRequest, $wgUser, $wgUseOldSearchUI;
33 // Strip underscores from title parameter; most of the time we'll want
34 // text form here. But don't strip underscores from actual text params!
35 $titleParam = str_replace( '_', ' ', $par );
36 // Fetch the search term
37 $search = str_replace( "\n", " ", $wgRequest->getText( 'search', $titleParam ) );
38 $class = $wgUseOldSearchUI ?
'SpecialSearchOld' : 'SpecialSearch';
39 $searchPage = new $class( $wgRequest, $wgUser );
40 if( $wgRequest->getVal( 'fulltext' )
41 ||
!is_null( $wgRequest->getVal( 'offset' ))
42 ||
!is_null( $wgRequest->getVal( 'searchx' )) )
44 $searchPage->showResults( $search );
46 $searchPage->goResult( $search );
51 * implements Special:Search - Run text & title search and display the output
52 * @ingroup SpecialPage
57 * Set up basic search parameters from the request and user settings.
58 * Typically you'll pass $wgRequest and $wgUser.
60 * @param WebRequest $request
64 function __construct( &$request, &$user ) {
65 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
66 $this->mPrefix
= $request->getVal('prefix', '');
67 # Extract requested namespaces
68 $this->namespaces
= $this->powerSearch( $request );
69 if( empty( $this->namespaces
) ) {
70 $this->namespaces
= SearchEngine
::userNamespaces( $user );
72 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
73 $this->searchAdvanced
= $request->getVal( 'advanced' );
74 $this->active
= 'advanced';
75 $this->sk
= $user->getSkin();
76 $this->didYouMeanHtml
= ''; # html of did you mean... link
77 $this->fulltext
= $request->getVal('fulltext');
81 * If an exact title match can be found, jump straight ahead to it.
84 public function goResult( $term ) {
86 $this->setupPage( $term );
87 # Try to go to page as entered.
88 $t = Title
::newFromText( $term );
89 # If the string cannot be used to create a title
91 return $this->showResults( $term );
93 # If there's an exact or very near match, jump right there.
94 $t = SearchEngine
::getNearMatch( $term );
95 if( !is_null( $t ) ) {
96 $wgOut->redirect( $t->getFullURL() );
99 # No match, generate an edit URL
100 $t = Title
::newFromText( $term );
101 if( !is_null( $t ) ) {
103 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
104 # If the feature is enabled, go straight to the edit page
106 $wgOut->redirect( $t->getFullURL( array( 'action' => 'edit' ) ) );
110 return $this->showResults( $term );
114 * @param string $term
116 public function showResults( $term ) {
117 global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
118 wfProfileIn( __METHOD__
);
120 $sk = $wgUser->getSkin();
122 $this->searchEngine
= SearchEngine
::create();
123 $search =& $this->searchEngine
;
124 $search->setLimitOffset( $this->limit
, $this->offset
);
125 $search->setNamespaces( $this->namespaces
);
126 $search->showRedirects
= $this->searchRedirects
;
127 $search->prefix
= $this->mPrefix
;
128 $term = $search->transformSearchTerm($term);
130 $this->setupPage( $term );
132 if( $wgDisableTextSearch ) {
133 global $wgSearchForwardUrl;
134 if( $wgSearchForwardUrl ) {
135 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
136 $wgOut->redirect( $url );
137 wfProfileOut( __METHOD__
);
140 global $wgInputEncoding;
142 Xml
::openElement( 'fieldset' ) .
143 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
144 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
145 wfMsg( 'googlesearch',
146 htmlspecialchars( $term ),
147 htmlspecialchars( $wgInputEncoding ),
148 htmlspecialchars( wfMsg( 'searchbutton' ) )
150 Xml
::closeElement( 'fieldset' )
152 wfProfileOut( __METHOD__
);
156 $t = Title
::newFromText( $term );
158 // fetch search results
159 $rewritten = $search->replacePrefixes($term);
161 $titleMatches = $search->searchTitle( $rewritten );
162 if( !($titleMatches instanceof SearchResultTooMany
))
163 $textMatches = $search->searchText( $rewritten );
165 // did you mean... suggestions
166 if( $textMatches && $textMatches->hasSuggestion() ) {
167 $st = SpecialPage
::getTitleFor( 'Search' );
169 # mirror Go/Search behaviour of original request ..
170 $didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
172 if($this->fulltext
!= NULL)
173 $didYouMeanParams['fulltext'] = $this->fulltext
;
175 $stParams = array_merge(
177 $this->powerSearchOptions()
180 $suggestionSnippet = $textMatches->getSuggestionSnippet();
182 if( $suggestionSnippet == '' )
183 $suggestionSnippet = null;
185 $suggestLink = $sk->linkKnown(
192 $this->didYouMeanHtml
= '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
194 // start rendering the page
199 'id' => ( $this->searchAdvanced ?
'powersearch' : 'search' ),
201 'action' => $wgScript
206 Xml
::openElement( 'table', array( 'id'=>'mw-search-top-table', 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
207 Xml
::openElement( 'tr' ) .
208 Xml
::openElement( 'td' ) . "\n" .
209 $this->shortDialog( $term ) .
210 Xml
::closeElement('td') .
211 Xml
::closeElement('tr') .
212 Xml
::closeElement('table')
215 // Sometimes the search engine knows there are too many hits
216 if( $titleMatches instanceof SearchResultTooMany
) {
217 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
218 wfProfileOut( __METHOD__
);
222 $filePrefix = $wgContLang->getFormattedNsText(NS_FILE
).':';
223 if( '' === trim( $term ) ||
$filePrefix === trim( $term ) ) {
224 $wgOut->addHTML( $this->searchFocus() );
225 $wgOut->addHTML( $this->formHeader($term, 0, 0));
226 if( $this->searchAdvanced
) {
227 $wgOut->addHTML( $this->powerSearchBox( $term ) );
229 $wgOut->addHTML( '</form>' );
230 // Empty query -- straight view of search form
231 wfProfileOut( __METHOD__
);
235 // Get number of results
236 $titleMatchesNum = $titleMatches ?
$titleMatches->numRows() : 0;
237 $textMatchesNum = $textMatches ?
$textMatches->numRows() : 0;
238 // Total initial query matches (possible false positives)
239 $num = $titleMatchesNum +
$textMatchesNum;
241 // Get total actual results (after second filtering, if any)
242 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
243 $titleMatches->getTotalHits() : $titleMatchesNum;
244 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
245 $textMatches->getTotalHits() : $textMatchesNum;
247 // get total number of results if backend can calculate it
249 if($titleMatches && !is_null( $titleMatches->getTotalHits() ) )
250 $totalRes +
= $titleMatches->getTotalHits();
251 if($textMatches && !is_null( $textMatches->getTotalHits() ))
252 $totalRes +
= $textMatches->getTotalHits();
254 // show number of results and current offset
255 $wgOut->addHTML( $this->formHeader($term, $num, $totalRes));
256 if( $this->searchAdvanced
) {
257 $wgOut->addHTML( $this->powerSearchBox( $term ) );
260 $wgOut->addHtml( Xml
::closeElement( 'form' ) );
261 $wgOut->addHtml( "<div class='searchresults'>" );
263 // show direct page/create link
265 if( !$t->exists() ) {
266 $wgOut->addWikiMsg( 'searchmenu-new', wfEscapeWikiText( $t->getPrefixedText() ) );
268 $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) );
271 // preserve the paragraph for margins etc...
272 $wgOut->addHTML('<p></p>');
276 if( $num ||
$this->offset
) {
277 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
278 SpecialPage
::getTitleFor( 'Search' ),
279 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
280 max( $titleMatchesNum, $textMatchesNum ) < $this->limit
282 //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
283 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
285 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
288 if( $titleMatches ) {
289 if( $numTitleMatches > 0 ) {
290 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
291 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
293 $titleMatches->free();
296 // output appropriate heading
297 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
298 // if no title matches the heading is redundant
299 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
300 } elseif( $totalRes == 0 ) {
301 # Don't show the 'no text matches' if we received title matches
302 # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
304 // show interwiki results if any
305 if( $textMatches->hasInterwikiResults() ) {
306 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
309 if( $numTextMatches > 0 ) {
310 $wgOut->addHTML( $this->showMatches( $textMatches ) );
313 $textMatches->free();
316 $wgOut->addWikiMsg( 'search-nonefound' );
318 $wgOut->addHtml( "</div>" );
320 $wgOut->addHTML( $this->searchFocus() );
323 if( $num ||
$this->offset
) {
324 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
326 wfProfileOut( __METHOD__
);
332 protected function setupPage( $term ) {
334 // Figure out the active search profile header
335 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
336 if( $this->searchAdvanced
)
337 $this->active
= 'advanced';
338 else if( $this->namespaces
=== array(NS_FILE
) ||
$this->startsWithImage( $term ) )
339 $this->active
= 'images';
340 elseif( $this->namespaces
=== $nsAllSet ||
$this->startsWithAll( $term ) )
341 $this->active
= 'all';
342 elseif( $this->namespaces
=== SearchEngine
::defaultNamespaces() )
343 $this->active
= 'default';
344 elseif( $this->namespaces
=== SearchEngine
::helpNamespaces() )
345 $this->active
= 'help';
347 $this->active
= 'advanced';
348 # Should advanced UI be used?
349 $this->searchAdvanced
= ($this->active
=== 'advanced');
350 if( !empty( $term ) ) {
351 $wgOut->setPageTitle( wfMsg( 'searchresults') );
352 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
354 $wgOut->setArticleRelated( false );
355 $wgOut->setRobotPolicy( 'noindex,nofollow' );
356 // add javascript specific to special:search
357 $wgOut->addScriptFile( 'search.js' );
361 * Extract "power search" namespace settings from the request object,
362 * returning a list of index numbers to search.
364 * @param WebRequest $request
367 protected function powerSearch( &$request ) {
369 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
370 if( $request->getCheck( 'ns' . $ns ) ) {
378 * Reconstruct the 'power search' options for links
381 protected function powerSearchOptions() {
383 foreach( $this->namespaces
as $n ) {
386 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
387 if( $this->searchAdvanced
) {
388 $opt['advanced'] = $this->searchAdvanced
;
394 * Show whole set of results
396 * @param SearchResultSet $matches
398 protected function showMatches( &$matches ) {
400 wfProfileIn( __METHOD__
);
402 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
405 $infoLine = $matches->getInfo();
406 if( !is_null($infoLine) ) {
407 $out .= "\n<!-- {$infoLine} -->\n";
409 $off = $this->offset +
1;
410 $out .= "<ul class='mw-search-results'>\n";
411 while( $result = $matches->next() ) {
412 $out .= $this->showHit( $result, $terms );
416 // convert the whole thing to desired language variant
417 $out = $wgContLang->convert( $out );
418 wfProfileOut( __METHOD__
);
423 * Format a single hit result
424 * @param SearchResult $result
425 * @param array $terms terms to highlight
427 protected function showHit( $result, $terms ) {
428 global $wgContLang, $wgLang, $wgUser;
429 wfProfileIn( __METHOD__
);
431 if( $result->isBrokenTitle() ) {
432 wfProfileOut( __METHOD__
);
433 return "<!-- Broken link in search result -->\n";
436 $sk = $wgUser->getSkin();
437 $t = $result->getTitle();
439 $titleSnippet = $result->getTitleSnippet($terms);
441 if( $titleSnippet == '' )
442 $titleSnippet = null;
444 $link = $this->sk
->linkKnown(
449 //If page content is not readable, just return the title.
450 //This is not quite safe, but better than showing excerpts from non-readable pages
451 //Note that hiding the entry entirely would screw up paging.
452 if( !$t->userCanRead() ) {
453 wfProfileOut( __METHOD__
);
454 return "<li>{$link}</li>\n";
457 // If the page doesn't *exist*... our search index is out of date.
458 // The least confusing at this point is to drop the result.
459 // You may get less results, but... oh well. :P
460 if( $result->isMissingRevision() ) {
461 wfProfileOut( __METHOD__
);
462 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
465 // format redirects / relevant sections
466 $redirectTitle = $result->getRedirectTitle();
467 $redirectText = $result->getRedirectSnippet($terms);
468 $sectionTitle = $result->getSectionTitle();
469 $sectionText = $result->getSectionSnippet($terms);
472 if( !is_null($redirectTitle) ) {
473 if( $redirectText == '' )
474 $redirectText = null;
476 $redirect = "<span class='searchalttitle'>" .
479 $this->sk
->linkKnown(
490 if( !is_null($sectionTitle) ) {
491 if( $sectionText == '' )
494 $section = "<span class='searchalttitle'>" .
496 'search-section', $this->sk
->linkKnown(
504 // format text extract
505 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
508 if( is_null( $result->getScore() ) ) {
509 // Search engine doesn't report scoring info
512 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
513 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
517 // format description
518 $byteSize = $result->getByteSize();
519 $wordCount = $result->getWordCount();
520 $timestamp = $result->getTimestamp();
522 'search-result-size',
523 array( 'parsemag', 'escape' ),
524 $this->sk
->formatSize( $byteSize ),
527 $date = $wgLang->timeanddate( $timestamp );
529 // link to related articles if supported
531 if( $result->hasRelated() ) {
532 $st = SpecialPage
::getTitleFor( 'Search' );
533 $stParams = array_merge(
534 $this->powerSearchOptions(),
536 'search' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText(),
537 'fulltext' => wfMsg( 'search' )
541 $related = ' -- ' . $sk->linkKnown(
543 wfMsg('search-relatedarticle'),
549 // Include a thumbnail for media files...
550 if( $t->getNamespace() == NS_FILE
) {
551 $img = wfFindFile( $t );
553 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
555 $desc = $img->getShortDesc();
556 wfProfileOut( __METHOD__
);
557 // Float doesn't seem to interact well with the bullets.
558 // Table messes up vertical alignment of the bullets.
559 // Bullets are therefore disabled (didn't look great anyway).
561 '<table class="searchResultImage">' .
563 '<td width="120" align="center" valign="top">' .
564 $thumb->toHtml( array( 'desc-link' => true ) ) .
566 '<td valign="top">' .
569 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
578 wfProfileOut( __METHOD__
);
579 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
580 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
586 * Show results from other wikis
588 * @param SearchResultSet $matches
590 protected function showInterwiki( &$matches, $query ) {
592 wfProfileIn( __METHOD__
);
593 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
595 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
596 wfMsg('search-interwiki-caption')."</div>\n";
597 $off = $this->offset +
1;
598 $out .= "<ul class='mw-search-iwresults'>\n";
600 // work out custom project captions
601 $customCaptions = array();
602 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
603 foreach($customLines as $line) {
604 $parts = explode(":",$line,2);
605 if(count($parts) == 2) // validate line
606 $customCaptions[$parts[0]] = $parts[1];
610 while( $result = $matches->next() ) {
611 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
612 $prev = $result->getInterwikiPrefix();
614 // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
615 $out .= "</ul></div>\n";
617 // convert the whole thing to desired language variant
618 $out = $wgContLang->convert( $out );
619 wfProfileOut( __METHOD__
);
624 * Show single interwiki link
626 * @param SearchResult $result
627 * @param string $lastInterwiki
628 * @param array $terms
629 * @param string $query
630 * @param array $customCaptions iw prefix -> caption
632 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
633 wfProfileIn( __METHOD__
);
634 global $wgContLang, $wgLang;
636 if( $result->isBrokenTitle() ) {
637 wfProfileOut( __METHOD__
);
638 return "<!-- Broken link in search result -->\n";
641 $t = $result->getTitle();
643 $titleSnippet = $result->getTitleSnippet($terms);
645 if( $titleSnippet == '' )
646 $titleSnippet = null;
648 $link = $this->sk
->linkKnown(
653 // format redirect if any
654 $redirectTitle = $result->getRedirectTitle();
655 $redirectText = $result->getRedirectSnippet($terms);
657 if( !is_null($redirectTitle) ) {
658 if( $redirectText == '' )
659 $redirectText = null;
661 $redirect = "<span class='searchalttitle'>" .
664 $this->sk
->linkKnown(
673 // display project name
674 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
675 if( key_exists($t->getInterwiki(),$customCaptions) )
676 // captions from 'search-interwiki-custom'
677 $caption = $customCaptions[$t->getInterwiki()];
679 // default is to show the hostname of the other wiki which might suck
680 // if there are many wikis on one hostname
681 $parsed = parse_url($t->getFullURL());
682 $caption = wfMsg('search-interwiki-default', $parsed['host']);
684 // "more results" link (special page stuff could be localized, but we might not know target lang)
685 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
686 $searchLink = $this->sk
->linkKnown(
688 wfMsg('search-interwiki-more'),
692 'fulltext' => 'Search'
695 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
696 {$searchLink}</span>{$caption}</div>\n<ul>";
699 $out .= "<li>{$link} {$redirect}</li>\n";
700 wfProfileOut( __METHOD__
);
706 * Generates the power search box at bottom of [[Special:Search]]
707 * @param $term string: search term
708 * @return $out string: HTML form
710 protected function powerSearchBox( $term ) {
711 global $wgScript, $wgContLang;
713 // Groups namespaces into rows according to subject
715 foreach( SearchEngine
::searchableNamespaces() as $namespace => $name ) {
716 $subject = MWNamespace
::getSubject( $namespace );
717 if( !array_key_exists( $subject, $rows ) ) {
718 $rows[$subject] = "";
720 $name = str_replace( '_', ' ', $name );
722 $name = wfMsg( 'blanknamespace' );
726 'td', array( 'style' => 'white-space: nowrap' )
731 "mw-search-ns{$namespace}",
732 in_array( $namespace, $this->namespaces
)
734 Xml
::closeElement( 'td' );
736 $rows = array_values( $rows );
737 $numRows = count( $rows );
739 // Lays out namespaces in multiple floating two-column tables so they'll
740 // be arranged nicely while still accommodating different screen widths
741 $namespaceTables = '';
742 for( $i = 0; $i < $numRows; $i +
= 4 ) {
743 $namespaceTables .= Xml
::openElement(
745 array( 'cellpadding' => 0, 'cellspacing' => 0, 'border' => 0 )
747 for( $j = $i; $j < $i +
4 && $j < $numRows; $j++
) {
748 $namespaceTables .= Xml
::tags( 'tr', null, $rows[$j] );
750 $namespaceTables .= Xml
::closeElement( 'table' );
752 // Show redirects check only if backend supports it
754 if( $this->searchEngine
->acceptListRedirects() ) {
757 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' )
760 Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
762 // Return final output
766 array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
768 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
769 Xml
::element( 'h4', null, wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) ) .
772 array( 'id' => 'mw-search-togglebox' ),
773 Xml
::label( wfMsg( 'powersearch-togglelabel' ), 'mw-search-togglelabel' ) .
778 'id' => 'mw-search-toggleall',
779 'onclick' => 'mwToggleSearchCheckboxes("all");',
780 'value' => wfMsg( 'powersearch-toggleall' )
787 'id' => 'mw-search-togglenone',
788 'onclick' => 'mwToggleSearchCheckboxes("none");',
789 'value' => wfMsg( 'powersearch-togglenone'
794 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
796 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
798 Xml
::hidden( 'title', SpecialPage
::getTitleFor( 'Search' )->getPrefixedText() ) .
799 Xml
::hidden( 'advanced', $this->searchAdvanced
) .
800 Xml
::hidden( 'fulltext', 'Advanced search' ) .
801 Xml
::closeElement( 'fieldset' );
804 protected function searchFocus() {
805 global $wgJsMimeType;
806 return "<script type=\"$wgJsMimeType\">" .
807 "hookEvent(\"load\", function() {" .
808 "document.getElementById('searchText').focus();" .
813 protected function formHeader( $term, $resultsShown, $totalNum ) {
814 global $wgContLang, $wgCanonicalNamespaceNames, $wgLang;
816 $out = Xml
::openElement('div', array( 'class' => 'mw-search-formheader' ) );
819 if( $this->startsWithImage( $term ) ) {
821 $bareterm = substr( $term, strpos( $term, ':' ) +
1 );
823 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
825 // Builds list of Search Types (profiles)
828 'message' => 'searchprofile-articles',
829 'tooltip' => 'searchprofile-articles-tooltip',
830 'namespaces' => SearchEngine
::defaultNamespaces(),
831 'namespace-messages' => SearchEngine
::namespacesAsText(
832 SearchEngine
::defaultNamespaces()
836 'message' => 'searchprofile-images',
837 'tooltip' => 'searchprofile-images-tooltip',
838 'namespaces' => array( NS_FILE
),
841 'message' => 'searchprofile-project',
842 'tooltip' => 'searchprofile-project-tooltip',
843 'namespaces' => SearchEngine
::helpNamespaces(),
844 'namespace-messages' => SearchEngine
::namespacesAsText(
845 SearchEngine
::helpNamespaces()
849 'message' => 'searchprofile-everything',
850 'tooltip' => 'searchprofile-everything-tooltip',
851 'namespaces' => $nsAllSet,
854 'message' => 'searchprofile-advanced',
855 'tooltip' => 'searchprofile-advanced-tooltip',
856 'namespaces' => $this->namespaces
,
857 'parameters' => array( 'advanced' => 1 ),
860 // Outputs XML for Search Types
861 $out .= Xml
::openElement( 'div', array( 'class' => 'search-types' ) );
862 $out .= Xml
::openElement( 'ul' );
863 foreach ( $profiles as $id => $profile ) {
864 $tooltipParam = isset( $profile['namespace-messages'] ) ?
865 $wgLang->commaList( $profile['namespace-messages'] ) : null;
869 'class' => $this->active
== $id ?
'current' : 'normal'
871 $this->makeSearchLink(
873 $profile['namespaces'],
874 wfMsg( $profile['message'] ),
875 wfMsg( $profile['tooltip'], $tooltipParam ),
876 isset( $profile['parameters'] ) ?
$profile['parameters'] : array()
880 $out .= Xml
::closeElement( 'ul' );
881 $out .= Xml
::closeElement('div') ;
884 if ( $resultsShown > 0 ) {
885 if ( $totalNum > 0 ){
886 $top = wfMsgExt('showingresultsheader', array( 'parseinline' ),
887 $this->offset+
1, $this->offset+
$resultsShown, $totalNum, $term, $resultsShown );
888 } elseif ( $resultsShown >= $this->limit
) {
889 $top = wfShowingResults( $this->offset
, $this->limit
);
891 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $resultsShown );
893 $out .= Xml
::tags( 'div', array( 'class' => 'results-info' ),
894 Xml
::tags( 'ul', null, Xml
::tags( 'li', null, $top ) )
898 $out .= Xml
::element( 'div', array( 'style' => 'clear:both' ), '', false );
899 $out .= Xml
::closeElement('div');
901 // Adds hidden namespace fields
902 if ( !$this->searchAdvanced
) {
903 foreach( $this->namespaces
as $ns ) {
904 $out .= Xml
::hidden( "ns{$ns}", '1' );
911 protected function shortDialog( $term ) {
912 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
913 $searchable = SearchEngine
::searchableNamespaces();
914 $out = Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
915 // Keep redirect setting
916 $out .= Xml
::hidden( "redirs", (int)$this->searchRedirects
);
918 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
919 $out .= Xml
::hidden( 'fulltext', 'Search' );
920 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ) );
921 return $out . $this->didYouMeanHtml
;
924 /** Make a search link with some target namespaces */
925 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
927 foreach( $namespaces as $n ) {
930 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
932 $st = SpecialPage
::getTitleFor( 'Search' );
933 $stParams = array_merge(
936 'fulltext' => wfMsg( 'search' )
944 'href' => $st->getLocalURL( $stParams ),
946 'onmousedown' => 'mwSearchHeaderClick(this);',
947 'onkeydown' => 'mwSearchHeaderClick(this);'),
952 /** Check if query starts with image: prefix */
953 protected function startsWithImage( $term ) {
956 $p = explode( ':', $term );
957 if( count( $p ) > 1 ) {
958 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
963 /** Check if query starts with all: prefix */
964 protected function startsWithAll( $term ) {
966 $allkeyword = wfMsgForContent('searchall');
968 $p = explode( ':', $term );
969 if( count( $p ) > 1 ) {
970 return $p[0] == $allkeyword;
977 * implements Special:Search - Run text & title search and display the output
978 * @ingroup SpecialPage
980 class SpecialSearchOld
{
983 * Set up basic search parameters from the request and user settings.
984 * Typically you'll pass $wgRequest and $wgUser.
986 * @param WebRequest $request
990 function __construct( &$request, &$user ) {
991 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
992 $this->mPrefix
= $request->getVal('prefix', '');
993 $this->namespaces
= $this->powerSearch( $request );
994 if( empty( $this->namespaces
) ) {
995 $this->namespaces
= SearchEngine
::userNamespaces( $user );
998 $this->searchRedirects
= $request->getcheck( 'redirs' ) ?
true : false;
999 $this->fulltext
= $request->getVal('fulltext');
1003 * If an exact title match can be found, jump straight ahead to it.
1004 * @param string $term
1007 function goResult( $term ) {
1011 $this->setupPage( $term );
1013 # Try to go to page as entered.
1014 $t = Title
::newFromText( $term );
1016 # If the string cannot be used to create a title
1017 if( is_null( $t ) ){
1018 return $this->showResults( $term );
1021 # If there's an exact or very near match, jump right there.
1022 $t = SearchEngine
::getNearMatch( $term );
1023 if( !is_null( $t ) ) {
1024 $wgOut->redirect( $t->getFullURL() );
1028 # No match, generate an edit URL
1029 $t = Title
::newFromText( $term );
1030 if( ! is_null( $t ) ) {
1031 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
1032 # If the feature is enabled, go straight to the edit page
1033 if ( $wgGoToEdit ) {
1034 $wgOut->redirect( $t->getFullURL( array( 'action' => 'edit' ) ) );
1039 $extra = $wgOut->parse( '=='.wfMsgNoTrans( 'notitlematches' )."==\n" );
1040 if( $t->quickUserCan( 'create' ) && $t->quickUserCan( 'edit' ) ) {
1041 $extra .= wfMsgExt( 'noexactmatch', 'parse', wfEscapeWikiText( $term ) );
1043 $extra .= wfMsgExt( 'noexactmatch-nocreate', 'parse', wfEscapeWikiText( $term ) );
1046 $this->showResults( $term, $extra );
1050 * @param string $term
1051 * @param string $extra Extra HTML to add after "did you mean"
1053 public function showResults( $term, $extra = '' ) {
1054 wfProfileIn( __METHOD__
);
1055 global $wgOut, $wgUser;
1056 $sk = $wgUser->getSkin();
1058 $search = SearchEngine
::create();
1059 $search->setLimitOffset( $this->limit
, $this->offset
);
1060 $search->setNamespaces( $this->namespaces
);
1061 $search->showRedirects
= $this->searchRedirects
;
1062 $search->prefix
= $this->mPrefix
;
1063 $term = $search->transformSearchTerm($term);
1065 $this->setupPage( $term );
1067 $rewritten = $search->replacePrefixes($term);
1068 $titleMatches = $search->searchTitle( $rewritten );
1069 $textMatches = $search->searchText( $rewritten );
1071 // did you mean... suggestions
1072 if($textMatches && $textMatches->hasSuggestion()){
1073 $st = SpecialPage
::getTitleFor( 'Search' );
1075 # mirror Go/Search behaviour of original request
1076 $didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
1077 if($this->fulltext
!= NULL)
1078 $didYouMeanParams['fulltext'] = $this->fulltext
;
1079 $stParams = array_merge(
1081 $this->powerSearchOptions()
1084 $suggestionSnippet = $textMatches->getSuggestionSnippet();
1086 if( $suggestionSnippet == '' )
1087 $suggestionSnippet = null;
1089 $suggestLink = $sk->linkKnown(
1096 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
1099 $wgOut->addHTML( $extra );
1101 $wgOut->wrapWikiMsg( "<div class='mw-searchresult'>\n$1</div>", 'searchresulttext' );
1103 if( '' === trim( $term ) ) {
1104 // Empty query -- straight view of search form
1105 $wgOut->setSubtitle( '' );
1106 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1107 $wgOut->addHTML( $this->powerSearchFocus() );
1108 wfProfileOut( __METHOD__
);
1112 global $wgDisableTextSearch;
1113 if ( $wgDisableTextSearch ) {
1114 global $wgSearchForwardUrl;
1115 if( $wgSearchForwardUrl ) {
1116 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
1117 $wgOut->redirect( $url );
1118 wfProfileOut( __METHOD__
);
1121 global $wgInputEncoding;
1123 Xml
::openElement( 'fieldset' ) .
1124 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
1125 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
1126 wfMsg( 'googlesearch',
1127 htmlspecialchars( $term ),
1128 htmlspecialchars( $wgInputEncoding ),
1129 htmlspecialchars( wfMsg( 'searchbutton' ) )
1131 Xml
::closeElement( 'fieldset' )
1133 wfProfileOut( __METHOD__
);
1137 $wgOut->addHTML( $this->shortDialog( $term ) );
1139 // Sometimes the search engine knows there are too many hits
1140 if ($titleMatches instanceof SearchResultTooMany
) {
1141 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
1142 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1143 $wgOut->addHTML( $this->powerSearchFocus() );
1144 wfProfileOut( __METHOD__
);
1148 // show number of results
1149 $num = ( $titleMatches ?
$titleMatches->numRows() : 0 )
1150 +
( $textMatches ?
$textMatches->numRows() : 0);
1152 if($titleMatches && !is_null($titleMatches->getTotalHits()))
1153 $totalNum +
= $titleMatches->getTotalHits();
1154 if($textMatches && !is_null($textMatches->getTotalHits()))
1155 $totalNum +
= $textMatches->getTotalHits();
1157 if ( $totalNum > 0 ){
1158 $top = wfMsgExt('showingresultstotal', array( 'parseinline' ),
1159 $this->offset+
1, $this->offset+
$num, $totalNum, $num );
1160 } elseif ( $num >= $this->limit
) {
1161 $top = wfShowingResults( $this->offset
, $this->limit
);
1163 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $num );
1165 $wgOut->addHTML( "<p class='mw-search-numberresults'>{$top}</p>\n" );
1169 if( $num ||
$this->offset
) {
1170 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
1171 SpecialPage
::getTitleFor( 'Search' ),
1173 $this->powerSearchOptions(),
1174 array( 'search' => $term ) ),
1175 ($num < $this->limit
) );
1176 $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
1177 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
1179 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
1182 if( $titleMatches ) {
1183 if( $titleMatches->numRows() ) {
1184 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
1185 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
1187 $titleMatches->free();
1190 if( $textMatches ) {
1191 // output appropriate heading
1192 if( $textMatches->numRows() ) {
1194 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
1195 else // if no title matches the heading is redundant
1196 $wgOut->addHTML("<hr/>");
1197 } elseif( $num == 0 ) {
1198 # Don't show the 'no text matches' if we received title matches
1199 $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
1201 // show interwiki results if any
1202 if( $textMatches->hasInterwikiResults() )
1203 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ));
1205 if( $textMatches->numRows() )
1206 $wgOut->addHTML( $this->showMatches( $textMatches ) );
1208 $textMatches->free();
1212 $wgOut->addWikiMsg( 'nonefound' );
1214 if( $num ||
$this->offset
) {
1215 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
1217 $wgOut->addHTML( $this->powerSearchBox( $term ) );
1218 wfProfileOut( __METHOD__
);
1221 #------------------------------------------------------------------
1222 # Private methods below this line
1227 function setupPage( $term ) {
1229 if( !empty( $term ) ){
1230 $wgOut->setPageTitle( wfMsg( 'searchresults') );
1231 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) );
1233 $subtitlemsg = ( Title
::newFromText( $term ) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
1234 $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
1235 $wgOut->setArticleRelated( false );
1236 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1240 * Extract "power search" namespace settings from the request object,
1241 * returning a list of index numbers to search.
1243 * @param WebRequest $request
1247 function powerSearch( &$request ) {
1249 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1250 if( $request->getCheck( 'ns' . $ns ) ) {
1258 * Reconstruct the 'power search' options for links
1262 function powerSearchOptions() {
1264 foreach( $this->namespaces
as $n ) {
1265 $opt['ns' . $n] = 1;
1267 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
1272 * Show whole set of results
1274 * @param SearchResultSet $matches
1276 function showMatches( &$matches ) {
1277 wfProfileIn( __METHOD__
);
1280 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1284 $infoLine = $matches->getInfo();
1285 if( !is_null($infoLine) )
1286 $out .= "\n<!-- {$infoLine} -->\n";
1289 $off = $this->offset +
1;
1290 $out .= "<ul class='mw-search-results'>\n";
1292 while( $result = $matches->next() ) {
1293 $out .= $this->showHit( $result, $terms );
1297 // convert the whole thing to desired language variant
1299 $out = $wgContLang->convert( $out );
1300 wfProfileOut( __METHOD__
);
1305 * Format a single hit result
1306 * @param SearchResult $result
1307 * @param array $terms terms to highlight
1309 function showHit( $result, $terms ) {
1310 wfProfileIn( __METHOD__
);
1311 global $wgUser, $wgContLang, $wgLang;
1313 if( $result->isBrokenTitle() ) {
1314 wfProfileOut( __METHOD__
);
1315 return "<!-- Broken link in search result -->\n";
1318 $t = $result->getTitle();
1319 $sk = $wgUser->getSkin();
1321 $titleSnippet = $result->getTitleSnippet($terms);
1323 if( $titleSnippet == '' )
1324 $titleSnippet = null;
1326 $link = $sk->linkKnown(
1331 //If page content is not readable, just return the title.
1332 //This is not quite safe, but better than showing excerpts from non-readable pages
1333 //Note that hiding the entry entirely would screw up paging.
1334 if (!$t->userCanRead()) {
1335 wfProfileOut( __METHOD__
);
1336 return "<li>{$link}</li>\n";
1339 // If the page doesn't *exist*... our search index is out of date.
1340 // The least confusing at this point is to drop the result.
1341 // You may get less results, but... oh well. :P
1342 if( $result->isMissingRevision() ) {
1343 wfProfileOut( __METHOD__
);
1344 return "<!-- missing page " .
1345 htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
1348 // format redirects / relevant sections
1349 $redirectTitle = $result->getRedirectTitle();
1350 $redirectText = $result->getRedirectSnippet($terms);
1351 $sectionTitle = $result->getSectionTitle();
1352 $sectionText = $result->getSectionSnippet($terms);
1354 if( !is_null($redirectTitle) ) {
1355 if( $redirectText == '' )
1356 $redirectText = null;
1358 $redirect = "<span class='searchalttitle'>" .
1371 if( !is_null($sectionTitle) ) {
1372 if( $sectionText == '' )
1373 $sectionText = null;
1375 $section = "<span class='searchalttitle'>" .
1386 // format text extract
1387 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
1390 if( is_null( $result->getScore() ) ) {
1391 // Search engine doesn't report scoring info
1394 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
1395 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
1399 // format description
1400 $byteSize = $result->getByteSize();
1401 $wordCount = $result->getWordCount();
1402 $timestamp = $result->getTimestamp();
1403 $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
1404 $sk->formatSize( $byteSize ),
1406 $date = $wgLang->timeanddate( $timestamp );
1408 // link to related articles if supported
1410 if( $result->hasRelated() ){
1411 $st = SpecialPage
::getTitleFor( 'Search' );
1412 $stParams = array_merge(
1413 $this->powerSearchOptions(),
1415 'search' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText(),
1416 'fulltext' => wfMsg( 'search' )
1420 $related = ' -- ' . $sk->linkKnown(
1422 wfMsg('search-relatedarticle'),
1428 // Include a thumbnail for media files...
1429 if( $t->getNamespace() == NS_FILE
) {
1430 $img = wfFindFile( $t );
1432 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
1434 $desc = $img->getShortDesc();
1435 wfProfileOut( __METHOD__
);
1437 // Float doesn't seem to interact well with the bullets.
1438 // Table messes up vertical alignment of the bullet, but I'm
1439 // not sure what more I can do about that. :(
1441 '<table class="searchResultImage">' .
1443 '<td width="120" align="center">' .
1444 $thumb->toHtml( array( 'desc-link' => true ) ) .
1446 '<td valign="top">' .
1449 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
1458 wfProfileOut( __METHOD__
);
1459 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
1460 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
1466 * Show results from other wikis
1468 * @param SearchResultSet $matches
1470 function showInterwiki( &$matches, $query ) {
1471 wfProfileIn( __METHOD__
);
1474 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
1476 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".wfMsg('search-interwiki-caption')."</div>\n";
1477 $off = $this->offset +
1;
1478 $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
1480 // work out custom project captions
1481 $customCaptions = array();
1482 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
1483 foreach($customLines as $line){
1484 $parts = explode(":",$line,2);
1485 if(count($parts) == 2) // validate line
1486 $customCaptions[$parts[0]] = $parts[1];
1491 while( $result = $matches->next() ) {
1492 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
1493 $prev = $result->getInterwikiPrefix();
1495 // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
1496 $out .= "</ul></div>\n";
1498 // convert the whole thing to desired language variant
1500 $out = $wgContLang->convert( $out );
1501 wfProfileOut( __METHOD__
);
1506 * Show single interwiki link
1508 * @param SearchResult $result
1509 * @param string $lastInterwiki
1510 * @param array $terms
1511 * @param string $query
1512 * @param array $customCaptions iw prefix -> caption
1514 function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
1515 wfProfileIn( __METHOD__
);
1516 global $wgUser, $wgContLang, $wgLang;
1518 if( $result->isBrokenTitle() ) {
1519 wfProfileOut( __METHOD__
);
1520 return "<!-- Broken link in search result -->\n";
1523 $t = $result->getTitle();
1524 $sk = $wgUser->getSkin();
1526 $titleSnippet = $result->getTitleSnippet($terms);
1528 if( $titleSnippet == '' )
1529 $titleSnippet = null;
1531 $link = $sk->linkKnown(
1536 // format redirect if any
1537 $redirectTitle = $result->getRedirectTitle();
1538 $redirectText = $result->getRedirectSnippet($terms);
1540 if( !is_null($redirectTitle) ) {
1541 if( $redirectText == '' )
1542 $redirectText = null;
1544 $redirect = "<span class='searchalttitle'>" .
1556 // display project name
1557 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()){
1558 if( key_exists($t->getInterwiki(),$customCaptions) )
1559 // captions from 'search-interwiki-custom'
1560 $caption = $customCaptions[$t->getInterwiki()];
1562 // default is to show the hostname of the other wiki which might suck
1563 // if there are many wikis on one hostname
1564 $parsed = parse_url($t->getFullURL());
1565 $caption = wfMsg('search-interwiki-default', $parsed['host']);
1567 // "more results" link (special page stuff could be localized, but we might not know target lang)
1568 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
1569 $searchLink = $sk->linkKnown(
1571 wfMsg( 'search-interwiki-more' ),
1575 'fulltext' => 'Search'
1578 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>{$searchLink}</span>{$caption}</div>\n<ul>";
1581 $out .= "<li>{$link} {$redirect}</li>\n";
1582 wfProfileOut( __METHOD__
);
1588 * Generates the power search box at bottom of [[Special:Search]]
1589 * @param $term string: search term
1590 * @return $out string: HTML form
1592 function powerSearchBox( $term ) {
1593 global $wgScript, $wgContLang;
1595 $namespaces = SearchEngine
::searchableNamespaces();
1597 // group namespaces into rows according to subject; try not to make too
1598 // many assumptions about namespace numbering
1600 foreach( $namespaces as $ns => $name ) {
1601 $subj = MWNamespace
::getSubject( $ns );
1602 if( !array_key_exists( $subj, $rows ) ) {
1605 $name = str_replace( '_', ' ', $name );
1607 $name = wfMsg( 'blanknamespace' );
1609 $rows[$subj] .= Xml
::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
1610 Xml
::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $this->namespaces
) ) .
1611 Xml
::closeElement( 'td' ) . "\n";
1613 $rows = array_values( $rows );
1614 $numRows = count( $rows );
1616 // lay out namespaces in multiple floating two-column tables so they'll
1617 // be arranged nicely while still accommodating different screen widths
1618 $rowsPerTable = 3; // seems to look nice
1620 // float to the right on RTL wikis
1621 $tableStyle = ( $wgContLang->isRTL() ?
1622 'float: right; margin: 0 0 1em 1em' :
1623 'float: left; margin: 0 1em 1em 0' );
1626 for( $i = 0; $i < $numRows; $i +
= $rowsPerTable ) {
1627 $tables .= Xml
::openElement( 'table', array( 'style' => $tableStyle ) );
1628 for( $j = $i; $j < $i +
$rowsPerTable && $j < $numRows; $j++
) {
1629 $tables .= "<tr>\n" . $rows[$j] . "</tr>";
1631 $tables .= Xml
::closeElement( 'table' ) . "\n";
1634 $redirect = Xml
::check( 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' ) );
1635 $redirectLabel = Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
1636 $searchField = Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
1637 $searchButton = Xml
::submitButton( wfMsg( 'powersearch' ) ) . "\n";
1638 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1639 $searchHiddens = Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
1640 $searchHiddens .= Xml
::hidden( 'fulltext', 'Advanced search' ) . "\n";
1642 $out = Xml
::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
1643 Xml
::fieldset( wfMsg( 'powersearch-legend' ),
1645 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
1648 "<hr style=\"clear: both\" />\n" .
1650 $redirect . " " . $redirectLabel .
1652 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
1663 function powerSearchFocus() {
1664 global $wgJsMimeType;
1665 return "<script type=\"$wgJsMimeType\">" .
1666 "hookEvent(\"load\", function(){" .
1667 "document.getElementById('powerSearchText').focus();" .
1672 function shortDialog($term) {
1675 $out = Xml
::openElement( 'form', array(
1678 'action' => $wgScript
1680 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
1681 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . ' ';
1682 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
1683 if( in_array( $ns, $this->namespaces
) ) {
1684 $out .= Xml
::hidden( "ns{$ns}", '1' );
1687 $out .= Xml
::hidden( 'title', $searchTitle->getPrefixedText() );
1688 $out .= Xml
::hidden( 'fulltext', 'Search' );
1689 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ) );
1690 $out .= Xml
::closeElement( 'form' );