jenkins-bot has submitted this change and it was merged.
Change subject: Make sure translator see license text even if use manually
created URL
......................................................................
Make sure translator see license text even if use manually created URL
When users try to access the translation view directly for
an article that they have not explicitly started before,
instead of being directed to the translation view,
they will be directed to the translation dashboard.
There, the New translation dialog will open and they will be able
to start the translation with a single click
(after reading the legal terms, as we all usually do).
If draft URL parameter is present, this step is avoided because drafts
are created after following the above step. In case translators try
a URL with an invalid draft, there will be draft validation (it is
a separate task).
A domain level cookie with short expiration time is used as a token to
indicate that the translator went through the normal translation
workflow. Note that this cookie is not host level, but at domain level,
domain being .wikipedia.org for Wikipedia. This allows CX to redirect
users between source and target language wikis.
Make sure to test this in a multi-language wiki setup and with
the following line in LocalSettings.php:
$wgContentTranslationTranslateInTarget = true;
Bug: T76178
Change-Id: I640ebdd801f99f85a27733b8b30dede21f0a4e8c
---
M modules/dashboard/ext.cx.dashboard.js
M modules/source/ext.cx.source.js
M modules/source/ext.cx.source.selector.js
M specials/SpecialContentTranslation.php
4 files changed, 74 insertions(+), 9 deletions(-)
Approvals:
Jsahleen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/dashboard/ext.cx.dashboard.js
b/modules/dashboard/ext.cx.dashboard.js
index 2f4f9f8..882ee74 100644
--- a/modules/dashboard/ext.cx.dashboard.js
+++ b/modules/dashboard/ext.cx.dashboard.js
@@ -58,7 +58,15 @@
};
CXDashboard.prototype.listen = function () {
- this.$newTranslationButton.cxSourceSelector();
+ var query,
+ sourceSelectorOptions = {};
+
+ query =new mw.Uri().query;
+ sourceSelectorOptions.sourceLanguage = query.from;
+ sourceSelectorOptions.targetLanguage = query.to;
+ sourceSelectorOptions.sourceTitle = query.page;
+ sourceSelectorOptions.targetTitle = query.targettitle;
+ this.$newTranslationButton.cxSourceSelector(
sourceSelectorOptions );
};
$.fn.cxDashboard = function ( siteMapper, options ) {
diff --git a/modules/source/ext.cx.source.js b/modules/source/ext.cx.source.js
index 974434f..52379c2 100644
--- a/modules/source/ext.cx.source.js
+++ b/modules/source/ext.cx.source.js
@@ -77,7 +77,7 @@
};
ContentTranslationSource.prototype.showDashboard = function () {
- location.href = mw.util.getUrl( 'Special:ContentTranslation' );
+ location.href = mw.util.getUrl( 'Special:ContentTranslation' );
};
/**
diff --git a/modules/source/ext.cx.source.selector.js
b/modules/source/ext.cx.source.selector.js
index b191155..79d4a31 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -55,11 +55,31 @@
*/
CXSourceSelector.prototype.init = function () {
var cxSourceSelector = this;
+
this.getLanguagePairs().then( function () {
cxSourceSelector.render();
cxSourceSelector.listen();
} );
+ };
+
+ /**
+ * Prefill the selector if values are passed as options.
+ */
+ CXSourceSelector.prototype.prefill = function () {
+ if ( this.options.sourceLanguage ) {
+ this.sourceLanguageChangeHandler(
this.options.sourceLanguage );
+ }
+ if ( this.options.targetLanguage ) {
+ this.targetLanguageChangeHandler(
this.options.targetLanguage );
+ }
+ if ( this.options.sourceTitle ) {
+ this.$sourceTitleInput.val( this.options.sourceTitle
).trigger( 'input' );
+ this.show();
+ }
+ if ( this.options.targetTitle ) {
+ this.$targetTitleInput.val( this.options.targetTitle
).trigger( 'input' );
+ }
};
/**
@@ -676,21 +696,54 @@
};
/**
+ * Set CX Token in cookie.
+ * This token gurantees that the translator read the license agreement
+ * and starting a translation 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 date = new Date();
+ // At this point, the translator saw the license agreement.
+ // Save that information in a domain cookie
+ $.cookie(
+ [ 'cx', sourceLanguage, targetLanguage, sourceTitle
].join( '_' ),
+ true, {
+ prefix: '',
+ // Use Domain cookie. Example:
domain=.wikipedia.org
+ domain: '.' + location.hostname.split( '.'
).splice( 1 ).join( '.' ),
+ expires: date.setTime( date.getTime() + ( 5 *
60 * 1000 ) ) // 5 minutes from now
+ }
+ );
+ }
+
+ /**
* Start a new page translation in Special:CX
*/
CXSourceSelector.prototype.startPageInCX = function () {
- var targetTitle;
+ var targetTitle, sourceTitle, sourceLanguage, targetLanguage;
+
+ sourceLanguage = this.getSourceLanguage();
+ targetLanguage = this.getTargetLanguage();
+ sourceTitle = this.$sourceTitleInput.val();
if ( this.$targetTitleInput.val() === '' ) {
targetTitle = this.$sourceTitleInput.val();
} else {
targetTitle = this.$targetTitleInput.val();
}
+
+ // Set CX token as cookie.
+ setCXToken( sourceLanguage, targetLanguage, sourceTitle );
+
location.href = this.siteMapper.getCXUrl(
- this.$sourceTitleInput.val(),
+ sourceTitle,
targetTitle,
- this.getSourceLanguage(),
- this.getTargetLanguage()
+ sourceLanguage,
+ targetLanguage
);
};
@@ -838,6 +891,8 @@
);
$( 'body' ).append( this.$dialog );
+
+ this.prefill();
};
/**
diff --git a/specials/SpecialContentTranslation.php
b/specials/SpecialContentTranslation.php
index 6ad5f43..e95fd76 100644
--- a/specials/SpecialContentTranslation.php
+++ b/specials/SpecialContentTranslation.php
@@ -30,6 +30,9 @@
$skin = $this->getSkin();
$request = $this->getRequest();
+ $token = implode( '_', array(
+ 'cx', $request->getVal( 'from' ), $request->getVal(
'to' ), $request->getVal( 'page' )
+ ) );
// Direct access, isListed only affects Special:SpecialPages
if ( !ContentTranslationHooks::isEnabledForUser(
$this->getUser() ) ) {
$out->showErrorPage( 'nosuchspecialpage',
'nospecialpagetext' );
@@ -37,9 +40,8 @@
}
$out->addModuleStyles( 'mediawiki.ui.button' );
- if ( $request->getVal( 'from' ) === null ||
- $request->getVal( 'to' ) === null ||
- $request->getVal( 'page' ) === null
+ if ( $request->getCookie( $token, '' ) === null &&
+ $request->getVal( 'draft' ) === null
) {
$out->addModules( 'ext.cx.dashboard' );
} else {
--
To view, visit https://gerrit.wikimedia.org/r/179105
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I640ebdd801f99f85a27733b8b30dede21f0a4e8c
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: BBlack <[email protected]>
Gerrit-Reviewer: Jsahleen <[email protected]>
Gerrit-Reviewer: Pginer <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits