jenkins-bot has submitted this change and it was merged.
Change subject: Hack MWTemplate so it also does partial type matches
......................................................................
Hack MWTemplate so it also does partial type matches
For extension-specific types such as mw: , we require that all
types be matched. But we want MWTemplateNode to match
anything with an mw:Object/Template type, even if it also has
other types (like mw:WikiLink/Category in our test case).
Hack this into MWTemplate by matching on /^mw:/ then using
a matchFunction to assert that mw:Object/Template is in the
typeof attribute.
Update the test case. Because it's now a template, there's a bunch
of store stuff involved. Remove the other test case for about
group forcing because it's now a duplicate of this one.
Change-Id: Iacbe952a66d610c19b46bd76b84c50488857ac29
---
M modules/ve/dm/nodes/ve.dm.MWTemplateNode.js
M modules/ve/test/dm/ve.dm.example.js
2 files changed, 52 insertions(+), 31 deletions(-)
Approvals:
Esanders: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/dm/nodes/ve.dm.MWTemplateNode.js
b/modules/ve/dm/nodes/ve.dm.MWTemplateNode.js
index a5d40c9..b48e71c 100644
--- a/modules/ve/dm/nodes/ve.dm.MWTemplateNode.js
+++ b/modules/ve/dm/nodes/ve.dm.MWTemplateNode.js
@@ -30,7 +30,16 @@
ve.dm.MWTemplateNode.static.matchTagNames = null;
-ve.dm.MWTemplateNode.static.matchRdfaTypes = [ 'mw:Object/Template' ];
+// We're interested in all nodes that have mw:Object/Template, even if they
also have other mw:
+// types. So we match all mw: types, then use a matchFunction to assert that
mw:Object/Template
+// is in there.
+ve.dm.MWTemplateNode.static.matchRdfaTypes = [ 'mw:Object/Template', /^mw:/ ];
+
+ve.dm.MWTemplateNode.static.matchFunction = function ( domElement ) {
+ return ve.indexOf( 'mw:Object/Template',
+ ( domElement.getAttribute( 'typeof' ) || '' ).split( ' ' )
+ ) !== -1;
+};
ve.dm.MWTemplateNode.static.getHashObject = function ( dataElement ) {
return {
diff --git a/modules/ve/test/dm/ve.dm.example.js
b/modules/ve/test/dm/ve.dm.example.js
index 6d3a43a..259dc66 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -865,7 +865,33 @@
'html/0/data-parsoid':
'{\"tsr\":[18,34],\"src\":\"{{Inline|1,234}}\",\"dsr\":[18,34,null,null]}',
'html/0/typeof': 'mw:Object/Template'
},
- }
+ },
+ 'mixed': '<link about="#mwt1" rel="mw:WikiLink/Category"
typeof="mw:Object/Template"
data-mw="{"id":"mwt1","target":{"wt":"Inline"},"params":{"1":{"wt":"5,678"}}}"><span
about="#mwt1">Foo</span>',
+ 'mixedDataOpen': {
+ 'type': 'MWtemplateInline',
+ 'attributes': {
+ 'mw': {
+ 'id': 'mwt1',
+ 'target': { 'wt': 'Inline' },
+ 'params': {
+ '1': { 'wt': '5,678' }
+ }
+ },
+ 'mwOriginal': {
+ 'id': 'mwt1',
+ 'target': { 'wt': 'Inline' },
+ 'params': {
+ '1': { 'wt': '5,678' }
+ }
+ },
+ 'html/0/about': '#mwt1',
+ 'html/0/rel': 'mw:WikiLink/Category',
+ 'html/0/typeof': 'mw:Object/Template',
+ 'html/0/data-mw':
'{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"5,678\"}}}',
+ 'html/1/about': '#mwt1'
+ }
+ },
+ 'mixedDataClose' : { 'type': '/MWtemplateInline' }
};
ve.dm.example.MWTemplate.blockParamsHash = ve.getHash(
ve.dm.MWTemplateNode.static.getHashObject( ve.dm.example.MWTemplate.blockData )
);
@@ -878,6 +904,12 @@
ve.dm.example.MWTemplate.inlineStoreItems = {
'hash': ve.dm.example.MWTemplate.inlineParamsHash,
'value': $( ve.dm.example.MWTemplate.inlineOpen +
ve.dm.example.MWTemplate.inlineContent + ve.dm.example.MWTemplate.inlineClose
).get()
+};
+
+ve.dm.example.MWTemplate.mixedParamsHash = ve.getHash(
ve.dm.MWTemplateNode.static.getHashObject(
ve.dm.example.MWTemplate.mixedDataOpen ) );
+ve.dm.example.MWTemplate.mixedStoreItems = {
+ 'hash': ve.dm.example.MWTemplate.mixedParamsHash,
+ 'value': $( ve.dm.example.MWTemplate.mixed ).get()
};
ve.dm.example.domToDataCases = {
@@ -2210,22 +2242,16 @@
'<meta typeof="mw:Placeholder" data-parsoid="foobar"
/></body>',
'data': ve.dm.example.withMeta
},
- 'RDFa types spread across two attributes': {
- 'html': '<body><link rel="mw:WikiLink/Category"
href="./Category:Foo" about="#mwt1" typeof="mw:Object/Template"></body>',
+ 'RDFa types spread across two attributes, about grouping is forced': {
+ 'html': '<body>' + ve.dm.example.MWTemplate.mixed + '</body>',
'data': [
- {
- 'type': 'alienMeta',
- 'attributes': {
- 'style': 'link',
- 'key': 'mw:WikiLink/Category',
- 'value': './Category:Foo',
- 'html/0/rel': 'mw:WikiLink/Category',
- 'html/0/href': './Category:Foo',
- 'html/0/about': '#mwt1',
- 'html/0/typeof': 'mw:Object/Template'
- }
- },
- { 'type': '/alienMeta' },
+ { 'type': 'paragraph', 'internal': { 'generated':
'wrapper' } },
+ ve.dm.example.MWTemplate.mixedDataOpen,
+ ve.dm.example.MWTemplate.mixedDataClose,
+ { 'type': '/paragraph' }
+ ],
+ 'storeItems': [
+ ve.dm.example.MWTemplate.mixedStoreItems
]
},
'about grouping': {
@@ -2293,20 +2319,6 @@
}
},
{ 'type': '/alienBlock' }
- ]
- },
- 'about grouping is forced': {
- 'html': '<body><link rel="mw:WikiLink/Category"
href="./Category:Foo" about="#mwt1" typeof="mw:Object/Template"><span
about="#mwt1">Foo</span></body>',
- 'data': [
- { 'type': 'paragraph', 'internal': { 'generated':
'wrapper' } },
- {
- 'type': 'alienInline',
- 'attributes': {
- 'domElements': $( '<link
rel="mw:WikiLink/Category" href="./Category:Foo" about="#mwt1"
typeof="mw:Object/Template"><span about="#mwt1">Foo</span>' ).get()
- }
- },
- { 'type': '/alienInline' },
- { 'type': '/paragraph' }
]
},
'mw:Entity': {
--
To view, visit https://gerrit.wikimedia.org/r/62323
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iacbe952a66d610c19b46bd76b84c50488857ac29
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits