Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/304967
Change subject: Source filter: Do not remove references list
......................................................................
Source filter: Do not remove references list
In pt.wikipedia.org, it was noticed that the references list is
created using {{ReferĂȘncias}} template. It creates an <h2> for
header and then a <div> containing reference list.
While filtering out block level templates, the <h2> is removed since
it is not a references list and while doing that the elements connected
with same about attributes are also removed, resulting removal of
reference list inside the <div>.
While doing template removal, we check if the template is reference
list or its children are reference list. If so, we do not remove
them since reference list is must for successful reference adaptation
and publishing. But we missed to check if one of the related element
with same about attribute is reference list.
This patch corrects it and keeps the reference list.
Bug: T142983
Bug: T142753
Change-Id: I89e24763f1df0fb93bb247d40032307c1016ca8d
---
M modules/source/ext.cx.source.filter.js
1 file changed, 27 insertions(+), 23 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/67/304967/1
diff --git a/modules/source/ext.cx.source.filter.js
b/modules/source/ext.cx.source.filter.js
index 75c7777..6d4c373 100644
--- a/modules/source/ext.cx.source.filter.js
+++ b/modules/source/ext.cx.source.filter.js
@@ -70,21 +70,28 @@
}
/**
- * Check if the template contains <references> transclusion
+ * Check if the template contains <references> transclusion in itself,
in
+ * its children, or in the related elements.
*
* @param {jQuery} $template
* @return {boolean} Whether the template contains <references> or not.
*/
- function hasReferences( $template ) {
- if (
- $template.is( '[typeof~="mw:Extension/references"]' ) ||
- $template.find( '[typeof~="mw:Extension/references"]'
).length
- ) {
- return true;
- }
+ CXSourceFilter.prototype.hasReferences = function ( $template ) {
+ var hasReference = false,
+ $relatedElements = this.getRelatedElements( $template );
- return false;
- }
+ $relatedElements.each( function () {
+ if (
+ $( this ).is(
'[typeof~="mw:Extension/references"]' ) ||
+ $( this ).find(
'[typeof~="mw:Extension/references"]' ).length
+ ) {
+ hasReference = true;
+ return false;
+ }
+ } );
+
+ return hasReference;
+ };
/**
* Filter the templates present in the source article based on the
configuration.
@@ -146,7 +153,7 @@
// Check whether this template contains <references>.
// If so, let it pass even without being whitelisted in
the template configuration
// because we want references to appear in the
published translation.
- if ( hasReferences( $template ) ) {
+ if ( sourceFilter.hasReferences( $template ) ) {
mw.log( '[CX] Keeping references transclusion:
' + templateName );
} else {
mw.log( '[CX] Removing template: ' +
templateName );
@@ -170,7 +177,7 @@
* @param {jQuery} $template The main element of the template.
*/
CXSourceFilter.prototype.removeTemplate = function ( $template ) {
- this.removeRelatedElements( $template );
+ this.getRelatedElements( $template ).remove();
};
/**
@@ -179,17 +186,17 @@
* @param {jQuery} $timelineMap The <map> element of the timeline.
*/
CXSourceFilter.prototype.removeTimeline = function ( $timelineMap ) {
- this.removeRelatedElements( $timelineMap );
+ this.getRelatedElements( $timelineMap ).remove();
};
/**
- * Remove a DOM element and all elements that are related to it
+ * Get a DOM element and all elements that are related to it
* according to the "about" attribute.
* See
https://www.mediawiki.org/wiki/Parsoid/MediaWiki_DOM_spec#Transclusion_content .
*
* @param {jQuery} $element
*/
- CXSourceFilter.prototype.removeRelatedElements = function ( $element ) {
+ CXSourceFilter.prototype.getRelatedElements = function ( $element ) {
var about;
// Templates and some other special elements, such as
<timeline>s,
@@ -200,15 +207,12 @@
about = $element.attr( 'about' );
if ( about ) {
- // Remove all the related elements.
- // This is supposed to include the main element,
- // because all the elements in the group are
- // supposed to have the same "about" value.
- this.$container.find( '[about="' + about + '"]'
).remove();
- } else {
- // If there is no about value, just remove this element.
- $element.remove();
+ // This will include the main element,
+ // because all the elements in the group have the same
"about" value.
+ return this.$container.find( '[about="' + about + '"]'
);
}
+ // If there is no about value, just return this element.
+ return $element;
};
CXSourceFilter.prototype.listen = function () {
--
To view, visit https://gerrit.wikimedia.org/r/304967
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I89e24763f1df0fb93bb247d40032307c1016ca8d
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