From: This, that and the other Date: Thu, 12 Jan 2017 14:17:41 +0000 (+1100) Subject: Break up $wgDummyLanguageCodes X-Git-Tag: 1.31.0-rc.0~3839^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=48ab87d0a37da80c2e2ae3a20f645548d2a787f9 Break up $wgDummyLanguageCodes $wgDummyLanguageCodes is a set and mapping of different language codes: * Renamed language codes: ['als' => 'gsw', 'bat-smg' => 'sgs', 'be-xold' => 'be-tarask', 'fiu-vro' => 'vro', 'roa-rup' => 'rup', 'zh-classical' => 'lzh', 'zh-min-nan' => 'nan', 'zh-yue' => 'yue']. The old language codes are deprecated because they are invalid but should be supported for compatibility reasons for a while. * Language codes of macro languages, which get mapped to the main language: ['bh' => 'bho', 'no' => 'nb']. * Language variants which get mapped to main language: ['simple' => 'en']. * Internal language codes of the private-use-area which get mapped to itself: ['qqq' => 'qqq', 'qqx' => 'qqx'] This is a very strange conglomeration which should get differentiated, and were split up in the following ways: * Renamed language codes are available from LanguageCode::getDeprecatedCodeMapping(). * Language codes of macro languages and the variants that are mapped to the main language are available as $wgExtraLanguageCodes and are set in DefaultSettings.php. * Internal language codes are set in $wgDummyLanguageCodes in Setup.php. Change-Id: If73c74ee87d8235381449cab7dcd9f46b0f23590 --- diff --git a/autoload.php b/autoload.php index a38fca2655..e035828f91 100644 --- a/autoload.php +++ b/autoload.php @@ -688,6 +688,7 @@ $wgAutoloadLocalClasses = [ 'LanguageBe_tarask' => __DIR__ . '/languages/classes/LanguageBe_tarask.php', 'LanguageBg' => __DIR__ . '/languages/classes/LanguageBg.php', 'LanguageBs' => __DIR__ . '/languages/classes/LanguageBs.php', + 'LanguageCode' => __DIR__ . '/languages/LanguageCode.php', 'LanguageConverter' => __DIR__ . '/languages/LanguageConverter.php', 'LanguageCu' => __DIR__ . '/languages/classes/LanguageCu.php', 'LanguageDsb' => __DIR__ . '/languages/classes/LanguageDsb.php', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 77061dfcc8..eedf34c69e 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2808,8 +2808,9 @@ $wgUsePrivateIPs = false; * MediaWiki out of the box. Not all languages listed there have translations, * see languages/messages/ for the list of languages with some localisation. * - * Warning: Don't use language codes listed in $wgDummyLanguageCodes like "no" - * for Norwegian (use "nb" instead), or things will break unexpectedly. + * Warning: Don't use any of MediaWiki's deprecated language codes listed in + * LanguageCode::getDeprecatedCodeMapping or $wgDummyLanguageCodes, like "no" + * for Norwegian (use "nb" instead). If you do, things will break unexpectedly. * * This defines the default interface language for all users, but users can * change it in their preferences. @@ -2868,25 +2869,22 @@ $wgExtraInterlanguageLinkPrefixes = []; $wgExtraLanguageNames = []; /** - * List of language codes that don't correspond to an actual language. - * These codes are mostly left-offs from renames, or other legacy things. - * This array makes them not appear as a selectable language on the installer, - * and excludes them when running the transstat.php script. - */ -$wgDummyLanguageCodes = [ - 'als' => 'gsw', - 'bat-smg' => 'sgs', - 'be-x-old' => 'be-tarask', - 'bh' => 'bho', - 'fiu-vro' => 'vro', - 'no' => 'nb', - 'qqq' => 'qqq', # Used for message documentation. - 'qqx' => 'qqx', # Used for viewing message keys. - 'roa-rup' => 'rup', - 'simple' => 'en', - 'zh-classical' => 'lzh', - 'zh-min-nan' => 'nan', - 'zh-yue' => 'yue', + * List of mappings from one language code to another. + * This array makes the codes not appear as a selectable language on the + * installer, and excludes them when running the transstat.php script. + * + * In Setup.php, the variable $wgDummyLanguageCodes is created by combining + * these codes with a list of "deprecated" codes, which are mostly leftovers + * from renames or other legacy things, and the internal codes 'qqq' and 'qqx'. + * If a mapping in $wgExtraLanguageCodes collide with a built-in mapping, the + * value in $wgExtraLanguageCodes will be used. + * + * @since 1.29 + */ +$wgExtraLanguageCodes = [ + 'bh' => 'bho', // Bihari language family + 'no' => 'nb', // Norwegian language family + 'simple' => 'en', // Simple English ]; /** diff --git a/includes/Setup.php b/includes/Setup.php index f6631eadb9..2babce74ea 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -403,6 +403,14 @@ if ( is_array( $wgExtraNamespaces ) ) { $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces; } +// Merge in the legacy language codes, unless overridden in the config +if ( !isset( $wgDummyLanguageCodes ) ) { + $wgDummyLanguageCodes = [ + 'qqq' => 'qqq', // Used for message documentation + 'qqx' => 'qqx', // Used for viewing message keys + ] + $wgExtraLanguageCodes + LanguageCode::getDeprecatedCodeMapping(); +} + // These are now the same, always // To determine the user language, use $wgLang->getCode() $wgContLanguageCode = $wgLanguageCode; diff --git a/languages/LanguageCode.php b/languages/LanguageCode.php new file mode 100644 index 0000000000..7c9da77ba6 --- /dev/null +++ b/languages/LanguageCode.php @@ -0,0 +1,54 @@ + 'gsw', + 'bat-smg' => 'sgs', + 'be-x-old' => 'be-tarask', + 'fiu-vro' => 'vro', + 'roa-rup' => 'rup', + 'zh-classical' => 'lzh', + 'zh-min-nan' => 'nan', + 'zh-yue' => 'yue', + ]; + } +} diff --git a/tests/phpunit/languages/LanguageCodeTest.php b/tests/phpunit/languages/LanguageCodeTest.php new file mode 100644 index 0000000000..b33360cfe9 --- /dev/null +++ b/tests/phpunit/languages/LanguageCodeTest.php @@ -0,0 +1,40 @@ +assertInstanceOf( LanguageCode::class, $instance ); + } + + public function testGetDeprecatedCodeMapping() { + $map = LanguageCode::getDeprecatedCodeMapping(); + + $this->assertInternalType( 'array', $map ); + $this->assertContainsOnly( 'string', array_keys( $map ) ); + $this->assertArrayNotHasKey( '', $map ); + $this->assertContainsOnly( 'string', $map ); + $this->assertNotContains( '', $map ); + + // Codes special to MediaWiki should never appear in a map of "deprecated" codes + $this->assertArrayNotHasKey( 'qqq', $map, 'documentation' ); + $this->assertNotContains( 'qqq', $map, 'documentation' ); + $this->assertArrayNotHasKey( 'qqx', $map, 'debug code' ); + $this->assertNotContains( 'qqx', $map, 'debug code' ); + + // Valid language codes that are currently not "deprecated" + $this->assertArrayNotHasKey( 'bh', $map, 'family of Bihari languages' ); + $this->assertArrayNotHasKey( 'no', $map, 'family of Norwegian languages' ); + $this->assertArrayNotHasKey( 'simple', $map ); + } + +}