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;
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 $searchPage = new SpecialSearch( $wgRequest, $wgUser );
39 if( $wgRequest->getVal( 'fulltext' )
40 ||
!is_null( $wgRequest->getVal( 'offset' ))
41 ||
!is_null( $wgRequest->getVal( 'searchx' )) )
43 $searchPage->showResults( $search );
45 $searchPage->goResult( $search );
50 * implements Special:Search - Run text & title search and display the output
51 * @ingroup SpecialPage
56 * Set up basic search parameters from the request and user settings.
57 * Typically you'll pass $wgRequest and $wgUser.
59 * @param WebRequest $request
63 function __construct( &$request, &$user ) {
64 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
65 $this->mPrefix
= $request->getVal('prefix', '');
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
76 $this->fulltext
= $request->getVal('fulltext');
80 * If an exact title match can be found, jump straight ahead to it.
83 public function goResult( $term ) {
85 $this->setupPage( $term );
86 # Try to go to page as entered.
87 $t = Title
::newFromText( $term );
88 # If the string cannot be used to create a title
90 return $this->showResults( $term );
92 # If there's an exact or very near match, jump right there.
93 $t = SearchEngine
::getNearMatch( $term );
94 if( !is_null( $t ) ) {
95 $wgOut->redirect( $t->getFullURL() );
98 # No match, generate an edit URL
99 $t = Title
::newFromText( $term );
100 if( !is_null( $t ) ) {
102 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
103 # If the feature is enabled, go straight to the edit page
105 $wgOut->redirect( $t->getFullURL( array( 'action' => 'edit' ) ) );
109 return $this->showResults( $term );
113 * @param string $term
115 public function showResults( $term ) {
116 global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
117 wfProfileIn( __METHOD__
);
119 $sk = $wgUser->getSkin();
121 $this->searchEngine
= SearchEngine
::create();
122 $search =& $this->searchEngine
;
123 $search->setLimitOffset( $this->limit
, $this->offset
);
124 $search->setNamespaces( $this->namespaces
);
125 $search->showRedirects
= $this->searchRedirects
;
126 $search->prefix
= $this->mPrefix
;
127 $term = $search->transformSearchTerm($term);
129 $this->setupPage( $term );
131 if( $wgDisableTextSearch ) {
132 global $wgSearchForwardUrl;
133 if( $wgSearchForwardUrl ) {
134 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
135 $wgOut->redirect( $url );
136 wfProfileOut( __METHOD__
);
139 global $wgInputEncoding;
141 Xml
::openElement( 'fieldset' ) .
142 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
143 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
144 wfMsg( 'googlesearch',
145 htmlspecialchars( $term ),
146 htmlspecialchars( $wgInputEncoding ),
147 htmlspecialchars( wfMsg( 'searchbutton' ) )
149 Xml
::closeElement( 'fieldset' )
151 wfProfileOut( __METHOD__
);
155 $t = Title
::newFromText( $term );
157 // fetch search results
158 $rewritten = $search->replacePrefixes($term);
160 $titleMatches = $search->searchTitle( $rewritten );
161 if( !($titleMatches instanceof SearchResultTooMany
))
162 $textMatches = $search->searchText( $rewritten );
164 // did you mean... suggestions
165 if( $textMatches && $textMatches->hasSuggestion() ) {
166 $st = SpecialPage
::getTitleFor( 'Search' );
168 # mirror Go/Search behaviour of original request ..
169 $didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
171 if($this->fulltext
!= NULL)
172 $didYouMeanParams['fulltext'] = $this->fulltext
;
174 $stParams = array_merge(
176 $this->powerSearchOptions()
179 $suggestionSnippet = $textMatches->getSuggestionSnippet();
181 if( $suggestionSnippet == '' )
182 $suggestionSnippet = null;
184 $suggestLink = $sk->linkKnown(
191 $this->didYouMeanHtml
= '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
193 // start rendering the page
198 'id' => ( $this->searchAdvanced ?
'powersearch' : 'search' ),
200 'action' => $wgScript
205 Xml
::openElement( 'table', array( 'id'=>'mw-search-top-table', 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
206 Xml
::openElement( 'tr' ) .
207 Xml
::openElement( 'td' ) . "\n" .
208 $this->shortDialog( $term ) .
209 Xml
::closeElement('td') .
210 Xml
::closeElement('tr') .
211 Xml
::closeElement('table')
214 // Sometimes the search engine knows there are too many hits
215 if( $titleMatches instanceof SearchResultTooMany
) {
216 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
217 wfProfileOut( __METHOD__
);
221 $filePrefix = $wgContLang->getFormattedNsText(NS_FILE
).':';
222 if( '' === trim( $term ) ||
$filePrefix === trim( $term ) ) {
223 $wgOut->addHTML( $this->searchFocus() );
224 $wgOut->addHTML( $this->formHeader($term, 0, 0));
225 if( $this->searchAdvanced
) {
226 $wgOut->addHTML( $this->powerSearchBox( $term ) );
228 $wgOut->addHTML( '</form>' );
229 // Empty query -- straight view of search form
230 wfProfileOut( __METHOD__
);
234 // Get number of results
235 $titleMatchesNum = $titleMatches ?
$titleMatches->numRows() : 0;
236 $textMatchesNum = $textMatches ?
$textMatches->numRows() : 0;
237 // Total initial query matches (possible false positives)
238 $num = $titleMatchesNum +
$textMatchesNum;
240 // Get total actual results (after second filtering, if any)
241 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
242 $titleMatches->getTotalHits() : $titleMatchesNum;
243 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
244 $textMatches->getTotalHits() : $textMatchesNum;
246 // get total number of results if backend can calculate it
248 if($titleMatches && !is_null( $titleMatches->getTotalHits() ) )
249 $totalRes +
= $titleMatches->getTotalHits();
250 if($textMatches && !is_null( $textMatches->getTotalHits() ))
251 $totalRes +
= $textMatches->getTotalHits();
253 // show number of results and current offset
254 $wgOut->addHTML( $this->formHeader($term, $num, $totalRes));
255 if( $this->searchAdvanced
) {
256 $wgOut->addHTML( $this->powerSearchBox( $term ) );
259 $wgOut->addHtml( Xml
::closeElement( 'form' ) );
260 $wgOut->addHtml( "<div class='searchresults'>" );
263 if( $num ||
$this->offset
) {
264 // Show the create link ahead
265 $this->showCreateLink( $t );
266 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
267 SpecialPage
::getTitleFor( 'Search' ),
268 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
269 max( $titleMatchesNum, $textMatchesNum ) < $this->limit
271 //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
272 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
274 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
277 if( $titleMatches ) {
278 if( $numTitleMatches > 0 ) {
279 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
280 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
282 $titleMatches->free();
285 // output appropriate heading
286 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
287 // if no title matches the heading is redundant
288 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
289 } elseif( $totalRes == 0 ) {
290 # Don't show the 'no text matches' if we received title matches
291 # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
293 // show interwiki results if any
294 if( $textMatches->hasInterwikiResults() ) {
295 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
298 if( $numTextMatches > 0 ) {
299 $wgOut->addHTML( $this->showMatches( $textMatches ) );
302 $textMatches->free();
305 $wgOut->addWikiMsg( 'search-nonefound', wfEscapeWikiText( $term ) );
306 $this->showCreateLink( $t );
308 $wgOut->addHtml( "</div>" );
310 $wgOut->addHTML( $this->searchFocus() );
313 if( $num ||
$this->offset
) {
314 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
316 wfProfileOut( __METHOD__
);
319 protected function showCreateLink( $t ) {
322 // show direct page/create link
324 if( !$t->isKnown() ) {
325 $wgOut->addWikiMsg( 'searchmenu-new', wfEscapeWikiText( $t->getPrefixedText() ) );
327 $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) );
330 // preserve the paragraph for margins etc...
331 $wgOut->addHTML('<p></p>');
338 protected function setupPage( $term ) {
340 // Figure out the active search profile header
341 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
342 if( $this->searchAdvanced
)
343 $this->active
= 'advanced';
345 $profiles = $this->getSearchProfiles();
347 foreach( $profiles as $key => $data ) {
348 if ( $this->namespaces
== $data['namespaces'] && $key != 'advanced')
349 $this->active
= $key;
353 # Should advanced UI be used?
354 $this->searchAdvanced
= ($this->active
=== 'advanced');
355 if( !empty( $term ) ) {
356 $wgOut->setPageTitle( wfMsg( 'searchresults') );
357 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
359 $wgOut->setArticleRelated( false );
360 $wgOut->setRobotPolicy( 'noindex,nofollow' );
361 // add javascript specific to special:search
362 $wgOut->addScriptFile( 'search.js' );
366 * Extract "power search" namespace settings from the request object,
367 * returning a list of index numbers to search.
369 * @param WebRequest $request
372 protected function powerSearch( &$request ) {
374 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
375 if( $request->getCheck( 'ns' . $ns ) ) {
383 * Reconstruct the 'power search' options for links
386 protected function powerSearchOptions() {
388 foreach( $this->namespaces
as $n ) {
391 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
392 if( $this->searchAdvanced
) {
393 $opt['advanced'] = $this->searchAdvanced
;
399 * Show whole set of results
401 * @param SearchResultSet $matches
403 protected function showMatches( &$matches ) {
405 wfProfileIn( __METHOD__
);
407 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
410 $infoLine = $matches->getInfo();
411 if( !is_null($infoLine) ) {
412 $out .= "\n<!-- {$infoLine} -->\n";
414 $off = $this->offset +
1;
415 $out .= "<ul class='mw-search-results'>\n";
416 while( $result = $matches->next() ) {
417 $out .= $this->showHit( $result, $terms );
421 // convert the whole thing to desired language variant
422 $out = $wgContLang->convert( $out );
423 wfProfileOut( __METHOD__
);
428 * Format a single hit result
429 * @param SearchResult $result
430 * @param array $terms terms to highlight
432 protected function showHit( $result, $terms ) {
433 global $wgContLang, $wgLang, $wgUser;
434 wfProfileIn( __METHOD__
);
436 if( $result->isBrokenTitle() ) {
437 wfProfileOut( __METHOD__
);
438 return "<!-- Broken link in search result -->\n";
441 $sk = $wgUser->getSkin();
442 $t = $result->getTitle();
444 $titleSnippet = $result->getTitleSnippet($terms);
446 if( $titleSnippet == '' )
447 $titleSnippet = null;
451 wfRunHooks( 'ShowSearchHitTitle',
452 array( &$link_t, &$titleSnippet, $result, $terms, $this ) );
454 $link = $this->sk
->linkKnown(
459 //If page content is not readable, just return the title.
460 //This is not quite safe, but better than showing excerpts from non-readable pages
461 //Note that hiding the entry entirely would screw up paging.
462 if( !$t->userCanRead() ) {
463 wfProfileOut( __METHOD__
);
464 return "<li>{$link}</li>\n";
467 // If the page doesn't *exist*... our search index is out of date.
468 // The least confusing at this point is to drop the result.
469 // You may get less results, but... oh well. :P
470 if( $result->isMissingRevision() ) {
471 wfProfileOut( __METHOD__
);
472 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
475 // format redirects / relevant sections
476 $redirectTitle = $result->getRedirectTitle();
477 $redirectText = $result->getRedirectSnippet($terms);
478 $sectionTitle = $result->getSectionTitle();
479 $sectionText = $result->getSectionSnippet($terms);
482 if( !is_null($redirectTitle) ) {
483 if( $redirectText == '' )
484 $redirectText = null;
486 $redirect = "<span class='searchalttitle'>" .
489 $this->sk
->linkKnown(
500 if( !is_null($sectionTitle) ) {
501 if( $sectionText == '' )
504 $section = "<span class='searchalttitle'>" .
506 'search-section', $this->sk
->linkKnown(
514 // format text extract
515 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
518 if( is_null( $result->getScore() ) ) {
519 // Search engine doesn't report scoring info
522 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
523 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
527 // format description
528 $byteSize = $result->getByteSize();
529 $wordCount = $result->getWordCount();
530 $timestamp = $result->getTimestamp();
532 'search-result-size',
533 array( 'parsemag', 'escape' ),
534 $this->sk
->formatSize( $byteSize ),
535 $wgLang->formatNum( $wordCount )
537 $date = $wgLang->timeanddate( $timestamp );
539 // link to related articles if supported
541 if( $result->hasRelated() ) {
542 $st = SpecialPage
::getTitleFor( 'Search' );
543 $stParams = array_merge(
544 $this->powerSearchOptions(),
546 'search' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText(),
547 'fulltext' => wfMsg( 'search' )
551 $related = ' -- ' . $sk->linkKnown(
553 wfMsg('search-relatedarticle'),
559 // Include a thumbnail for media files...
560 if( $t->getNamespace() == NS_FILE
) {
561 $img = wfFindFile( $t );
563 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
565 $desc = $img->getShortDesc();
566 wfProfileOut( __METHOD__
);
567 // Float doesn't seem to interact well with the bullets.
568 // Table messes up vertical alignment of the bullets.
569 // Bullets are therefore disabled (didn't look great anyway).
571 '<table class="searchResultImage">' .
573 '<td width="120" align="center" valign="top">' .
574 $thumb->toHtml( array( 'desc-link' => true ) ) .
576 '<td valign="top">' .
579 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
588 wfProfileOut( __METHOD__
);
589 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
590 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
596 * Show results from other wikis
598 * @param SearchResultSet $matches
600 protected function showInterwiki( &$matches, $query ) {
602 wfProfileIn( __METHOD__
);
603 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
605 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
606 wfMsg('search-interwiki-caption')."</div>\n";
607 $off = $this->offset +
1;
608 $out .= "<ul class='mw-search-iwresults'>\n";
610 // work out custom project captions
611 $customCaptions = array();
612 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
613 foreach($customLines as $line) {
614 $parts = explode(":",$line,2);
615 if(count($parts) == 2) // validate line
616 $customCaptions[$parts[0]] = $parts[1];
620 while( $result = $matches->next() ) {
621 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
622 $prev = $result->getInterwikiPrefix();
624 // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
625 $out .= "</ul></div>\n";
627 // convert the whole thing to desired language variant
628 $out = $wgContLang->convert( $out );
629 wfProfileOut( __METHOD__
);
634 * Show single interwiki link
636 * @param SearchResult $result
637 * @param string $lastInterwiki
638 * @param array $terms
639 * @param string $query
640 * @param array $customCaptions iw prefix -> caption
642 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
643 wfProfileIn( __METHOD__
);
644 global $wgContLang, $wgLang;
646 if( $result->isBrokenTitle() ) {
647 wfProfileOut( __METHOD__
);
648 return "<!-- Broken link in search result -->\n";
651 $t = $result->getTitle();
653 $titleSnippet = $result->getTitleSnippet($terms);
655 if( $titleSnippet == '' )
656 $titleSnippet = null;
658 $link = $this->sk
->linkKnown(
663 // format redirect if any
664 $redirectTitle = $result->getRedirectTitle();
665 $redirectText = $result->getRedirectSnippet($terms);
667 if( !is_null($redirectTitle) ) {
668 if( $redirectText == '' )
669 $redirectText = null;
671 $redirect = "<span class='searchalttitle'>" .
674 $this->sk
->linkKnown(
683 // display project name
684 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
685 if( key_exists($t->getInterwiki(),$customCaptions) )
686 // captions from 'search-interwiki-custom'
687 $caption = $customCaptions[$t->getInterwiki()];
689 // default is to show the hostname of the other wiki which might suck
690 // if there are many wikis on one hostname
691 $parsed = parse_url($t->getFullURL());
692 $caption = wfMsg('search-interwiki-default', $parsed['host']);
694 // "more results" link (special page stuff could be localized, but we might not know target lang)
695 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
696 $searchLink = $this->sk
->linkKnown(
698 wfMsg('search-interwiki-more'),
702 'fulltext' => 'Search'
705 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
706 {$searchLink}</span>{$caption}</div>\n<ul>";
709 $out .= "<li>{$link} {$redirect}</li>\n";
710 wfProfileOut( __METHOD__
);
716 * Generates the power search box at bottom of [[Special:Search]]
717 * @param $term string: search term
718 * @return $out string: HTML form
720 protected function powerSearchBox( $term ) {
721 global $wgScript, $wgContLang;
723 // Groups namespaces into rows according to subject
725 foreach( SearchEngine
::searchableNamespaces() as $namespace => $name ) {
726 $subject = MWNamespace
::getSubject( $namespace );
727 if( !array_key_exists( $subject, $rows ) ) {
728 $rows[$subject] = "";
730 $name = str_replace( '_', ' ', $name );
732 $name = wfMsg( 'blanknamespace' );
736 'td', array( 'style' => 'white-space: nowrap' )
741 "mw-search-ns{$namespace}",
742 in_array( $namespace, $this->namespaces
)
744 Xml
::closeElement( 'td' );
746 $rows = array_values( $rows );
747 $numRows = count( $rows );
749 // Lays out namespaces in multiple floating two-column tables so they'll
750 // be arranged nicely while still accommodating different screen widths
751 $namespaceTables = '';
752 for( $i = 0; $i < $numRows; $i +
= 4 ) {
753 $namespaceTables .= Xml
::openElement(
755 array( 'cellpadding' => 0, 'cellspacing' => 0, 'border' => 0 )
757 for( $j = $i; $j < $i +
4 && $j < $numRows; $j++
) {
758 $namespaceTables .= Xml
::tags( 'tr', null, $rows[$j] );
760 $namespaceTables .= Xml
::closeElement( 'table' );
762 // Show redirects check only if backend supports it
764 if( $this->searchEngine
->acceptListRedirects() ) {
767 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' )
770 Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
772 // Return final output
776 array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
778 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
779 Xml
::tags( 'h4', null, wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) ) .
782 array( 'id' => 'mw-search-togglebox' ),
783 Xml
::label( wfMsg( 'powersearch-togglelabel' ), 'mw-search-togglelabel' ) .
788 'id' => 'mw-search-toggleall',
789 'onclick' => 'mwToggleSearchCheckboxes("all");',
790 'value' => wfMsg( 'powersearch-toggleall' )
797 'id' => 'mw-search-togglenone',
798 'onclick' => 'mwToggleSearchCheckboxes("none");',
799 'value' => wfMsg( 'powersearch-togglenone' )
803 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
805 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
807 Xml
::hidden( 'title', SpecialPage
::getTitleFor( 'Search' )->getPrefixedText() ) .
808 Xml
::hidden( 'advanced', $this->searchAdvanced
) .
809 Xml
::hidden( 'fulltext', 'Advanced search' ) .
810 Xml
::closeElement( 'fieldset' );
813 protected function searchFocus() {
814 return Html
::inlineScript(
815 "hookEvent(\"load\", function() {" .
816 "document.getElementById('searchText').focus();" .
820 protected function getSearchProfiles() {
821 // Builds list of Search Types (profiles)
822 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
826 'message' => 'searchprofile-articles',
827 'tooltip' => 'searchprofile-articles-tooltip',
828 'namespaces' => SearchEngine
::defaultNamespaces(),
829 'namespace-messages' => SearchEngine
::namespacesAsText(
830 SearchEngine
::defaultNamespaces()
834 'message' => 'searchprofile-images',
835 'tooltip' => 'searchprofile-images-tooltip',
836 'namespaces' => array( NS_FILE
),
839 'message' => 'searchprofile-project',
840 'tooltip' => 'searchprofile-project-tooltip',
841 'namespaces' => SearchEngine
::helpNamespaces(),
842 'namespace-messages' => SearchEngine
::namespacesAsText(
843 SearchEngine
::helpNamespaces()
847 'message' => 'searchprofile-everything',
848 'tooltip' => 'searchprofile-everything-tooltip',
849 'namespaces' => $nsAllSet,
852 'message' => 'searchprofile-advanced',
853 'tooltip' => 'searchprofile-advanced-tooltip',
854 'namespaces' => $this->namespaces
,
855 'parameters' => array( 'advanced' => 1 ),
859 wfRunHooks( 'SpecialSearchProfiles', array( &$profiles ) );
861 foreach( $profiles as $key => &$data ) {
862 sort($data['namespaces']);
868 protected function formHeader( $term, $resultsShown, $totalNum ) {
869 global $wgContLang, $wgLang;
871 $out = Xml
::openElement('div', array( 'class' => 'mw-search-formheader' ) );
874 if( $this->startsWithImage( $term ) ) {
876 $bareterm = substr( $term, strpos( $term, ':' ) +
1 );
880 $profiles = $this->getSearchProfiles();
882 // Outputs XML for Search Types
883 $out .= Xml
::openElement( 'div', array( 'class' => 'search-types' ) );
884 $out .= Xml
::openElement( 'ul' );
885 foreach ( $profiles as $id => $profile ) {
886 $tooltipParam = isset( $profile['namespace-messages'] ) ?
887 $wgLang->commaList( $profile['namespace-messages'] ) : null;
891 'class' => $this->active
== $id ?
'current' : 'normal'
893 $this->makeSearchLink(
895 $profile['namespaces'],
896 wfMsg( $profile['message'] ),
897 wfMsg( $profile['tooltip'], $tooltipParam ),
898 isset( $profile['parameters'] ) ?
$profile['parameters'] : array()
902 $out .= Xml
::closeElement( 'ul' );
903 $out .= Xml
::closeElement('div') ;
906 if ( $resultsShown > 0 ) {
907 if ( $totalNum > 0 ){
908 $top = wfMsgExt( 'showingresultsheader', array( 'parseinline' ),
909 $wgLang->formatNum( $this->offset +
1 ),
910 $wgLang->formatNum( $this->offset +
$resultsShown ),
911 $wgLang->formatNum( $totalNum ),
912 wfEscapeWikiText( $term ),
913 $wgLang->formatNum( $resultsShown )
915 } elseif ( $resultsShown >= $this->limit
) {
916 $top = wfShowingResults( $this->offset
, $this->limit
);
918 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $resultsShown );
920 $out .= Xml
::tags( 'div', array( 'class' => 'results-info' ),
921 Xml
::tags( 'ul', null, Xml
::tags( 'li', null, $top ) )
925 $out .= Xml
::element( 'div', array( 'style' => 'clear:both' ), '', false );
926 $out .= Xml
::closeElement('div');
928 // Adds hidden namespace fields
929 if ( !$this->searchAdvanced
) {
930 foreach( $this->namespaces
as $ns ) {
931 $out .= Xml
::hidden( "ns{$ns}", '1' );
938 protected function shortDialog( $term ) {
939 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
940 $searchable = SearchEngine
::searchableNamespaces();
941 $out = Html
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
942 // Keep redirect setting
943 $out .= Html
::hidden( "redirs", (int)$this->searchRedirects
) . "\n";
945 $out .= Html
::input( 'search', $term, 'search', array(
946 'id' => 'searchText',
950 $out .= Html
::hidden( 'fulltext', 'Search' ) . "\n";
951 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ) ) . "\n";
952 return $out . $this->didYouMeanHtml
;
955 /** Make a search link with some target namespaces */
956 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
958 foreach( $namespaces as $n ) {
961 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
963 $st = SpecialPage
::getTitleFor( 'Search' );
964 $stParams = array_merge(
967 'fulltext' => wfMsg( 'search' )
975 'href' => $st->getLocalURL( $stParams ),
977 'onmousedown' => 'mwSearchHeaderClick(this);',
978 'onkeydown' => 'mwSearchHeaderClick(this);'),
983 /** Check if query starts with image: prefix */
984 protected function startsWithImage( $term ) {
987 $p = explode( ':', $term );
988 if( count( $p ) > 1 ) {
989 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
994 /** Check if query starts with all: prefix */
995 protected function startsWithAll( $term ) {
997 $allkeyword = wfMsgForContent('searchall');
999 $p = explode( ':', $term );
1000 if( count( $p ) > 1 ) {
1001 return $p[0] == $allkeyword;