summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialSearch.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/specials/SpecialSearch.php')
-rw-r--r--includes/specials/SpecialSearch.php299
1 files changed, 178 insertions, 121 deletions
diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php
index 5f5b6b4d..8609c740 100644
--- a/includes/specials/SpecialSearch.php
+++ b/includes/specials/SpecialSearch.php
@@ -42,6 +42,9 @@ class SpecialSearch extends SpecialPage {
/// Search engine
protected $searchEngine;
+ /// Search engine type, if not default
+ protected $searchEngineType;
+
/// For links
protected $extraParams = array();
@@ -78,7 +81,7 @@ class SpecialSearch extends SpecialPage {
/**
* Entry point
*
- * @param $par String or null
+ * @param string $par or null
*/
public function execute( $par ) {
$this->setHeaders();
@@ -98,6 +101,8 @@ class SpecialSearch extends SpecialPage {
$this->load();
+ $this->searchEngineType = $request->getVal( 'srbackend' );
+
if ( $request->getVal( 'fulltext' )
|| !is_null( $request->getVal( 'offset' ) )
|| !is_null( $request->getVal( 'searchx' ) ) )
@@ -137,8 +142,8 @@ class SpecialSearch extends SpecialPage {
if ( $profile === null ) {
// BC with old request format
$profile = 'advanced';
- foreach( $profiles as $key => $data ) {
- if ( $nslist === $data['namespaces'] && $key !== 'advanced') {
+ foreach ( $profiles as $key => $data ) {
+ if ( $nslist === $data['namespaces'] && $key !== 'advanced' ) {
$profile = $key;
}
}
@@ -159,7 +164,7 @@ class SpecialSearch extends SpecialPage {
$default = $request->getBool( 'profile' ) ? 0 : 1;
$this->searchRedirects = $request->getBool( 'redirs', $default ) ? 1 : 0;
$this->didYouMeanHtml = ''; # html of did you mean... link
- $this->fulltext = $request->getVal('fulltext');
+ $this->fulltext = $request->getVal( 'fulltext' );
$this->profile = $profile;
}
@@ -173,7 +178,7 @@ class SpecialSearch extends SpecialPage {
# Try to go to page as entered.
$t = Title::newFromText( $term );
# If the string cannot be used to create a title
- if( is_null( $t ) ) {
+ if ( is_null( $t ) ) {
$this->showResults( $term );
return;
}
@@ -185,19 +190,19 @@ class SpecialSearch extends SpecialPage {
return;
}
- if( !is_null( $t ) ) {
+ if ( !is_null( $t ) ) {
$this->getOutput()->redirect( $t->getFullURL() );
return;
}
# No match, generate an edit URL
$t = Title::newFromText( $term );
- if( !is_null( $t ) ) {
+ if ( !is_null( $t ) ) {
global $wgGoToEdit;
wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
wfDebugLog( 'nogomatch', $t->getText(), false );
# If the feature is enabled, go straight to the edit page
- if( $wgGoToEdit ) {
+ if ( $wgGoToEdit ) {
$this->getOutput()->redirect( $t->getFullURL( array( 'action' => 'edit' ) ) );
return;
}
@@ -218,7 +223,7 @@ class SpecialSearch extends SpecialPage {
$search->showRedirects = $this->searchRedirects; // BC
$search->setFeatureData( 'list-redirects', $this->searchRedirects );
$search->prefix = $this->mPrefix;
- $term = $search->transformSearchTerm($term);
+ $term = $search->transformSearchTerm( $term );
wfRunHooks( 'SpecialSearchSetupEngine', array( $this, $this->profile, $search ) );
@@ -250,21 +255,27 @@ class SpecialSearch extends SpecialPage {
$t = Title::newFromText( $term );
// fetch search results
- $rewritten = $search->replacePrefixes($term);
+ $rewritten = $search->replacePrefixes( $term );
$titleMatches = $search->searchTitle( $rewritten );
- if( !( $titleMatches instanceof SearchResultTooMany ) ) {
+ if ( !( $titleMatches instanceof SearchResultTooMany ) ) {
$textMatches = $search->searchText( $rewritten );
}
+ $textStatus = null;
+ if ( $textMatches instanceof Status ) {
+ $textStatus = $textMatches;
+ $textMatches = null;
+ }
+
// did you mean... suggestions
- if( $textMatches && $textMatches->hasSuggestion() ) {
+ if ( $textMatches && !$textStatus && $textMatches->hasSuggestion() ) {
$st = SpecialPage::getTitleFor( 'Search' );
- # mirror Go/Search behaviour of original request ..
+ # mirror Go/Search behavior of original request ..
$didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() );
- if( $this->fulltext != null ) {
+ if ( $this->fulltext != null ) {
$didYouMeanParams['fulltext'] = $this->fulltext;
}
@@ -275,7 +286,7 @@ class SpecialSearch extends SpecialPage {
$suggestionSnippet = $textMatches->getSuggestionSnippet();
- if( $suggestionSnippet == '' ) {
+ if ( $suggestionSnippet == '' ) {
$suggestionSnippet = null;
}
@@ -288,6 +299,13 @@ class SpecialSearch extends SpecialPage {
$this->didYouMeanHtml = '<div class="searchdidyoumean">' . $this->msg( 'search-suggest' )->rawParams( $suggestLink )->text() . '</div>';
}
+
+ if ( !wfRunHooks( 'SpecialSearchResultsPrepend', array( $this, $out, $term ) ) ) {
+ # Hook requested termination
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
// start rendering the page
$out->addHtml(
Xml::openElement(
@@ -304,20 +322,20 @@ class SpecialSearch extends SpecialPage {
Xml::openElement( 'tr' ) .
Xml::openElement( 'td' ) . "\n" .
$this->shortDialog( $term ) .
- Xml::closeElement('td') .
- Xml::closeElement('tr') .
- Xml::closeElement('table')
+ Xml::closeElement( 'td' ) .
+ Xml::closeElement( 'tr' ) .
+ Xml::closeElement( 'table' )
);
// Sometimes the search engine knows there are too many hits
- if( $titleMatches instanceof SearchResultTooMany ) {
+ if ( $titleMatches instanceof SearchResultTooMany ) {
$out->wrapWikiMsg( "==$1==\n", 'toomanymatches' );
wfProfileOut( __METHOD__ );
return;
}
- $filePrefix = $wgContLang->getFormattedNsText(NS_FILE).':';
- if( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
+ $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
+ if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
$out->addHTML( $this->formHeader( $term, 0, 0 ) );
$out->addHtml( $this->getProfileForm( $this->profile, $term ) );
$out->addHTML( '</form>' );
@@ -340,21 +358,22 @@ class SpecialSearch extends SpecialPage {
// get total number of results if backend can calculate it
$totalRes = 0;
- if($titleMatches && !is_null( $titleMatches->getTotalHits() ) )
+ if ( $titleMatches && !is_null( $titleMatches->getTotalHits() ) ) {
$totalRes += $titleMatches->getTotalHits();
- if($textMatches && !is_null( $textMatches->getTotalHits() ))
+ }
+ if ( $textMatches && !is_null( $textMatches->getTotalHits() ) ) {
$totalRes += $textMatches->getTotalHits();
+ }
// show number of results and current offset
$out->addHTML( $this->formHeader( $term, $num, $totalRes ) );
$out->addHtml( $this->getProfileForm( $this->profile, $term ) );
-
$out->addHtml( Xml::closeElement( 'form' ) );
$out->addHtml( "<div class='searchresults'>" );
// prev/next links
- if( $num || $this->offset ) {
+ if ( $num || $this->offset ) {
// Show the create link ahead
$this->showCreateLink( $t );
$prevnext = $this->getLanguage()->viewPrevNext( $this->getTitle(), $this->offset, $this->limit,
@@ -368,42 +387,49 @@ class SpecialSearch extends SpecialPage {
}
$out->parserOptions()->setEditSection( false );
- if( $titleMatches ) {
- if( $numTitleMatches > 0 ) {
+ if ( $titleMatches ) {
+ if ( $numTitleMatches > 0 ) {
$out->wrapWikiMsg( "==$1==\n", 'titlematches' );
$out->addHTML( $this->showMatches( $titleMatches ) );
}
$titleMatches->free();
}
- if( $textMatches ) {
+ if ( $textMatches && !$textStatus ) {
// output appropriate heading
- if( $numTextMatches > 0 && $numTitleMatches > 0 ) {
+ if ( $numTextMatches > 0 && $numTitleMatches > 0 ) {
// if no title matches the heading is redundant
$out->wrapWikiMsg( "==$1==\n", 'textmatches' );
- } elseif( $totalRes == 0 ) {
+ } elseif ( $totalRes == 0 ) {
# Don't show the 'no text matches' if we received title matches
# $out->wrapWikiMsg( "==$1==\n", 'notextmatches' );
}
// show interwiki results if any
- if( $textMatches->hasInterwikiResults() ) {
+ if ( $textMatches->hasInterwikiResults() ) {
$out->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
}
// show results
- if( $numTextMatches > 0 ) {
+ if ( $numTextMatches > 0 ) {
$out->addHTML( $this->showMatches( $textMatches ) );
}
$textMatches->free();
}
- if( $num === 0 ) {
- $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>", array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
- $this->showCreateLink( $t );
+ if ( $num === 0 ) {
+ if ( $textStatus ) {
+ $out->addHTML( '<div class="error">' .
+ htmlspecialchars( $textStatus->getWikiText( 'search-error' ) ) . '</div>' );
+ } else {
+ $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>",
+ array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
+ $this->showCreateLink( $t );
+ }
}
$out->addHtml( "</div>" );
- if( $num || $this->offset ) {
+ if ( $num || $this->offset ) {
$out->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
}
+ wfRunHooks( 'SpecialSearchResultsAppend', array( $this, $out, $term ) );
wfProfileOut( __METHOD__ );
}
@@ -414,16 +440,16 @@ class SpecialSearch extends SpecialPage {
// show direct page/create link if applicable
// Check DBkey !== '' in case of fragment link only.
- if( is_null( $t ) || $t->getDBkey() === '' ) {
+ if ( is_null( $t ) || $t->getDBkey() === '' ) {
// invalid title
// preserve the paragraph for margins etc...
$this->getOutput()->addHtml( '<p></p>' );
return;
}
- if( $t->isKnown() ) {
+ if ( $t->isKnown() ) {
$messageName = 'searchmenu-exists';
- } elseif( $t->userCan( 'create' ) ) {
+ } elseif ( $t->userCan( 'create', $this->getUser() ) ) {
$messageName = 'searchmenu-new';
} else {
$messageName = 'searchmenu-new-nocreate';
@@ -432,7 +458,7 @@ class SpecialSearch extends SpecialPage {
wfRunHooks( 'SpecialSearchCreateLink', array( $t, &$params ) );
// Extensions using the hook might still return an empty $messageName
- if( $messageName ) {
+ if ( $messageName ) {
$this->getOutput()->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", $params );
} else {
// preserve the paragraph for margins etc...
@@ -445,11 +471,13 @@ class SpecialSearch extends SpecialPage {
*/
protected function setupPage( $term ) {
# Should advanced UI be used?
- $this->searchAdvanced = ($this->profile === 'advanced');
+ $this->searchAdvanced = ( $this->profile === 'advanced' );
$out = $this->getOutput();
- if( strval( $term ) !== '' ) {
+ if ( strval( $term ) !== '' ) {
$out->setPageTitle( $this->msg( 'searchresults' ) );
- $out->setHTMLTitle( $this->msg( 'pagetitle', $this->msg( 'searchresults-title', $term )->plain() ) );
+ $out->setHTMLTitle( $this->msg( 'pagetitle' )->rawParams(
+ $this->msg( 'searchresults-title' )->rawParams( $term )->text()
+ ) );
}
// add javascript specific to special:search
$out->addModules( 'mediawiki.special.search' );
@@ -464,8 +492,8 @@ class SpecialSearch extends SpecialPage {
*/
protected function powerSearch( &$request ) {
$arr = array();
- foreach( SearchEngine::searchableNamespaces() as $ns => $name ) {
- if( $request->getCheck( 'ns' . $ns ) ) {
+ foreach ( SearchEngine::searchableNamespaces() as $ns => $name ) {
+ if ( $request->getCheck( 'ns' . $ns ) ) {
$arr[] = $ns;
}
}
@@ -481,10 +509,10 @@ class SpecialSearch extends SpecialPage {
protected function powerSearchOptions() {
$opt = array();
$opt['redirs'] = $this->searchRedirects ? 1 : 0;
- if( $this->profile !== 'advanced' ) {
+ if ( $this->profile !== 'advanced' ) {
$opt['profile'] = $this->profile;
} else {
- foreach( $this->namespaces as $n ) {
+ foreach ( $this->namespaces as $n ) {
$opt['ns' . $n] = 1;
}
}
@@ -506,12 +534,12 @@ class SpecialSearch extends SpecialPage {
$out = "";
$infoLine = $matches->getInfo();
- if( !is_null($infoLine) ) {
+ if ( !is_null( $infoLine ) ) {
$out .= "\n<!-- {$infoLine} -->\n";
}
$out .= "<ul class='mw-search-results'>\n";
$result = $matches->next();
- while( $result ) {
+ while ( $result ) {
$out .= $this->showHit( $result, $terms );
$result = $matches->next();
}
@@ -527,24 +555,25 @@ class SpecialSearch extends SpecialPage {
* Format a single hit result
*
* @param $result SearchResult
- * @param $terms Array: terms to highlight
+ * @param array $terms terms to highlight
*
* @return string
*/
protected function showHit( $result, $terms ) {
wfProfileIn( __METHOD__ );
- if( $result->isBrokenTitle() ) {
+ if ( $result->isBrokenTitle() ) {
wfProfileOut( __METHOD__ );
return "<!-- Broken link in search result -->\n";
}
$t = $result->getTitle();
- $titleSnippet = $result->getTitleSnippet($terms);
+ $titleSnippet = $result->getTitleSnippet( $terms );
- if( $titleSnippet == '' )
+ if ( $titleSnippet == '' ) {
$titleSnippet = null;
+ }
$link_t = clone $t;
@@ -559,7 +588,7 @@ class SpecialSearch extends SpecialPage {
//If page content is not readable, just return the title.
//This is not quite safe, but better than showing excerpts from non-readable pages
//Note that hiding the entry entirely would screw up paging.
- if( !$t->userCan( 'read' ) ) {
+ if ( !$t->userCan( 'read', $this->getUser() ) ) {
wfProfileOut( __METHOD__ );
return "<li>{$link}</li>\n";
}
@@ -567,21 +596,22 @@ class SpecialSearch extends SpecialPage {
// If the page doesn't *exist*... our search index is out of date.
// The least confusing at this point is to drop the result.
// You may get less results, but... oh well. :P
- if( $result->isMissingRevision() ) {
+ if ( $result->isMissingRevision() ) {
wfProfileOut( __METHOD__ );
return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
}
// format redirects / relevant sections
$redirectTitle = $result->getRedirectTitle();
- $redirectText = $result->getRedirectSnippet($terms);
+ $redirectText = $result->getRedirectSnippet( $terms );
$sectionTitle = $result->getSectionTitle();
- $sectionText = $result->getSectionSnippet($terms);
+ $sectionText = $result->getSectionSnippet( $terms );
$redirect = '';
- if( !is_null($redirectTitle) ) {
- if( $redirectText == '' )
+ if ( !is_null( $redirectTitle ) ) {
+ if ( $redirectText == '' ) {
$redirectText = null;
+ }
$redirect = "<span class='searchalttitle'>" .
$this->msg( 'search-redirect' )->rawParams(
@@ -591,9 +621,10 @@ class SpecialSearch extends SpecialPage {
$section = '';
- if( !is_null($sectionTitle) ) {
- if( $sectionText == '' )
+ if ( !is_null( $sectionTitle ) ) {
+ if ( $sectionText == '' ) {
$sectionText = null;
+ }
$section = "<span class='searchalttitle'>" .
$this->msg( 'search-section' )->rawParams(
@@ -602,12 +633,12 @@ class SpecialSearch extends SpecialPage {
}
// format text extract
- $extract = "<div class='searchresult'>".$result->getTextSnippet($terms)."</div>";
+ $extract = "<div class='searchresult'>" . $result->getTextSnippet( $terms ) . "</div>";
$lang = $this->getLanguage();
// format score
- if( is_null( $result->getScore() ) ) {
+ if ( is_null( $result->getScore() ) ) {
// Search engine doesn't report scoring info
$score = '';
} else {
@@ -623,7 +654,7 @@ class SpecialSearch extends SpecialPage {
$size = $this->msg( 'search-result-size', $lang->formatSize( $byteSize ) )
->numParams( $wordCount )->escaped();
- if( $t->getNamespace() == NS_CATEGORY ) {
+ if ( $t->getNamespace() == NS_CATEGORY ) {
$cat = Category::newFromTitle( $t );
$size = $this->msg( 'search-result-category-size' )
->numParams( $cat->getPageCount(), $cat->getSubcatCount(), $cat->getFileCount() )
@@ -634,7 +665,7 @@ class SpecialSearch extends SpecialPage {
// link to related articles if supported
$related = '';
- if( $result->hasRelated() ) {
+ if ( $result->hasRelated() ) {
$st = SpecialPage::getTitleFor( 'Search' );
$stParams = array_merge(
$this->powerSearchOptions(),
@@ -654,11 +685,11 @@ class SpecialSearch extends SpecialPage {
}
// Include a thumbnail for media files...
- if( $t->getNamespace() == NS_FILE ) {
+ if ( $t->getNamespace() == NS_FILE ) {
$img = wfFindFile( $t );
- if( $img ) {
+ if ( $img ) {
$thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
- if( $thumb ) {
+ if ( $thumb ) {
$desc = $this->msg( 'parentheses' )->rawParams( $img->getShortDesc() )->escaped();
wfProfileOut( __METHOD__ );
// Float doesn't seem to interact well with the bullets.
@@ -667,7 +698,7 @@ class SpecialSearch extends SpecialPage {
return "<li>" .
'<table class="searchResultImage">' .
'<tr>' .
- '<td width="120" style="text-align: center; vertical-align: top;">' .
+ '<td style="width: 120px; text-align: center; vertical-align: top;">' .
$thumb->toHtml( array( 'desc-link' => true ) ) .
'</td>' .
'<td style="vertical-align: top;">' .
@@ -682,11 +713,21 @@ class SpecialSearch extends SpecialPage {
}
}
- wfProfileOut( __METHOD__ );
- return "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
- "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
- "</li>\n";
+ $html = null;
+
+ if ( wfRunHooks( 'ShowSearchHit', array(
+ $this, $result, $terms,
+ &$link, &$redirect, &$section, &$extract,
+ &$score, &$size, &$date, &$related,
+ &$html
+ ) ) ) {
+ $html = "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
+ "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
+ "</li>\n";
+ }
+ wfProfileOut( __METHOD__ );
+ return $html;
}
/**
@@ -702,22 +743,23 @@ class SpecialSearch extends SpecialPage {
wfProfileIn( __METHOD__ );
$terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
- $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
- $this->msg( 'search-interwiki-caption' )->text() . "</div>\n";
+ $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>" .
+ $this->msg( 'search-interwiki-caption' )->text() . "</div>\n";
$out .= "<ul class='mw-search-iwresults'>\n";
// work out custom project captions
$customCaptions = array();
$customLines = explode( "\n", $this->msg( 'search-interwiki-custom' )->text() ); // format per line <iwprefix>:<caption>
- foreach($customLines as $line) {
- $parts = explode(":",$line,2);
- if(count($parts) == 2) // validate line
+ foreach ( $customLines as $line ) {
+ $parts = explode( ":", $line, 2 );
+ if ( count( $parts ) == 2 ) { // validate line
$customCaptions[$parts[0]] = $parts[1];
+ }
}
$prev = null;
$result = $matches->next();
- while( $result ) {
+ while ( $result ) {
$out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
$prev = $result->getInterwikiPrefix();
$result = $matches->next();
@@ -738,24 +780,25 @@ class SpecialSearch extends SpecialPage {
* @param $lastInterwiki String
* @param $terms Array
* @param $query String
- * @param $customCaptions Array: iw prefix -> caption
+ * @param array $customCaptions iw prefix -> caption
*
* @return string
*/
- protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
+ protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions ) {
wfProfileIn( __METHOD__ );
- if( $result->isBrokenTitle() ) {
+ if ( $result->isBrokenTitle() ) {
wfProfileOut( __METHOD__ );
return "<!-- Broken link in search result -->\n";
}
$t = $result->getTitle();
- $titleSnippet = $result->getTitleSnippet($terms);
+ $titleSnippet = $result->getTitleSnippet( $terms );
- if( $titleSnippet == '' )
+ if ( $titleSnippet == '' ) {
$titleSnippet = null;
+ }
$link = Linker::linkKnown(
$t,
@@ -764,11 +807,12 @@ class SpecialSearch extends SpecialPage {
// format redirect if any
$redirectTitle = $result->getRedirectTitle();
- $redirectText = $result->getRedirectSnippet($terms);
+ $redirectText = $result->getRedirectSnippet( $terms );
$redirect = '';
- if( !is_null($redirectTitle) ) {
- if( $redirectText == '' )
+ if ( !is_null( $redirectTitle ) ) {
+ if ( $redirectText == '' ) {
$redirectText = null;
+ }
$redirect = "<span class='searchalttitle'>" .
$this->msg( 'search-redirect' )->rawParams(
@@ -778,8 +822,8 @@ class SpecialSearch extends SpecialPage {
$out = "";
// display project name
- if(is_null($lastInterwiki) || $lastInterwiki != $t->getInterwiki()) {
- if( array_key_exists($t->getInterwiki(),$customCaptions) ) {
+ if ( is_null( $lastInterwiki ) || $lastInterwiki != $t->getInterwiki() ) {
+ if ( array_key_exists( $t->getInterwiki(), $customCaptions ) ) {
// captions from 'search-interwiki-custom'
$caption = $customCaptions[$t->getInterwiki()];
} else {
@@ -789,7 +833,7 @@ class SpecialSearch extends SpecialPage {
$caption = $this->msg( 'search-interwiki-default', $parsed['host'] )->text();
}
// "more results" link (special page stuff could be localized, but we might not know target lang)
- $searchTitle = Title::newFromText($t->getInterwiki().":Special:Search");
+ $searchTitle = Title::newFromText( $t->getInterwiki() . ":Special:Search" );
$searchLink = Linker::linkKnown(
$searchTitle,
$this->msg( 'search-interwiki-more' )->text(),
@@ -831,22 +875,26 @@ class SpecialSearch extends SpecialPage {
/**
* Generates the power search box at [[Special:Search]]
*
- * @param $term String: search term
+ * @param string $term search term
* @param $opts array
* @return String: HTML form
*/
protected function powerSearchBox( $term, $opts ) {
+ global $wgContLang;
+
// Groups namespaces into rows according to subject
$rows = array();
- foreach( SearchEngine::searchableNamespaces() as $namespace => $name ) {
+ foreach ( SearchEngine::searchableNamespaces() as $namespace => $name ) {
$subject = MWNamespace::getSubject( $namespace );
- if( !array_key_exists( $subject, $rows ) ) {
+ if ( !array_key_exists( $subject, $rows ) ) {
$rows[$subject] = "";
}
- $name = str_replace( '_', ' ', $name );
- if( $name == '' ) {
+
+ $name = $wgContLang->getConverter()->convertNamespace( $namespace );
+ if ( $name == '' ) {
$name = $this->msg( 'blanknamespace' )->text();
}
+
$rows[$subject] .=
Xml::openElement(
'td', array( 'style' => 'white-space: nowrap' )
@@ -859,27 +907,30 @@ class SpecialSearch extends SpecialPage {
) .
Xml::closeElement( 'td' );
}
+
$rows = array_values( $rows );
$numRows = count( $rows );
// Lays out namespaces in multiple floating two-column tables so they'll
// be arranged nicely while still accommodating different screen widths
$namespaceTables = '';
- for( $i = 0; $i < $numRows; $i += 4 ) {
+ for ( $i = 0; $i < $numRows; $i += 4 ) {
$namespaceTables .= Xml::openElement(
'table',
array( 'cellpadding' => 0, 'cellspacing' => 0 )
);
- for( $j = $i; $j < $i + 4 && $j < $numRows; $j++ ) {
+
+ for ( $j = $i; $j < $i + 4 && $j < $numRows; $j++ ) {
$namespaceTables .= Xml::tags( 'tr', null, $rows[$j] );
}
+
$namespaceTables .= Xml::closeElement( 'table' );
}
$showSections = array( 'namespaceTables' => $namespaceTables );
// Show redirects check only if backend supports it
- if( $this->getSearchEngine()->supports( 'list-redirects' ) ) {
+ if ( $this->getSearchEngine()->supports( 'list-redirects' ) ) {
$showSections['redirects'] =
Xml::checkLabel( $this->msg( 'powersearch-redir' )->text(), 'redirs', 'redirs', $this->searchRedirects );
}
@@ -888,16 +939,15 @@ class SpecialSearch extends SpecialPage {
$hidden = '';
unset( $opts['redirs'] );
- foreach( $opts as $key => $value ) {
+ foreach ( $opts as $key => $value ) {
$hidden .= Html::hidden( $key, $value );
}
// Return final output
- return
- Xml::openElement(
+ return Xml::openElement(
'fieldset',
array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
) .
- Xml::element( 'legend', null, $this->msg('powersearch-legend' )->text() ) .
+ Xml::element( 'legend', null, $this->msg( 'powersearch-legend' )->text() ) .
Xml::tags( 'h4', null, $this->msg( 'powersearch-ns' )->parse() ) .
Html::element( 'div', array( 'id' => 'mw-search-togglebox' ) ) .
Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
@@ -949,8 +999,10 @@ class SpecialSearch extends SpecialPage {
wfRunHooks( 'SpecialSearchProfiles', array( &$profiles ) );
- foreach( $profiles as &$data ) {
- if ( !is_array( $data['namespaces'] ) ) continue;
+ foreach ( $profiles as &$data ) {
+ if ( !is_array( $data['namespaces'] ) ) {
+ continue;
+ }
sort( $data['namespaces'] );
}
@@ -964,10 +1016,10 @@ class SpecialSearch extends SpecialPage {
* @return string
*/
protected function formHeader( $term, $resultsShown, $totalNum ) {
- $out = Xml::openElement('div', array( 'class' => 'mw-search-formheader' ) );
+ $out = Xml::openElement( 'div', array( 'class' => 'mw-search-formheader' ) );
$bareterm = $term;
- if( $this->startsWithImage( $term ) ) {
+ if ( $this->startsWithImage( $term ) ) {
// Deletes prefixes
$bareterm = substr( $term, strpos( $term, ':' ) + 1 );
}
@@ -1001,11 +1053,11 @@ class SpecialSearch extends SpecialPage {
);
}
$out .= Xml::closeElement( 'ul' );
- $out .= Xml::closeElement('div') ;
+ $out .= Xml::closeElement( 'div' );
// Results-info
if ( $resultsShown > 0 ) {
- if ( $totalNum > 0 ){
+ if ( $totalNum > 0 ) {
$top = $this->msg( 'showingresultsheader' )
->numParams( $this->offset + 1, $this->offset + $resultsShown, $totalNum )
->params( wfEscapeWikiText( $term ) )
@@ -1026,7 +1078,7 @@ class SpecialSearch extends SpecialPage {
}
$out .= Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
- $out .= Xml::closeElement('div');
+ $out .= Xml::closeElement( 'div' );
return $out;
}
@@ -1053,15 +1105,15 @@ class SpecialSearch extends SpecialPage {
* Make a search link with some target namespaces
*
* @param $term String
- * @param $namespaces Array ignored
- * @param $label String: link's text
- * @param $tooltip String: link's tooltip
- * @param $params Array: query string parameters
+ * @param array $namespaces ignored
+ * @param string $label link's text
+ * @param string $tooltip link's tooltip
+ * @param array $params query string parameters
* @return String: HTML fragment
*/
protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params = array() ) {
$opt = $params;
- foreach( $namespaces as $n ) {
+ foreach ( $namespaces as $n ) {
$opt['ns' . $n] = 1;
}
$opt['redirs'] = $this->searchRedirects;
@@ -1078,7 +1130,8 @@ class SpecialSearch extends SpecialPage {
'a',
array(
'href' => $this->getTitle()->getLocalURL( $stParams ),
- 'title' => $tooltip),
+ 'title' => $tooltip
+ ),
$label
);
}
@@ -1086,14 +1139,14 @@ class SpecialSearch extends SpecialPage {
/**
* Check if query starts with image: prefix
*
- * @param $term String: the string to check
+ * @param string $term the string to check
* @return Boolean
*/
protected function startsWithImage( $term ) {
global $wgContLang;
$p = explode( ':', $term );
- if( count( $p ) > 1 ) {
+ if ( count( $p ) > 1 ) {
return $wgContLang->getNsIndex( $p[0] ) == NS_FILE;
}
return false;
@@ -1102,7 +1155,7 @@ class SpecialSearch extends SpecialPage {
/**
* Check if query starts with all: prefix
*
- * @param $term String: the string to check
+ * @param string $term the string to check
* @return Boolean
*/
protected function startsWithAll( $term ) {
@@ -1110,8 +1163,8 @@ class SpecialSearch extends SpecialPage {
$allkeyword = $this->msg( 'searchall' )->inContentLanguage()->text();
$p = explode( ':', $term );
- if( count( $p ) > 1 ) {
- return $p[0] == $allkeyword;
+ if ( count( $p ) > 1 ) {
+ return $p[0] == $allkeyword;
}
return false;
}
@@ -1123,7 +1176,8 @@ class SpecialSearch extends SpecialPage {
*/
public function getSearchEngine() {
if ( $this->searchEngine === null ) {
- $this->searchEngine = SearchEngine::create();
+ $this->searchEngine = $this->searchEngineType ?
+ SearchEngine::create( $this->searchEngineType ) : SearchEngine::create();
}
return $this->searchEngine;
}
@@ -1141,4 +1195,7 @@ class SpecialSearch extends SpecialPage {
$this->extraParams[$key] = $value;
}
+ protected function getGroupName() {
+ return 'pages';
+ }
}