Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/194468
Change subject: References: Update the implementaiton to match new Parsoid
output
......................................................................
References: Update the implementaiton to match new Parsoid output
In T88290, parsoid changed the way references are handled. Instead
of keeping the reference content(the HTML corresponding to reference),
now it is in references list.
* Updated the way reference content is accessed and shown in reference card
* Make sure reference list is added to translation when a section with
at least one reference is added to translation.
Bug: T90776
Change-Id: If0e23faeaf5a240b32fbd795521e493df47f0ad1
---
M modules/tools/ext.cx.tools.reference.js
M modules/translation/ext.cx.translation.js
2 files changed, 39 insertions(+), 6 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/68/194468/1
diff --git a/modules/tools/ext.cx.tools.reference.js
b/modules/tools/ext.cx.tools.reference.js
index daab04d..264b81c 100644
--- a/modules/tools/ext.cx.tools.reference.js
+++ b/modules/tools/ext.cx.tools.reference.js
@@ -85,26 +85,57 @@
};
/**
+ * Get the reference content for the given reference Id.
+ * The content is taken from the reference list section , linked
+ * by mw-data.body.id. See T88290
+ * @param {string} referenceId The reference element Identifier.
+ * @return {string} The HTML content of the reference.
+ */
+ ReferenceCard.prototype.getReferenceContent = function ( referenceId ) {
+ var reference, referenceContentElement;
+
+ reference = this.getReferenceData( referenceId );
+ if ( !reference || !reference.body ) {
+ return null;
+ }
+ referenceContentElement = document.getElementById(
reference.body.id );
+
+ return referenceContentElement &&
referenceContentElement.outerHTML;
+ };
+
+ /**
+ * Add the reference list, usually at the end of translation
+ */
+ ReferenceCard.prototype.addReferenceList = function () {
+ var $referenceList;
+
+ $referenceList = $( '[typeof*="mw:Extension/references"]' );
+
+ if ( $referenceList.length === 1 ) {
+ // Only one reference list - means the target reference
list not added yet.
+ mw.hook( 'mw.cx.translation.add' ).fire(
$referenceList.parent().attr( 'id' ), 'click' );
+ }
+ };
+ /**
* Start presenting the reference card
* @param {string} referenceId The reference element Identifier.
* @param {string} language Language code of language where this
reference exist.
*/
ReferenceCard.prototype.start = function ( referenceId, language ) {
- var $sourceReference, $targetReference, reference;
+ var $sourceReference, $targetReference, referenceContent;
// Reference Ids are weird strings like "cite_ref-12-0", jquery
fails to do look up with them
$sourceReference = $( document.getElementById( referenceId ) );
$targetReference = $( document.getElementById( 'cx' +
referenceId ) );
- reference = this.getReferenceData( referenceId );
-
- if ( !reference ) {
+ referenceContent = this.getReferenceContent( referenceId );
+ if ( !referenceContent ) {
this.stop();
return;
}
this.$card.find( '.card__reference-number' )
.text( $sourceReference.text() );
this.$card.find( '.card__reference-content' )
- .html( reference.body.html );
+ .html( referenceContent );
if ( $targetReference.length ) {
this.$reference = $targetReference;
this.$removeReference.on( 'click', $.proxy(
this.removeReference, this ) );
@@ -217,6 +248,7 @@
$referenceContent.children().attr( 'data-mw', JSON.stringify(
adaptedData ) );
mwData.body.html = $referenceContent.html();
$targetReference.attr( 'data-mw', JSON.stringify( mwData ) );
+ this.addReferenceList();
};
function referenceClickHandler() {
@@ -256,7 +288,6 @@
$sourceSection = mw.cx.getSourceSection( $section.data(
'source' ) );
$section.attr( 'data-mw', JSON.stringify(
$sourceSection.data( 'mw' ) ) );
}
-
}
mw.cx.tools.reference = ReferenceCard;
diff --git a/modules/translation/ext.cx.translation.js
b/modules/translation/ext.cx.translation.js
index 7e40e42..2be5fc2 100644
--- a/modules/translation/ext.cx.translation.js
+++ b/modules/translation/ext.cx.translation.js
@@ -317,6 +317,8 @@
mw.cx.getSourceSection( sourceSectionId ).removeClass(
'cx-highlight' );
// Fill in the preceding parent heading, if not yet filled
+ // TODO: This must be triggerd by 'mw.cx.translation.add' hook
and not by
+ // a click to allow programmatically add sections and get
consistent behavior
if (
$previousSection.is( '.placeholder' ) &&
ContentTranslationEditor.isParentHeading(
--
To view, visit https://gerrit.wikimedia.org/r/194468
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If0e23faeaf5a240b32fbd795521e493df47f0ad1
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