3 * Implements Special:Search
5 * Copyright © 2004 Brion Vibber <brion@pobox.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
23 * @ingroup SpecialPage
27 * implements Special:Search - Run text & title search and display the output
28 * @ingroup SpecialPage
30 class SpecialSearch
extends SpecialPage
{
32 public function __construct() {
33 parent
::__construct( 'Search' );
39 * @param $par String or null
41 public function execute( $par ) {
42 global $wgRequest, $wgUser;
45 $this->outputHeader();
47 // Strip underscores from title parameter; most of the time we'll want
48 // text form here. But don't strip underscores from actual text params!
49 $titleParam = str_replace( '_', ' ', $par );
51 // Fetch the search term
52 $search = str_replace( "\n", " ", $wgRequest->getText( 'search', $titleParam ) );
54 $this->load( $wgRequest, $wgUser );
56 if ( $wgRequest->getVal( 'fulltext' )
57 ||
!is_null( $wgRequest->getVal( 'offset' ) )
58 ||
!is_null( $wgRequest->getVal( 'searchx' ) ) )
60 $this->showResults( $search );
62 $this->goResult( $search );
67 * Set up basic search parameters from the request and user settings.
68 * Typically you'll pass $wgRequest and $wgUser.
70 * @param $request WebRequest
73 public function load( &$request, &$user ) {
74 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
75 $this->mPrefix
= $request->getVal('prefix', '');
76 # Extract requested namespaces
77 $this->namespaces
= $this->powerSearch( $request );
78 if( empty( $this->namespaces
) ) {
79 $this->namespaces
= SearchEngine
::userNamespaces( $user );
81 $this->searchRedirects
= $request->getCheck( 'redirs' );
82 $this->searchAdvanced
= $request->getVal( 'advanced' );
83 $this->active
= 'advanced';
84 $this->sk
= $user->getSkin();
85 $this->didYouMeanHtml
= ''; # html of did you mean... link
86 $this->fulltext
= $request->getVal('fulltext');
90 * If an exact title match can be found, jump straight ahead to it.
94 public function goResult( $term ) {
96 $this->setupPage( $term );
97 # Try to go to page as entered.
98 $t = Title
::newFromText( $term );
99 # If the string cannot be used to create a title
100 if( is_null( $t ) ) {
101 return $this->showResults( $term );
103 # If there's an exact or very near match, jump right there.
104 $t = SearchEngine
::getNearMatch( $term );
106 if ( !wfRunHooks( 'SpecialSearchGo', array( &$t, &$term ) ) ) {
107 # Hook requested termination
111 if( !is_null( $t ) ) {
112 $wgOut->redirect( $t->getFullURL() );
115 # No match, generate an edit URL
116 $t = Title
::newFromText( $term );
117 if( !is_null( $t ) ) {
119 wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
120 # If the feature is enabled, go straight to the edit page
122 $wgOut->redirect( $t->getFullURL( array( 'action' => 'edit' ) ) );
126 return $this->showResults( $term );
130 * @param $term String
132 public function showResults( $term ) {
133 global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
134 wfProfileIn( __METHOD__
);
136 $sk = $wgUser->getSkin();
138 $this->searchEngine
= SearchEngine
::create();
139 $search =& $this->searchEngine
;
140 $search->setLimitOffset( $this->limit
, $this->offset
);
141 $search->setNamespaces( $this->namespaces
);
142 $search->showRedirects
= $this->searchRedirects
;
143 $search->prefix
= $this->mPrefix
;
144 $term = $search->transformSearchTerm($term);
146 $this->setupPage( $term );
148 if( $wgDisableTextSearch ) {
149 global $wgSearchForwardUrl;
150 if( $wgSearchForwardUrl ) {
151 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
152 $wgOut->redirect( $url );
153 wfProfileOut( __METHOD__
);
156 global $wgInputEncoding;
158 Xml
::openElement( 'fieldset' ) .
159 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
160 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
161 wfMsg( 'googlesearch',
162 htmlspecialchars( $term ),
163 htmlspecialchars( $wgInputEncoding ),
164 htmlspecialchars( wfMsg( 'searchbutton' ) )
166 Xml
::closeElement( 'fieldset' )
168 wfProfileOut( __METHOD__
);
172 $t = Title
::newFromText( $term );
174 // fetch search results
175 $rewritten = $search->replacePrefixes($term);
177 $titleMatches = $search->searchTitle( $rewritten );
178 if( !($titleMatches instanceof SearchResultTooMany
))
179 $textMatches = $search->searchText( $rewritten );
181 // did you mean... suggestions
182 if( $textMatches && $textMatches->hasSuggestion() ) {
183 $st = SpecialPage
::getTitleFor( 'Search' );
185 # mirror Go/Search behaviour of original request ..
186 $didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
188 if($this->fulltext
!= null)
189 $didYouMeanParams['fulltext'] = $this->fulltext
;
191 $stParams = array_merge(
193 $this->powerSearchOptions()
196 $suggestionSnippet = $textMatches->getSuggestionSnippet();
198 if( $suggestionSnippet == '' )
199 $suggestionSnippet = null;
201 $suggestLink = $sk->linkKnown(
208 $this->didYouMeanHtml
= '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
210 // start rendering the page
215 'id' => ( $this->searchAdvanced ?
'powersearch' : 'search' ),
217 'action' => $wgScript
222 Xml
::openElement( 'table', array( 'id'=>'mw-search-top-table', 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
223 Xml
::openElement( 'tr' ) .
224 Xml
::openElement( 'td' ) . "\n" .
225 $this->shortDialog( $term ) .
226 Xml
::closeElement('td') .
227 Xml
::closeElement('tr') .
228 Xml
::closeElement('table')
231 // Sometimes the search engine knows there are too many hits
232 if( $titleMatches instanceof SearchResultTooMany
) {
233 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
234 wfProfileOut( __METHOD__
);
238 $filePrefix = $wgContLang->getFormattedNsText(NS_FILE
).':';
239 if( trim( $term ) === '' ||
$filePrefix === trim( $term ) ) {
240 $wgOut->addHTML( $this->formHeader($term, 0, 0));
241 if( $this->searchAdvanced
) {
242 $wgOut->addHTML( $this->powerSearchBox( $term ) );
244 $wgOut->addHTML( '</form>' );
245 // Empty query -- straight view of search form
246 wfProfileOut( __METHOD__
);
250 // Get number of results
251 $titleMatchesNum = $titleMatches ?
$titleMatches->numRows() : 0;
252 $textMatchesNum = $textMatches ?
$textMatches->numRows() : 0;
253 // Total initial query matches (possible false positives)
254 $num = $titleMatchesNum +
$textMatchesNum;
256 // Get total actual results (after second filtering, if any)
257 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
258 $titleMatches->getTotalHits() : $titleMatchesNum;
259 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
260 $textMatches->getTotalHits() : $textMatchesNum;
262 // get total number of results if backend can calculate it
264 if($titleMatches && !is_null( $titleMatches->getTotalHits() ) )
265 $totalRes +
= $titleMatches->getTotalHits();
266 if($textMatches && !is_null( $textMatches->getTotalHits() ))
267 $totalRes +
= $textMatches->getTotalHits();
269 // show number of results and current offset
270 $wgOut->addHTML( $this->formHeader($term, $num, $totalRes));
271 if( $this->searchAdvanced
) {
272 $wgOut->addHTML( $this->powerSearchBox( $term ) );
275 $wgOut->addHtml( Xml
::closeElement( 'form' ) );
276 $wgOut->addHtml( "<div class='searchresults'>" );
279 if( $num ||
$this->offset
) {
280 // Show the create link ahead
281 $this->showCreateLink( $t );
282 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
283 SpecialPage
::getTitleFor( 'Search' ),
284 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
285 max( $titleMatchesNum, $textMatchesNum ) < $this->limit
287 //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
288 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
290 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
293 $wgOut->parserOptions()->setEditSection( false );
294 if( $titleMatches ) {
295 if( $numTitleMatches > 0 ) {
296 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
297 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
299 $titleMatches->free();
302 // output appropriate heading
303 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
304 // if no title matches the heading is redundant
305 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
306 } elseif( $totalRes == 0 ) {
307 # Don't show the 'no text matches' if we received title matches
308 # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
310 // show interwiki results if any
311 if( $textMatches->hasInterwikiResults() ) {
312 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
315 if( $numTextMatches > 0 ) {
316 $wgOut->addHTML( $this->showMatches( $textMatches ) );
319 $textMatches->free();
322 $wgOut->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>", array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
323 $this->showCreateLink( $t );
325 $wgOut->addHtml( "</div>" );
327 if( $num ||
$this->offset
) {
328 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
330 wfProfileOut( __METHOD__
);
333 protected function showCreateLink( $t ) {
336 // show direct page/create link if applicable
339 if( $t->isKnown() ) {
340 $messageName = 'searchmenu-exists';
341 } elseif( $t->userCan( 'create' ) ) {
342 $messageName = 'searchmenu-new';
344 $messageName = 'searchmenu-new-nocreate';
348 $wgOut->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) );
350 // preserve the paragraph for margins etc...
351 $wgOut->addHtml( '<p></p>' );
358 protected function setupPage( $term ) {
360 // Figure out the active search profile header
361 if( $this->searchAdvanced
) {
362 $this->active
= 'advanced';
364 $profiles = $this->getSearchProfiles();
366 foreach( $profiles as $key => $data ) {
367 if ( $this->namespaces
== $data['namespaces'] && $key != 'advanced')
368 $this->active
= $key;
372 # Should advanced UI be used?
373 $this->searchAdvanced
= ($this->active
=== 'advanced');
374 if( !empty( $term ) ) {
375 $wgOut->setPageTitle( wfMsg( 'searchresults') );
376 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
378 // add javascript specific to special:search
379 $wgOut->addModules( 'mediawiki.legacy.search' );
380 $wgOut->addModules( 'mediawiki.special.search' );
384 * Extract "power search" namespace settings from the request object,
385 * returning a list of index numbers to search.
387 * @param $request WebRequest
390 protected function powerSearch( &$request ) {
392 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
393 if( $request->getCheck( 'ns' . $ns ) ) {
401 * Reconstruct the 'power search' options for links
405 protected function powerSearchOptions() {
407 foreach( $this->namespaces
as $n ) {
410 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
411 if( $this->searchAdvanced
) {
412 $opt['advanced'] = $this->searchAdvanced
;
418 * Show whole set of results
420 * @param $matches SearchResultSet
422 protected function showMatches( &$matches ) {
424 wfProfileIn( __METHOD__
);
426 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
429 $infoLine = $matches->getInfo();
430 if( !is_null($infoLine) ) {
431 $out .= "\n<!-- {$infoLine} -->\n";
433 $out .= "<ul class='mw-search-results'>\n";
434 while( $result = $matches->next() ) {
435 $out .= $this->showHit( $result, $terms );
439 // convert the whole thing to desired language variant
440 $out = $wgContLang->convert( $out );
441 wfProfileOut( __METHOD__
);
446 * Format a single hit result
448 * @param $result SearchResult
449 * @param $terms Array: terms to highlight
451 protected function showHit( $result, $terms ) {
452 global $wgLang, $wgUser;
453 wfProfileIn( __METHOD__
);
455 if( $result->isBrokenTitle() ) {
456 wfProfileOut( __METHOD__
);
457 return "<!-- Broken link in search result -->\n";
460 $sk = $wgUser->getSkin();
461 $t = $result->getTitle();
463 $titleSnippet = $result->getTitleSnippet($terms);
465 if( $titleSnippet == '' )
466 $titleSnippet = null;
470 wfRunHooks( 'ShowSearchHitTitle',
471 array( &$link_t, &$titleSnippet, $result, $terms, $this ) );
473 $link = $this->sk
->linkKnown(
478 //If page content is not readable, just return the title.
479 //This is not quite safe, but better than showing excerpts from non-readable pages
480 //Note that hiding the entry entirely would screw up paging.
481 if( !$t->userCanRead() ) {
482 wfProfileOut( __METHOD__
);
483 return "<li>{$link}</li>\n";
486 // If the page doesn't *exist*... our search index is out of date.
487 // The least confusing at this point is to drop the result.
488 // You may get less results, but... oh well. :P
489 if( $result->isMissingRevision() ) {
490 wfProfileOut( __METHOD__
);
491 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
494 // format redirects / relevant sections
495 $redirectTitle = $result->getRedirectTitle();
496 $redirectText = $result->getRedirectSnippet($terms);
497 $sectionTitle = $result->getSectionTitle();
498 $sectionText = $result->getSectionSnippet($terms);
501 if( !is_null($redirectTitle) ) {
502 if( $redirectText == '' )
503 $redirectText = null;
505 $redirect = "<span class='searchalttitle'>" .
508 $this->sk
->linkKnown(
519 if( !is_null($sectionTitle) ) {
520 if( $sectionText == '' )
523 $section = "<span class='searchalttitle'>" .
525 'search-section', $this->sk
->linkKnown(
533 // format text extract
534 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
537 if( is_null( $result->getScore() ) ) {
538 // Search engine doesn't report scoring info
541 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
542 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
546 // format description
547 $byteSize = $result->getByteSize();
548 $wordCount = $result->getWordCount();
549 $timestamp = $result->getTimestamp();
551 'search-result-size',
552 array( 'parsemag', 'escape' ),
553 $this->sk
->formatSize( $byteSize ),
554 $wgLang->formatNum( $wordCount )
557 if( $t->getNamespace() == NS_CATEGORY
) {
558 $cat = Category
::newFromTitle( $t );
560 'search-result-category-size',
561 array( 'parsemag', 'escape' ),
562 $wgLang->formatNum( $cat->getPageCount() ),
563 $wgLang->formatNum( $cat->getSubcatCount() ),
564 $wgLang->formatNum( $cat->getFileCount() )
568 $date = $wgLang->timeanddate( $timestamp );
570 // link to related articles if supported
572 if( $result->hasRelated() ) {
573 $st = SpecialPage
::getTitleFor( 'Search' );
574 $stParams = array_merge(
575 $this->powerSearchOptions(),
577 'search' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText(),
578 'fulltext' => wfMsg( 'search' )
582 $related = ' -- ' . $sk->linkKnown(
584 wfMsg('search-relatedarticle'),
590 // Include a thumbnail for media files...
591 if( $t->getNamespace() == NS_FILE
) {
592 $img = wfFindFile( $t );
594 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
596 $desc = $img->getShortDesc();
597 wfProfileOut( __METHOD__
);
598 // Float doesn't seem to interact well with the bullets.
599 // Table messes up vertical alignment of the bullets.
600 // Bullets are therefore disabled (didn't look great anyway).
602 '<table class="searchResultImage">' .
604 '<td width="120" align="center" valign="top">' .
605 $thumb->toHtml( array( 'desc-link' => true ) ) .
607 '<td valign="top">' .
610 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
619 wfProfileOut( __METHOD__
);
620 return "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
621 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
627 * Show results from other wikis
629 * @param $matches SearchResultSet
630 * @param $query String
632 protected function showInterwiki( &$matches, $query ) {
634 wfProfileIn( __METHOD__
);
635 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
637 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
638 wfMsg('search-interwiki-caption')."</div>\n";
639 $out .= "<ul class='mw-search-iwresults'>\n";
641 // work out custom project captions
642 $customCaptions = array();
643 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
644 foreach($customLines as $line) {
645 $parts = explode(":",$line,2);
646 if(count($parts) == 2) // validate line
647 $customCaptions[$parts[0]] = $parts[1];
651 while( $result = $matches->next() ) {
652 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
653 $prev = $result->getInterwikiPrefix();
655 // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
656 $out .= "</ul></div>\n";
658 // convert the whole thing to desired language variant
659 $out = $wgContLang->convert( $out );
660 wfProfileOut( __METHOD__
);
665 * Show single interwiki link
667 * @param $result SearchResult
668 * @param $lastInterwiki String
669 * @param $terms Array
670 * @param $query String
671 * @param $customCaptions Array: iw prefix -> caption
673 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
674 wfProfileIn( __METHOD__
);
676 if( $result->isBrokenTitle() ) {
677 wfProfileOut( __METHOD__
);
678 return "<!-- Broken link in search result -->\n";
681 $t = $result->getTitle();
683 $titleSnippet = $result->getTitleSnippet($terms);
685 if( $titleSnippet == '' )
686 $titleSnippet = null;
688 $link = $this->sk
->linkKnown(
693 // format redirect if any
694 $redirectTitle = $result->getRedirectTitle();
695 $redirectText = $result->getRedirectSnippet($terms);
697 if( !is_null($redirectTitle) ) {
698 if( $redirectText == '' )
699 $redirectText = null;
701 $redirect = "<span class='searchalttitle'>" .
704 $this->sk
->linkKnown(
713 // display project name
714 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
715 if( key_exists($t->getInterwiki(),$customCaptions) )
716 // captions from 'search-interwiki-custom'
717 $caption = $customCaptions[$t->getInterwiki()];
719 // default is to show the hostname of the other wiki which might suck
720 // if there are many wikis on one hostname
721 $parsed = parse_url($t->getFullURL());
722 $caption = wfMsg('search-interwiki-default', $parsed['host']);
724 // "more results" link (special page stuff could be localized, but we might not know target lang)
725 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
726 $searchLink = $this->sk
->linkKnown(
728 wfMsg('search-interwiki-more'),
732 'fulltext' => 'Search'
735 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
736 {$searchLink}</span>{$caption}</div>\n<ul>";
739 $out .= "<li>{$link} {$redirect}</li>\n";
740 wfProfileOut( __METHOD__
);
746 * Generates the power search box at bottom of [[Special:Search]]
748 * @param $term String: search term
749 * @return String: HTML form
751 protected function powerSearchBox( $term ) {
752 // Groups namespaces into rows according to subject
754 foreach( SearchEngine
::searchableNamespaces() as $namespace => $name ) {
755 $subject = MWNamespace
::getSubject( $namespace );
756 if( !array_key_exists( $subject, $rows ) ) {
757 $rows[$subject] = "";
759 $name = str_replace( '_', ' ', $name );
761 $name = wfMsg( 'blanknamespace' );
765 'td', array( 'style' => 'white-space: nowrap' )
770 "mw-search-ns{$namespace}",
771 in_array( $namespace, $this->namespaces
)
773 Xml
::closeElement( 'td' );
775 $rows = array_values( $rows );
776 $numRows = count( $rows );
778 // Lays out namespaces in multiple floating two-column tables so they'll
779 // be arranged nicely while still accommodating different screen widths
780 $namespaceTables = '';
781 for( $i = 0; $i < $numRows; $i +
= 4 ) {
782 $namespaceTables .= Xml
::openElement(
784 array( 'cellpadding' => 0, 'cellspacing' => 0, 'border' => 0 )
786 for( $j = $i; $j < $i +
4 && $j < $numRows; $j++
) {
787 $namespaceTables .= Xml
::tags( 'tr', null, $rows[$j] );
789 $namespaceTables .= Xml
::closeElement( 'table' );
791 // Show redirects check only if backend supports it
793 if( $this->searchEngine
->acceptListRedirects() ) {
796 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' )
799 Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
801 // Return final output
805 array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
807 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
808 Xml
::tags( 'h4', null, wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) ) .
811 array( 'id' => 'mw-search-togglebox' ),
812 Xml
::label( wfMsg( 'powersearch-togglelabel' ), 'mw-search-togglelabel' ) .
817 'id' => 'mw-search-toggleall',
818 'onclick' => 'mwToggleSearchCheckboxes("all");',
819 'value' => wfMsg( 'powersearch-toggleall' )
826 'id' => 'mw-search-togglenone',
827 'onclick' => 'mwToggleSearchCheckboxes("none");',
828 'value' => wfMsg( 'powersearch-togglenone' )
832 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
834 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
836 Html
::hidden( 'title', SpecialPage
::getTitleFor( 'Search' )->getPrefixedText() ) .
837 Html
::hidden( 'advanced', $this->searchAdvanced
) .
838 Html
::hidden( 'fulltext', 'Advanced search' ) .
839 Xml
::closeElement( 'fieldset' );
842 protected function getSearchProfiles() {
843 // Builds list of Search Types (profiles)
844 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
848 'message' => 'searchprofile-articles',
849 'tooltip' => 'searchprofile-articles-tooltip',
850 'namespaces' => SearchEngine
::defaultNamespaces(),
851 'namespace-messages' => SearchEngine
::namespacesAsText(
852 SearchEngine
::defaultNamespaces()
856 'message' => 'searchprofile-images',
857 'tooltip' => 'searchprofile-images-tooltip',
858 'namespaces' => array( NS_FILE
),
861 'message' => 'searchprofile-project',
862 'tooltip' => 'searchprofile-project-tooltip',
863 'namespaces' => SearchEngine
::helpNamespaces(),
864 'namespace-messages' => SearchEngine
::namespacesAsText(
865 SearchEngine
::helpNamespaces()
869 'message' => 'searchprofile-everything',
870 'tooltip' => 'searchprofile-everything-tooltip',
871 'namespaces' => $nsAllSet,
874 'message' => 'searchprofile-advanced',
875 'tooltip' => 'searchprofile-advanced-tooltip',
876 'namespaces' => $this->namespaces
,
877 'parameters' => array( 'advanced' => 1 ),
881 wfRunHooks( 'SpecialSearchProfiles', array( &$profiles ) );
883 foreach( $profiles as &$data ) {
884 sort($data['namespaces']);
890 protected function formHeader( $term, $resultsShown, $totalNum ) {
893 $out = Xml
::openElement('div', array( 'class' => 'mw-search-formheader' ) );
896 if( $this->startsWithImage( $term ) ) {
898 $bareterm = substr( $term, strpos( $term, ':' ) +
1 );
901 $profiles = $this->getSearchProfiles();
903 // Outputs XML for Search Types
904 $out .= Xml
::openElement( 'div', array( 'class' => 'search-types' ) );
905 $out .= Xml
::openElement( 'ul' );
906 foreach ( $profiles as $id => $profile ) {
907 $tooltipParam = isset( $profile['namespace-messages'] ) ?
908 $wgLang->commaList( $profile['namespace-messages'] ) : null;
912 'class' => $this->active
== $id ?
'current' : 'normal'
914 $this->makeSearchLink(
916 $profile['namespaces'],
917 wfMsg( $profile['message'] ),
918 wfMsg( $profile['tooltip'], $tooltipParam ),
919 isset( $profile['parameters'] ) ?
$profile['parameters'] : array()
923 $out .= Xml
::closeElement( 'ul' );
924 $out .= Xml
::closeElement('div') ;
927 if ( $resultsShown > 0 ) {
928 if ( $totalNum > 0 ){
929 $top = wfMsgExt( 'showingresultsheader', array( 'parseinline' ),
930 $wgLang->formatNum( $this->offset +
1 ),
931 $wgLang->formatNum( $this->offset +
$resultsShown ),
932 $wgLang->formatNum( $totalNum ),
933 wfEscapeWikiText( $term ),
934 $wgLang->formatNum( $resultsShown )
936 } elseif ( $resultsShown >= $this->limit
) {
937 $top = wfShowingResults( $this->offset
, $this->limit
);
939 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $resultsShown );
941 $out .= Xml
::tags( 'div', array( 'class' => 'results-info' ),
942 Xml
::tags( 'ul', null, Xml
::tags( 'li', null, $top ) )
946 $out .= Xml
::element( 'div', array( 'style' => 'clear:both' ), '', false );
947 $out .= Xml
::closeElement('div');
949 // Adds hidden namespace fields
950 if ( !$this->searchAdvanced
) {
951 foreach( $this->namespaces
as $ns ) {
952 $out .= Html
::hidden( "ns{$ns}", '1' );
959 protected function shortDialog( $term ) {
960 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
961 $out = Html
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
962 // Keep redirect setting
963 $out .= Html
::hidden( "redirs", (int)$this->searchRedirects
) . "\n";
965 $out .= Html
::input( 'search', $term, 'search', array(
966 'id' => $this->searchAdvanced ?
'powerSearchText' : 'searchText',
970 $out .= Html
::hidden( 'fulltext', 'Search' ) . "\n";
971 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ) ) . "\n";
972 return $out . $this->didYouMeanHtml
;
976 * Make a search link with some target namespaces
978 * @param $term String
979 * @param $namespaces Array
980 * @param $label String: link's text
981 * @param $tooltip String: link's tooltip
982 * @param $params Array: query string parameters
983 * @return String: HTML fragment
985 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
987 foreach( $namespaces as $n ) {
990 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
992 $st = SpecialPage
::getTitleFor( 'Search' );
993 $stParams = array_merge(
996 'fulltext' => wfMsg( 'search' )
1001 return Xml
::element(
1004 'href' => $st->getLocalURL( $stParams ),
1005 'title' => $tooltip,
1006 'onmousedown' => 'mwSearchHeaderClick(this);',
1007 'onkeydown' => 'mwSearchHeaderClick(this);'),
1013 * Check if query starts with image: prefix
1015 * @param $term String: the string to check
1018 protected function startsWithImage( $term ) {
1021 $p = explode( ':', $term );
1022 if( count( $p ) > 1 ) {
1023 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
1029 * Check if query starts with all: prefix
1031 * @param $term String: the string to check
1034 protected function startsWithAll( $term ) {
1036 $allkeyword = wfMsgForContent('searchall');
1038 $p = explode( ':', $term );
1039 if( count( $p ) > 1 ) {
1040 return $p[0] == $allkeyword;