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 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 string $term
116 public function showResults( $term ) {
117 global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
118 wfProfileIn( __METHOD__
);
120 $sk = $wgUser->getSkin();
122 $this->searchEngine
= SearchEngine
::create();
123 $search =& $this->searchEngine
;
124 $search->setLimitOffset( $this->limit
, $this->offset
);
125 $search->setNamespaces( $this->namespaces
);
126 $search->showRedirects
= $this->searchRedirects
;
127 $search->prefix
= $this->mPrefix
;
128 $term = $search->transformSearchTerm($term);
130 $this->setupPage( $term );
132 if( $wgDisableTextSearch ) {
133 global $wgSearchForwardUrl;
134 if( $wgSearchForwardUrl ) {
135 $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl );
136 $wgOut->redirect( $url );
137 wfProfileOut( __METHOD__
);
140 global $wgInputEncoding;
142 Xml
::openElement( 'fieldset' ) .
143 Xml
::element( 'legend', null, wfMsg( 'search-external' ) ) .
144 Xml
::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
145 wfMsg( 'googlesearch',
146 htmlspecialchars( $term ),
147 htmlspecialchars( $wgInputEncoding ),
148 htmlspecialchars( wfMsg( 'searchbutton' ) )
150 Xml
::closeElement( 'fieldset' )
152 wfProfileOut( __METHOD__
);
156 $t = Title
::newFromText( $term );
158 // fetch search results
159 $rewritten = $search->replacePrefixes($term);
161 $titleMatches = $search->searchTitle( $rewritten );
162 if( !($titleMatches instanceof SearchResultTooMany
))
163 $textMatches = $search->searchText( $rewritten );
165 // did you mean... suggestions
166 if( $textMatches && $textMatches->hasSuggestion() ) {
167 $st = SpecialPage
::getTitleFor( 'Search' );
169 # mirror Go/Search behaviour of original request ..
170 $didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
172 if($this->fulltext
!= null)
173 $didYouMeanParams['fulltext'] = $this->fulltext
;
175 $stParams = array_merge(
177 $this->powerSearchOptions()
180 $suggestionSnippet = $textMatches->getSuggestionSnippet();
182 if( $suggestionSnippet == '' )
183 $suggestionSnippet = null;
185 $suggestLink = $sk->linkKnown(
192 $this->didYouMeanHtml
= '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
194 // start rendering the page
199 'id' => ( $this->searchAdvanced ?
'powersearch' : 'search' ),
201 'action' => $wgScript
206 Xml
::openElement( 'table', array( 'id'=>'mw-search-top-table', 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
207 Xml
::openElement( 'tr' ) .
208 Xml
::openElement( 'td' ) . "\n" .
209 $this->shortDialog( $term ) .
210 Xml
::closeElement('td') .
211 Xml
::closeElement('tr') .
212 Xml
::closeElement('table')
215 // Sometimes the search engine knows there are too many hits
216 if( $titleMatches instanceof SearchResultTooMany
) {
217 $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
218 wfProfileOut( __METHOD__
);
222 $filePrefix = $wgContLang->getFormattedNsText(NS_FILE
).':';
223 if( trim( $term ) === '' ||
$filePrefix === trim( $term ) ) {
224 $wgOut->addHTML( $this->searchFocus() );
225 $wgOut->addHTML( $this->formHeader($term, 0, 0));
226 if( $this->searchAdvanced
) {
227 $wgOut->addHTML( $this->powerSearchBox( $term ) );
229 $wgOut->addHTML( '</form>' );
230 // Empty query -- straight view of search form
231 wfProfileOut( __METHOD__
);
235 // Get number of results
236 $titleMatchesNum = $titleMatches ?
$titleMatches->numRows() : 0;
237 $textMatchesNum = $textMatches ?
$textMatches->numRows() : 0;
238 // Total initial query matches (possible false positives)
239 $num = $titleMatchesNum +
$textMatchesNum;
241 // Get total actual results (after second filtering, if any)
242 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
243 $titleMatches->getTotalHits() : $titleMatchesNum;
244 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
245 $textMatches->getTotalHits() : $textMatchesNum;
247 // get total number of results if backend can calculate it
249 if($titleMatches && !is_null( $titleMatches->getTotalHits() ) )
250 $totalRes +
= $titleMatches->getTotalHits();
251 if($textMatches && !is_null( $textMatches->getTotalHits() ))
252 $totalRes +
= $textMatches->getTotalHits();
254 // show number of results and current offset
255 $wgOut->addHTML( $this->formHeader($term, $num, $totalRes));
256 if( $this->searchAdvanced
) {
257 $wgOut->addHTML( $this->powerSearchBox( $term ) );
260 $wgOut->addHtml( Xml
::closeElement( 'form' ) );
261 $wgOut->addHtml( "<div class='searchresults'>" );
264 if( $num ||
$this->offset
) {
265 // Show the create link ahead
266 $this->showCreateLink( $t );
267 $prevnext = wfViewPrevNext( $this->offset
, $this->limit
,
268 SpecialPage
::getTitleFor( 'Search' ),
269 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
270 max( $titleMatchesNum, $textMatchesNum ) < $this->limit
272 //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
273 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
275 wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
278 if( $titleMatches ) {
279 if( $numTitleMatches > 0 ) {
280 $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
281 $wgOut->addHTML( $this->showMatches( $titleMatches ) );
283 $titleMatches->free();
286 // output appropriate heading
287 if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
288 // if no title matches the heading is redundant
289 $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
290 } elseif( $totalRes == 0 ) {
291 # Don't show the 'no text matches' if we received title matches
292 # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
294 // show interwiki results if any
295 if( $textMatches->hasInterwikiResults() ) {
296 $wgOut->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
299 if( $numTextMatches > 0 ) {
300 $wgOut->addHTML( $this->showMatches( $textMatches ) );
303 $textMatches->free();
306 $wgOut->addWikiMsg( 'search-nonefound', wfEscapeWikiText( $term ) );
307 $this->showCreateLink( $t );
309 $wgOut->addHtml( "</div>" );
311 $wgOut->addHTML( $this->searchFocus() );
314 if( $num ||
$this->offset
) {
315 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
317 wfProfileOut( __METHOD__
);
320 protected function showCreateLink( $t ) {
323 // show direct page/create link if applicable
326 if( $t->isKnown() ) {
327 $messageName = 'searchmenu-exists';
328 } elseif( $t->userCan( 'create' ) ) {
329 $messageName = 'searchmenu-new';
333 $wgOut->addWikiMsg( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) );
335 // preserve the paragraph for margins etc...
336 $wgOut->addHtml( '<p></p>' );
343 protected function setupPage( $term ) {
345 // Figure out the active search profile header
346 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
347 if( $this->searchAdvanced
)
348 $this->active
= 'advanced';
350 $profiles = $this->getSearchProfiles();
352 foreach( $profiles as $key => $data ) {
353 if ( $this->namespaces
== $data['namespaces'] && $key != 'advanced')
354 $this->active
= $key;
358 # Should advanced UI be used?
359 $this->searchAdvanced
= ($this->active
=== 'advanced');
360 if( !empty( $term ) ) {
361 $wgOut->setPageTitle( wfMsg( 'searchresults') );
362 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
364 $wgOut->setArticleRelated( false );
365 $wgOut->setRobotPolicy( 'noindex,nofollow' );
366 // add javascript specific to special:search
367 $wgOut->addScriptFile( 'search.js' );
371 * Extract "power search" namespace settings from the request object,
372 * returning a list of index numbers to search.
374 * @param WebRequest $request
377 protected function powerSearch( &$request ) {
379 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
380 if( $request->getCheck( 'ns' . $ns ) ) {
388 * 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 SearchResultSet $matches
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
434 * @param SearchResult $result
435 * @param array $terms terms to highlight
437 protected function showHit( $result, $terms ) {
438 global $wgContLang, $wgLang, $wgUser;
439 wfProfileIn( __METHOD__
);
441 if( $result->isBrokenTitle() ) {
442 wfProfileOut( __METHOD__
);
443 return "<!-- Broken link in search result -->\n";
446 $sk = $wgUser->getSkin();
447 $t = $result->getTitle();
449 $titleSnippet = $result->getTitleSnippet($terms);
451 if( $titleSnippet == '' )
452 $titleSnippet = null;
456 wfRunHooks( 'ShowSearchHitTitle',
457 array( &$link_t, &$titleSnippet, $result, $terms, $this ) );
459 $link = $this->sk
->linkKnown(
464 //If page content is not readable, just return the title.
465 //This is not quite safe, but better than showing excerpts from non-readable pages
466 //Note that hiding the entry entirely would screw up paging.
467 if( !$t->userCanRead() ) {
468 wfProfileOut( __METHOD__
);
469 return "<li>{$link}</li>\n";
472 // If the page doesn't *exist*... our search index is out of date.
473 // The least confusing at this point is to drop the result.
474 // You may get less results, but... oh well. :P
475 if( $result->isMissingRevision() ) {
476 wfProfileOut( __METHOD__
);
477 return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
480 // format redirects / relevant sections
481 $redirectTitle = $result->getRedirectTitle();
482 $redirectText = $result->getRedirectSnippet($terms);
483 $sectionTitle = $result->getSectionTitle();
484 $sectionText = $result->getSectionSnippet($terms);
487 if( !is_null($redirectTitle) ) {
488 if( $redirectText == '' )
489 $redirectText = null;
491 $redirect = "<span class='searchalttitle'>" .
494 $this->sk
->linkKnown(
505 if( !is_null($sectionTitle) ) {
506 if( $sectionText == '' )
509 $section = "<span class='searchalttitle'>" .
511 'search-section', $this->sk
->linkKnown(
519 // format text extract
520 $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
523 if( is_null( $result->getScore() ) ) {
524 // Search engine doesn't report scoring info
527 $percent = sprintf( '%2.1f', $result->getScore() * 100 );
528 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
532 // format description
533 $byteSize = $result->getByteSize();
534 $wordCount = $result->getWordCount();
535 $timestamp = $result->getTimestamp();
537 'search-result-size',
538 array( 'parsemag', 'escape' ),
539 $this->sk
->formatSize( $byteSize ),
540 $wgLang->formatNum( $wordCount )
543 if( $t->getNamespace() == NS_CATEGORY
) {
544 $cat = Category
::newFromTitle( $t );
546 'search-result-category-size',
547 array( 'parsemag', 'escape' ),
548 $wgLang->formatNum( $cat->getPageCount() ),
549 $wgLang->formatNum( $cat->getSubcatCount() ),
550 $wgLang->formatNum( $cat->getFileCount() )
554 $date = $wgLang->timeanddate( $timestamp );
556 // link to related articles if supported
558 if( $result->hasRelated() ) {
559 $st = SpecialPage
::getTitleFor( 'Search' );
560 $stParams = array_merge(
561 $this->powerSearchOptions(),
563 'search' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText(),
564 'fulltext' => wfMsg( 'search' )
568 $related = ' -- ' . $sk->linkKnown(
570 wfMsg('search-relatedarticle'),
576 // Include a thumbnail for media files...
577 if( $t->getNamespace() == NS_FILE
) {
578 $img = wfFindFile( $t );
580 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
582 $desc = $img->getShortDesc();
583 wfProfileOut( __METHOD__
);
584 // Float doesn't seem to interact well with the bullets.
585 // Table messes up vertical alignment of the bullets.
586 // Bullets are therefore disabled (didn't look great anyway).
588 '<table class="searchResultImage">' .
590 '<td width="120" align="center" valign="top">' .
591 $thumb->toHtml( array( 'desc-link' => true ) ) .
593 '<td valign="top">' .
596 "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
605 wfProfileOut( __METHOD__
);
606 return "<li>{$link} {$redirect} {$section} {$extract}\n" .
607 "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
613 * Show results from other wikis
615 * @param SearchResultSet $matches
617 protected function showInterwiki( &$matches, $query ) {
619 wfProfileIn( __METHOD__
);
620 $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
622 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
623 wfMsg('search-interwiki-caption')."</div>\n";
624 $off = $this->offset +
1;
625 $out .= "<ul class='mw-search-iwresults'>\n";
627 // work out custom project captions
628 $customCaptions = array();
629 $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
630 foreach($customLines as $line) {
631 $parts = explode(":",$line,2);
632 if(count($parts) == 2) // validate line
633 $customCaptions[$parts[0]] = $parts[1];
637 while( $result = $matches->next() ) {
638 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
639 $prev = $result->getInterwikiPrefix();
641 // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
642 $out .= "</ul></div>\n";
644 // convert the whole thing to desired language variant
645 $out = $wgContLang->convert( $out );
646 wfProfileOut( __METHOD__
);
651 * Show single interwiki link
653 * @param SearchResult $result
654 * @param string $lastInterwiki
655 * @param array $terms
656 * @param string $query
657 * @param array $customCaptions iw prefix -> caption
659 protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
660 wfProfileIn( __METHOD__
);
661 global $wgContLang, $wgLang;
663 if( $result->isBrokenTitle() ) {
664 wfProfileOut( __METHOD__
);
665 return "<!-- Broken link in search result -->\n";
668 $t = $result->getTitle();
670 $titleSnippet = $result->getTitleSnippet($terms);
672 if( $titleSnippet == '' )
673 $titleSnippet = null;
675 $link = $this->sk
->linkKnown(
680 // format redirect if any
681 $redirectTitle = $result->getRedirectTitle();
682 $redirectText = $result->getRedirectSnippet($terms);
684 if( !is_null($redirectTitle) ) {
685 if( $redirectText == '' )
686 $redirectText = null;
688 $redirect = "<span class='searchalttitle'>" .
691 $this->sk
->linkKnown(
700 // display project name
701 if(is_null($lastInterwiki) ||
$lastInterwiki != $t->getInterwiki()) {
702 if( key_exists($t->getInterwiki(),$customCaptions) )
703 // captions from 'search-interwiki-custom'
704 $caption = $customCaptions[$t->getInterwiki()];
706 // default is to show the hostname of the other wiki which might suck
707 // if there are many wikis on one hostname
708 $parsed = parse_url($t->getFullURL());
709 $caption = wfMsg('search-interwiki-default', $parsed['host']);
711 // "more results" link (special page stuff could be localized, but we might not know target lang)
712 $searchTitle = Title
::newFromText($t->getInterwiki().":Special:Search");
713 $searchLink = $this->sk
->linkKnown(
715 wfMsg('search-interwiki-more'),
719 'fulltext' => 'Search'
722 $out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
723 {$searchLink}</span>{$caption}</div>\n<ul>";
726 $out .= "<li>{$link} {$redirect}</li>\n";
727 wfProfileOut( __METHOD__
);
733 * Generates the power search box at bottom of [[Special:Search]]
734 * @param $term string: search term
735 * @return $out string: HTML form
737 protected function powerSearchBox( $term ) {
738 global $wgScript, $wgContLang;
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 Xml
::hidden( 'title', SpecialPage
::getTitleFor( 'Search' )->getPrefixedText() ) .
825 Xml
::hidden( 'advanced', $this->searchAdvanced
) .
826 Xml
::hidden( 'fulltext', 'Advanced search' ) .
827 Xml
::closeElement( 'fieldset' );
830 protected function searchFocus() {
831 $id = $this->searchAdvanced ?
'powerSearchText' : 'searchText';
832 return Html
::inlineScript(
833 "hookEvent(\"load\", function() {" .
834 "document.getElementById('$id').focus();" .
838 protected function getSearchProfiles() {
839 // Builds list of Search Types (profiles)
840 $nsAllSet = array_keys( SearchEngine
::searchableNamespaces() );
844 'message' => 'searchprofile-articles',
845 'tooltip' => 'searchprofile-articles-tooltip',
846 'namespaces' => SearchEngine
::defaultNamespaces(),
847 'namespace-messages' => SearchEngine
::namespacesAsText(
848 SearchEngine
::defaultNamespaces()
852 'message' => 'searchprofile-images',
853 'tooltip' => 'searchprofile-images-tooltip',
854 'namespaces' => array( NS_FILE
),
857 'message' => 'searchprofile-project',
858 'tooltip' => 'searchprofile-project-tooltip',
859 'namespaces' => SearchEngine
::helpNamespaces(),
860 'namespace-messages' => SearchEngine
::namespacesAsText(
861 SearchEngine
::helpNamespaces()
865 'message' => 'searchprofile-everything',
866 'tooltip' => 'searchprofile-everything-tooltip',
867 'namespaces' => $nsAllSet,
870 'message' => 'searchprofile-advanced',
871 'tooltip' => 'searchprofile-advanced-tooltip',
872 'namespaces' => $this->namespaces
,
873 'parameters' => array( 'advanced' => 1 ),
877 wfRunHooks( 'SpecialSearchProfiles', array( &$profiles ) );
879 foreach( $profiles as $key => &$data ) {
880 sort($data['namespaces']);
886 protected function formHeader( $term, $resultsShown, $totalNum ) {
887 global $wgContLang, $wgLang;
889 $out = Xml
::openElement('div', array( 'class' => 'mw-search-formheader' ) );
892 if( $this->startsWithImage( $term ) ) {
894 $bareterm = substr( $term, strpos( $term, ':' ) +
1 );
897 $profiles = $this->getSearchProfiles();
899 // Outputs XML for Search Types
900 $out .= Xml
::openElement( 'div', array( 'class' => 'search-types' ) );
901 $out .= Xml
::openElement( 'ul' );
902 foreach ( $profiles as $id => $profile ) {
903 $tooltipParam = isset( $profile['namespace-messages'] ) ?
904 $wgLang->commaList( $profile['namespace-messages'] ) : null;
908 'class' => $this->active
== $id ?
'current' : 'normal'
910 $this->makeSearchLink(
912 $profile['namespaces'],
913 wfMsg( $profile['message'] ),
914 wfMsg( $profile['tooltip'], $tooltipParam ),
915 isset( $profile['parameters'] ) ?
$profile['parameters'] : array()
919 $out .= Xml
::closeElement( 'ul' );
920 $out .= Xml
::closeElement('div') ;
923 if ( $resultsShown > 0 ) {
924 if ( $totalNum > 0 ){
925 $top = wfMsgExt( 'showingresultsheader', array( 'parseinline' ),
926 $wgLang->formatNum( $this->offset +
1 ),
927 $wgLang->formatNum( $this->offset +
$resultsShown ),
928 $wgLang->formatNum( $totalNum ),
929 wfEscapeWikiText( $term ),
930 $wgLang->formatNum( $resultsShown )
932 } elseif ( $resultsShown >= $this->limit
) {
933 $top = wfShowingResults( $this->offset
, $this->limit
);
935 $top = wfShowingResultsNum( $this->offset
, $this->limit
, $resultsShown );
937 $out .= Xml
::tags( 'div', array( 'class' => 'results-info' ),
938 Xml
::tags( 'ul', null, Xml
::tags( 'li', null, $top ) )
942 $out .= Xml
::element( 'div', array( 'style' => 'clear:both' ), '', false );
943 $out .= Xml
::closeElement('div');
945 // Adds hidden namespace fields
946 if ( !$this->searchAdvanced
) {
947 foreach( $this->namespaces
as $ns ) {
948 $out .= Xml
::hidden( "ns{$ns}", '1' );
955 protected function shortDialog( $term ) {
956 $searchTitle = SpecialPage
::getTitleFor( 'Search' );
957 $searchable = SearchEngine
::searchableNamespaces();
958 $out = Html
::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
959 // Keep redirect setting
960 $out .= Html
::hidden( "redirs", (int)$this->searchRedirects
) . "\n";
962 $out .= Html
::input( 'search', $term, 'search', array(
963 'id' => $this->searchAdvanced ?
'powerSearchText' : 'searchText',
967 $out .= Html
::hidden( 'fulltext', 'Search' ) . "\n";
968 $out .= Xml
::submitButton( wfMsg( 'searchbutton' ) ) . "\n";
969 return $out . $this->didYouMeanHtml
;
972 /** Make a search link with some target namespaces */
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);'),
1000 /** Check if query starts with image: prefix */
1001 protected function startsWithImage( $term ) {
1004 $p = explode( ':', $term );
1005 if( count( $p ) > 1 ) {
1006 return $wgContLang->getNsIndex( $p[0] ) == NS_FILE
;
1011 /** Check if query starts with all: prefix */
1012 protected function startsWithAll( $term ) {
1014 $allkeyword = wfMsgForContent('searchall');
1016 $p = explode( ':', $term );
1017 if( count( $p ) > 1 ) {
1018 return $p[0] == $allkeyword;