jenkins-bot has submitted this change and it was merged.
Change subject: Store original DOM elements of transclusions
......................................................................
Store original DOM elements of transclusions
Prevents changing of DOM attributes on unmodified transclusions
as they can clash in the store.
Also use 'original' over 'orig' consistently.
Bug: 50079
Change-Id: Ib13bb206c49b1f5b186e40632a5c109def0f042e
---
M modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js
M modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
M modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js
M modules/ve/test/dm/ve.dm.example.js
4 files changed, 165 insertions(+), 99 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js
b/modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js
index c1698c8..bd5f82d 100644
--- a/modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js
+++ b/modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js
@@ -43,7 +43,7 @@
'type': this.name,
'attributes': {
'mw': mwData,
- 'origMw': mwDataJSON,
+ 'originalMw': mwDataJSON,
'about': domElements[0].getAttribute( 'about' ),
'domElements': ve.copyArray( domElements ),
'refGroup': refGroup,
@@ -53,7 +53,7 @@
};
ve.dm.MWReferenceListNode.static.toDomElements = function ( dataElement, doc )
{
- var el, els, mwData, origMw,
+ var el, els, mwData, originalMw,
attribs = dataElement.attributes;
if ( attribs.domElements ) {
@@ -80,11 +80,11 @@
}
el.setAttribute( 'typeof', 'mw:Extension/references' );
- // If mwData and origMw are the same, use origMw to prevent
reserialization.
+ // If mwData and originalMw are the same, use originalMw to prevent
reserialization.
// Reserialization has the potential to reorder keys and so change the
DOM unnecessarily
- origMw = attribs.origMw;
- if ( origMw && ve.compare( mwData, JSON.parse( origMw ) ) ) {
- el.setAttribute( 'data-mw', origMw );
+ originalMw = attribs.originalMw;
+ if ( originalMw && ve.compare( mwData, JSON.parse( originalMw ) ) ) {
+ el.setAttribute( 'data-mw', originalMw );
} else {
el.setAttribute( 'data-mw', JSON.stringify( mwData ) );
}
diff --git a/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
b/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
index a90ee43..37c6589 100644
--- a/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
+++ b/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
@@ -56,7 +56,7 @@
'type': this.name,
'attributes': {
'mw': mwData,
- 'origMw': mwDataJSON,
+ 'originalMw': mwDataJSON,
'about': about,
'listIndex': listIndex,
'listGroup': listGroup,
@@ -69,7 +69,7 @@
};
ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc,
converter ) {
- var itemNodeHtml, mwData, i, iLen, keyedNodes, setContents, origMw,
+ var itemNodeHtml, mwData, i, iLen, keyedNodes, setContents, originalMw,
el = doc.createElement( 'span' ),
itemNodeWrapper = doc.createElement( 'div' ),
itemNode = converter.internalList.getItemNode(
dataElement.attributes.listIndex ),
@@ -125,11 +125,11 @@
delete mwData.attrs.refGroup;
}
- // If mwAttr and origMw are the same, use origMw to prevent
reserialization.
+ // If mwAttr and originalMw are the same, use originalMw to prevent
reserialization.
// Reserialization has the potential to reorder keys and so change the
DOM unnecessarily
- origMw = dataElement.attributes.origMw;
- if ( origMw && ve.compare( mwData, JSON.parse( origMw ) ) ) {
- el.setAttribute( 'data-mw', origMw );
+ originalMw = dataElement.attributes.originalMw;
+ if ( originalMw && ve.compare( mwData, JSON.parse( originalMw ) ) ) {
+ el.setAttribute( 'data-mw', originalMw );
} else {
el.setAttribute( 'data-mw', JSON.stringify( mwData ) );
}
diff --git a/modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js
b/modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js
index 6750060..b6d96c1 100644
--- a/modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js
+++ b/modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js
@@ -69,7 +69,8 @@
'type': type,
'attributes': {
'mw': mwData,
- 'origMw': mwDataJSON
+ 'originalDomElements': ve.copyArray( domElements ),
+ 'originalMw': mwDataJSON
}
};
@@ -82,16 +83,16 @@
ve.dm.MWTransclusionNode.static.toDomElements = function ( dataElement, doc,
converter ) {
var el,
index = converter.getStore().indexOfHash( ve.getHash(
this.getHashObject( dataElement ) ) ),
- origMw = dataElement.attributes.origMw;
+ originalMw = dataElement.attributes.originalMw;
// If the transclusion is unchanged just send back the
// original DOM elements so selser can skip over it
if (
index === dataElement.attributes.originalIndex ||
- ( origMw && ve.compare( dataElement.attributes.mw, JSON.parse(
origMw ) ) )
+ ( originalMw && ve.compare( dataElement.attributes.mw,
JSON.parse( originalMw ) ) )
) {
// The object in the store is also used for CE rendering so
return a copy
- return ve.copyDomElements( converter.getStore().value( index ),
doc );
+ return ve.copyDomElements(
dataElement.attributes.originalDomElements, doc );
} else {
el = doc.createElement( 'span' );
// All we need to send back to Parsoid is the original
transclusion marker, with a
diff --git a/modules/ve/test/dm/ve.dm.example.js
b/modules/ve/test/dm/ve.dm.example.js
index 3a7c12c..64a9fec 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -860,82 +860,87 @@
'blockSpan': '<span about="#mwt1" typeof="mw:Transclusion"
data-mw="{"target":{"wt":"Test"},"params":{"1":{"wt":"Hello,
world!"}},"id":"mwt1"}"
data-parsoid="{"tsr":[18,40],"src":"{{Test|Hello,
world!}}","dsr":[18,40,null,null]}"></span>',
'blockSpanModified': '<span about="#mwt1" typeof="mw:Transclusion"
data-mw="{"id":"mwt1","target":{"wt":"Test"},"params":{"1":{"wt":"Hello,
globe!"}}}"
data-parsoid="{"tsr":[18,40],"src":"{{Test|Hello,
world!}}","dsr":[18,40,null,null]}"></span>',
'blockContent': '<p about="#mwt1" data-parsoid="{}">Hello, world!</p>',
- 'blockData': {
- 'type': 'mwTransclusionBlock',
- 'attributes': {
- 'mw': {
- 'id': 'mwt1',
- 'target': { 'wt' : 'Test' },
- 'params': {
- '1': { 'wt': 'Hello, world!' }
- }
- },
- 'origMw':
'{\"target\":{\"wt\":\"Test\"},\"params\":{\"1\":{\"wt\":\"Hello,
world!\"}},\"id\":\"mwt1\"}',
- 'originalIndex': 0
- },
- 'htmlAttributes': [
- { 'values': {
- 'about': '#mwt1',
- 'data-mw':
'{\"target\":{\"wt\":\"Test\"},\"params\":{\"1\":{\"wt\":\"Hello,
world!\"}},\"id\":\"mwt1\"}',
- 'data-parsoid':
'{\"tsr\":[18,40],\"src\":\"{{Test|Hello,
world!}}\",\"dsr\":[18,40,null,null]}',
- 'typeof': 'mw:Transclusion'
- } },
- { 'values': {
- 'about': '#mwt1',
- 'data-parsoid': '{}'
- } }
- ]
- },
'inlineOpen': '<span about="#mwt1" typeof="mw:Transclusion"
data-mw="{"id":"mwt1","target":{"wt":"Inline"},"params":{"1":{"wt":"1,234"}}}"
data-parsoid="{"tsr":[18,34],"src":"{{Inline|1,234}}","dsr":[18,34,null,null]}">',
'inlineOpenModified': '<span about="#mwt1" typeof="mw:Transclusion"
data-mw="{"id":"mwt1","target":{"wt":"Inline"},"params":{"1":{"wt":"5,678"}}}"
data-parsoid="{"tsr":[18,34],"src":"{{Inline|1,234}}","dsr":[18,34,null,null]}">',
'inlineContent': '$1,234.00',
'inlineClose': '</span>',
- 'inlineData': {
- 'type': 'mwTransclusionInline',
- 'attributes': {
- 'mw': {
- 'id': 'mwt1',
- 'target': { 'wt' : 'Inline' },
- 'params': {
- '1': { 'wt': '1,234' }
- }
- },
- 'origMw':
'{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"1,234\"}}}',
- 'originalIndex': 0
- },
- 'htmlAttributes': [ { 'values': {
- 'about': '#mwt1',
- 'data-mw':
'{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"1,234\"}}}',
- 'data-parsoid':
'{\"tsr\":[18,34],\"src\":\"{{Inline|1,234}}\",\"dsr\":[18,34,null,null]}',
- 'typeof': 'mw:Transclusion'
- } } ]
- },
'mixed': '<link about="#mwt1" rel="mw:WikiLink/Category"
typeof="mw:Transclusion"
data-mw="{"id":"mwt1","target":{"wt":"Inline"},"params":{"1":{"wt":"5,678"}}}"><span
about="#mwt1">Foo</span>',
- 'mixedDataOpen': {
- 'type': 'mwTransclusionInline',
- 'attributes': {
- 'mw': {
- 'id': 'mwt1',
- 'target': { 'wt': 'Inline' },
- 'params': {
- '1': { 'wt': '5,678' }
- }
- },
- 'origMw':
'{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"5,678\"}}}',
- 'originalIndex': 0
- },
- 'htmlAttributes': [
- { 'values': {
- 'about': '#mwt1',
- 'rel': 'mw:WikiLink/Category',
- 'typeof': 'mw:Transclusion',
- 'data-mw':
'{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"5,678\"}}}'
- } },
- { 'values': { 'about': '#mwt1' } }
- ]
- },
- 'mixedDataClose' : { 'type': '/mwTransclusionInline' }
+ 'pairOne': '<p about="#mwt1" typeof="mw:Transclusion"
data-mw="{"params":{"1":{"wt":"foo"}}}"
data-parsoid="1">foo</p>',
+ 'pairTwo': '<p about="#mwt2" typeof="mw:Transclusion"
data-mw="{"params":{"1":{"wt":"foo"}}}"
data-parsoid="2">foo</p>'
};
+ve.dm.example.MWTransclusion.blockData = {
+ 'type': 'mwTransclusionBlock',
+ 'attributes': {
+ 'mw': {
+ 'id': 'mwt1',
+ 'target': { 'wt' : 'Test' },
+ 'params': {
+ '1': { 'wt': 'Hello, world!' }
+ }
+ },
+ 'originalDomElements': $(
ve.dm.example.MWTransclusion.blockSpan +
ve.dm.example.MWTransclusion.blockContent ).toArray(),
+ 'originalMw':
'{\"target\":{\"wt\":\"Test\"},\"params\":{\"1\":{\"wt\":\"Hello,
world!\"}},\"id\":\"mwt1\"}',
+ 'originalIndex': 0
+ },
+ 'htmlAttributes': [
+ { 'values': {
+ 'about': '#mwt1',
+ 'data-mw':
'{\"target\":{\"wt\":\"Test\"},\"params\":{\"1\":{\"wt\":\"Hello,
world!\"}},\"id\":\"mwt1\"}',
+ 'data-parsoid':
'{\"tsr\":[18,40],\"src\":\"{{Test|Hello,
world!}}\",\"dsr\":[18,40,null,null]}',
+ 'typeof': 'mw:Transclusion'
+ } },
+ { 'values': {
+ 'about': '#mwt1',
+ 'data-parsoid': '{}'
+ } }
+ ]
+};
+ve.dm.example.MWTransclusion.inlineData = {
+ 'type': 'mwTransclusionInline',
+ 'attributes': {
+ 'mw': {
+ 'id': 'mwt1',
+ 'target': { 'wt' : 'Inline' },
+ 'params': {
+ '1': { 'wt': '1,234' }
+ }
+ },
+ 'originalDomElements': $(
ve.dm.example.MWTransclusion.inlineOpen +
ve.dm.example.MWTransclusion.inlineContent +
ve.dm.example.MWTransclusion.inlineClose ).toArray(),
+ 'originalMw':
'{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"1,234\"}}}',
+ 'originalIndex': 0
+ },
+ 'htmlAttributes': [ { 'values': {
+ 'about': '#mwt1',
+ 'data-mw':
'{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"1,234\"}}}',
+ 'data-parsoid':
'{\"tsr\":[18,34],\"src\":\"{{Inline|1,234}}\",\"dsr\":[18,34,null,null]}',
+ 'typeof': 'mw:Transclusion'
+ } } ]
+};
+ve.dm.example.MWTransclusion.mixedDataOpen = {
+ 'type': 'mwTransclusionInline',
+ 'attributes': {
+ 'mw': {
+ 'id': 'mwt1',
+ 'target': { 'wt': 'Inline' },
+ 'params': {
+ '1': { 'wt': '5,678' }
+ }
+ },
+ 'originalDomElements': $( ve.dm.example.MWTransclusion.mixed
).toArray(),
+ 'originalMw':
'{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"5,678\"}}}',
+ 'originalIndex': 0
+ },
+ 'htmlAttributes': [
+ { 'values': {
+ 'about': '#mwt1',
+ 'rel': 'mw:WikiLink/Category',
+ 'typeof': 'mw:Transclusion',
+ 'data-mw':
'{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"5,678\"}}}'
+ } },
+ { 'values': { 'about': '#mwt1' } }
+ ]
+};
+ve.dm.example.MWTransclusion.mixedDataClose = { 'type':
'/mwTransclusionInline' };
ve.dm.example.MWTransclusion.blockParamsHash = ve.getHash(
ve.dm.MWTransclusionNode.static.getHashObject(
ve.dm.example.MWTransclusion.blockData ) );
ve.dm.example.MWTransclusion.blockStoreItems = {
@@ -1105,6 +1110,66 @@
},
'normalizedHtml':
ve.dm.example.MWTransclusion.inlineOpenModified +
ve.dm.example.MWTransclusion.inlineClose
},
+ 'two mw:Transclusion nodes with identical params but different
htmlAttributes': {
+ 'html': '<body>' +
+ ve.dm.example.MWTransclusion.pairOne +
+ ve.dm.example.MWTransclusion.pairTwo +
+ '</body>',
+ 'data': [
+ {
+ 'type': 'mwTransclusionBlock',
+ 'attributes': {
+ 'mw': {
+ 'params': { '1': { 'wt': 'foo'
} }
+ },
+ 'originalMw':
'{"params":{"1":{"wt":"foo"}}}',
+ 'originalDomElements': $(
ve.dm.example.MWTransclusion.pairOne ).toArray(),
+ 'originalIndex': 0
+ },
+ 'htmlAttributes': [
+ {
+ 'values': {
+ 'about': '#mwt1',
+ 'data-mw':
'{"params":{"1":{"wt":"foo"}}}',
+ 'data-parsoid': '1',
+ 'typeof':
'mw:Transclusion'
+ }
+ }
+ ]
+ },
+ { 'type': '/mwTransclusionBlock' },
+ {
+ 'type': 'mwTransclusionBlock',
+ 'attributes': {
+ 'mw': {
+ 'params': { '1': { 'wt': 'foo'
} }
+ },
+ 'originalMw':
'{"params":{"1":{"wt":"foo"}}}',
+ 'originalDomElements': $(
ve.dm.example.MWTransclusion.pairTwo ).toArray(),
+ 'originalIndex': 0
+ },
+ 'htmlAttributes': [
+ {
+ 'values': {
+ 'about': '#mwt2',
+ 'data-mw':
'{"params":{"1":{"wt":"foo"}}}',
+ 'data-parsoid': '2',
+ 'typeof':
'mw:Transclusion'
+ }
+ }
+ ]
+ },
+ { 'type': '/mwTransclusionBlock' },
+ { 'type': 'internalList' },
+ { 'type': '/internalList' }
+ ],
+ 'storeItems': [
+ {
+ 'hash':
'{"mw":{"params":{"1":{"wt":"foo"}}},"type":"mwTransclusionBlock"}',
+ 'value': $( '<p about="#mwt1"
typeof="mw:Transclusion"
data-mw="{"params":{"1":{"wt":"foo"}}}"
data-parsoid="1">foo</p>' ).toArray()
+ }
+ ]
+ },
'mw:Reference': {
'html':
'<body>' +
@@ -1151,7 +1216,7 @@
'listKey': 'bar',
'refGroup': '',
'mw': { 'body': { 'html': '' },
'attrs': { 'name': 'bar' } },
- 'origMw':
'{"body":{"html":""},"attrs":{"name":"bar"}}',
+ 'originalMw':
'{"body":{"html":""},"attrs":{"name":"bar"}}',
'contentsUsed': false
},
'htmlAttributes': [
@@ -1186,7 +1251,7 @@
'listKey': 'quux',
'refGroup': '',
'mw': { 'body': { 'html': 'Quux' },
'attrs': { 'name': 'quux' } },
- 'origMw':
'{"body":{"html":"Quux"},"attrs":{"name":"quux"}}',
+ 'originalMw':
'{"body":{"html":"Quux"},"attrs":{"name":"quux"}}',
'contentsUsed': true
},
'htmlAttributes': [
@@ -1221,7 +1286,7 @@
'listKey': 'bar',
'refGroup': '',
'mw': { 'body': { 'html': 'Bar' },
'attrs': { 'name': 'bar' } },
- 'origMw':
'{"body":{"html":"Bar"},"attrs":{"name":"bar"}}',
+ 'originalMw':
'{"body":{"html":"Bar"},"attrs":{"name":"bar"}}',
'contentsUsed': true
},
'htmlAttributes': [
@@ -1256,7 +1321,7 @@
'listKey': null,
'refGroup': 'g1',
'mw': { 'body': { 'html': 'No name' },
'attrs': { 'group': 'g1' } },
- 'origMw': '{"body":{"html":"No
name"},"attrs":{"group":"g1"}}',
+ 'originalMw': '{"body":{"html":"No
name"},"attrs":{"group":"g1"}}',
'contentsUsed': true
},
'htmlAttributes': [
@@ -1290,7 +1355,7 @@
'name': 'references',
'attrs': {}
},
- 'origMw':
'{"name":"references","attrs":{}}',
+ 'originalMw':
'{"name":"references","attrs":{}}',
'domElements': $(
'<ol class="references"
about="#mwt12" typeof="mw:Extension/references" '+
'data-mw="{"name":"references","attrs":{}}" ' +
@@ -1371,7 +1436,7 @@
},
'name': 'ref'
},
- 'origMw':
'{"name":"ref","body":{"html":"Foo<!-- bar -->"},"attrs":{}}',
+ 'originalMw':
'{"name":"ref","body":{"html":"Foo<!-- bar -->"},"attrs":{}}',
'refGroup': ''
},
'htmlAttributes': [
@@ -3548,7 +3613,7 @@
'body': { 'html': 'No name 1' },
'name': 'ref'
},
- 'origMw': '{"name":"ref","body":{"html":"No name
1"},"attrs":{}}',
+ 'originalMw': '{"name":"ref","body":{"html":"No name
1"},"attrs":{}}',
'refGroup': ''
},
'htmlAttributes': [ { 'values': {
@@ -3578,7 +3643,7 @@
'body': { 'html': 'Bar' },
'name': 'ref'
},
- 'origMw': '{"body":{"html":""},"attrs":{"name":"bar"}}',
+ 'originalMw':
'{"body":{"html":""},"attrs":{"name":"bar"}}',
'refGroup': ''
},
'htmlAttributes': [ { 'values': {
@@ -3606,7 +3671,7 @@
'body': { 'html': 'Quux' },
'name': 'ref'
},
- 'origMw':
'{"name":"ref","body":{"html":"Quux"},"attrs":{"name":"quux"}}',
+ 'originalMw':
'{"name":"ref","body":{"html":"Quux"},"attrs":{"name":"quux"}}',
'refGroup': ''
},
'htmlAttributes': [ { 'values': {
@@ -3633,7 +3698,7 @@
'attrs': { 'name': 'bar' },
'name': 'ref'
},
- 'origMw': '{"body":{"html":""},"attrs":{"name":"bar"}}',
+ 'originalMw':
'{"body":{"html":""},"attrs":{"name":"bar"}}',
'refGroup': ''
},
'htmlAttributes': [ { 'values': {
@@ -3663,7 +3728,7 @@
'body': { 'html': 'No name 2' },
'name': 'ref'
},
- 'origMw': '{"name":"ref","body":{"html":"No name
2"},"attrs":{}}',
+ 'originalMw': '{"name":"ref","body":{"html":"No name
2"},"attrs":{}}',
'refGroup': ''
},
'htmlAttributes': [ { 'values': {
@@ -3690,7 +3755,7 @@
'body': { 'html': 'No name 3' },
'name': 'ref'
},
- 'origMw': '{"name":"ref","body":{"html":"No name
3"},"attrs":{}}',
+ 'originalMw': '{"name":"ref","body":{"html":"No name
3"},"attrs":{}}',
'refGroup': ''
},
'htmlAttributes': [ { 'values': {
@@ -3713,7 +3778,7 @@
'name': 'references',
'attrs': {}
},
- 'origMw': '{"name":"references","attrs":{}"}',
+ 'originalMw': '{"name":"references","attrs":{}"}',
//'domElements': HTML,
'listGroup': 'mwReference/',
'refGroup': ''
--
To view, visit https://gerrit.wikimedia.org/r/70133
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib13bb206c49b1f5b186e40632a5c109def0f042e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits