Subramanya Sastry has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/398895 )
Change subject: Linter: Use extension mechanism to provide ext-specific lint
handers
......................................................................
Linter: Use extension mechanism to provide ext-specific lint handers
* Refactoring of previous patch.
* Move cite-specific lint handling code to the Cite extension.
Change-Id: Ib57f0303605a73408333e133f8051be0b8d45d69
---
M lib/ext/Cite/index.js
M lib/wt2html/pp/processors/linter.js
2 files changed, 44 insertions(+), 35 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/95/398895/1
diff --git a/lib/ext/Cite/index.js b/lib/ext/Cite/index.js
index ced0b51..6f7265a 100644
--- a/lib/ext/Cite/index.js
+++ b/lib/ext/Cite/index.js
@@ -168,6 +168,12 @@
}),
};
+Ref.prototype.lintHandler = function(ref, env, tplInfo, domLinter) {
+ var linkBackId = ref.firstChild.getAttribute('href').replace(/[^#]*#/,
'');
+ var refContent = ref.ownerDocument.getElementById(linkBackId).lastChild;
+ domLinter(refContent, env, tplInfo.isTemplated ? tplInfo : null);
+};
+
/**
* Helper class used by <references> implementation
*/
@@ -664,6 +670,22 @@
},
};
+References.prototype.lintHandler = function(ref, env, tplInfo, domLinter) {
+ // Nothing to do
+ //
+ // FIXME: Not entirely true for scenarios where the <ref> tags
+ // are defined in the references section that is itself templated.
+ //
+ // {{1x|<references>\n<ref name='x'><b>foo</ref>\n</references>}}
+ //
+ // In this example, the references tag has the right tplInfo and
+ // when the <ref> tag is processed in the body of the article where
+ // it is accessed, there is no relevant template or dsr info available.
+ //
+ // Ignoring for now.
+ return;
+};
+
/* --------------------------------------------
* This handles wikitext like this:
*
@@ -766,10 +788,12 @@
name: 'ref',
tokenHandler:
this.ref.tokenHandler.bind(this.ref),
serialHandler: this.ref.serialHandler,
+ lintHandler: this.ref.lintHandler,
}, {
name: 'references',
tokenHandler:
this.references.tokenHandler.bind(this.references),
serialHandler: this.references.serialHandler,
+ lintHandler: this.references.lintHandler,
},
],
styles: [
diff --git a/lib/wt2html/pp/processors/linter.js
b/lib/wt2html/pp/processors/linter.js
index f84fd86..32cc7c5 100644
--- a/lib/wt2html/pp/processors/linter.js
+++ b/lib/wt2html/pp/processors/linter.js
@@ -957,8 +957,6 @@
}
}
-var lintRef, lintReferences;
-
function findLints(root, env, tplInfo) {
var node = root.firstChild;
while (node !== null) {
@@ -967,26 +965,35 @@
continue;
}
- var nextNode;
+ var nodeTypeOf = null;
+ // !tplInfo check is to protect against templated content in
+ // extensions which might in turn be nested in templated
content.
if (!tplInfo && DU.isFirstEncapsulationWrapperNode(node)) {
- var about = node.getAttribute("about");
+ nodeTypeOf = node.getAttribute('typeof');
tplInfo = {
first: node,
- last:
JSUtils.lastItem(DU.getAboutSiblings(node, about)),
+ last:
JSUtils.lastItem(DU.getAboutSiblings(node, node.getAttribute("about"))),
dsr: DU.getDataParsoid(node).dsr,
- isTemplated:
/\bmw:Transclusion\b/.test(node.getAttribute('typeof')),
+ isTemplated:
/\bmw:Transclusion\b/.test(nodeTypeOf),
clear: false,
};
}
- // FIXME: Special hack for Cite extension.
- // In a later patch, make this an extension hook.
- if
(/\bmw:Extension\/references\b/.test(node.getAttribute('typeof'))) {
- lintReferences(node, env, tplInfo);
- } else if
(/\bmw:Extension\/ref\b/.test(node.getAttribute('typeof'))) {
- lintRef(node, env, tplInfo);
- } else {
+ // Let native extensions lint their content
+ var done = false;
+ if (/\bmw:Extension\/\b/.test(nodeTypeOf)) {
+ var extTag = nodeTypeOf.replace(/^.*\bmw:Extension\/([^
]+).*$/, '$1');
+ var nativeExt = env.conf.wiki.extensionTags.get(extTag);
+ if (nativeExt && nativeExt.lintHandler) {
+ nativeExt.lintHandler(node, env, tplInfo,
findLints);
+ done = true;
+ }
+ }
+
+ var nextNode;
+ // Default node handler
+ if (!done) {
// Lint this node
nextNode = logWikitextFixups(node, env, tplInfo);
if (tplInfo && tplInfo.clear) {
@@ -1006,28 +1013,6 @@
node = nextNode || node.nextSibling;
}
}
-
-lintReferences = function(refs, env, tplInfo) {
- // Nothing to do
- //
- // FIXME: Not entirely true for scenarios where the <ref> tags
- // are defined in the references section that is itself templated.
- //
- // {{1x|<references>\n<ref name='x'><b>foo</ref>\n</references>}}
- //
- // In this example, the references tag has the right tplInfo and
- // when the <ref> tag is processed in the body of the article where
- // it is accessed, there is no relevant template or dsr info available.
- //
- // Ignoring for now.
- return;
-};
-
-lintRef = function(ref, env, tplInfo) {
- var linkBackId = ref.firstChild.getAttribute('href').replace(/[^#]*#/,
'');
- var refContent = ref.ownerDocument.getElementById(linkBackId).lastChild;
- findLints(refContent, env, tplInfo.isTemplated ? tplInfo : null);
-};
function linter(body, env, options, atTopLevel) {
// Only on the final DOM for the top-level page.
--
To view, visit https://gerrit.wikimedia.org/r/398895
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib57f0303605a73408333e133f8051be0b8d45d69
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits