Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172528
Change subject: WIP: Draft translations
......................................................................
WIP: Draft translations
Change-Id: If97c80f6df69dab9eac68faf7d9a4fc0097df837
---
M ContentTranslation.hooks.php
M Resources.php
M api/ApiContentTranslationPublish.php
M i18n/en.json
M i18n/qqq.json
A includes/Draft.php
M includes/Translation.php
M modules/header/ext.cx.header.js
M modules/header/styles/ext.cx.header.less
A modules/publish/ext.cx.draft.js
M modules/publish/ext.cx.publish.js
M sql/contenttranslation.sql
12 files changed, 180 insertions(+), 18 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/28/172528/1
diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
index 5be3f6a..513b5ca 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -76,6 +76,7 @@
global $wgContentTranslationServerURL,
$wgContentTranslationTranslateInTarget,
$wgContentTranslationExperimentalFeatures,
+ $wgContentTranslationDatabase,
$wgContentTranslationSiteTemplates;
// Temporary BC code for old configuration
@@ -86,5 +87,6 @@
$vars['wgContentTranslationSiteTemplates'] =
$wgContentTranslationSiteTemplates;
$vars['wgContentTranslationTranslateInTarget'] =
$wgContentTranslationTranslateInTarget;
$vars['wgContentTranslationExperimentalFeatures'] =
$wgContentTranslationExperimentalFeatures;
+ $vars['wgContentTranslationDatabase'] =
$wgContentTranslationDatabase;
}
}
diff --git a/Resources.php b/Resources.php
index c1e8dfe..778af9c 100644
--- a/Resources.php
+++ b/Resources.php
@@ -100,6 +100,7 @@
'cx-error-page-not-found',
'cx-header-new-translation',
'cx-publish-button',
+ 'cx-save-draft-button',
'cx-special-login-error',
'cx-translation-target-page-exists',
'login',
@@ -403,6 +404,7 @@
$wgResourceModules['ext.cx.publish'] = array(
'scripts' => array(
'publish/ext.cx.publish.js',
+ 'publish/ext.cx.draft.js',
),
'styles' => array(
'publish/styles/ext.cx.publish.less',
@@ -417,6 +419,7 @@
'cx-publish-page-success',
'cx-publish-page-error',
'cx-publish-button-publishing',
+ 'cx-save-draft-saving',
'cx-publish-captcha-title',
),
) + $resourcePaths;
diff --git a/api/ApiContentTranslationPublish.php
b/api/ApiContentTranslationPublish.php
index d43a990..f344e34 100644
--- a/api/ApiContentTranslationPublish.php
+++ b/api/ApiContentTranslationPublish.php
@@ -96,11 +96,18 @@
public function execute() {
$params = $this->extractRequestParams();
- $title = Title::newFromText( $params['title'] );
- if ( !$title ) {
- $this->dieUsageMsg( 'invalidtitle', $params['title'] );
+ if( $params['status'] === 'draft' ) {
+ $this->saveAsDraft();
+ }else {
+ $this->publish();
}
+ }
+
+ public function publish() {
+ $params = $this->extractRequestParams();
+
+ $title = Title::newFromText( $params['title'] );
try {
$wikitext = $this->convertHtmlToWikitext( $title,
$params['html'] );
} catch ( MWException $e ) {
@@ -142,6 +149,15 @@
$this->getResult()->addValue( null, $this->getModuleName(),
$result );
}
+ public function saveAsDraft() {
+ $params = $this->extractRequestParams();
+ $this->saveTranslationHistory( $params );
+ $result = array(
+ 'result' => 'success',
+ );
+ $this->getResult()->addValue( null, $this->getModuleName(),
$result );
+ }
+
public function saveTranslationHistory( $params ) {
global $wgContentTranslationDatabase;
@@ -162,7 +178,7 @@
'targetURL' =>
ContentTranslation\SiteMapper::getPageURL(
$params['to'], $params['title']
),
- 'status' => 'published',
+ 'status' => $params['status'],
'progress' => $params['progress'],
// XXX Do not overwrite startedTranslator when we have
"draft save" feature.
'startedTranslator' => $translator->getGlobalUserId(),
@@ -170,6 +186,9 @@
) );
$translation->save();
$translator->addTranslation( $translation->getTranslationId() );
+ if( $params['status'] === 'draft') {
+
+ }
}
public function getAllowedParams() {
@@ -196,6 +215,9 @@
ApiBase::PARAM_REQUIRED => true,
),
'sourcerevision' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'status' => array(
ApiBase::PARAM_REQUIRED => true,
),
'categories' => null,
@@ -233,6 +255,7 @@
'to' => 'The target language code.',
'sourcetitle' => 'The title of the source page.',
'sourcerevision' => 'The revision of the source page.',
+ 'status' => 'draft or published. If draft, translation
will be saved as draft. If published, translation will be published',
'progress' => 'Translation progress as JSON.',
'categories' => 'The categories to be added to the
published page.',
'wpCaptchaId' => 'Captcha ID (when saving with a
captcha response).',
diff --git a/i18n/en.json b/i18n/en.json
index c34d025..53a078e 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -100,5 +100,7 @@
"apihelp-cxpublish-param-sourcerevision": "The revision of the source
page.",
"apihelp-cxpublish-param-categories": "The categories to be added to
the published page.",
"apihelp-cxpublish-param-wpCaptchaId": "Captcha ID (when saving with a
captcha response).",
- "apihelp-cxpublish-param-wpCaptchaWord": "Answer to the captcha (when
saving with a captcha response)."
+ "apihelp-cxpublish-param-wpCaptchaWord": "Answer to the captcha (when
saving with a captcha response).",
+ "cx-save-draft-button": "Save",
+ "cx-save-draft-saving": "Saving"
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 9489ac9..79cdb45 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -104,5 +104,7 @@
"apihelp-cxpublish-param-sourcerevision":
"{{doc-apihelp-param|cxpublish|sourcerevision}}",
"apihelp-cxpublish-param-categories":
"{{doc-apihelp-param|cxpublish|categories}}",
"apihelp-cxpublish-param-wpCaptchaId":
"{{doc-apihelp-param|cxpublish|wpCaptchaId}}",
- "apihelp-cxpublish-param-wpCaptchaWord":
"{{doc-apihelp-param|cxpublish|wpCaptchaWord}}"
+ "apihelp-cxpublish-param-wpCaptchaWord":
"{{doc-apihelp-param|cxpublish|wpCaptchaWord}}",
+ "cx-save-draft-button": "Label of button to save the translation as
draft.",
+ "cx-save-draft-saving": "Label of button to save the translation as
draft while saving is in progress"
}
diff --git a/includes/Draft.php b/includes/Draft.php
new file mode 100644
index 0000000..5a3a8c1
--- /dev/null
+++ b/includes/Draft.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * ContentTranslation Translation Draft
+ * Database access method for drafts table.
+ */
+namespace ContentTranslation;
+
+class Draft {
+ public static function save( $translationId, $content ) {
+ $dbw = Database::getConnection( DB_MASTER );
+ $dbw->replace(
+ 'drafts',
+ array( 'draft_id' ),
+ array(
+ 'draft_id' => $translationId,
+ 'draft_content' => $content,
+ 'draft_timestamp' => $dbw->timestamp(),
+ ),
+ __METHOD__
+ );
+ }
+
+ public static function getDraft( $translationId ) {
+ $dbw = Database::getConnection( DB_SLAVE );
+ $dbw->select(
+ 'drafts',
+ array( 'draft_id', 'draft_content',
'draft_start_timestamp' ),
+ array(
+ 'draft_id'=> $translationId
+ ),
+ __METHOD__
+ );
+ }
+}
diff --git a/includes/Translation.php b/includes/Translation.php
index 7f04d76..0249a3a 100644
--- a/includes/Translation.php
+++ b/includes/Translation.php
@@ -10,10 +10,10 @@
}
public function save() {
- $dbw = Database::getConnection( DB_SLAVE );
+ $dbw = Database::getConnection( DB_MASTER );
$dbw->replace(
'translations',
- array( 'translation_id' ),
+ array( 'translation_pair' ),
array(
'translation_source_title' =>
$this->translation['sourceTitle'],
'translation_target_title' =>
$this->translation['targetTitle'],
diff --git a/modules/header/ext.cx.header.js b/modules/header/ext.cx.header.js
index 408e5f4..057e1de 100644
--- a/modules/header/ext.cx.header.js
+++ b/modules/header/ext.cx.header.js
@@ -23,6 +23,7 @@
this.siteMapper = siteMapper;
this.$publishButton = null;
+ this.$draftButton = null;
this.$infoBar = null;
this.init();
@@ -39,6 +40,7 @@
*/
ContentTranslationHeader.prototype.setPublishButtonState = function (
weights ) {
this.$publishButton.show().prop( 'disabled', weights.any === 0
);
+ this.$draftButton.show().prop( 'disabled', weights.any === 0 );
};
/**
@@ -132,6 +134,9 @@
this.$publishButton.on( 'click', function () {
mw.hook( 'mw.cx.publish' ).fire();
} );
+ this.$draftButton.on( 'click', function () {
+ mw.hook( 'mw.cx.save' ).fire();
+ } );
// Click handler for remove icon in info bar.
this.$infoBar.on( 'click', '.remove', function () {
@@ -178,9 +183,19 @@
.text( mw.msg( 'cx-publish-button' ) )
.hide();
+ if( mw.config.get( 'wgContentTranslationDatabase' ) ){
+ this.$draftButton = $( '<button>' )
+ .addClass( 'draft mw-ui-button
mw-ui-progressive' )
+ .prop( 'disabled', true )
+ .text( mw.msg( 'cx-save-draft-button' ) )
+ .hide();
+ }else {
+ this.$draftButton = $();
+ }
+
$publishArea = $( '<div>' )
.addClass( 'cx-header__publish' )
- .append( this.$publishButton );
+ .append( this.$draftButton, this.$publishButton );
$headerBar = $( '<div>' )
.addClass( 'cx-header__bar' )
diff --git a/modules/header/styles/ext.cx.header.less
b/modules/header/styles/ext.cx.header.less
index feb10d7..defbde4 100644
--- a/modules/header/styles/ext.cx.header.less
+++ b/modules/header/styles/ext.cx.header.less
@@ -95,6 +95,12 @@
.cx-header__publish {
.mw-ui-item;
.mw-ui-one-third;
+ .draft {
+ .mw-ui-one-third;
+ }
+ .publish {
+ .mw-ui-two-thirds;
+ }
}
.cx-header.sticky {
diff --git a/modules/publish/ext.cx.draft.js b/modules/publish/ext.cx.draft.js
new file mode 100644
index 0000000..bb324e6
--- /dev/null
+++ b/modules/publish/ext.cx.draft.js
@@ -0,0 +1,69 @@
+/**
+ * ContentTranslation - Publish article
+ *
+ * @file
+ * @ingroup Extensions
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+( function ( $, mw ) {
+ 'use strict';
+
+ /**
+ * Publish the translation
+ */
+ function save() {
+ var $publishArea, $draftButton, translatedTitle,
+ draftContent, targetTitle,params,apiParams,
+ api = new mw.Api();
+
+ $publishArea = $( '.cx-header__publish' );
+ $draftButton = $publishArea.find( 'button.draft' );
+
+ translatedTitle = $( '.cx-column--translation > h2' ).text();
+ draftContent = $( '.cx-column--translation .cx-column__content'
).clone();
+ targetTitle = 'User:' + mw.user.getName() + '/' +
translatedTitle;
+
+ $draftButton
+ .prop( 'disabled', true )
+ .text( mw.msg( 'cx-save-draft-saving' ) );
+ params = {
+ from: mw.cx.sourceLanguage,
+ to: mw.cx.targetLanguage,
+ sourcetitle: mw.cx.sourceTitle,
+ title: targetTitle,
+ html: draftContent.html(),
+ status: 'draft',
+ sourcerevision: mw.cx.sourceRevision,
+ progress: JSON.stringify( mw.cx.getProgress() )
+ };
+
+ apiParams = $.extend( {}, params, {
+ action: 'cxpublish'
+ } );
+ api.postWithToken( 'edit', apiParams, {
+ timeout: 100 * 1000 // in milliseconds
+ } ).done( function () {
+ mw.hook( 'mw.cx.translation.saved' ).fire();
+ } ).fail( function () {
+ mw.hook( 'mw.cx.error' ).fire( mw.msg(
'cx-publish-page-error' ) );
+ } ).always( function () {
+ $draftButton
+ .prop( 'disabled', false )
+ .text( mw.msg( 'cx-save-draft-button' ) );
+ } );
+
+ }
+
+ $( function () {
+ mw.hook( 'mw.cx.save' ).add( $.proxy( save, this ) );
+ // Publish when CTRL+S is pressed.
+ $( document ).on( 'keydown', function ( e ) {
+ if ( e.ctrlKey && e.which === 83 ) {
+ e.preventDefault();
+ mw.hook( 'mw.cx.save' ).fire();
+ return false;
+ }
+ } );
+ } );
+}( jQuery, mediaWiki ) );
diff --git a/modules/publish/ext.cx.publish.js
b/modules/publish/ext.cx.publish.js
index 76a8685..41cf4c6 100644
--- a/modules/publish/ext.cx.publish.js
+++ b/modules/publish/ext.cx.publish.js
@@ -139,6 +139,7 @@
sourcetitle: mw.cx.sourceTitle,
title: targetTitle,
html: translatedContent,
+ status: 'published',
sourcerevision: mw.cx.sourceRevision,
categories: categories,
progress: JSON.stringify( mw.cx.getProgress() )
@@ -216,13 +217,5 @@
$( function () {
mw.hook( 'mw.cx.publish' ).add( $.proxy( publish, this ) );
- // Publish when CTRL+S is pressed.
- $( document ).on( 'keydown', function ( e ) {
- if ( e.ctrlKey && e.which === 83 ) {
- e.preventDefault();
- mw.hook( 'mw.cx.publish' ).fire();
- return false;
- }
- } );
} );
}( jQuery, mediaWiki ) );
diff --git a/sql/contenttranslation.sql b/sql/contenttranslation.sql
index 3fe8ed2..d9a4c5c 100644
--- a/sql/contenttranslation.sql
+++ b/sql/contenttranslation.sql
@@ -37,10 +37,23 @@
) /*$wgDBTableOptions*/;
CREATE TABLE /*_*/translators (
- -- Translators id - global user id?
+ -- Translators id - global user id
translator_user_id int not null,
-- Translation id - foreign key to translations.translation_id
translator_translation_id int not null
) /*$wgDBTableOptions*/;
+
+CREATE TABLE /*_*/drafts (
+ -- Draft Id - foreign key to translations.translation_id
+ draft_id int not null,
+ -- Draft save timestamp
+ draft_timestamp varchar(14) binary not null,
+ -- Translation draft content
+ draft_content mediumblob
+) /*$wgDBTableOptions*/;
+
+
+CREATE UNIQUE INDEX /*i*/translation_pair ON /*_*/translations (
translation_source_title, translation_source_language,
translation_target_language);
+
CREATE UNIQUE INDEX /*i*/translation_translators ON /*_*/translators
(translator_user_id, translator_translation_id);
--
To view, visit https://gerrit.wikimedia.org/r/172528
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If97c80f6df69dab9eac68faf7d9a4fc0097df837
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