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
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 $request WebRequest
62 public function __construct( &$request, &$user ) {
63 list( $this->limit
, $this->offset
) = $request->getLimitOffset( 20, 'searchlimit' );
64 $this->mPrefix
= $request->getVal('prefix', '');
65 # Extract requested namespaces
66 $this->namespaces
= $this->powerSearch( $request );
67 if( empty( $this->namespaces
) ) {
68 $this->namespaces
= SearchEngine
::userNamespaces( $user );
70 $this->searchRedirects
= $request->getCheck( 'redirs' );
71 $this->searchAdvanced
= $request->getVal( 'advanced' );
72 $this->active
= 'advanced';
73 $this->sk
= $user->getSkin();
74 $this->didYouMeanHtml
= ''; # html of did you mean... link
75 $this->fulltext
= $request->getVal('fulltext');
79 * 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 wfRunHooks( 'SpecialSearchGomatch', array( &$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 $term String
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->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->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>", array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
306 $this->showCreateLink( $t );
308 $wgOut->addHtml( "</div>" );
310 if( $num ||
$this->offset
) {
311 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
313 wfProfileOut( __METHOD__
);
316 protected function showCreateLink( $t ) {
319 // show direct page/create link if applicable
322 if( $t->isKnown() ) {
323 $messageName = 'searchmenu-exists';
324 } elseif( $t->userCan( 'create' ) ) {
325 $messageName = 'searchmenu-new';
327 $messageName = 'searchmenu-new-nocreate';
331 $wgOut->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) );
333 // preserve the paragraph for margins etc...
334 $wgOut->addHtml( '<p></p>' );
341 protected function setupPage( $term ) {
343 // Figure out the active search profile header
344 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
345 if( $this->searchAdvanced
)
346 $this->active
= 'advanced';
348 $profiles = $this->getSearchProfiles();
350 foreach( $profiles as $key => $data ) {
351 if ( $this->namespaces
== $data['namespaces'] && $key != 'advanced')
352 $this->active
= $key;
356 # Should advanced UI be used?
357 $this->searchAdvanced
= ($this->active
=== 'advanced');
358 if( !empty( $term ) ) {
359 $wgOut->setPageTitle( wfMsg( 'searchresults') );
360 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
362 $wgOut->setArticleRelated( false );
363 $wgOut->setRobotPolicy( 'noindex,nofollow' );
364 // add javascript specific to special:search
365 $wgOut->addModules( 'mediawiki.legacy.search' );
366 $wgOut->addModules( 'mediawiki.special.search' );
370 * Extract "power search" namespace settings from the request object,
371 * returning a list of index numbers to search.
373 * @param $request WebRequest
376 protected function powerSearch( &$request ) {
378 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
379 if( $request->getCheck( 'ns' . $ns ) ) {
387 * Reconstruct the 'power search' options for links
391 protected function powerSearchOptions() {
393 foreach( $this->namespaces
as $n ) {
396 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
397 if( $this->searchAdvanced
) {
398 $opt['advanced'] = $this->searchAdvanced
;
404 * Show whole set of results
406 * @param $matches SearchResultSet
408 protected function showMatches( &$matches ) {
410 wfProfileIn( __METHOD__
);
412 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
415 $infoLine = $matches->getInfo();
416 if( !is_null($infoLine) ) {
417 $out .= "\n<!-- {$infoLine} -->\n";
419 $off = $this->offset +
1;
420 $out .= "<ul class='mw-search-results'>\n";
421 while( $result = $matches->next() ) {
422 $out .= $this->showHit( $result, $terms );
426 // convert the whole thing to desired language variant
427 $out = $wgContLang->convert( $out );
428 wfProfileOut( __METHOD__
);
433 * Format a single hit result
435 * @param $result SearchResult
436 * @param $terms Array: terms to highlight
438 protected function showHit( $result, $terms ) {
439 global $wgLang, $wgUser;
440 wfProfileIn( __METHOD__
);
442 if( $result->isBrokenTitle() ) {
443 wfProfileOut( __METHOD__
);
444 return "<!-- Broken link in search result -->\n";
447 $sk = $wgUser->getSkin();
448 $t = $result->getTitle();
450 $titleSnippet = $result->getTitleSnippet($terms);
452 if( $titleSnippet == '' )
453 $titleSnippet = null;
457 wfRunHooks( 'ShowSearchHitTitle',
458 array( &$link_t, &$titleSnippet, $result, $terms, $this ) );
460 $link = $this->sk
->linkKnown(
465 //If page content is not readable, just return the title.
466 //This is not quite safe, but better than showing excerpts from non-readable pages
467 //Note that hiding the entry entirely would screw up paging.
468 if( !$t->userCanRead() ) {
469 wfProfileOut( __METHOD__
);
470 return "<li>{$link}</li>\n";
473 // If the page doesn't *exist*... our search index is out of date.
474 // The least confusing at this point is to drop the result.
475 // You may get less results, but... oh well. :P
476 if( $result->isMissingRevision() ) {
477 wfProfileOut( __METHOD__
);
478 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
481 // format redirects / relevant sections
482 $redirectTitle = $result->getRedirectTitle();
483 $redirectText = $result->getRedirectSnippet($terms);
484 $sectionTitle = $result->getSectionTitle();
485 $sectionText = $result->getSectionSnippet($terms);
488 if( !is_null($redirectTitle) ) {
489 if( $redirectText == '' )
490 $redirectText = null;
492 $redirect = "<span class='searchalttitle'>" .
495 $this->sk
->linkKnown(
506 if( !is_null($sectionTitle) ) {
507 if( $sectionText == '' )
510 $section = "<span class='searchalttitle'>" .
512 'search-section', $this->sk
->linkKnown(
520 // format text extract
521 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
524 if( is_null( $result->getScore() ) ) {
525 // Search engine doesn't report scoring info
528 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
529 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
533 // format description
534 $byteSize = $result->getByteSize();
535 $wordCount = $result->getWordCount();
536 $timestamp = $result->getTimestamp();
538 'search-result-size',
539 array( 'parsemag', 'escape' ),
540 $this->sk
->formatSize( $byteSize ),
541 $wgLang->formatNum( $wordCount )
544 if( $t->getNamespace() == NS_CATEGORY
) {
545 $cat = Category
::newFromTitle( $t );
547 'search-result-category-size',
548 array( 'parsemag', 'escape' ),
549 $wgLang->formatNum( $cat->getPageCount() ),
550 $wgLang->formatNum( $cat->getSubcatCount() ),
551 $wgLang->formatNum( $cat->getFileCount() )
555 $date = $wgLang->timeanddate( $timestamp );
557 // link to related articles if supported
559 if( $result->hasRelated() ) {
560 $st = SpecialPage
::getTitleFor( 'Search' );
561 $stParams = array_merge(
562 $this->powerSearchOptions(),
564 'search' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText(),
565 'fulltext' => wfMsg( 'search' )
569 $related = ' -- ' . $sk->linkKnown(
571 wfMsg('search-relatedarticle'),
577 // Include a thumbnail for media files...
578 if( $t->getNamespace() == NS_FILE
) {
579 $img = wfFindFile( $t );
581 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
583 $desc = $img->getShortDesc();
584 wfProfileOut( __METHOD__
);
585 // Float doesn't seem to interact well with the bullets.
586 // Table messes up vertical alignment of the bullets.
587 // Bullets are therefore disabled (didn't look great anyway).
589 '<table class="searchResultImage">' .
591 '<td width="120" align="center" valign="top">' .
592 $thumb->toHtml( array( 'desc-link' => true ) ) .
594 '<td valign="top">' .
597 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
606 wfProfileOut( __METHOD__
);
607 return "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
608 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
614 * Show results from other wikis
616 * @param $matches SearchResultSet
617 * @param $query String
619 protected function showInterwiki( &$matches, $query ) {
621 wfProfileIn( __METHOD__
);
622 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
624 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
625 wfMsg('search-interwiki-caption')."</div>\n";
626 $off = $this->offset +
1;
627 $out .= "<ul class='mw-search-iwresults'>\n";
629 // work out custom project captions
630 $customCaptions = array();
631 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
632 foreach($customLines as $line) {
633 $parts = explode(":",$line,2);
634 if(count($parts) == 2) // validate line
635 $customCaptions[$parts[0]] = $parts[1];
639 while( $result = $matches->next() ) {
640 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
641 $prev = $result->getInterwikiPrefix();
643 // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
644 $out .= "</ul></div>\n";
646 // convert the whole thing to desired language variant
647 $out = $wgContLang->convert( $out );
648 wfProfileOut( __METHOD__
);
653 * Show single interwiki link
655 * @param $result SearchResult
656 * @param $lastInterwiki String
657 * @param $terms Array
658 * @param $query String
659 * @param $customCaptions Array: iw prefix -> caption
661 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
662 wfProfileIn( __METHOD__
);
664 if( $result->isBrokenTitle() ) {
665 wfProfileOut( __METHOD__
);
666 return "<!-- Broken link in search result -->\n";
669 $t = $result->getTitle();
671 $titleSnippet = $result->getTitleSnippet($terms);
673 if( $titleSnippet == '' )
674 $titleSnippet = null;
676 $link = $this->sk
->linkKnown(
681 // format redirect if any
682 $redirectTitle = $result->getRedirectTitle();
683 $redirectText = $result->getRedirectSnippet($terms);
685 if( !is_null($redirectTitle) ) {
686 if( $redirectText == '' )
687 $redirectText = null;
689 $redirect = "<span class='searchalttitle'>" .
692 $this->sk
->linkKnown(
701 // display project name
702 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
703 if( key_exists($t->getInterwiki(),$customCaptions) )
704 // captions from 'search-interwiki-custom'
705 $caption = $customCaptions[$t->getInterwiki()];
707 // default is to show the hostname of the other wiki which might suck
708 // if there are many wikis on one hostname
709 $parsed = parse_url($t->getFullURL());
710 $caption = wfMsg('search-interwiki-default', $parsed['host']);
712 // "more results" link (special page stuff could be localized, but we might not know target lang)
713 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
714 $searchLink = $this->sk
->linkKnown(
716 wfMsg('search-interwiki-more'),
720 'fulltext' => 'Search'
723 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
724 {$searchLink}</span>{$caption}</div>\n<ul>";
727 $out .= "<li>{$link} {$redirect}</li>\n";
728 wfProfileOut( __METHOD__
);
734 * Generates the power search box at bottom of [[Special:Search]]
736 * @param $term String: search term
737 * @return String: HTML form
739 protected function powerSearchBox( $term ) {
740 // Groups namespaces into rows according to subject
742 foreach( SearchEngine
::searchableNamespaces() as $namespace => $name ) {
743 $subject = MWNamespace
::getSubject( $namespace );
744 if( !array_key_exists( $subject, $rows ) ) {
745 $rows[$subject] = "";
747 $name = str_replace( '_', ' ', $name );
749 $name = wfMsg( 'blanknamespace' );
753 'td', array( 'style' => 'white-space: nowrap' )
758 "mw-search-ns{$namespace}",
759 in_array( $namespace, $this->namespaces
)
761 Xml
::closeElement( 'td' );
763 $rows = array_values( $rows );
764 $numRows = count( $rows );
766 // Lays out namespaces in multiple floating two-column tables so they'll
767 // be arranged nicely while still accommodating different screen widths
768 $namespaceTables = '';
769 for( $i = 0; $i < $numRows; $i +
= 4 ) {
770 $namespaceTables .= Xml
::openElement(
772 array( 'cellpadding' => 0, 'cellspacing' => 0, 'border' => 0 )
774 for( $j = $i; $j < $i +
4 && $j < $numRows; $j++
) {
775 $namespaceTables .= Xml
::tags( 'tr', null, $rows[$j] );
777 $namespaceTables .= Xml
::closeElement( 'table' );
779 // Show redirects check only if backend supports it
781 if( $this->searchEngine
->acceptListRedirects() ) {
784 'redirs', $this->searchRedirects
, array( 'value' => '1', 'id' => 'redirs' )
787 Xml
::label( wfMsg( 'powersearch-redir' ), 'redirs' );
789 // Return final output
793 array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
795 Xml
::element( 'legend', null, wfMsg('powersearch-legend') ) .
796 Xml
::tags( 'h4', null, wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) ) .
799 array( 'id' => 'mw-search-togglebox' ),
800 Xml
::label( wfMsg( 'powersearch-togglelabel' ), 'mw-search-togglelabel' ) .
805 'id' => 'mw-search-toggleall',
806 'onclick' => 'mwToggleSearchCheckboxes("all");',
807 'value' => wfMsg( 'powersearch-toggleall' )
814 'id' => 'mw-search-togglenone',
815 'onclick' => 'mwToggleSearchCheckboxes("none");',
816 'value' => wfMsg( 'powersearch-togglenone' )
820 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
822 Xml
::element( 'div', array( 'class' => 'divider' ), '', false ) .
824 Html
::hidden( 'title', SpecialPage
::getTitleFor( 'Search' )->getPrefixedText() ) .
825 Html
::hidden( 'advanced', $this->searchAdvanced
) .
826 Html
::hidden( 'fulltext', 'Advanced search' ) .
827 Xml
::closeElement( 'fieldset' );
830 protected function getSearchProfiles() {
831 // Builds list of Search Types (profiles)
832 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
836 'message' => 'searchprofile-articles',
837 'tooltip' => 'searchprofile-articles-tooltip',
838 'namespaces' => SearchEngine
::defaultNamespaces(),
839 'namespace-messages' => SearchEngine
::namespacesAsText(
840 SearchEngine
::defaultNamespaces()
844 'message' => 'searchprofile-images',
845 'tooltip' => 'searchprofile-images-tooltip',
846 'namespaces' => array( NS_FILE
),
849 'message' => 'searchprofile-project',
850 'tooltip' => 'searchprofile-project-tooltip',
851 'namespaces' => SearchEngine
::helpNamespaces(),
852 'namespace-messages' => SearchEngine
::namespacesAsText(
853 SearchEngine
::helpNamespaces()
857 'message' => 'searchprofile-everything',
858 'tooltip' => 'searchprofile-everything-tooltip',
859 'namespaces' => $nsAllSet,
862 'message' => 'searchprofile-advanced',
863 'tooltip' => 'searchprofile-advanced-tooltip',
864 'namespaces' => $this->namespaces
,
865 'parameters' => array( 'advanced' => 1 ),
869 wfRunHooks( 'SpecialSearchProfiles', array( &$profiles ) );
871 foreach( $profiles as &$data ) {
872 sort($data['namespaces']);
878 protected function formHeader( $term, $resultsShown, $totalNum ) {
881 $out = Xml
::openElement('div', array( 'class' => 'mw-search-formheader' ) );
884 if( $this->startsWithImage( $term ) ) {
886 $bareterm = substr( $term, strpos( $term, ':' ) +
1 );
889 $profiles = $this->getSearchProfiles();
891 // Outputs XML for Search Types
892 $out .= Xml
::openElement( 'div', array( 'class' => 'search-types' ) );
893 $out .= Xml
::openElement( 'ul' );
894 foreach ( $profiles as $id => $profile ) {
895 $tooltipParam = isset( $profile['namespace-messages'] ) ?
896 $wgLang->commaList( $profile['namespace-messages'] ) : null;
900 'class' => $this->active
== $id ?
'current' : 'normal'
902 $this->makeSearchLink(
904 $profile['namespaces'],
905 wfMsg( $profile['message'] ),
906 wfMsg( $profile['tooltip'], $tooltipParam ),
907 isset( $profile['parameters'] ) ?
$profile['parameters'] : array()
911 $out .= Xml
::closeElement( 'ul' );
912 $out .= Xml
::closeElement('div') ;
915 if ( $resultsShown > 0 ) {
916 if ( $totalNum > 0 ){
917 $top = wfMsgExt( 'showingresultsheader', array( 'parseinline' ),
918 $wgLang->formatNum( $this->offset +
1 ),
919 $wgLang->formatNum( $this->offset +
$resultsShown ),
920 $wgLang->formatNum( $totalNum ),
921 wfEscapeWikiText( $term ),
922 $wgLang->formatNum( $resultsShown )
924 } elseif ( $resultsShown >= $this->limit
) {
925 $top = wfShowingResults( $this->offset
, $this->limit
);
927 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $resultsShown );
929 $out .= Xml
::tags( 'div', array( 'class' => 'results-info' ),
930 Xml
::tags( 'ul', null, Xml
::tags( 'li', null, $top ) )
934 $out .= Xml
::element( 'div', array( 'style' => 'clear:both' ), '', false );
935 $out .= Xml
::closeElement('div');
937 // Adds hidden namespace fields
938 if ( !$this->searchAdvanced
) {
939 foreach( $this->namespaces
as $ns ) {
940 $out .= Html
::hidden( "ns{$ns}", '1' );
947 protected function shortDialog( $term ) {
948 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
949 $out = Html
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
950 // Keep redirect setting
951 $out .= Html
::hidden( "redirs", (int)$this->searchRedirects
) . "\n";
953 $out .= Html
::input( 'search', $term, 'search', array(
954 'id' => $this->searchAdvanced ?
'powerSearchText' : 'searchText',
958 $out .= Html
::hidden( 'fulltext', 'Search' ) . "\n";
959 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ) ) . "\n";
960 return $out . $this->didYouMeanHtml
;
964 * Make a search link with some target namespaces
966 * @param $term String
967 * @param $namespaces Array
968 * @param $label String: link's text
969 * @param $tooltip String: link's tooltip
970 * @param $params Array: query string parameters
971 * @return String: HTML fragment
973 protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
975 foreach( $namespaces as $n ) {
978 $opt['redirs'] = $this->searchRedirects ?
1 : 0;
980 $st = SpecialPage
::getTitleFor( 'Search' );
981 $stParams = array_merge(
984 'fulltext' => wfMsg( 'search' )
992 'href' => $st->getLocalURL( $stParams ),
994 'onmousedown' => 'mwSearchHeaderClick(this);',
995 'onkeydown' => 'mwSearchHeaderClick(this);'),
1001 * Check if query starts with image: prefix
1003 * @param $term String: the string to check
1006 protected function startsWithImage( $term ) {
1009 $p = explode( ':', $term );
1010 if( count( $p ) > 1 ) {
1011 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
1017 * Check if query starts with all: prefix
1019 * @param $term String: the string to check
1022 protected function startsWithAll( $term ) {
1024 $allkeyword = wfMsgForContent('searchall');
1026 $p = explode( ':', $term );
1027 if( count( $p ) > 1 ) {
1028 return $p[0] == $allkeyword;