Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/138777
Change subject: Blacklist all templates for the source article ...................................................................... Blacklist all templates for the source article Do not present them to translator. In follow up commits, we will selectively enable them Change-Id: Ib634f4e1c4f2b944efa41692f5055ba1d520561e --- M Resources.php A modules/source/conf/en-es.json A modules/source/conf/es-ca.json A modules/source/ext.cx.source.filter.js M modules/source/ext.cx.source.js M modules/translation/ext.cx.translation.js 6 files changed, 87 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/77/138777/1 diff --git a/Resources.php b/Resources.php index ed368a6..7219cca 100644 --- a/Resources.php +++ b/Resources.php @@ -56,7 +56,10 @@ ) + $resourcePaths; $wgResourceModules['ext.cx.source'] = array( - 'scripts' => 'source/ext.cx.source.js', + 'scripts' => array( + 'source/ext.cx.source.js', + 'source/ext.cx.source.filter.js' + ), 'styles' => array( 'source/styles/ext.cx.source.less', ), diff --git a/modules/source/conf/en-es.json b/modules/source/conf/en-es.json new file mode 100644 index 0000000..bcf487e --- /dev/null +++ b/modules/source/conf/en-es.json @@ -0,0 +1,3 @@ +{ + "enabled": [] +} diff --git a/modules/source/conf/es-ca.json b/modules/source/conf/es-ca.json new file mode 100644 index 0000000..bcf487e --- /dev/null +++ b/modules/source/conf/es-ca.json @@ -0,0 +1,3 @@ +{ + "enabled": [] +} diff --git a/modules/source/ext.cx.source.filter.js b/modules/source/ext.cx.source.filter.js new file mode 100644 index 0000000..fadb89a --- /dev/null +++ b/modules/source/ext.cx.source.filter.js @@ -0,0 +1,72 @@ +/** + * ContentTranslation Tools + * A tool that allows editors to translate pages from one language + * to another with the help of machine translation and other translation tools + * + * @file + * @ingroup Extensions + * @copyright See AUTHORS.txt + * @license GPL-2.0+ + */ +( function ( $, mw ) { + 'use strict'; + + /** + * Fetch the source content filter configuration for the given + * language pairs + */ + function fetchFilterConfiguration( sourceLanguage, targetLanguage ) { + return $.getJSON( mw.config.get( 'wgExtensionAssetsPath' ) + + '/ContentTranslation/modules/source/conf/' + sourceLanguage + '-' + targetLanguage + '.json' ); + } + + /** + * CXSourceFilter + * + * @class + */ + function CXSourceFilter( element ) { + this.$container = $( element ); + this.listen(); + } + + CXSourceFilter.prototype.filter = function ( configuration ) { + $( '[typeof="mw:Transclusion"]' ).each( function () { + var templateName = $( this ).data( 'mw' ).parts[ 0 ].template.target.wt; + if ( configuration.enabled && configuration.enabled.indexOf( templateName ) >= 0 ) { + mw.log( '[CX] Keeping template:' + templateName ); + } else { + mw.log( '[CX] Removing template:' + templateName ); + $( this ).remove(); + } + } ); + mw.hook( 'mw.cx.source.ready' ).fire(); + }; + + CXSourceFilter.prototype.listen = function () { + var filter = this; + mw.hook( 'mw.cx.source.loaded' ).add( function () { + fetchFilterConfiguration( mw.cx.sourceLanguage, mw.cx.targetLanguage ).done( function ( configuration ) { + filter.filter( configuration ); + } ).fail( function () { + filter.filter(); + } ); + } ); + }; + + $.fn.cxFilterSource = function () { + return this.each( function () { + var $this = $( this ), + data = $this.data( 'cxSourceFilter' ); + + if ( !data ) { + $this.data( + 'cxSourceFilter', ( data = new CXSourceFilter( this ) ) + ); + } + + } ); + }; + + $.fn.cxSource.defaults = {}; +}( jQuery, mediaWiki ) ); diff --git a/modules/source/ext.cx.source.js b/modules/source/ext.cx.source.js index 20cc248..5b14dbc 100644 --- a/modules/source/ext.cx.source.js +++ b/modules/source/ext.cx.source.js @@ -22,7 +22,7 @@ $.get( mw.config.get( 'wgContentTranslationServerURL' ) + '/page/' + language + '/' + title ) .done( function ( response ) { mw.cx.data = response; - mw.hook( 'mw.cx.source.ready' ).fire(); + mw.hook( 'mw.cx.source.loaded' ).fire(); } ).fail( function () { $( '.cx-header__infobar' ) .text( mw.msg( 'cx-error-server-connection' ) ) @@ -95,7 +95,7 @@ }; ContentTranslationSource.prototype.load = function () { - this.$content.html( mw.cx.data.segmentedContent ); + this.$content.html( mw.cx.data.segmentedContent ).cxFilterSource(); // @todo figure out what should be done here this.$content.find( 'base' ).detach(); @@ -103,7 +103,7 @@ // Disable all links this.disableLinks(); - mw.hook( 'mw.cx.source.loaded' ).fire(); + mw.hook( 'mw.cx.source.ready' ).fire(); }; /** @@ -122,7 +122,7 @@ }; ContentTranslationSource.prototype.listen = function () { - mw.hook( 'mw.cx.source.ready' ).add( $.proxy( this.load, this ) ); + mw.hook( 'mw.cx.source.loaded' ).add( $.proxy( this.load, this ) ); this.$content.on( 'click', function () { var selection = window.getSelection().toString(); diff --git a/modules/translation/ext.cx.translation.js b/modules/translation/ext.cx.translation.js index 74995f4..e0acbbd 100644 --- a/modules/translation/ext.cx.translation.js +++ b/modules/translation/ext.cx.translation.js @@ -81,7 +81,7 @@ ContentTranslationEditor.prototype.listen = function () { mw.hook( 'mw.cx.translation.add' ).add( $.proxy( this.update, this ) ); - mw.hook( 'mw.cx.source.loaded' ).add( $.proxy( this.addPlaceholders, this ) ); + mw.hook( 'mw.cx.source.ready' ).add( $.proxy( this.addPlaceholders, this ) ); }; /** -- To view, visit https://gerrit.wikimedia.org/r/138777 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib634f4e1c4f2b944efa41692f5055ba1d520561e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits