Save data-attribs in DOMs of nested refs

* 4ea8dbd8 exposed a bug handling of nested <refs> (done via
  templates). It caused crashers in rt-testing of a few pages.
  Ex: enwiki/António de Oliveira Salazar?oldid=676623209

* Reproducible with the following wikitext:
-------------------------------------
x <ref>y {{sfn|Kay|1970|pp=123}}</ref>
<references />
-------------------------------------

* This patch fixes the problem by making sure data-mw and
  data-parsoid of the DOM for the nested ref are saved before
  serialization to a string.

* Removed the saveHandler from dom.t.unpackDOMFragments.js and
  reused the simpler dom-walk code added as part of this patch.

* Also updated comments in ext.Cite.js

* Hard to introduce nested <ref> in parser tests, so no
  new tests for this scenario.

Change-Id: I2298bbe87ccddd87f307d206d77d78fcfb0d8a75
This commit is contained in:
Subramanya Sastry 2015-08-18 12:55:55 -05:00
parent 7b901bc99b
commit 37206e2a12

View file

@ -374,13 +374,17 @@ References.prototype.extractRefFromNode = function(node, refsData,
if (dp.hasRefInRef) {
var html = DU.parseHTML(content).body;
refInRefProcessor(html);
// Save data attribs for the nested DOM
// since we are serializing it to a string.
DU.saveDataAttribsForDOM(html);
content = DU.serializeChildren(html);
}
if (content) {
// If there are multiple <ref>s with the same name, but different
// content, we need to record this one's content instead of
// linking to <references>.
// If there are multiple <ref>s with the same name, but different content,
// the content of the first <ref> shows up in the <references> section.
// in order to ensure lossless RT-ing for later <refs>, we have to record
// HTML inline for all of them.
if (ref.hasMultiples && content !== ref.content) {
body = { 'html': content };
} else {
@ -388,6 +392,9 @@ References.prototype.extractRefFromNode = function(node, refsData,
}
}
// data-mw will not be empty in scenarios where the <ref> is also templated.
// In those cases, the transclusion markup takes precedence over the <ref> markup.
// So, we aren't updating data-mw.
if (!Object.keys(dataMW).length) {
dataMW = {
'name': 'ref',
@ -417,6 +424,7 @@ References.prototype.extractRefFromNode = function(node, refsData,
var dataParsoid = {
src: dp.src,
dsr: dp.dsr,
pi: dp.pi,
};
DU.setDataParsoid(span, dataParsoid);
DU.setDataMw(span, dataMW);