Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/294030
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
Change-Id: I9e496e7515b5e1846e4ea48d0b8eebe0f0917712
---
M ContentTranslation.hooks.php
M modules/publish/ext.cx.publish.js
A tests/qunit/publish/ext.cx.publish.prepare.test.js
3 files changed, 57 insertions(+), 4 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/30/294030/1
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..1a91cdc 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,23 @@
// 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' ].join( ' ' );
// removeAttr takes a space-separated list of
attributes to remove.
- $section.removeAttr( attributesToRemove.join( ' ' ) );
+ $section.removeAttr( attributesToRemove )
+ .removeClass( classesToRemove )
+ .find( '*' )
+ .removeClass( classesToRemove )
+ .removeAttr( attributesToRemove );
// 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/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: newchange
Gerrit-Change-Id: I9e496e7515b5e1846e4ea48d0b8eebe0f0917712
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