jenkins-bot has submitted this change and it was merged.

Change subject: (Bug 57618) Bug fix in dom-fragment unpacking of transcluded 
extensions
......................................................................


(Bug 57618) Bug fix in dom-fragment unpacking of transcluded extensions

* When extensions were transcluded at the top-level, DOMFragment
  unpacking code would simply use the mw:Transclusion typeof and
  ignore the typeof on the expansion html. This lost the references
  typeof (mw:Extension/references) on the <ol> node which in turn
  meant that references were not being populated there.

* This patch fixes the unpacking to not exit dom fragment unpacking
  early and fixes the data-mw of the extension wrapper to use the
  transclusion data-mw so we get best of both worlds.

* Updated existing useless references test with useful content which
  would have caught this bug quite early on.

Change-Id: I7c4738391ca73115d8ebe23ed7a9b2587f6e22d1
---
M js/lib/dom.t.unpackDOMFragments.js
M js/tests/parserTests.txt
2 files changed, 17 insertions(+), 14 deletions(-)

Approvals:
  GWicke: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/js/lib/dom.t.unpackDOMFragments.js 
b/js/lib/dom.t.unpackDOMFragments.js
index 83cc9f5..3c9725c 100644
--- a/js/lib/dom.t.unpackDOMFragments.js
+++ b/js/lib/dom.t.unpackDOMFragments.js
@@ -184,18 +184,15 @@
                        }
 
                        var html = node.data.parsoid.html;
-                       if (!html || 
/(?:^|\s)mw:Transclusion(?=$|\s)/.test(typeOf)) {
-                               // Ex: A multi-part template with an extension 
in its
-                               // output (possibly passed in as a parameter).
-                               //
-                               // Example:
-                               // echo '{{echo|<math>1+1</math>}}' | node 
parse --extensions math
-                               //
-                               // Simply remove the mw:DOMFragment typeof for 
now, as the
-                               // entire content will still be encapsulated as 
a
-                               // mw:Transclusion.
-                               DU.removeTypeOf(node, 'mw:DOMFragment');
-                               return true;
+                       if (!html) {
+                               // Not sure why this would happen at all -- 
raising fatal exception
+                               // to see what code paths are causing this
+                               console.error("Parsing page: " + env.page.name);
+                               console.error("Missing data.parsoid.html for 
dom-fragment: " + node.outerHTML);
+                               console.trace();
+                               throw new Error("Missing data.parsoid.html in 
DOMFragment unpacking");
+                               // DU.removeTypeOf(node, 'mw:DOMFragment');
+                               // return true;
                        }
 
                        dummyNode.innerHTML = html;
@@ -212,6 +209,12 @@
 
                        var contentNode = dummyNode.firstChild;
 
+                       // Transfer mw:Transclusion typeof
+                       if (/(?:^|\s)mw:Transclusion(?=$|\s)/.test(typeOf)) {
+                               contentNode.setAttribute("data-mw", 
node.getAttribute("data-mw"));
+                               DU.addTypeOf(contentNode, "mw:Transclusion");
+                       }
+
                        // Update DSR
                        //
                        // There is currently no DSR for DOMFragments nested 
inside
diff --git a/js/tests/parserTests.txt b/js/tests/parserTests.txt
index bb70846..37744ae 100644
--- a/js/tests/parserTests.txt
+++ b/js/tests/parserTests.txt
@@ -16863,9 +16863,9 @@
 !!options
 parsoid
 !!input
-{{echo|<references />}}
+<ref>Foo</ref> {{echo|<references />}}
 !!result
-<ol class="references" about="#mwt2" typeof="mw:Transclusion" 
data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<references
 />"}},"i":0}}]}'></ol>
+<span about="#mwt3" class="reference" 
data-mw='{"name":"ref","body":{"html":"Foo"},"attrs":{}}' id="cite_ref-1-0" 
rel="dc:references" typeof="mw:Extension/ref"><a 
href="#cite_note-1">[1]</a></span> <ol class="references" 
typeof="mw:Extension/references mw:Transclusion" about="#mwt4" 
data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;references
 />"}},"i":0}}]}'><li about="#cite_note-1" id="cite_note-1"><span 
rel="mw:referencedBy"><a href="#cite_ref-1-0">↑</a></span> Foo</li></ol>
 !!end
 
 !! test

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7c4738391ca73115d8ebe23ed7a9b2587f6e22d1
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: GWicke <gwi...@wikimedia.org>
Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to