Nikerabbit has uploaded a new change for review.

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

Change subject: Set mw.cx.translationId for new translations
......................................................................

Set mw.cx.translationId for new translations

This makes cxsave to work on initial translation as well. Temporary
solution until draft module is merged to cxsave.

Ensure that translation ids are ints.

Change-Id: I3d5ad83307e07b146058bec51311e7745089b59e
---
M api/ApiContentTranslationPublish.php
M includes/Translation.php
M modules/translation/ext.cx.translation.draft.js
3 files changed, 14 insertions(+), 3 deletions(-)


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

diff --git a/api/ApiContentTranslationPublish.php 
b/api/ApiContentTranslationPublish.php
index ee33bc3..090413f 100755
--- a/api/ApiContentTranslationPublish.php
+++ b/api/ApiContentTranslationPublish.php
@@ -382,6 +382,12 @@
                        // Save the draft
                        ContentTranslation\Draft::save( $translationId, 
$this->getHtml() );
                }
+
+               $result = array(
+                       'translationid' => $translationId
+               );
+
+               $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
        }
 
        public function getAllowedParams() {
diff --git a/includes/Translation.php b/includes/Translation.php
index 9053ef7..66db0cc 100644
--- a/includes/Translation.php
+++ b/includes/Translation.php
@@ -39,7 +39,7 @@
                        __METHOD__
                );
 
-               $this->translation['id'] = $dbw->insertId();
+               $this->translation['id'] = (int)$dbw->insertId();
        }
 
        public function update() {
@@ -452,7 +452,7 @@
         */
        public static function newFromRow( $row ) {
                $translation = new Translation( array(
-                       'id' => $row->translation_id,
+                       'id' => (int)$row->translation_id,
                        'sourceTitle' => $row->translation_source_title,
                        'targetTitle' => $row->translation_target_title,
                        'sourceLanguage' => $row->translation_source_language,
diff --git a/modules/translation/ext.cx.translation.draft.js 
b/modules/translation/ext.cx.translation.draft.js
index 40bf4ff..35a0b44 100644
--- a/modules/translation/ext.cx.translation.draft.js
+++ b/modules/translation/ext.cx.translation.draft.js
@@ -389,7 +389,7 @@
                } );
                api.postWithToken( 'edit', apiParams, {
                        timeout: 100 * 1000 // in milliseconds
-               } ).done( function () {
+               } ).done( function ( results ) {
                        mw.hook( 'mw.cx.translation.saved' ).fire(
                                mw.cx.sourceLanguage,
                                mw.cx.targetLanguage,
@@ -399,6 +399,11 @@
                        timer = setInterval( function () {
                                checkAndSave();
                        }, 5 * 60 * 1000 );
+
+                       // If this is new translation, we don't have 
translationid before first save.
+                       if ( results.cxpublish.translationid ) {
+                               mw.cx.translationId = 
results.cxpublish.translationid;
+                       }
                } ).fail( function ( errorCode, details ) {
                        var extra;
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d5ad83307e07b146058bec51311e7745089b59e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to