jenkins-bot has submitted this change and it was merged.

Change subject: Do not attempt adding orphan section unless source article is 
old revision
......................................................................


Do not attempt adding orphan section unless source article is old revision

We are attempting orphan section fitting in lastest revision and if that
fails we load old revision of source.

We are changing that behavior. The orphan section fitting will be attempted
only on old source revision.

So the improvised translation reload steps are:
1. Try to find matching source section ids and restore translation against it
2. Try to find matching sequence Id in source and restore translation against it
3. Load the source article's revision that was used for the translation. and 
attempt
   step #1 and #2
4. If the source article is old revision, add orphan sections in translation 
column
   when #1 and #2 failed.

Translation drafts that are months old will not have source revision id in CX 
database.
Such translations will be treated as translations with source article is not 
changed,
and section restore algorithm will be applied.

Testplan:
1. Start translating a new article. When in transtlation view, without adding
   any sections, in URL add revision=an_old_revision param. So the original
   translation becomes based on that revision.
2. Translate some sections
3. Refresh the page. Observer that all sections are restored. Also note a 
warning
   that you are translating an older revision of the source article.
4. Go to dashboard and restore the translation. Observer that there is no 
revision
   param in URL. Observe the 'restoring...' indicator. You should see that page 
get
   reloaded with revision param in URL. The revision id will be the revision of
   original source article. Observe that all sections are restored properly

Bug: T130178
Change-Id: I45e63b31ac3d501f75cc101dc6b29a2025337846
---
M modules/translation/ext.cx.translation.loader.js
M modules/translation/ext.cx.translation.storage.js
M tests/qunit/translation/ext.cx.translation.loader.test.js
3 files changed, 32 insertions(+), 8 deletions(-)

Approvals:
  Nikerabbit: Checked; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/translation/ext.cx.translation.loader.js 
b/modules/translation/ext.cx.translation.loader.js
index 31a92bb..4291b22 100644
--- a/modules/translation/ext.cx.translation.loader.js
+++ b/modules/translation/ext.cx.translation.loader.js
@@ -16,7 +16,7 @@
                this.translationUnits = null;
                this.$sourceColumn = null;
                this.$translationColumn = null;
-               this.disabled = false;
+               this.originalRevision = false;
        }
 
        /**
@@ -38,7 +38,6 @@
                                translation.status === 'draft'
                        ) {
                                self.showConflictWarning( translation );
-                               self.disabled = true;
                                return false;
                        }
                        // Set the translationId
@@ -99,9 +98,19 @@
                                self.translationUnits = 
self.getTranslationUnits( self.translationUnits );
                        }
                        mw.hook( 'mw.cx.translation.placeholders.ready' ).add( 
function () {
+                               if ( parseInt( 
self.translation.sourceRevisionId ) === parseInt( mw.cx.sourceRevision ) ||
+                                       // Very old drafts will have revision 
id as 0. Consider them as original source for
+                                       // the translation and use agressive 
section restore algorithm
+                                       parseInt( 
self.translation.sourceRevisionId ) === 0
+                               ) {
+                                       // Since we are using older revision, 
the original revision used for translation,
+                                       // use agressive section restore 
algorithm.
+                                       self.originalRevision = true;
+                               }
                                self.restore();
-                               mw.hook( 'mw.cx.draft.restored' ).fire();
-                               if ( self.translation.sourceRevisionId !== 
mw.cx.sourceRevision ) {
+                               if ( self.originalRevision && new 
mw.Uri().query.revision ) {
+                                       // Show a message to translator that we 
loaded an older revision of
+                                       // source article.
                                        self.showOldRevisionWarning();
                                }
                        } );
@@ -125,7 +134,7 @@
 
                diffUrl = mw.cx.siteMapper.getPageUrl( mw.cx.sourceLanguage, 
mw.cx.sourceTitle, {
                        type: 'revision',
-                       diff: mw.cx.sourceRevision,
+                       diff: 'cur',
                        oldid: this.translation.sourceRevisionId
                } );
                mw.hook( 'mw.cx.warning' ).fire( mw.message( 
'cx-page-old-revision-loaded', diffUrl ) );
@@ -200,7 +209,7 @@
                        if ( !$restoredSection ) {
                                mw.log( 'Source section not found for ' + 
sourceSectionId );
                                // Insert right after last matched section if 
possible
-                               if ( $lastRestoredSection && 
$lastRestoredSection.length ) {
+                               if ( this.originalRevision && 
$lastRestoredSection && $lastRestoredSection.length ) {
                                        $lastRestoredSection = 
this.addOprhanTranslationUnit(
                                                sourceSectionId, 
$lastRestoredSection, 'after'
                                        );
@@ -213,6 +222,10 @@
                                $lastRestoredSection = $restoredSection;
                                // As a last resort, if we did not add orphans 
immediately, add them
                                // now before this section.
+                               if ( !this.originalRevision ) {
+                                       // Dont use orphan sections unless we 
are using old source article
+                                       continue;
+                               }
                                for ( i = 0; i < orphans.length; i++ ) {
                                        $lastRestoredSection = 
this.addOprhanTranslationUnit( orphans[ i ], $lastRestoredSection );
                                        if ( $restoredSection && 
$restoredSection.length ) {
@@ -223,7 +236,7 @@
                        }
                }
 
-               if ( orphans.length ) {
+               if ( orphans.length && !this.originalRevision ) {
                        mw.log( 'Draft restoration failed. Loading older 
revision.' );
                        window.location = mw.cx.siteMapper.getCXUrl(
                                mw.cx.sourceTitle,
@@ -233,6 +246,8 @@
                                null, // campaign
                                this.translation.sourceRevisionId
                        );
+               } else {
+                       mw.hook( 'mw.cx.draft.restored' ).fire();
                }
 
                mw.hook( 'mw.cx.translation.continued' ).fire(
diff --git a/modules/translation/ext.cx.translation.storage.js 
b/modules/translation/ext.cx.translation.storage.js
index 365d103..a64c338 100644
--- a/modules/translation/ext.cx.translation.storage.js
+++ b/modules/translation/ext.cx.translation.storage.js
@@ -85,6 +85,14 @@
 
                mw.hook( 'mw.cx.translation.save' ).add( $.proxy( this.save, 
this ) );
 
+               mw.hook( 'mw.cx.draft.restoring' ).add( function () {
+                       // Do not save while restoring is being attempted
+                       self.disabled = true;
+               } );
+               mw.hook( 'mw.cx.draft.restored' ).add( function () {
+                       self.disabled = false;
+               } );
+
                // Save when CTRL+S is pressed.
                $( document ).on( 'keydown', function ( e ) {
                        // See 
https://medium.com/medium-eng/the-curious-case-of-disappearing-polish-s-fa398313d4df
diff --git a/tests/qunit/translation/ext.cx.translation.loader.test.js 
b/tests/qunit/translation/ext.cx.translation.loader.test.js
index 24055b7..f9eeb68 100644
--- a/tests/qunit/translation/ext.cx.translation.loader.test.js
+++ b/tests/qunit/translation/ext.cx.translation.loader.test.js
@@ -52,7 +52,8 @@
        QUnit.test( 'Translation daft restore test', function ( assert ) {
                var i;
                QUnit.expect( tests.length );
-
+               // Without old revision flag set true, orphan sections wont get 
added.
+               this.translatonLoader.originalRevision = true;
                for ( i = 0; i < tests.length; i++ ) {
                        this.translatonLoader.translationUnits = 
this.translatonLoader.getTranslationUnits( tests[ i ].draft );
                        this.translatonLoader.$sourceColumn = $( tests[ i 
].source );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I45e63b31ac3d501f75cc101dc6b29a2025337846
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Nikerabbit <[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

Reply via email to