merge r16576 from SerbianVariants branch; should fix 'go' variant search on non-defau...
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 20 Sep 2006 14:38:32 +0000 (14:38 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 20 Sep 2006 14:38:32 +0000 (14:38 +0000)
includes/SearchEngine.php
includes/SpecialSearch.php

index 6af1e41..5e59888 100644 (file)
@@ -50,62 +50,72 @@ class SearchEngine {
         * @return Title
         * @private
         */
-       function getNearMatch( $term ) {
+       function getNearMatch( $searchterm ) {
                global $wgContLang;
-               # Exact match? No need to look further.
-               $title = Title::newFromText( $term );
-               if (is_null($title))
-                       return NULL;
 
-               if ( $title->getNamespace() == NS_SPECIAL || $title->exists() ) {
-                       return $title;
-               }
+               $allSearchTerms = array($searchterm);
 
-               # Now try all lower case (i.e. first letter capitalized)
-               #
-               $title = Title::newFromText( $wgContLang->lc( $term ) );
-               if ( $title->exists() ) {
-                       return $title;
+               if($wgContLang->hasVariants()){
+                       $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm));
                }
 
-               # Now try capitalized string
-               #
-               $title = Title::newFromText( $wgContLang->ucwords( $term ) );
-               if ( $title->exists() ) {
-                       return $title;
-               }
+               foreach($allSearchTerms as $term){
 
-               # Now try all upper case
-               #
-               $title = Title::newFromText( $wgContLang->uc( $term ) );
-               if ( $title->exists() ) {
-                       return $title;
-               }
+                       # Exact match? No need to look further.
+                       $title = Title::newFromText( $term );
+                       if (is_null($title))
+                               return NULL;
 
-               # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
-               $title = Title::newFromText( $wgContLang->ucwordbreaks($term) );
-               if ( $title->exists() ) {
-                       return $title;
-               }
+                       if ( $title->getNamespace() == NS_SPECIAL || $title->exists() ) {
+                               return $title;
+                       }
 
-               global $wgCapitalLinks, $wgContLang;
-               if( !$wgCapitalLinks ) {
-                       // Catch differs-by-first-letter-case-only
-                       $title = Title::newFromText( $wgContLang->ucfirst( $term ) );
+                       # Now try all lower case (i.e. first letter capitalized)
+                       #
+                       $title = Title::newFromText( $wgContLang->lc( $term ) );
                        if ( $title->exists() ) {
                                return $title;
                        }
-                       $title = Title::newFromText( $wgContLang->lcfirst( $term ) );
+
+                       # Now try capitalized string
+                       #
+                       $title = Title::newFromText( $wgContLang->ucwords( $term ) );
+                       if ( $title->exists() ) {
+                               return $title;
+                       }
+
+                       # Now try all upper case
+                       #
+                       $title = Title::newFromText( $wgContLang->uc( $term ) );
                        if ( $title->exists() ) {
                                return $title;
                        }
+
+                       # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
+                       $title = Title::newFromText( $wgContLang->ucwordbreaks($term) );
+                       if ( $title->exists() ) {
+                               return $title;
+                       }
+
+                       global $wgCapitalLinks, $wgContLang;
+                       if( !$wgCapitalLinks ) {
+                               // Catch differs-by-first-letter-case-only
+                               $title = Title::newFromText( $wgContLang->ucfirst( $term ) );
+                               if ( $title->exists() ) {
+                                       return $title;
+                               }
+                               $title = Title::newFromText( $wgContLang->lcfirst( $term ) );
+                               if ( $title->exists() ) {
+                                       return $title;
+                               }
+                       }
                }
 
-               $title = Title::newFromText( $term );
+               $title = Title::newFromText( $searchterm );
 
                # Entering an IP address goes to the contributions page
                if ( ( $title->getNamespace() == NS_USER && User::isIP($title->getText() ) )
-                       || User::isIP( trim( $term ) ) ) {
+                       || User::isIP( trim( $searchterm ) ) ) {
                        return Title::makeTitle( NS_SPECIAL, "Contributions/" . $title->getDbkey() );
                }
 
@@ -116,7 +126,7 @@ class SearchEngine {
                }
 
                # Quoted term? Try without the quotes...
-               if( preg_match( '/^"([^"]+)"$/', $term, $matches ) ) {
+               if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) {
                        return SearchEngine::getNearMatch( $matches[1] );
                }
 
index a479182..057b487 100644 (file)
@@ -97,19 +97,6 @@ class SpecialSearch {
                        return;
                }
 
-               # if language supports variants, search in all variants
-               if($wgContLang->hasVariants()){
-                       $allTermVariants = $wgContLang->convertLinkToAllVariants($term);
-
-                       foreach($allTermVariants as $termVariant){
-                               $t = SearchEngine::getNearMatch( $termVariant );
-                               if( !is_null( $t ) ) {
-                                       $wgOut->redirect( $t->getFullURL() );
-                                       return;
-                               }
-                       }
-               }
-
                # No match, generate an edit URL
                $t = Title::newFromText( $term );
                if( is_null( $t ) ) {