Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/276715
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.
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
Change-Id: I45e63b31ac3d501f75cc101dc6b29a2025337846
---
M modules/translation/ext.cx.translation.loader.js
M tests/qunit/translation/ext.cx.translation.loader.test.js
2 files changed, 14 insertions(+), 3 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/15/276715/1
diff --git a/modules/translation/ext.cx.translation.loader.js
b/modules/translation/ext.cx.translation.loader.js
index 31a92bb..6a7b493 100644
--- a/modules/translation/ext.cx.translation.loader.js
+++ b/modules/translation/ext.cx.translation.loader.js
@@ -17,6 +17,7 @@
this.$sourceColumn = null;
this.$translationColumn = null;
this.disabled = false;
+ this.oldRevision = false;
}
/**
@@ -102,7 +103,12 @@
self.restore();
mw.hook( 'mw.cx.draft.restored' ).fire();
if ( self.translation.sourceRevisionId !==
mw.cx.sourceRevision ) {
+ // Show a message to translator that we
loaded an older revision of
+ // source article.
self.showOldRevisionWarning();
+ // Since we are using older revision,
use agressive section restore
+ // algorithm.
+ self.oldRevision = true;
}
} );
}, function ( errorCode, details ) {
@@ -200,7 +206,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.oldRevision && $lastRestoredSection
&& $lastRestoredSection.length ) {
$lastRestoredSection =
this.addOprhanTranslationUnit(
sourceSectionId,
$lastRestoredSection, 'after'
);
@@ -213,6 +219,10 @@
$lastRestoredSection = $restoredSection;
// As a last resort, if we did not add orphans
immediately, add them
// now before this section.
+ if ( !this.oldRevision ) {
+ // 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 +233,7 @@
}
}
- if ( orphans.length ) {
+ if ( orphans.length && !this.oldRevision ) {
mw.log( 'Draft restoration failed. Loading older
revision.' );
window.location = mw.cx.siteMapper.getCXUrl(
mw.cx.sourceTitle,
diff --git a/tests/qunit/translation/ext.cx.translation.loader.test.js
b/tests/qunit/translation/ext.cx.translation.loader.test.js
index 24055b7..1a3910a 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.oldRevision = 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: newchange
Gerrit-Change-Id: I45e63b31ac3d501f75cc101dc6b29a2025337846
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