C. Scott Ananian has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/351669 )
Change subject: Refactor TemplateHandler to improve commonality of native and
PHP expansion.
......................................................................
Refactor TemplateHandler to improve commonality of native and PHP expansion.
Change-Id: I5e2a52ef1248f06e0b69172c84cfa71c6ecb5a75
---
M lib/wt2html/tt/TemplateHandler.js
1 file changed, 41 insertions(+), 42 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/69/351669/1
diff --git a/lib/wt2html/tt/TemplateHandler.js
b/lib/wt2html/tt/TemplateHandler.js
index 858f553..333de90 100644
--- a/lib/wt2html/tt/TemplateHandler.js
+++ b/lib/wt2html/tt/TemplateHandler.js
@@ -125,6 +125,30 @@
var accumReceiveToksFromSibling;
var accumReceiveToksFromChild;
+ var templateName;
+
+ if (this.options.wrapTemplates) {
+ templateName = tgt.target;
+ // We still need to check for loops and depth limit violations
+ // because of the higher precedence of extension tags, which can
+ // result in nested templates even while using the php
preprocessor
+ // for expansion.
+ var checkRes = tgt && this.checkRes(templateName);
+ if (Array.isArray(checkRes)) {
+ cb({ tokens: checkRes });
+ return;
+ }
+ // Check if we have an expansion for this template in the cache
+ // already
+ var cachedTransclusion = env.transclusionCache[text];
+ if (cachedTransclusion) {
+ // cache hit: reuse the expansion DOM
+ var opts = { setDSR: true, isForeignContent: true };
+ toks = DU.encapsulateExpansionHTML(env, token,
cachedTransclusion, opts);
+ cb({ tokens: toks });
+ return;
+ }
+ }
if (env.conf.parsoid.usePHPPreProcessor) {
if (this.options.wrapTemplates) {
@@ -138,48 +162,25 @@
// It's sufficient to pass `[]` in place of attribs
since they
// won't be used. In `usePHPPreProcessor`, there is no
parameter
// substitution coming from the frame.
-
- var templateName = tgt.target;
var attribs = [];
- // We still need to check for loops and depth limit
violations
- // because of the higher precedence of extension tags,
which can
- // result in nested templates even while using the php
preprocessor
- // for expansion.
- var checkRes = this.checkRes(templateName);
- if (Array.isArray(checkRes)) {
- cb({ tokens: checkRes });
- return;
- }
+ // Use a TokenAccumulator to divide the template
processing
+ // in two parts: The child part will take care of the
main
+ // template element (including parameters) and the
sibling
+ // will process the returned template expansion
+ state.accum = new TokenAccumulator(this.manager, cb);
+ accumReceiveToksFromSibling =
state.accum.receiveToksFromSibling.bind(state.accum);
+ accumReceiveToksFromChild =
state.accum.receiveToksFromChild.bind(state.accum);
+ var srcHandler = state.srcCB.bind(
+ this, state, frame,
+ accumReceiveToksFromSibling,
+ { name: templateName, attribs: attribs,
cacheKey: text });
- // Check if we have an expansion for this template in
the cache
- // already
- var cachedTransclusion = env.transclusionCache[text];
- if (cachedTransclusion) {
- // cache hit: reuse the expansion DOM
- var opts = { setDSR: true, isForeignContent:
true };
- toks = DU.encapsulateExpansionHTML(env, token,
cachedTransclusion, opts);
- cb({ tokens: toks });
- } else {
- // Use a TokenAccumulator to divide the
template processing
- // in two parts: The child part will take care
of the main
- // template element (including parameters) and
the sibling
- // will process the returned template expansion
- state.accum = new
TokenAccumulator(this.manager, cb);
- accumReceiveToksFromSibling =
state.accum.receiveToksFromSibling.bind(state.accum);
- accumReceiveToksFromChild =
state.accum.receiveToksFromChild.bind(state.accum);
- var srcHandler = state.srcCB.bind(
- this, state, frame,
- accumReceiveToksFromSibling,
- { name: templateName, attribs:
attribs, cacheKey: text });
-
- // Process the main template element
- this._encapsulateTemplate(state,
- accumReceiveToksFromChild);
- // Fetch and process the template expansion
- this.fetchExpandedTpl(env.page.name || '',
- text,
accumReceiveToksFromSibling, srcHandler);
- }
+ // Process the main template element
+ this._encapsulateTemplate(state,
accumReceiveToksFromChild);
+ // Fetch and process the template expansion
+ this.fetchExpandedTpl(env.page.name || '',
+ text, accumReceiveToksFromSibling, srcHandler);
} else {
// We don't perform recursive template expansion-
something
// template-like that the PHP parser did not expand.
This is
@@ -201,10 +202,8 @@
// console.warn("onTemplate created TA-" +
state.accum.uid);
accumReceiveToksFromSibling =
state.accum.receiveToksFromSibling.bind(state.accum);
accumReceiveToksFromChild =
state.accum.receiveToksFromChild.bind(state.accum);
-
// Process the main template element
- this._encapsulateTemplate(state,
-
state.accum.receiveToksFromChild.bind(state.accum));
+ this._encapsulateTemplate(state,
accumReceiveToksFromChild);
} else {
// Don't wrap templates, so we don't need to use the
// TokenAccumulator and can return the expansion
directly
--
To view, visit https://gerrit.wikimedia.org/r/351669
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e2a52ef1248f06e0b69172c84cfa71c6ecb5a75
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: C. Scott Ananian <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits