Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/179105
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
For users that try to access the translation view directly for an article
they have not explicitly started before, instead of directing them to the
Translation view, they will be directed to the Translation Dashboard.
There, the new translation dialog will be 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. Since 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 seperate task)
A domain level cookie with short expiration time is used as 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 with
$wgContentTranslationTranslateInTarget = true; setting and in a multi
language wiki setup.
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(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/05/179105/1
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 1b71fc5..d1a187a 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' );
+ }
};
/**
@@ -615,21 +635,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
);
};
@@ -766,6 +819,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: newchange
Gerrit-Change-Id: I640ebdd801f99f85a27733b8b30dede21f0a4e8c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits