Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/71275


Change subject: Preserve the contents of secondary reference definitions
......................................................................

Preserve the contents of secondary reference definitions

We currently change <ref name="foo">Foo</ref> ... <ref name="foo">Foo</ref>
to <ref name="foo">Foo</ref> ... <ref name="foo" /> , because know
that the second ref tag isn't canonical and so we blank it.

Instead, we now preserve the contents of all ref tags that come after
the canonical one.

Change-Id: I45a51a879271890fe46c4184f1029f12d27af678
---
M modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
M modules/ve/test/dm/ve.dm.mwExample.js
2 files changed, 66 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/75/71275/1

diff --git a/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js 
b/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
index 9743190..cf7b19c 100644
--- a/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
+++ b/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
@@ -70,8 +70,8 @@
 };
 
 ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, 
converter ) {
-       var itemNodeHtml, originalHtml, mwData, i, iLen, keyedNodes, 
setContents, originalMw,
-               childDomElements,
+       var itemNodeHtml, originalHtml, mwData, i, iLen, keyedNodes, 
setContents, contentsAlreadySet,
+               originalMw, childDomElements,
                el = doc.createElement( 'span' ),
                itemNodeWrapper = doc.createElement( 'div' ),
                itemNode = converter.internalList.getItemNode( 
dataElement.attributes.listIndex ),
@@ -85,14 +85,30 @@
 
        setContents = dataElement.attributes.contentsUsed || 
dataElement.attributes.listKey === null;
 
-       if ( !setContents ) {
+       keyedNodes = converter.internalList
+               .getNodeGroup( dataElement.attributes.listGroup )
+               .keyedNodes[dataElement.attributes.listKey];
+       if ( setContents ) {
+               // Check if a previous node has already set the content. If so, 
we don't overwrite this
+               // node's contents.
+               contentsAlreadySet = false;
+               if ( keyedNodes ) {
+                       for ( i = 0, iLen = keyedNodes.length; i < iLen; i++ ) {
+                               if ( keyedNodes[i].element === dataElement ) {
+                                       break;
+                               }
+                               if ( 
keyedNodes[i].element.attributes.contentsUsed ) {
+                                       contentsAlreadySet = true;
+                                       break;
+                               }
+                       }
+               }
+       } else {
                // Check if any other nodes with this key provided content. If 
not
                // then we attach the contents to the first reference with this 
key
-               keyedNodes = converter.internalList
-                       .getNodeGroup( dataElement.attributes.listGroup )
-                               .keyedNodes[dataElement.attributes.listKey];
+
                // Check that this the first reference with its key
-               if ( dataElement === keyedNodes[0].element ) {
+               if ( keyedNodes && dataElement === keyedNodes[0].element ) {
                        setContents = true;
                        // Check no other reference originally defined the 
contents
                        // As this is keyedNodes[0] we can start at 1
@@ -105,7 +121,7 @@
                }
        }
 
-       if ( setContents ) {
+       if ( setContents && !contentsAlreadySet ) {
                converter.getDomSubtreeFromData(
                        itemNode.getDocument().getFullData( new ve.Range( 
itemNodeRange.start, itemNodeRange.end ), true ),
                        itemNodeWrapper
@@ -116,8 +132,6 @@
                if ( !$( '<div>' ).html( originalHtml ).get( 0 ).isEqualNode( 
itemNodeWrapper ) ) {
                        ve.setProp( mwData, 'body', 'html', itemNodeHtml );
                }
-       } else {
-               delete mwData.body;
        }
 
        // Set or clear key
diff --git a/modules/ve/test/dm/ve.dm.mwExample.js 
b/modules/ve/test/dm/ve.dm.mwExample.js
index 30f4fd2..e034d96 100644
--- a/modules/ve/test/dm/ve.dm.mwExample.js
+++ b/modules/ve/test/dm/ve.dm.mwExample.js
@@ -315,6 +315,12 @@
                                                
'data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;body&quot;:{&quot;html&quot;:&quot;No
 name&quot;},&quot;attrs&quot;:{&quot;group&quot;:&quot;g1&quot;}}">' +
                                                '<a href="#cite_note-3" 
data-parsoid="{}">[3]</a>' +
                                        '</span>' +
+                                       ' Quux' +
+                                       '<span id="cite_ref-bar-1-2" 
class="reference" about="#mwt9" typeof="mw:Extension/ref" ' +
+                                               'data-parsoid="{}" ' +
+                                               
'data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;body&quot;:{&quot;html&quot;:&quot;Different
 content&quot;},&quot;attrs&quot;:{&quot;name&quot;:&quot;bar&quot;}}">' +
+                                               '<a href="#cite_note-bar-1" 
data-parsoid="{}">[1]</a>'+
+                                       '</span>' +
                                '</p>' +
                                '<ol class="references" about="#mwt12" 
typeof="mw:Extension/references" ' +
                                        
'data-mw="{&quot;name&quot;:&quot;references&quot;,&quot;attrs&quot;:{}}" ' +
@@ -468,6 +474,42 @@
                                ]
                        },
                        { 'type': '/mwReference' },
+                       ' ', 'Q', 'u', 'u', 'x',
+                       {
+                               'type': 'mwReference',
+                               'attributes': {
+                                       'about': '#mwt9',
+                                       'listIndex': 0,
+                                       'listGroup': 'mwReference/',
+                                       'listKey': 'bar',
+                                       'refGroup': '',
+                                       'mw': { 'name': 'ref', 'body': { 
'html': 'Different content' }, 'attrs': { 'name': 'bar' } },
+                                       'originalMw': 
'{"name":"ref","body":{"html":"Different content"},"attrs":{"name":"bar"}}',
+                                       'childDomElements': $( '<a 
href="#cite_note-bar-1" data-parsoid="{}">[1]</a>' ).toArray(),
+                                       'contentsUsed': false
+                               },
+                               'htmlAttributes': [
+                                       {
+                                               'values': {
+                                                       'about': '#mwt9',
+                                                       'class': 'reference',
+                                                       'data-mw': 
'{"name":"ref","body":{"html":"Different content"},"attrs":{"name":"bar"}}',
+                                                       'data-parsoid': '{}',
+                                                       'id': 
'cite_ref-bar-1-2',
+                                                       'typeof': 
'mw:Extension/ref'
+                                               },
+                                               'children': [
+                                                       {
+                                                               'values': {
+                                                                       'href': 
'#cite_note-bar-1',
+                                                                       
'data-parsoid': '{}'
+                                                               }
+                                                       }
+                                               ]
+                                       }
+                               ]
+                       },
+                       { 'type': '/mwReference' },
                        { 'type': '/paragraph' },
                        {
                                'type': 'mwReferenceList',

-- 
To view, visit https://gerrit.wikimedia.org/r/71275
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I45a51a879271890fe46c4184f1029f12d27af678
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to