Santhosh has uploaded a new change for review.

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

Change subject: Fix: Link adapation does not happen when language code and 
domain differs
......................................................................

Fix: Link adapation does not happen when language code and domain differs

Testplan:
Translate:
Special:ContentTranslation&page=LaTeX&from=simple&to=bho
Without this patch, user will see all links in translation
template as missing. With this patch, links will be adapated
to bh.

Bug: T99888
Change-Id: I2d5021c27f8b03563ef5a16723bed3ea83d0e701
---
M modules/base/ext.cx.sitemapper.js
M modules/tools/ext.cx.tools.link.js
2 files changed, 31 insertions(+), 21 deletions(-)


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

diff --git a/modules/base/ext.cx.sitemapper.js 
b/modules/base/ext.cx.sitemapper.js
index 6d7aa72..aec45af 100644
--- a/modules/base/ext.cx.sitemapper.js
+++ b/modules/base/ext.cx.sitemapper.js
@@ -11,21 +11,6 @@
 ( function ( $, mw ) {
        'use strict';
 
-       // 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
-       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'
-       };
 
        /**
         * Handles providing urls to different wikis.
@@ -35,6 +20,30 @@
                this.config = siteconfig;
        };
 
+
+       /**
+        * 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
+        */
+       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'
+               };
+
+               return languageToWikiDomainMapping[ language ] || language;
+       };
+
        /**
         * Get the API for a remote wiki.
         *
@@ -42,10 +51,10 @@
         * @return {mediawiki.Api}
         */
        mw.cx.SiteMapper.prototype.getApi = function ( language ) {
-               var url;
+               var url, domain;
 
-               language = languageToWikiDomainMapping[ language ] || language;
-               url = this.config.api.replace( '$1', language );
+               domain = this.getWikiDomainCode( language );
+               url = this.config.api.replace( '$1', domain );
                return new mw.Api( {
                        ajax: {
                                url: url
@@ -63,15 +72,16 @@
         */
        mw.cx.SiteMapper.prototype.getPageUrl = function ( language, title, 
params ) {
                var base = this.config.view,
+                       domain,
                        extra = '';
 
-               language = languageToWikiDomainMapping[ language ] || language;
+               domain = this.getWikiDomainCode( language );
                if ( params && !$.isEmptyObject( params ) ) {
                        base = this.config.action || this.config.view;
                        extra = ( base.indexOf( '?' ) !== -1 ? '&' : '?' ) + 
$.param( params );
                }
 
-               return base.replace( '$1', language ).replace( '$2', title ) + 
extra;
+               return base.replace( '$1', domain ).replace( '$2', title ) + 
extra;
        };
 
        /**
diff --git a/modules/tools/ext.cx.tools.link.js 
b/modules/tools/ext.cx.tools.link.js
index db689a3..3d6c90a 100644
--- a/modules/tools/ext.cx.tools.link.js
+++ b/modules/tools/ext.cx.tools.link.js
@@ -77,7 +77,7 @@
                        titles: titles.join( '|' ),
                        prop: 'langlinks',
                        lllimit: titles.length, // TODO: Default is 10 and max 
is 500. Do we need more than 500?
-                       lllang: language,
+                       lllang: mw.cx.siteMapper.getWikiDomainCode( language ),
                        redirects: true,
                        format: 'json'
                }, {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2d5021c27f8b03563ef5a16723bed3ea83d0e701
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to