Nikerabbit has uploaded a new change for review. https://gerrit.wikimedia.org/r/204520
Change subject: Make sure references templates not getting removed from source ...................................................................... Make sure references templates not getting removed from source Avoid a js error in postMT handler of translations module caused by that change. Fixes publishing of Dong_Qichang from fr to some other language which does not have a template configuration Change-Id: I60578c23b2c2863fd88bba4da2a124aa2c4dae48 --- M modules/source/ext.cx.source.filter.js M modules/translation/ext.cx.translation.js 2 files changed, 30 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/20/204520/1 diff --git a/modules/source/ext.cx.source.filter.js b/modules/source/ext.cx.source.filter.js index fe5940c..d5661a0 100644 --- a/modules/source/ext.cx.source.filter.js +++ b/modules/source/ext.cx.source.filter.js @@ -41,6 +41,20 @@ } /** + * Check if the template is references + * @param {jQuery} $template + * @return {boolean} Whether the template is references or not. + */ + function isReferences( $template ) { + if ( $template.is( '[typeof*="mw:Extension/references"]' ) || + $template.find( '[typeof*="mw:Extension/references"]' ).length ) { + return true; + } + + return false; + } + + /** * Simple check for inline templates. * @param {jQuery} $template * @return {boolean} Whether the template is inline or not. @@ -122,6 +136,13 @@ if ( isInlineTemplate( $template ) ) { mw.log( '[CX] Keeping inline template: ' + templateName ); + return; + } + // Even if the template configuration has not whitelisted the references + // template, we must keep it to get the references in published article + // working. So try to identify references template and keep it. + if ( isReferences( $template ) ) { + mw.log( '[CX] Keeping references template: ' + templateName ); } else { mw.log( '[CX] Removing template: ' + templateName ); sourceFilter.removeTemplate( $template ); diff --git a/modules/translation/ext.cx.translation.js b/modules/translation/ext.cx.translation.js index 67d71a8..b76b0b3 100644 --- a/modules/translation/ext.cx.translation.js +++ b/modules/translation/ext.cx.translation.js @@ -166,9 +166,16 @@ * @param {jQuery} $section */ ContentTranslationEditor.prototype.postProcessMT = function ( $section ) { - var selection, - $sourceSection = mw.cx.getSourceSection( $section.data( 'source' ) ); + var selection, $sourceSection; + if ( !$section || !$section.length ) { + // Empty references in some articles cause this. + // Example: See Notes section in + // https://fr.wikipedia.org/w/index.php?title=Dong_Qichang&oldid=100845438 + return; + } + + $sourceSection = mw.cx.getSourceSection( $section.data( 'source' ) ); mw.hook( 'mw.cx.translation.change' ).fire( $section ); mw.hook( 'mw.cx.translation.focus' ).fire( $section ); -- To view, visit https://gerrit.wikimedia.org/r/204520 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I60578c23b2c2863fd88bba4da2a124aa2c4dae48 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com> Gerrit-Reviewer: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits