(Bug 49182) Emit data-mw for references extension as well

* data-mw wasn't being emitted for references -- there was a FIXME
  for it.

* Tested fixes on example from 3c88b310.

* Removed meta-placeholder that was being emitted for <references />
  tags without any refs to emit since VE might add references and
  this wont be valid anymore.  Serializer can also handle references
  output without any content.  So, no need for that hack anymore.

  Verified by testing with "<references />" input

Change-Id: I3d2852f2c6a88bf22145add9b2173fd99d152775
This commit is contained in:
Subramanya Sastry 2013-06-05 11:06:10 -05:00
parent 23359fb60b
commit 882f530b92

View file

@ -378,29 +378,35 @@ References.prototype.extractRefFromNode = function(node) {
References.prototype.insertReferencesIntoDOM = function(refsNode) {
var group = refsNode.getAttribute("group") || '',
refGroup = this.refGroups[group];
if (refGroup && refGroup.refs.length > 0) {
var ol = refsNode.ownerDocument.createElement('ol'),
about = refsNode.getAttribute('about');
about = refsNode.getAttribute('about'),
src = refsNode.data.parsoid.src,
// Extract ext-source for <references>..</references> usage
body = src.replace(/<references[^>]*\/?>(.*)?/, "$1").replace("</references>" , "").trim(),
refGroup = this.refGroups[group],
ol = refsNode.ownerDocument.createElement('ol');
DU.addAttributes(ol, {
'about': about,
'class': 'references',
// SSS FIXME: data-mw for references is missing.
'data-mw': JSON.stringify({
'name': 'references',
// We'll have to output data-mw.body.extsrc in
// scenarios where original wikitext was of the form:
// "<references> lot of refs here </references>"
// Ex: See [[en:Barack Obama]]
'body': body.length > 0 ? { 'extsrc': body } : undefined,
'attrs': {
// Dont emit empty keys
'group': group || undefined
}
}),
'typeof': 'mw:Extension/references'
});
ol.data = refsNode.data;
if (refGroup) {
refGroup.refs.map(refGroup.renderLine.bind(refGroup, ol));
refsNode.parentNode.replaceChild(ol, refsNode);
} else {
// Not a valid references tag -- convert it to a placeholder tag that will rt as is.
refsNode.setAttribute('typeof', 'mw:Placeholder');
}
refsNode.parentNode.replaceChild(ol, refsNode);
// reset
this.reset(group);