da7f0d3174b525fe7a6056cd1d24bc488c367636
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 $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'>" );
262 // show direct page/create link
264 if( !$t->exists() ) {
265 $wgOut->addWikiMsg( 'searchmenu-new', wfEscapeWikiText( $t->getPrefixedText() ) );
267 $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) );
270 // preserve the paragraph for margins etc...
271 $wgOut->addHTML('<p></p>');
275 if( $num ||
$this->offset
) {
276 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
277 SpecialPage
::getTitleFor( 'Search' ),
278 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
279 max( $titleMatchesNum, $textMatchesNum ) < $this->limit
281 //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
282 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
284 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
287 if( $titleMatches ) {
288 if( $numTitleMatches > 0 ) {
289 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
290 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
292 $titleMatches->free();
295 // output appropriate heading
296 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
297 // if no title matches the heading is redundant
298 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
299 } elseif( $totalRes == 0 ) {
300 # Don't show the 'no text matches' if we received title matches
301 # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
303 // show interwiki results if any
304 if( $textMatches->hasInterwikiResults() ) {
305 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
308 if( $numTextMatches > 0 ) {
309 $wgOut->addHTML( $this->showMatches( $textMatches ) );
312 $textMatches->free();
315 $wgOut->addWikiMsg( 'search-nonefound', wfEscapeWikiText( $term ) );
317 $wgOut->addHtml( "</div>" );
319 $wgOut->addHTML( $this->searchFocus() );
322 if( $num ||
$this->offset
) {
323 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
325 wfProfileOut( __METHOD__
);
331 protected function setupPage( $term ) {
333 // Figure out the active search profile header
334 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
335 if( $this->searchAdvanced
)
336 $this->active
= 'advanced';
337 else if( $this->namespaces
=== array(NS_FILE
) ||
$this->startsWithImage( $term ) )
338 $this->active
= 'images';
339 elseif( $this->namespaces
=== $nsAllSet ||
$this->startsWithAll( $term ) )
340 $this->active
= 'all';
341 elseif( $this->namespaces
=== SearchEngine
::defaultNamespaces() )
342 $this->active
= 'default';
343 elseif( $this->namespaces
=== SearchEngine
::helpNamespaces() )
344 $this->active
= 'help';
346 $this->active
= 'advanced';
347 # Should advanced UI be used?
348 $this->searchAdvanced
= ($this->active
=== 'advanced');
349 if( !empty( $term ) ) {
350 $wgOut->setPageTitle( wfMsg( 'searchresults') );
351 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
353 $wgOut->setArticleRelated( false );
354 $wgOut->setRobotPolicy( 'noindex,nofollow' );
355 // add javascript specific to special:search
356 $wgOut->addScriptFile( 'search.js' );
360 * Extract "power search" namespace settings from the request object,
361 * returning a list of index numbers to search.
363 * @param WebRequest $request
366 protected function powerSearch( &$request ) {
368 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
369 if( $request->getCheck( 'ns' . $ns ) ) {
377 * Reconstruct the 'power search' options for links
380 protected function powerSearchOptions() {
382 foreach( $this->namespaces
as $n ) {
385 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
386 if( $this->searchAdvanced
) {
387 $opt['advanced'] = $this->searchAdvanced
;
393 * Show whole set of results
395 * @param SearchResultSet $matches
397 protected function showMatches( &$matches ) {
399 wfProfileIn( __METHOD__
);
401 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
404 $infoLine = $matches->getInfo();
405 if( !is_null($infoLine) ) {
406 $out .= "\n<!-- {$infoLine} -->\n";
408 $off = $this->offset +
1;
409 $out .= "<ul class='mw-search-results'>\n";
410 while( $result = $matches->next() ) {
411 $out .= $this->showHit( $result, $terms );
415 // convert the whole thing to desired language variant
416 $out = $wgContLang->convert( $out );
417 wfProfileOut( __METHOD__
);
422 * Format a single hit result
423 * @param SearchResult $result
424 * @param array $terms terms to highlight
426 protected function showHit( $result, $terms ) {
427 global $wgContLang, $wgLang, $wgUser;
428 wfProfileIn( __METHOD__
);
430 if( $result->isBrokenTitle() ) {
431 wfProfileOut( __METHOD__
);
432 return "<!-- Broken link in search result -->\n";
435 $sk = $wgUser->getSkin();
436 $t = $result->getTitle();
438 $titleSnippet = $result->getTitleSnippet($terms);
440 if( $titleSnippet == '' )
441 $titleSnippet = null;
443 $link = $this->sk
->linkKnown(
448 //If page content is not readable, just return the title.
449 //This is not quite safe, but better than showing excerpts from non-readable pages
450 //Note that hiding the entry entirely would screw up paging.
451 if( !$t->userCanRead() ) {
452 wfProfileOut( __METHOD__
);
453 return "<li>{$link}</li>\n";
456 // If the page doesn't *exist*... our search index is out of date.
457 // The least confusing at this point is to drop the result.
458 // You may get less results, but... oh well. :P
459 if( $result->isMissingRevision() ) {
460 wfProfileOut( __METHOD__
);
461 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
464 // format redirects / relevant sections
465 $redirectTitle = $result->getRedirectTitle();
466 $redirectText = $result->getRedirectSnippet($terms);
467 $sectionTitle = $result->getSectionTitle();
468 $sectionText = $result->getSectionSnippet($terms);
471 if( !is_null($redirectTitle) ) {
472 if( $redirectText == '' )
473 $redirectText = null;
475 $redirect = "<span class='searchalttitle'>" .
478 $this->sk
->linkKnown(
489 if( !is_null($sectionTitle) ) {
490 if( $sectionText == '' )
493 $section = "<span class='searchalttitle'>" .
495 'search-section', $this->sk
->linkKnown(
503 // format text extract
504 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
507 if( is_null( $result->getScore() ) ) {
508 // Search engine doesn't report scoring info
511 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
512 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
516 // format description
517 $byteSize = $result->getByteSize();
518 $wordCount = $result->getWordCount();
519 $timestamp = $result->getTimestamp();
521 'search-result-size',
522 array( 'parsemag', 'escape' ),
523 $this->sk
->formatSize( $byteSize ),
526 $date = $wgLang->timeanddate( $timestamp );
528 // link to related articles if supported
530 if( $result->hasRelated() ) {
531 $st = SpecialPage
::getTitleFor( 'Search' );
532 $stParams = array_merge(
533 $this->powerSearchOptions(),
535 'search' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText(),
536 'fulltext' => wfMsg( 'search' )
540 $related = ' -- ' . $sk->linkKnown(
542 wfMsg('search-relatedarticle'),
548 // Include a thumbnail for media files...
549 if( $t->getNamespace() == NS_FILE
) {
550 $img = wfFindFile( $t );
552 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
554 $desc = $img->getShortDesc();
555 wfProfileOut( __METHOD__
);
556 // Float doesn't seem to interact well with the bullets.
557 // Table messes up vertical alignment of the bullets.
558 // Bullets are therefore disabled (didn't look great anyway).
560 '<table class="searchResultImage">' .
562 '<td width="120" align="center" valign="top">' .
563 $thumb->toHtml( array( 'desc-link' => true ) ) .
565 '<td valign="top">' .
568 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
577 wfProfileOut( __METHOD__
);
578 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
579 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
585 * Show results from other wikis
587 * @param SearchResultSet $matches
589 protected function showInterwiki( &$matches, $query ) {
591 wfProfileIn( __METHOD__
);
592 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
594 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
595 wfMsg('search-interwiki-caption')."</div>\n";
596 $off = $this->offset +
1;
597 $out .= "<ul class='mw-search-iwresults'>\n";
599 // work out custom project captions
600 $customCaptions = array();
601 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
602 foreach($customLines as $line) {
603 $parts = explode(":",$line,2);
604 if(count($parts) == 2) // validate line
605 $customCaptions[$parts[0]] = $parts[1];
609 while( $result = $matches->next() ) {
610 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
611 $prev = $result->getInterwikiPrefix();
613 // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
614 $out .= "</ul></div>\n";
616 // convert the whole thing to desired language variant
617 $out = $wgContLang->convert( $out );
618 wfProfileOut( __METHOD__
);
623 * Show single interwiki link
625 * @param SearchResult $result
626 * @param string $lastInterwiki
627 * @param array $terms
628 * @param string $query
629 * @param array $customCaptions iw prefix -> caption
631 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
632 wfProfileIn( __METHOD__
);
633 global $wgContLang, $wgLang;
635 if( $result->isBrokenTitle() ) {
636 wfProfileOut( __METHOD__
);
637 return "<!-- Broken link in search result -->\n";
640 $t = $result->getTitle();
642 $titleSnippet = $result->getTitleSnippet($terms);
644 if( $titleSnippet == '' )
645 $titleSnippet = null;
647 $link = $this->sk
->linkKnown(
652 // format redirect if any
653 $redirectTitle = $result->getRedirectTitle();
654 $redirectText = $result->getRedirectSnippet($terms);
656 if( !is_null($redirectTitle) ) {
657 if( $redirectText == '' )
658 $redirectText = null;
660 $redirect = "<span class='searchalttitle'>" .
663 $this->sk
->linkKnown(
672 // display project name
673 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
674 if( key_exists($t->getInterwiki(),$customCaptions) )
675 // captions from 'search-interwiki-custom'
676 $caption = $customCaptions[$t->getInterwiki()];
678 // default is to show the hostname of the other wiki which might suck
679 // if there are many wikis on one hostname
680 $parsed = parse_url($t->getFullURL());
681 $caption = wfMsg('search-interwiki-default', $parsed['host']);
683 // "more results" link (special page stuff could be localized, but we might not know target lang)
684 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
685 $searchLink = $this->sk
->linkKnown(
687 wfMsg('search-interwiki-more'),
691 'fulltext' => 'Search'
694 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
695 {$searchLink}</span>{$caption}</div>\n<ul>";
698 $out .= "<li>{$link} {$redirect}</li>\n";
699 wfProfileOut( __METHOD__
);
705 * Generates the power search box at bottom of [[Special:Search]]
706 * @param $term string: search term
707 * @return $out string: HTML form
709 protected function powerSearchBox( $term ) {
710 global $wgScript, $wgContLang;
712 // Groups namespaces into rows according to subject
714 foreach( SearchEngine
::searchableNamespaces() as $namespace => $name ) {
715 $subject = MWNamespace
::getSubject( $namespace );
716 if( !array_key_exists( $subject, $rows ) ) {
717 $rows[$subject] = "";
719 $name = str_replace( '_', ' ', $name );
721 $name = wfMsg( 'blanknamespace' );
725 'td', array( 'style' => 'white-space: nowrap' )
730 "mw-search-ns{$namespace}",
731 in_array( $namespace, $this->namespaces
)
733 Xml
::closeElement( 'td' );
735 $rows = array_values( $rows );
736 $numRows = count( $rows );
738 // Lays out namespaces in multiple floating two-column tables so they'll
739 // be arranged nicely while still accommodating different screen widths
740 $namespaceTables = '';
741 for( $i = 0; $i < $numRows; $i +
= 4 ) {
742 $namespaceTables .= Xml
::openElement(
744 array( 'cellpadding' => 0, 'cellspacing' => 0, 'border' => 0 )
746 for( $j = $i; $j < $i +
4 && $j < $numRows; $j++
) {
747 $namespaceTables .= Xml
::tags( 'tr', null, $rows[$j] );
749 $namespaceTables .= Xml
::closeElement( 'table' );
751 // Show redirects check only if backend supports it
753 if( $this->searchEngine
->acceptListRedirects() ) {
756 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' )
759 Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
761 // Return final output
765 array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
767 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
768 Xml
::tags( 'h4', null, wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) ) .
771 array( 'id' => 'mw-search-togglebox' ),
772 Xml
::label( wfMsg( 'powersearch-togglelabel' ), 'mw-search-togglelabel' ) .
777 'id' => 'mw-search-toggleall',
778 'onclick' => 'mwToggleSearchCheckboxes("all");',
779 'value' => wfMsg( 'powersearch-toggleall' )
786 'id' => 'mw-search-togglenone',
787 'onclick' => 'mwToggleSearchCheckboxes("none");',
788 'value' => wfMsg( 'powersearch-togglenone'
793 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
795 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
797 Xml
::hidden( 'title', SpecialPage
::getTitleFor( 'Search' )->getPrefixedText() ) .
798 Xml
::hidden( 'advanced', $this->searchAdvanced
) .
799 Xml
::hidden( 'fulltext', 'Advanced search' ) .
800 Xml
::closeElement( 'fieldset' );
803 protected function searchFocus() {
804 return Html
::inlineScript(
805 "hookEvent(\"load\", function() {" .
806 "document.getElementById('searchText').focus();" .
810 protected function formHeader( $term, $resultsShown, $totalNum ) {
811 global $wgContLang, $wgCanonicalNamespaceNames, $wgLang;
813 $out = Xml
::openElement('div', array( 'class' => 'mw-search-formheader' ) );
816 if( $this->startsWithImage( $term ) ) {
818 $bareterm = substr( $term, strpos( $term, ':' ) +
1 );
820 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
822 // Builds list of Search Types (profiles)
825 'message' => 'searchprofile-articles',
826 'tooltip' => 'searchprofile-articles-tooltip',
827 'namespaces' => SearchEngine
::defaultNamespaces(),
828 'namespace-messages' => SearchEngine
::namespacesAsText(
829 SearchEngine
::defaultNamespaces()
833 'message' => 'searchprofile-images',
834 'tooltip' => 'searchprofile-images-tooltip',
835 'namespaces' => array( NS_FILE
),
838 'message' => 'searchprofile-project',
839 'tooltip' => 'searchprofile-project-tooltip',
840 'namespaces' => SearchEngine
::helpNamespaces(),
841 'namespace-messages' => SearchEngine
::namespacesAsText(
842 SearchEngine
::helpNamespaces()
846 'message' => 'searchprofile-everything',
847 'tooltip' => 'searchprofile-everything-tooltip',
848 'namespaces' => $nsAllSet,
851 'message' => 'searchprofile-advanced',
852 'tooltip' => 'searchprofile-advanced-tooltip',
853 'namespaces' => $this->namespaces
,
854 'parameters' => array( 'advanced' => 1 ),
857 // Outputs XML for Search Types
858 $out .= Xml
::openElement( 'div', array( 'class' => 'search-types' ) );
859 $out .= Xml
::openElement( 'ul' );
860 foreach ( $profiles as $id => $profile ) {
861 $tooltipParam = isset( $profile['namespace-messages'] ) ?
862 $wgLang->commaList( $profile['namespace-messages'] ) : null;
866 'class' => $this->active
== $id ?
'current' : 'normal'
868 $this->makeSearchLink(
870 $profile['namespaces'],
871 wfMsg( $profile['message'] ),
872 wfMsg( $profile['tooltip'], $tooltipParam ),
873 isset( $profile['parameters'] ) ?
$profile['parameters'] : array()
877 $out .= Xml
::closeElement( 'ul' );
878 $out .= Xml
::closeElement('div') ;
881 if ( $resultsShown > 0 ) {
882 if ( $totalNum > 0 ){
883 $top = wfMsgExt('showingresultsheader', array( 'parseinline' ),
884 $this->offset+
1, $this->offset+
$resultsShown, $totalNum, wfEscapeWikiText($term), $resultsShown );
885 } elseif ( $resultsShown >= $this->limit
) {
886 $top = wfShowingResults( $this->offset
, $this->limit
);
888 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $resultsShown );
890 $out .= Xml
::tags( 'div', array( 'class' => 'results-info' ),
891 Xml
::tags( 'ul', null, Xml
::tags( 'li', null, $top ) )
895 $out .= Xml
::element( 'div', array( 'style' => 'clear:both' ), '', false );
896 $out .= Xml
::closeElement('div');
898 // Adds hidden namespace fields
899 if ( !$this->searchAdvanced
) {
900 foreach( $this->namespaces
as $ns ) {
901 $out .= Xml
::hidden( "ns{$ns}", '1' );
908 protected function shortDialog( $term ) {
909 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
910 $searchable = SearchEngine
::searchableNamespaces();
911 $out = Xml
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
912 // Keep redirect setting
913 $out .= Xml
::hidden( "redirs", (int)$this->searchRedirects
);
915 $out .= Xml
::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
916 $out .= Xml
::hidden( 'fulltext', 'Search' );
917 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ) );
918 return $out . $this->didYouMeanHtml
;
921 /** Make a search link with some target namespaces */
922 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
924 foreach( $namespaces as $n ) {
927 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
929 $st = SpecialPage
::getTitleFor( 'Search' );
930 $stParams = array_merge(
933 'fulltext' => wfMsg( 'search' )
941 'href' => $st->getLocalURL( $stParams ),
943 'onmousedown' => 'mwSearchHeaderClick(this);',
944 'onkeydown' => 'mwSearchHeaderClick(this);'),
949 /** Check if query starts with image: prefix */
950 protected function startsWithImage( $term ) {
953 $p = explode( ':', $term );
954 if( count( $p ) > 1 ) {
955 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
960 /** Check if query starts with all: prefix */
961 protected function startsWithAll( $term ) {
963 $allkeyword = wfMsgForContent('searchall');
965 $p = explode( ':', $term );
966 if( count( $p ) > 1 ) {
967 return $p[0] == $allkeyword;