jenkins-bot has submitted this change and it was merged. Change subject: Set the CX Token when the red interlanguage link entry point used ......................................................................
Set the CX Token when the red interlanguage link entry point used Move the setCXToken method to sitemapper module to make it reusable Bug: T87509 Change-Id: I41f63361b603435b35a193cfbc4f50b93365f4bb --- M modules/base/ext.cx.sitemapper.js M modules/entrypoint/ext.cx.entrypoint.js M modules/source/ext.cx.source.selector.js 3 files changed, 40 insertions(+), 34 deletions(-) Approvals: Amire80: Looks good to me, approved Jsahleen: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/modules/base/ext.cx.sitemapper.js b/modules/base/ext.cx.sitemapper.js index 1aae4b6..704354d 100644 --- a/modules/base/ext.cx.sitemapper.js +++ b/modules/base/ext.cx.sitemapper.js @@ -126,4 +126,37 @@ return mw.util.getUrl( cxPage, queryParams ); }; + + + /** + * Set CX Token in a cookie. + * This token guarantees that the translator read the license agreement + * and starts translating from CX dashboard enabled as beta feature + * from any wiki under the top domain. + * + * @param {string} sourceLanguage Source language + * @param {string} targetLanguage Target language + * @param {string} sourceTitle Source title + */ + mw.cx.SiteMapper.prototype.setCXToken = function( sourceLanguage, targetLanguage, sourceTitle ) { + var slug, now, name, options, domain; + + now = new Date(); + slug = sourceTitle.replace( /\s/g, '-' ); + name = [ 'cx', slug, sourceLanguage, targetLanguage ].join( '_' ); + domain = location.hostname.indexOf( '.' ) > 0 ? + '.' + location.hostname.split( '.' ).splice( 1 ).join( '.' ) : + null; // Mostly domains like "localhost" + options = { + prefix: '', + // Use Domain cookie. Example: domain=.wikipedia.org + domain: domain, + expires: new Date( now.getTime() + ( 5 * 60 * 1000 ) ) // 5 mins from now. + }; + + // At this point, the translator saw the license agreement. + // Save that information in a domain cookie. + $.cookie( name, true, options ); + }; + }( jQuery, mediaWiki ) ); diff --git a/modules/entrypoint/ext.cx.entrypoint.js b/modules/entrypoint/ext.cx.entrypoint.js index 47cba1e..14920f3 100644 --- a/modules/entrypoint/ext.cx.entrypoint.js +++ b/modules/entrypoint/ext.cx.entrypoint.js @@ -146,10 +146,14 @@ * Start a new page translation in Special:CX */ CXEntryPoint.prototype.startPageInCX = function () { + var sourceLanguage = mw.config.get( 'wgContentLanguage' ), + sourceTitle = mw.config.get( 'wgTitle' ); + + this.siteMapper.setCXToken( sourceLanguage, this.options.targetLanguage, sourceTitle ); location.href = this.siteMapper.getCXUrl( - mw.config.get( 'wgTitle' ), + sourceTitle, this.$titleInput.val(), - mw.config.get( 'wgContentLanguage' ), + sourceLanguage, this.options.targetLanguage ); }; diff --git a/modules/source/ext.cx.source.selector.js b/modules/source/ext.cx.source.selector.js index a01c93a..006174b 100644 --- a/modules/source/ext.cx.source.selector.js +++ b/modules/source/ext.cx.source.selector.js @@ -750,37 +750,6 @@ }; /** - * Set CX Token in a cookie. - * This token guarantees that the translator read the license agreement - * and starts translating from CX dashboard enabled as beta feature - * from any wiki under the top domain. - * - * @param {string} sourceLanguage Source language - * @param {string} targetLanguage Target language - * @param {string} sourceTitle Source title - */ - function setCXToken( sourceLanguage, targetLanguage, sourceTitle ) { - var slug, now, name, options, domain; - - now = new Date(); - slug = sourceTitle.replace( /\s/g, '-' ); - name = [ 'cx', slug, sourceLanguage, targetLanguage ].join( '_' ); - domain = location.hostname.indexOf( '.' ) > 0 ? - '.' + location.hostname.split( '.' ).splice( 1 ).join( '.' ) : - null; // Mostly domains like "localhost" - options = { - prefix: '', - // Use Domain cookie. Example: domain=.wikipedia.org - domain: domain, - expires: new Date( now.getTime() + ( 5 * 60 * 1000 ) ) // 5 mins from now. - }; - - // At this point, the translator saw the license agreement. - // Save that information in a domain cookie. - $.cookie( name, true, options ); - } - - /** * Start a new page translation in Special:CX. */ CXSourceSelector.prototype.startPageInCX = function () { @@ -797,7 +766,7 @@ } // Set CX token as cookie. - setCXToken( sourceLanguage, targetLanguage, sourceTitle ); + this.siteMapper.setCXToken( sourceLanguage, targetLanguage, sourceTitle ); location.href = this.siteMapper.getCXUrl( sourceTitle, -- To view, visit https://gerrit.wikimedia.org/r/188030 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I41f63361b603435b35a193cfbc4f50b93365f4bb Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> Gerrit-Reviewer: Amire80 <amir.ahar...@mail.huji.ac.il> Gerrit-Reviewer: Jsahleen <jsahl...@wikimedia.org> Gerrit-Reviewer: Santhosh <santhosh.thottin...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits