/**
* Contain site class
* See search.doc
+ * @package MediaWiki
*/
/**
/**
* @todo document
+ * @package MediaWiki
*/
class SearchEngine {
/* private */ var $rawText, $filteredText, $searchTerms;
* that is done by showResults()
*/
function powersearch() {
- global $wgUser, $wgOut, $wgLang, $wgTitle, $wgRequest;
+ global $wgUser, $wgOut, $wgContLang, $wgTitle, $wgRequest;
$sk =& $wgUser->getSkin();
$search = $this->rawText;
}
# Do namespace checkboxes
- $namespaces = $wgLang->getNamespaces();
+ $namespaces = $wgContLang->getNamespaces();
foreach ( $namespaces as $i => $namespace ) {
# Skip virtual namespaces
if ( $i < 0 ) {
function parseQuery() {
global $wgDBmysql4;
+ if (strlen($this->filteredText) < 1)
+ return MW_SEARCH_BAD_QUERY;
+
if( $wgDBmysql4 ) {
# Use cleaner boolean search if available
return $this->parseQuery4();
}
function parseQuery3() {
- global $wgDBminWordLen, $wgLang;
+ global $wgDBminWordLen, $wgContLang;
# on non mysql4 database: get list of words we don't want to search for
require_once( 'FulltextStoplist.php' );
$last = $cond = '';
foreach ( $w as $word ) {
- $word = $wgLang->stripForSearch( $word );
+ $word = $wgContLang->stripForSearch( $word );
if ( 'and' == $word || 'or' == $word || 'not' == $word
|| '(' == $word || ')' == $word ) {
$cond .= ' ' . strtoupper( $word );
}
function parseQuery4() {
- global $wgLang;
+ global $wgContLang;
$lc = SearchEngine::legalSearchChars();
$searchon = '';
$this->searchTerms = array();
if( $this->strictMatching && ($terms[1] == '') ) {
$terms[1] = '+';
}
- $searchon .= $terms[1] . $wgLang->stripForSearch( $terms[2] );
- if( $terms[3] ) {
+ $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] );
+ if( !empty( $terms[3] ) ) {
$regexp = preg_quote( $terms[3] );
if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+";
} else {
}
function showHit( $row ) {
- global $wgUser, $wgOut, $wgLang;
+ global $wgUser, $wgOut, $wgContLang;
$t = Title::makeName( $row->cur_namespace, $row->cur_title );
if( is_null( $t ) ) {
continue;
}
- $pre = $wgLang->truncate( $m[1], -$contextchars, '...' );
+ $pre = $wgContLang->truncate( $m[1], -$contextchars, '...' );
if ( count( $m ) < 3 ) {
$post = '';
} else {
- $post = $wgLang->truncate( $m[3], $contextchars, '...' );
+ $post = $wgContLang->truncate( $m[3], $contextchars, '...' );
}
$found = $m[2];
} else {
$editurl = ''; # ??
}
- $wgOut->addHTML( '<p>' . wfMsg('nogomatch', $editurl ) . "</p>\n" );
+ $wgOut->addHTML( '<p>' . wfMsg('nogomatch', $editurl, htmlspecialchars( $search ) ) . "</p>\n" );
# Try a fuzzy title search
$anyhit = false;
* @static
*/
function doFuzzyTitleSearch( $search, $namespace ){
- global $wgLang, $wgOut;
+ global $wgContLang, $wgOut;
$this->setupPage();
$wikitext = '';
foreach($fuzzymatches as $res){
$t = str_replace('_', ' ', $res[1]);
- $tfull = $wgLang->getNsText( $namespace ) . ":$t|$t";
+ $tfull = $wgContLang->getNsText( $namespace ) . ":$t|$t";
if( $namespace == NS_MAIN )
- $tfull = "$t";
+ $tfull = $t;
$distance = $res[0];
$closeness = (strlen( $search ) - $distance) / strlen( $search );
$percent = intval( $closeness * 100 ) . '%';
}
if( $wikitext ){
if( $namespace != NS_MAIN )
- $wikitext = '=== ' . $wgLang->getNsText( $namespace ) . " ===\n" . $wikitext;
+ $wikitext = '=== ' . $wgContLang->getNsText( $namespace ) . " ===\n" . $wikitext;
$wgOut->addWikiText( $wikitext );
return true;
}