Scripts and data used for generating ZhConversion.php
[lhc/web/wiklou.git] / includes / SearchEngine.php
index 2b8d29f..28424e2 100644 (file)
@@ -2,6 +2,7 @@
 /**
  * Contain site class
  * See search.doc
+ * @package MediaWiki
  */
 
 /**
@@ -12,6 +13,7 @@ define( 'MW_SEARCH_BAD_QUERY', false );
 
 /**
  * @todo document
+ * @package MediaWiki
  */
 class SearchEngine {
        /* private */ var $rawText, $filteredText, $searchTerms;
@@ -81,7 +83,7 @@ class SearchEngine {
         * 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;
@@ -96,7 +98,7 @@ class SearchEngine {
                }
                
                # Do namespace checkboxes
-               $namespaces = $wgLang->getNamespaces();
+               $namespaces = $wgContLang->getNamespaces();
                foreach ( $namespaces as $i => $namespace ) {
                        # Skip virtual namespaces
                        if ( $i < 0 ) {
@@ -248,6 +250,9 @@ class SearchEngine {
 
        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();
@@ -258,7 +263,7 @@ class SearchEngine {
        }
        
        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' );
@@ -270,7 +275,7 @@ class SearchEngine {
 
                $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 );
@@ -301,7 +306,7 @@ class SearchEngine {
        }
        
        function parseQuery4() {
-               global $wgLang;
+               global $wgContLang;
                $lc = SearchEngine::legalSearchChars();
                $searchon = '';
                $this->searchTerms = array();
@@ -314,8 +319,8 @@ class SearchEngine {
                                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 {
@@ -377,7 +382,7 @@ class SearchEngine {
        }
 
        function showHit( $row ) {
-               global $wgUser, $wgOut, $wgLang;
+               global $wgUser, $wgOut, $wgContLang;
 
                $t = Title::makeName( $row->cur_namespace, $row->cur_title );
                if( is_null( $t ) ) {
@@ -409,12 +414,12 @@ class SearchEngine {
                                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];
@@ -502,7 +507,7 @@ class SearchEngine {
                } 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;
@@ -522,7 +527,7 @@ class SearchEngine {
         * @static
         */
        function doFuzzyTitleSearch( $search, $namespace ){
-               global $wgLang, $wgOut;
+               global $wgContLang, $wgOut;
                
                $this->setupPage();
                
@@ -534,9 +539,9 @@ class SearchEngine {
                $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 ) . '%';
@@ -545,7 +550,7 @@ class SearchEngine {
                }
                if( $wikitext ){
                        if( $namespace != NS_MAIN )
-                               $wikitext = '=== ' . $wgLang->getNsText( $namespace ) . " ===\n" . $wikitext;
+                               $wikitext = '=== ' . $wgContLang->getNsText( $namespace ) . " ===\n" . $wikitext;
                        $wgOut->addWikiText( $wikitext );
                        return true;
                }