https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111896
Revision: 111896
Author: robin
Date: 2012-02-19 22:47:50 +0000 (Sun, 19 Feb 2012)
Log Message:
-----------
More language codes and more matching names (by removing whitespace and
hyphens) -> better results!
Modified Paths:
--------------
trunk/extensions/WikimediaIncubator/SpecialSearchWiki.php
Modified: trunk/extensions/WikimediaIncubator/SpecialSearchWiki.php
===================================================================
--- trunk/extensions/WikimediaIncubator/SpecialSearchWiki.php 2012-02-19
22:31:30 UTC (rev 111895)
+++ trunk/extensions/WikimediaIncubator/SpecialSearchWiki.php 2012-02-19
22:47:50 UTC (rev 111896)
@@ -77,18 +77,19 @@
$lcLanguageQuery = strtolower( $languageQuery );
# The more important, the more below, because they override
earlier codes
- $validCodes = array_keys( Language::getLanguageNames() );
+ $validCodes = array_keys( Language::getTranslatedLanguageNames(
'en' ) );
if( in_array( $lcLanguageQuery, $validCodes ) ) {
$builtinCode = Language::factory( $lcLanguageQuery
)->getCode();
$results[$builtinCode] = 'langcode'; # Match language
code
}
- if( $codeByEnglishName = array_search( $lcLanguageQuery,
array_map( 'strtolower', $this->mEnglishNames ) ) ) {
+ $lcLanguageQuery = self::strip( $languageQuery );
+ if( $codeByEnglishName = array_search( $lcLanguageQuery,
array_map( 'self::strip', $this->mEnglishNames ) ) ) {
$results[$codeByEnglishName] = 'englishname'; # Match
name in English
}
- if( $codeUserLang = array_search( $lcLanguageQuery, array_map(
'strtolower', $this->mNamesUserLang ) ) ) {
+ if( $codeUserLang = array_search( $lcLanguageQuery, array_map(
'self::strip', $this->mNamesUserLang ) ) ) {
$results[$codeUserLang] = 'userlangname'; # Match name
in user language
}
- if( $codeByNativeName = array_search( $lcLanguageQuery,
array_map( 'strtolower', $this->mNativeNames ) ) ) {
+ if( $codeByNativeName = array_search( $lcLanguageQuery,
array_map( 'self::strip', $this->mNativeNames ) ) ) {
$results[$codeByNativeName] = 'nativename'; # Match
native name
}
@@ -103,6 +104,15 @@
}
/**
+ * Improve search by increasing the chance of matches
+ */
+ protected function strip( $str ) {
+ $str = strtolower( trim( $str ) );
+ $replace = array( ' ' => '', '-' => '' );
+ return str_replace( array_keys( $replace ), array_values(
$replace ), $str );
+ }
+
+ /**
* Go directly to the wiki if it exists, else to the Incubator test wiki
* @param $project String: project code
* @param $lang String: Language code
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs