jenkins-bot has submitted this change and it was merged.
Change subject: Improve the HTML preparation before publishing
......................................................................
Improve the HTML preparation before publishing
* Make sure that no CX related classes are added to output
* Make sure there is no CX related attributes added to output,
including contenteditable attribute
* Make sure the section does not have min-height style from section
alignment
* Add QUnit tests
Bug: T134071
Bug: T111000
Change-Id: I9e496e7515b5e1846e4ea48d0b8eebe0f0917712
---
M ContentTranslation.hooks.php
M modules/publish/ext.cx.publish.js
A tests/qunit/data/draft-sample-1.html
A tests/qunit/publish/ext.cx.publish.prepare.test.js
4 files changed, 72 insertions(+), 4 deletions(-)
Approvals:
Nikerabbit: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
index 0ad8b9f..e567c87 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -351,6 +351,7 @@
$modules['qunit']['ext.cx.publish.test'] = [
'scripts' => [
'tests/qunit/publish/ext.cx.publish.test.js',
+
'tests/qunit/publish/ext.cx.publish.prepare.test.js',
],
'dependencies' => [
'ext.cx.publish',
diff --git a/modules/publish/ext.cx.publish.js
b/modules/publish/ext.cx.publish.js
index 14bc52f..2c3c79e 100644
--- a/modules/publish/ext.cx.publish.js
+++ b/modules/publish/ext.cx.publish.js
@@ -335,7 +335,7 @@
$content.find( 'link, title, .placeholder' ).remove();
$content.find( mw.cx.getSectionSelector() ).each( function () {
- var attributesToRemove, $section = $( this );
+ var attributesToRemove, classesToRemove, $section = $(
this );
// Firefox inserts <br type="_moz"> in contenteditables
while clearing the content
// to keep the height and caret.
https://bugzilla.mozilla.org/show_bug.cgi?id=414223
@@ -370,15 +370,24 @@
// Remove attributes added by CX
attributesToRemove = [ 'data-cx-weight',
'data-cx-mt-provider', 'data-cx-state',
- 'data-source', 'data-seqid', 'data-cx-draft',
'contenteditable'
- ];
+ 'data-source', 'data-sourceid', 'data-linkid',
'data-seqid', 'data-cx-draft', 'contenteditable'
+ ].join( ' ' );
+ // Remove classes added by CX
+ classesToRemove = [ 'cx-link', 'cx-target-link',
'cx-source-link', 'cx-highlight' ]
+ .join( ' ' );
// removeAttr takes a space-separated list of
attributes to remove.
- $section.removeAttr( attributesToRemove.join( ' ' ) );
+ $section.removeAttr( attributesToRemove )
+ .removeClass( classesToRemove )
+ .find( '*' )
+ .removeAttr( attributesToRemove )
+ .removeClass( classesToRemove );
// Remove identifiers added by CX
if ( $section.prop( 'id' ).indexOf( 'cx' ) === 0 ) {
$section.removeAttr( 'id' );
}
+ // Remove the min-height set by section alignment
feature.
+ $section.css( 'min-height', '' );
} );
return $content.html();
diff --git a/tests/qunit/data/draft-sample-1.html
b/tests/qunit/data/draft-sample-1.html
new file mode 100644
index 0000000..b98319a
--- /dev/null
+++ b/tests/qunit/data/draft-sample-1.html
@@ -0,0 +1,14 @@
+<p data-cx-draft="true" style="min-height: 840px;" data-cx-weight="1295"
data-cx-mt-provider="Apertium" data-source="mw0g" class="" data-seqid="472"
id="cxmw0g" contenteditable="true">
+ <span class="cx-segment" data-segmentid="473">No obstante, la situación
era frágil. </span>
+ <span class="cx-segment" data-segmentid="474">Los griegos habían
aceptado el armisticio, pero, al saber que los otomanos lo habían rechazado,
continuaban luchando. </span>
+ <span class="cx-segment" data-segmentid="475">En septiembre 1827, una
operación conjunta de las fuerzas terrestres y navales griegas tenía como
objetivo reconquistar la región de <a class="cx-link cx-target-link"
data-linkid="476" href="Mesolongi" id="mw1A" rel="mw:WikiLink"
title="Mesolongi">Missolonghi.</a> </span><span class="cx-segment"
data-segmentid="477">El filoheleno
+ <a class="cx-link cx-target-link-unadapted cx-target-link"
data-linkid="478" href="//fr.wikipedia.org/wiki/Frank_Abney_Hastings" id="mw1Q"
rel="mw:WikiLink" title="Frank Abney Hastings">Frank Abney Hastings</a> mandaba
el único barco de vapor del Mediterráneo: el <i id="mw1w"><a class="cx-link
cx-target-link-unadapted cx-target-link" data-linkid="479"
href="//fr.wikipedia.org/wiki/Karteria" id="mw2A" rel="mw:WikiLink"
title="Karteria">Karteria.</a></i> </span>
+ <span class="cx-segment" data-segmentid="480">Formaba parte de la
escuadra griega de veintitrés buques mandada por Cochrane que tenía que
sostener a las fuerzas terrestres mandadas por <a class="cx-link
cx-target-link-unadapted cx-target-link" data-linkid="481"
href="//fr.wikipedia.org/wiki/Richard_Church" id="mw2Q" rel="mw:WikiLink"
title="Richard Church">Richard Church.</a> </span><span class="cx-segment"
data-segmentid="482">El almirante británico Codrington, conforme a las
disposiciones del tratado de Londres, neutralizó pacíficamente esta flota
griega, prohibiendo la operación terrestre. </span>
+ <span class="cx-segment" data-segmentid="483">Hastings permaneció en el
<a class="cx-link cx-target-link" data-linkid="484" href="Golfo de Corinto"
id="mw2g" rel="mw:WikiLink" title="Golfo de Corinto">golfo de Corinto</a> con
una pequeña escuadra de seis navíos. </span>
+ <span class="cx-segment" data-segmentid="485">En la bahía de <a
class="cx-link cx-target-link" data-linkid="486" href="Ámfisa" id="mw2w"
rel="mw:WikiLink" title="Ámfisa">Ámfisa</a> (entonces llamada Salona), se
encontraba una flota otomana de once naves, cinco de ellas de gran tonelaje,
protegida por baterías costeras. </span>
+ <span class="cx-segment" data-segmentid="487">El <a class="cx-link
cx-target-link" data-linkid="488" href="30 de septiembre" id="mw3A"
rel="mw:WikiLink" title="30 de septiembre">30 de septiembre</a>, la escuadra
griega la atacó. </span><span class="cx-segment" data-segmentid="489">Las <a
class="cx-link cx-target-link" data-linkid="490" href="Hidráulica#La rueda
hidráulica" id="mw3Q" rel="mw:WikiLink" title="Hidráulica#La rueda
hidráulica">ruedas hidráulicas</a> de la <i id="mw3g">Kartería</i> le permitían
girar prácticamente sin moverse y sus calderas le proporcionaban balas al rojo
vivo. Ella sola destruyó en media hora todos los barcos otomanos mientras que
el resto de la escuadra eliminaba las baterías costeras.<span
data-mw="{"name":"ref","body":{"id":"mw-reference-text-cite_note-38"},"attrs":{}}"
data-sourceid="cite_ref-38" about="#mwt152" class="mw-ref" id="cxcite_ref-38"
rel="dc:references" typeof="mw:Extension/ref" contenteditable="false"><a
href="#cite_note-38" style="counter-reset: mw-Ref 30;"><span
class="mw-reflink-text">[30]</span></a>
+ </span><span
data-mw="{"name":"ref","body":{"id":"mw-reference-text-cite_note-Brewer237-39"},"attrs":{"name":"Brewer237"}}"
data-sourceid="cite_ref-Brewer237_39-0" about="#mwt155" class="mw-ref"
id="cxcite_ref-Brewer237_39-0" rel="dc:references" typeof="mw:Extension/ref"
contenteditable="false"><a href="#cite_note-Brewer237-39" style="counter-reset:
mw-Ref 31;"><span class="mw-reflink-text">[31]</span></a>
+ </span><span
data-mw="{"name":"ref","body":{"id":"mw-reference-text-cite_note-40"},"attrs":{}}"
data-sourceid="cite_ref-40" about="#mwt158" class="mw-ref" id="cxcite_ref-40"
rel="dc:references" typeof="mw:Extension/ref" contenteditable="false"><a
href="#cite_note-40" style="counter-reset: mw-Ref 32;"><span
class="mw-reflink-text">[32]</span></a>
+ </span>
+ </span>
+</p>
diff --git a/tests/qunit/publish/ext.cx.publish.prepare.test.js
b/tests/qunit/publish/ext.cx.publish.prepare.test.js
new file mode 100644
index 0000000..467fb48
--- /dev/null
+++ b/tests/qunit/publish/ext.cx.publish.prepare.test.js
@@ -0,0 +1,44 @@
+/*!
+ * QUnit tests for Content Translation.
+ *
+ * @ingroup Extensions
+ * @licence GPL-2.0+
+ */
+
+( function ( $, mw ) {
+ 'use strict';
+
+ var testDataPath = mw.config.get( 'wgExtensionAssetsPath' ) +
+ '/ContentTranslation/tests/qunit/data/';
+ QUnit.module( 'ext.cx.publish.prepare', QUnit.newMwEnvironment( {
+ setup: function () {
+ this.sitemapper = new mw.cx.SiteMapper(
+ mw.config.get(
'wgContentTranslationSiteTemplates' )
+ );
+ }
+ } ) );
+
+ QUnit.test( 'Prepare draft for publish', function ( assert ) {
+ var $fixture = $( '#qunit-fixture' );
+
+ QUnit.expect( 5 );
+ QUnit.stop();
+ $fixture.load( testDataPath + 'draft-sample-1.html', function
() {
+ var cleanedHTML, publisher;
+
+ publisher = new mw.cx.publish();
+ cleanedHTML = publisher.prepareTranslationForPublish(
$fixture );
+ assert.strictEqual( $( cleanedHTML ).find(
'[contenteditable]' ).length, 0,
+ 'No contenteditable attributes left' );
+ assert.strictEqual( $( cleanedHTML ).find(
'[data-cx-draft]' ).length, 0,
+ 'No data-cx-draft attributes left' );
+ assert.strictEqual( $( cleanedHTML ).find(
'.cx-segment' ).length, 0,
+ 'No element has cx-segment class' );
+ assert.strictEqual( $( cleanedHTML ).find( '.cx-link'
).length, 0,
+ 'No element has cx-link class' );
+ assert.strictEqual( $( cleanedHTML ).css( 'min-height'
), '',
+ 'Section has no min-height' );
+ QUnit.start();
+ } );
+ } );
+}( jQuery, mediaWiki ) );
--
To view, visit https://gerrit.wikimedia.org/r/294030
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9e496e7515b5e1846e4ea48d0b8eebe0f0917712
Gerrit-PatchSet: 4
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