Catrope has uploaded a new change for review.
https://gerrit.wikimedia.org/r/62322
Change subject: Force about grouping for multi-element about groups
......................................................................
Force about grouping for multi-element about groups
When converting an element that starts an about group with at
least one other element in it, we now only consider models that
support about grouping. This prevents the first node from being
converted to something else and leaving the others hanging.
In practical terms, this means that elements like
<link rel="mw:WikiLink/Category" typeof="mw:Object/Template">
get alienated and pull in the rest of their about group, rather than
being converted to a category or alienMeta or whatever and
leaving the other elements to be converted normally.
Added a test case that asserts this. Really the result should be an
MWtemplate rather than an alien, but that's a separate issue.
Also removed superfluous mustMatchAll checks; we've already
filtered the array by the time we get there.
Change-Id: I522ba4c56d5bc52c7e9aab1e2535385540c1315d
---
M modules/ve/dm/ve.dm.Converter.js
M modules/ve/dm/ve.dm.ModelRegistry.js
M modules/ve/test/dm/ve.dm.example.js
3 files changed, 28 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/22/62322/1
diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index 44b2774..6425eb0 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -449,13 +449,13 @@
childDomElement = domElement.childNodes[i];
switch ( childDomElement.nodeType ) {
case Node.ELEMENT_NODE:
- modelName = this.modelRegistry.matchElement(
childDomElement );
+ aboutGroup = getAboutGroup( childDomElement );
+ modelName = this.modelRegistry.matchElement(
childDomElement, aboutGroup.length > 1 );
modelClass = this.modelRegistry.lookup(
modelName ) || ve.dm.AlienNode;
if ( modelClass.prototype instanceof
ve.dm.Annotation ) {
childDataElements =
this.createDataElements( modelClass, [ childDomElement ] );
} else {
// Node or meta item
- aboutGroup = getAboutGroup(
childDomElement );
childDomElements =
modelClass.static.enableAboutGrouping ?
aboutGroup : [ childDomElement
];
childDataElements =
this.createDataElements( modelClass, childDomElements );
diff --git a/modules/ve/dm/ve.dm.ModelRegistry.js
b/modules/ve/dm/ve.dm.ModelRegistry.js
index 6f7f453..f0f1e38 100644
--- a/modules/ve/dm/ve.dm.ModelRegistry.js
+++ b/modules/ve/dm/ve.dm.ModelRegistry.js
@@ -175,9 +175,10 @@
* The highest-ranking model whose test function does not return false, wins.
*
* @param {HTMLElement} element Element to match
+ * @param {boolean} [forceAboutGrouping] If true, only match models with about
grouping enabled
* @returns {string|null} Model type, or null if none found
*/
-ve.dm.ModelRegistry.prototype.matchElement = function ( element ) {
+ve.dm.ModelRegistry.prototype.matchElement = function ( element,
forceAboutGrouping ) {
var i, name, model, matches, winner, types, elementExtSpecificTypes,
matchTypes,
hasExtSpecificTypes,
tag = element.nodeName.toLowerCase(),
@@ -243,15 +244,16 @@
queue = ve.filterArray( queue, function ( name ) {
return matchesAllTypes( types, name ); } );
queue2 = ve.filterArray( queue2, function ( name ) {
return matchesAllTypes( types, name ); } );
}
+ if ( forceAboutGrouping ) {
+ // Filter out matches that don't support about grouping
+ queue = ve.filterArray( queue, function ( name ) {
return reg.registry[name].static.enableAboutGrouping; } );
+ queue2 = ve.filterArray( queue2, function ( name ) {
return reg.registry[name].static.enableAboutGrouping; } );
+ }
// Try string matches first, then regexp matches
queue.sort( byRegistrationOrderDesc );
queue2.sort( byRegistrationOrderDesc );
queue = queue.concat( queue2 );
for ( i = 0; i < queue.length; i++ ) {
- if ( mustMatchAll && !matchesAllTypes( types, queue[i]
) ) {
- // Skip matches that don't match all types if
that's required
- continue;
- }
if ( reg.registry[queue[i]].static.matchFunction(
element ) ) {
return queue[i];
}
@@ -271,13 +273,14 @@
queue = ve.filterArray( queue, function ( name ) {
return matchesAllTypes( types, name ); } );
queue2 = ve.filterArray( queue2, function ( name ) {
return matchesAllTypes( types, name ); } );
}
+ if ( forceAboutGrouping ) {
+ // Filter out matches that don't support about grouping
+ queue = ve.filterArray( queue, function ( name ) {
return reg.registry[name].static.enableAboutGrouping; } );
+ queue2 = ve.filterArray( queue2, function ( name ) {
return reg.registry[name].static.enableAboutGrouping; } );
+ }
// Only try regexp matches if there are no string matches
queue = queue.length > 0 ? queue : queue2;
for ( i = 0; i < queue.length; i++ ) {
- if ( mustMatchAll && !matchesAllTypes( types, queue[i]
) ) {
- // Skip matches that don't match all types if
that's required
- continue;
- }
if (
winningName === null ||
reg.registrationOrder[winningName] <
reg.registrationOrder[queue[i]]
diff --git a/modules/ve/test/dm/ve.dm.example.js
b/modules/ve/test/dm/ve.dm.example.js
index 31fa361..6d3a43a 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -2295,6 +2295,20 @@
{ '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': {
'html': '<body><p>a<span typeof="mw:Entity">¢</span>b<span
typeof="mw:Entity">¥</span><span typeof="mw:Entity">™</span></p></body>',
'data': [
--
To view, visit https://gerrit.wikimedia.org/r/62322
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I522ba4c56d5bc52c7e9aab1e2535385540c1315d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits