Index: trunk/extensions/WikimediaIncubator/SpecialSearchWiki.php |
— | — | @@ -77,18 +77,19 @@ |
78 | 78 | |
79 | 79 | $lcLanguageQuery = strtolower( $languageQuery ); |
80 | 80 | # The more important, the more below, because they override earlier codes |
81 | | - $validCodes = array_keys( Language::getLanguageNames() ); |
| 81 | + $validCodes = array_keys( Language::getTranslatedLanguageNames( 'en' ) ); |
82 | 82 | if( in_array( $lcLanguageQuery, $validCodes ) ) { |
83 | 83 | $builtinCode = Language::factory( $lcLanguageQuery )->getCode(); |
84 | 84 | $results[$builtinCode] = 'langcode'; # Match language code |
85 | 85 | } |
86 | | - if( $codeByEnglishName = array_search( $lcLanguageQuery, array_map( 'strtolower', $this->mEnglishNames ) ) ) { |
| 86 | + $lcLanguageQuery = self::strip( $languageQuery ); |
| 87 | + if( $codeByEnglishName = array_search( $lcLanguageQuery, array_map( 'self::strip', $this->mEnglishNames ) ) ) { |
87 | 88 | $results[$codeByEnglishName] = 'englishname'; # Match name in English |
88 | 89 | } |
89 | | - if( $codeUserLang = array_search( $lcLanguageQuery, array_map( 'strtolower', $this->mNamesUserLang ) ) ) { |
| 90 | + if( $codeUserLang = array_search( $lcLanguageQuery, array_map( 'self::strip', $this->mNamesUserLang ) ) ) { |
90 | 91 | $results[$codeUserLang] = 'userlangname'; # Match name in user language |
91 | 92 | } |
92 | | - if( $codeByNativeName = array_search( $lcLanguageQuery, array_map( 'strtolower', $this->mNativeNames ) ) ) { |
| 93 | + if( $codeByNativeName = array_search( $lcLanguageQuery, array_map( 'self::strip', $this->mNativeNames ) ) ) { |
93 | 94 | $results[$codeByNativeName] = 'nativename'; # Match native name |
94 | 95 | } |
95 | 96 | |
— | — | @@ -103,6 +104,15 @@ |
104 | 105 | } |
105 | 106 | |
106 | 107 | /** |
| 108 | + * Improve search by increasing the chance of matches |
| 109 | + */ |
| 110 | + protected function strip( $str ) { |
| 111 | + $str = strtolower( trim( $str ) ); |
| 112 | + $replace = array( ' ' => '', '-' => '' ); |
| 113 | + return str_replace( array_keys( $replace ), array_values( $replace ), $str ); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
107 | 117 | * Go directly to the wiki if it exists, else to the Incubator test wiki |
108 | 118 | * @param $project String: project code |
109 | 119 | * @param $lang String: Language code |