Subramanya Sastry has uploaded a new change for review.

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


Change subject: (Bug 49405) Dont rely on dp.src while serializing 
tpls/exts/params
......................................................................

(Bug 49405) Dont rely on dp.src while serializing tpls/exts/params

* Even though the serializer had the ability to serialize new
  transclusions, extension uses, or params, the serializer handler
  fetching code was still checking for the presence of original
  source for these uses which prevented new <ref> tags from being
  serialized properly.

* No change in parser test results.

Change-Id: I797b2bd87da10cd44c5eecd7b5c814777ea1a05e
---
M js/lib/mediawiki.WikitextSerializer.js
1 file changed, 41 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid 
refs/changes/88/67888/1

diff --git a/js/lib/mediawiki.WikitextSerializer.js 
b/js/lib/mediawiki.WikitextSerializer.js
index 2529c2f..8404603 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -2640,43 +2640,52 @@
                typeOf = node.getAttribute( 'typeof' ) || '';
 
        // XXX: Convert into separate handlers?
-       if ( dp.src !== undefined ) {
-               //console.log(node.parentNode.outerHTML);
-               if 
(/\bmw:(?:Transclusion\b|Param\b|Extension\/[^\s]+)/.test(typeOf)) {
-                       // Source-based template/extension round-tripping for 
now
-                       return {
-                               handle: function () {
-                                       // In RT-testing mode, there will not 
be any edits to tpls/extensions.
-                                       // So, use original source to eliminate 
spurious diffs showing up
-                                       // in RT testing results.
-                                       var src, dataMW;
-                                       if (state.rtTesting) {
-                                               src = dp.src;
-                                       } else if 
(/mw:Extension\//.test(typeOf)) {
-                                               dataMW = 
JSON.parse(node.getAttribute("data-mw"));
-                                               src = !dataMW ? dp.src : 
state.serializer._buildExtensionWT(state, node, dataMW);
+       if (/\bmw:(?:Transclusion\b|Param\b|Extension\/[^\s]+)/.test(typeOf)) {
+               // Source-based template/extension round-tripping for now
+               return {
+                       handle: function () {
+                               // In RT-testing mode, there will not be any 
edits to tpls/extensions.
+                               // So, use original source to eliminate 
spurious diffs showing up
+                               // in RT testing results.
+                               var src, dataMW;
+                               if (state.rtTesting && dp.src !== undefined) {
+                                       src = dp.src;
+                               } else if (/mw:Extension\//.test(typeOf)) {
+                                       dataMW = 
JSON.parse(node.getAttribute("data-mw"));
+                                       src = !dataMW ? dp.src : 
state.serializer._buildExtensionWT(state, node, dataMW);
+                               } else {
+                                       dataMW = 
JSON.parse(node.getAttribute("data-mw"));
+                                       if (dataMW) {
+                                               src = 
state.serializer._buildTemplateWT(state, dataMW.parts || [{ template: dataMW 
}]);
                                        } else {
-                                               dataMW = 
JSON.parse(node.getAttribute("data-mw"));
-                                               if (dataMW) {
-                                                       src = 
state.serializer._buildTemplateWT(state, dataMW.parts || [{ template: dataMW 
}]);
-                                               } else {
-                                                       console.error("ERROR: 
No data-mw for: " + node.outerHTML);
-                                                       src = dp.src;
-                                               }
+                                               console.error("ERROR: No 
data-mw for: " + node.outerHTML);
+                                               src = dp.src;
                                        }
+                               }
+
+                               if (src) {
                                        self.emitWikitext(src, state, cb, node);
                                        return 
self.skipOverEncapsulatedContent(node);
-                               },
-                               sepnls: {
-                                       // XXX: This is questionable, as the 
template can expand
-                                       // to newlines too. Which default 
should we pick for new
-                                       // content? We don't really want to 
make separator
-                                       // newlines in HTML significant for the 
semantics of the
-                                       // template content.
-                                       before: id({min:0, max:2})
+                               } else {
+                                       console.error("ERROR: No handler for: " 
+ node.outerHTML);
+                                       console.error("Serializing as HTML.");
+                                       return self._htmlElementHandler(node, 
state);
                                }
-                       };
-               } else if (typeOf === "mw:Placeholder" ||
+                       },
+                       sepnls: {
+                               // XXX: This is questionable, as the template 
can expand
+                               // to newlines too. Which default should we 
pick for new
+                               // content? We don't really want to make 
separator
+                               // newlines in HTML significant for the 
semantics of the
+                               // template content.
+                               before: id({min:0, max:2})
+                       }
+               };
+       }
+
+       if ( dp.src !== undefined ) {
+               //console.log(node.parentNode.outerHTML);
+               if (typeOf === "mw:Placeholder" ||
                                (typeOf === "mw:Nowiki" && node.textContent === 
dp.src )) {
                        // implement generic src round-tripping:
                        // return src, and drop the generated content

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I797b2bd87da10cd44c5eecd7b5c814777ea1a05e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>

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

Reply via email to