r111896 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111895‎ | r111896 | r111897 >
Date:22:47, 19 February 2012
Author:robin
Status:ok (Comments)
Tags:
Comment:
More language codes and more matching names (by removing whitespace and hyphens) -> better results!
Modified paths:
  • /trunk/extensions/WikimediaIncubator/SpecialSearchWiki.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikimediaIncubator/SpecialSearchWiki.php
@@ -77,18 +77,19 @@
7878
7979 $lcLanguageQuery = strtolower( $languageQuery );
8080 # The more important, the more below, because they override earlier codes
81 - $validCodes = array_keys( Language::getLanguageNames() );
 81+ $validCodes = array_keys( Language::getTranslatedLanguageNames( 'en' ) );
8282 if( in_array( $lcLanguageQuery, $validCodes ) ) {
8383 $builtinCode = Language::factory( $lcLanguageQuery )->getCode();
8484 $results[$builtinCode] = 'langcode'; # Match language code
8585 }
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 ) ) ) {
8788 $results[$codeByEnglishName] = 'englishname'; # Match name in English
8889 }
89 - if( $codeUserLang = array_search( $lcLanguageQuery, array_map( 'strtolower', $this->mNamesUserLang ) ) ) {
 90+ if( $codeUserLang = array_search( $lcLanguageQuery, array_map( 'self::strip', $this->mNamesUserLang ) ) ) {
9091 $results[$codeUserLang] = 'userlangname'; # Match name in user language
9192 }
92 - if( $codeByNativeName = array_search( $lcLanguageQuery, array_map( 'strtolower', $this->mNativeNames ) ) ) {
 93+ if( $codeByNativeName = array_search( $lcLanguageQuery, array_map( 'self::strip', $this->mNativeNames ) ) ) {
9394 $results[$codeByNativeName] = 'nativename'; # Match native name
9495 }
9596
@@ -103,6 +104,15 @@
104105 }
105106
106107 /**
 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+ /**
107117 * Go directly to the wiki if it exists, else to the Incubator test wiki
108118 * @param $project String: project code
109119 * @param $lang String: Language code

Comments

#Comment by Nikerabbit (talk | contribs)   07:34, 20 February 2012

Having autocompletetative input is probably better, because it is hard to get the language names right or to know which languages have translations and which not.

#Comment by SPQRobin (talk | contribs)   19:08, 20 February 2012

Indeed, but I don't have experience with that. If it isn't too difficult I'll do that. (And if it isn't, it should be done for the usual language selector too: http://www.gpaumier.org/blog/628_universal-language-picker/ !)

Status & tagging log