Amire80 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/233719

Change subject: Convert the language domain code mapping to a global variable
......................................................................

Convert the language domain code mapping to a global variable

Until now the same data was writte in two place - the PHP SiteMapper
and the JS SiteMapper.

Now it's in the global configuration variable
$wgContentTranslationDomainCodeMapping,
which makes it written only once, without having to sync
two files every time a change is needed.
It also makes it customizable per site.

Change-Id: I9cda0ef692a8bc29caa02e70fe42e50cbf5fee44
---
M ContentTranslation.hooks.php
M extension.json
M includes/SiteMapper.php
M modules/base/ext.cx.sitemapper.js
4 files changed, 19 insertions(+), 31 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/19/233719/1

diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
index dc7db2e..3875cd4 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -153,6 +153,7 @@
         */
        public static function addConfig( array &$vars ) {
                global $wgContentTranslationTranslateInTarget,
+                       $wgContentTranslationDomainCodeMapping,
                        $wgContentTranslationExperimentalFeatures,
                        $wgContentTranslationDatabase,
                        $wgContentTranslationSiteTemplates,
@@ -162,6 +163,7 @@
                        $wgContentTranslationTargetNamespace;
 
                $vars['wgContentTranslationTranslateInTarget'] = 
$wgContentTranslationTranslateInTarget;
+               $vars['wgContentTranslationDomainCodeMapping'] = 
$wgContentTranslationDomainCodeMapping;
                $vars['wgContentTranslationExperimentalFeatures'] = 
$wgContentTranslationExperimentalFeatures;
                $vars['wgContentTranslationDatabase'] = 
$wgContentTranslationDatabase;
                $vars['wgContentTranslationSiteTemplates'] = 
$wgContentTranslationSiteTemplates;
diff --git a/extension.json b/extension.json
index f12c192..1250a15 100644
--- a/extension.json
+++ b/extension.json
@@ -80,6 +80,18 @@
        },
        "config": {
                "ContentTranslationExperimentalFeatures": false,
+               "ContentTranslationDomainCodeMapping": {
+                       "be-tarask": "be-x-old",
+                       "bho": "bh",
+                       "crh-latn": "crh",
+                       "gsw": "als",
+                       "lzh": "zh-classical",
+                       "nan": "zh-min-nan",
+                       "rup": "roa-rup",
+                       "sgs": "bat-smg",
+                       "vro": "fiu-vro",
+                       "yue": "zh-yue"
+               },
                "ContentTranslationParsoid": {
                        "url": "http://parsoid-lb.eqiad.wikimedia.org/";,
                        "timeout": 100000,
diff --git a/includes/SiteMapper.php b/includes/SiteMapper.php
index e5f8ccc..e2f48a0 100644
--- a/includes/SiteMapper.php
+++ b/includes/SiteMapper.php
@@ -2,29 +2,15 @@
 namespace ContentTranslation;
 
 class SiteMapper {
-       // Some wikis have domain names that do not match the content language.
-       // NOTE: See modules/base/ext.cx.sitemapper.js
-       public static $languageToWikiDomainMapping = array(
-               'bho' => 'bh',
-               'crh-latn' => 'crh',
-               'gsw' => 'als',
-               'sgs' => 'bat-smg',
-               'be-tarask' => 'be-x-old',
-               'vro' => 'fiu-vro',
-               'rup' => 'roa-rup',
-               'lzh' => 'zh-classical',
-               'nan' => 'zh-min-nan',
-               'yue' => 'zh-yue',
-       );
-
        /**
         * Get the page URL constructed from the domain template of sites
         */
        public static function getPageURL( $language, $title ) {
-               global $wgContentTranslationSiteTemplates;
+               global $wgContentTranslationSiteTemplates,
+                       $wgContentTranslationDomainCodeMapping;
 
-               if ( isset( SiteMapper::$languageToWikiDomainMapping[$language] 
) ) {
-                       $domain = 
SiteMapper::$languageToWikiDomainMapping[$language];
+               if ( isset( $wgContentTranslationDomainCodeMapping[$language] ) 
) {
+                       $domain = 
$wgContentTranslationDomainCodeMapping[$language];
                } else {
                        $domain = $language;
                }
diff --git a/modules/base/ext.cx.sitemapper.js 
b/modules/base/ext.cx.sitemapper.js
index ffdd9fc..ac2d379 100644
--- a/modules/base/ext.cx.sitemapper.js
+++ b/modules/base/ext.cx.sitemapper.js
@@ -22,23 +22,11 @@
        /**
         * Some wikis have domain names that do not match the content language.
         * See: wgLanguageCode in 
operations/mediawiki-config/wmf-config/InitialiseSettings.php
-        * NOTE: Keep list of mapping in sync with includes/SiteMapper.php
         * @param {string} language Language code
         * @return {string}
         */
        mw.cx.SiteMapper.prototype.getWikiDomainCode = function ( language ) {
-               var languageToWikiDomainMapping = {
-                       bho: 'bh',
-                       'crh-latn': 'crh',
-                       gsw: 'als',
-                       sgs: 'bat-smg',
-                       'be-tarask': 'be-x-old',
-                       vro: 'fiu-vro',
-                       rup: 'roa-rup',
-                       lzh: 'zh-classical',
-                       nan: 'zh-min-nan',
-                       yue: 'zh-yue'
-               };
+               var languageToWikiDomainMapping = mw.config.get( 
'wgContentTranslationDomainCodeMapping' );
 
                return languageToWikiDomainMapping[ language ] || language;
        };

-- 
To view, visit https://gerrit.wikimedia.org/r/233719
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9cda0ef692a8bc29caa02e70fe42e50cbf5fee44
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to