jenkins-bot has submitted this change and it was merged. Change subject: Rename helper to Util.promiseToProcessContent ......................................................................
Rename helper to Util.promiseToProcessContent * This is also pulled out of https://gerrit.wikimedia.org/r/#/c/264026/ * The blacklist change is because async.map is parallel and the extra .then changes the ordering, I assume. Change-Id: Ibed37f4917310634895b4d6800b5c47343cf5257 --- M lib/utils/Util.js M tests/parserTests-blacklist.js 2 files changed, 26 insertions(+), 25 deletions(-) Approvals: Arlolra: Looks good to me, approved Subramanya Sastry: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/utils/Util.js b/lib/utils/Util.js index 92f4257..eb355d3 100644 --- a/lib/utils/Util.js +++ b/lib/utils/Util.js @@ -1100,22 +1100,18 @@ }, /** - * Processes an array of tokens all the way to DOM. - * Currently used internally within this file. + * A promise returning wrapper around processContentInPipeline that + * resolves with the docuemnt. */ - _processTokensToDOM: function(env, frame, tokens, opts, cb) { + promiseToProcessContent: function(env, frame, content, opts, cb) { cb = JSUtils.mkPromised(cb); - this.processContentInPipeline( - env, - frame, - tokens.concat([new pd.EOFTk()]), { - pipelineType: "tokens/x-mediawiki/expanded", - pipelineOpts: opts.pipelineOpts, - srcOffsets: opts ? opts.srcOffsets : undefined, - // processContentInPipeline has no error callback :( - documentCB: function(dom) { cb(null, dom); }, - } - ); + Util.processContentInPipeline(env, frame, content, { + pipelineType: opts.pipelineType, + pipelineOpts: opts.pipelineOpts, + srcOffsets: opts ? opts.srcOffsets : undefined, + // processContentInPipeline has no error callback :( + documentCB: function(dom) { cb(null, dom); }, + }); return cb.promise; }, @@ -1147,11 +1143,11 @@ */ expandValuesToDOM: function(env, frame, vals, wrapTemplates, finalCB) { if (!DU) { DU = require('./DOMUtils.js').DOMUtils; } - var self = this; async.map(vals, function(v, cb) { if (Array.isArray(v.html)) { // Set up pipeline options var opts = { + pipelineType: 'tokens/x-mediawiki/expanded', pipelineOpts: { attrExpansion: true, noPWrapping: true, @@ -1159,15 +1155,20 @@ wrapTemplates: wrapTemplates, }, }; - self._processTokensToDOM(env, frame, v.html, opts, function(err, dom) { - if (!err) { - // Since we aren't at the top level, data attrs - // were not applied in cleanup. However, tmp - // was stripped. - v.html = DU.ppToXML(dom.body, { innerXML: true }); - } - cb(err, v); - }); + var content = v.html.concat([new pd.EOFTk()]); + Util.promiseToProcessContent(env, frame, content, opts) + .then(function(dom) { + // Since we aren't at the top level, data attrs + // were not applied in cleanup. However, tmp + // was stripped. + v.html = DU.ppToXML(dom.body, { innerXML: true }); + return v; + }) + .catch(function(err) { + env.log('error', 'Expanding values to DOM', err); + return v; + }) + .nodify(cb); } else { cb(null, v); } diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js index b823780..49d01a1 100644 --- a/tests/parserTests-blacklist.js +++ b/tests/parserTests-blacklist.js @@ -109,7 +109,7 @@ add("wt2html", "Template with invalid target containing wikilink", "<p data-parsoid='{\"dsr\":[0,17,0,0]}'>{{<a rel=\"mw:WikiLink\" href=\"./Main_Page\" title=\"Main Page\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Main_Page\"},\"sa\":{\"href\":\"Main Page\"},\"dsr\":[2,15,2,2]}'>Main Page</a>}}</p>"); add("wt2html", "Template with complex arguments", "<p data-parsoid='{\"dsr\":[0,106,0,0]}'><a rel=\"mw:WikiLink\" href=\"./Template:Complextemplate\" title=\"Template:Complextemplate\" about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Template:Complextemplate\"},\"sa\":{\"href\":\"Template:complextemplate\"},\"dsr\":[0,106,null,null],\"pi\":[[{\"k\":\"param\",\"named\":true,\"spc\":[\"\\n \",\" \",\"\",\"\"]},{\"k\":\"1\"}]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"complextemplate\",\"href\":\"./Template:Complextemplate\"},\"params\":{\"1\":{\"wt\":\"[[Template:complextemplate|link]]\"},\"param\":{\"wt\":\"{{ templateasargtest |\\n templ = simple }}\"}},\"i\":0}}]}'>link</a><span about=\"#mwt1\"> This is a test template with parameter (test)</span></p>"); add("wt2html", "Template infinite loop", "<span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,9,null,null],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"loop1\",\"href\":\"./Template:Loop1\"},\"params\":{},\"i\":0}}]}'></span>"); -add("wt2html", "Template with targets containing wikilinks", "<p data-parsoid='{\"dsr\":[0,11,0,0]}'>{{<a rel=\"mw:WikiLink\" href=\"./Foo\" title=\"Foo\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Foo\"},\"sa\":{\"href\":\"foo\"},\"dsr\":[2,9,2,2]}'>foo</a>}}</p>\n\n<p data-parsoid='{\"dsr\":[13,33,0,0]}'>{{<a typeof=\"mw:ExpandedAttrs\" about=\"#mwt4\" rel=\"mw:WikiLink\" href=\"./Foo\" title=\"Foo\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Foo\"},\"sa\":{\"href\":\"{{echo|foo}}\"},\"dsr\":[15,31,null,null]}' data-mw='{\"attribs\":[[{\"txt\":\"href\"},{\"html\":\"<span about=\\\"#mwt3\\\" typeof=\\\"mw:Transclusion\\\" data-parsoid='{\\\"pi\\\":[[{\\\"k\\\":\\\"1\\\"}]],\\\"dsr\\\":[17,29,null,null]}' data-mw='{\\\"parts\\\":[{\\\"template\\\":{\\\"target\\\":{\\\"wt\\\":\\\"echo\\\",\\\"href\\\":\\\"./Template:Echo\\\"},\\\"params\\\":{\\\"1\\\":{\\\"wt\\\":\\\"foo\\\"}},\\\"i\\\":0}}]}'>foo</span>\"}]]}'>foo</a>}}</p>\n\n<p data-parsoid='{\"dsr\":[35,55,0,0]}'>{{<span about=\"#mwt6\" typeof=\"mw:Transclusion\" data-parsoid='{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[37,51,null,null]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"[[foo\"}},\"i\":0}}]}'>[[foo</span>]]}}</p>"); +add("wt2html", "Template with targets containing wikilinks", "<p data-parsoid='{\"dsr\":[0,11,0,0]}'>{{<a rel=\"mw:WikiLink\" href=\"./Foo\" title=\"Foo\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Foo\"},\"sa\":{\"href\":\"foo\"},\"dsr\":[2,9,2,2]}'>foo</a>}}</p>\n\n<p data-parsoid='{\"dsr\":[13,33,0,0]}'>{{<a typeof=\"mw:ExpandedAttrs\" about=\"#mwt6\" rel=\"mw:WikiLink\" href=\"./Foo\" title=\"Foo\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Foo\"},\"sa\":{\"href\":\"{{echo|foo}}\"},\"dsr\":[15,31,null,null]}' data-mw='{\"attribs\":[[{\"txt\":\"href\"},{\"html\":\"<span about=\\\"#mwt3\\\" typeof=\\\"mw:Transclusion\\\" data-parsoid='{\\\"pi\\\":[[{\\\"k\\\":\\\"1\\\"}]],\\\"dsr\\\":[17,29,null,null]}' data-mw='{\\\"parts\\\":[{\\\"template\\\":{\\\"target\\\":{\\\"wt\\\":\\\"echo\\\",\\\"href\\\":\\\"./Template:Echo\\\"},\\\"params\\\":{\\\"1\\\":{\\\"wt\\\":\\\"foo\\\"}},\\\"i\\\":0}}]}'>foo</span>\"}]]}'>foo</a>}}</p>\n\n<p data-parsoid='{\"dsr\":[35,55,0,0]}'>{{<span about=\"#mwt5\" typeof=\"mw:Transclusion\" data-parsoid='{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[37,51,null,null]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"[[foo\"}},\"i\":0}}]}'>[[foo</span>]]}}</p>"); add("wt2html", "int keyword", "<p about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,45,0,0],\"pi\":[[{\"k\":\"1\"},{\"k\":\"2\"}]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"int:youhavenewmessages\",\"function\":\"int\"},\"params\":{\"1\":{\"wt\":\"lots of money\"},\"2\":{\"wt\":\"not!\"}},\"i\":0}}]}'>Parser function implementation for pf_int missing in Parsoid.</p>"); add("wt2html", "int keyword - non-existing message", "<p about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,11,0,0],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"int:var\",\"function\":\"int\"},\"params\":{},\"i\":0}}]}'>Parser function implementation for pf_int missing in Parsoid.</p>"); add("wt2html", "Self-closed noinclude, includeonly, onlyinclude tags", "<meta typeof=\"mw:Includes/NoInclude\" data-parsoid='{\"src\":\"<noinclude />\",\"dsr\":[0,13,null,null]}'/>\n<meta typeof=\"mw:Includes/IncludeOnly\" data-parsoid='{\"src\":\"<includeonly />\",\"dsr\":[14,29,null,null]}'/>\n<meta typeof=\"mw:Includes/OnlyInclude\" data-parsoid='{\"src\":\"<onlyinclude />\",\"dsr\":[30,45,null,null]}'/>"); -- To view, visit https://gerrit.wikimedia.org/r/307020 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibed37f4917310634895b4d6800b5c47343cf5257 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Arlolra <[email protected]> Gerrit-Reviewer: Arlolra <[email protected]> Gerrit-Reviewer: Cscott <[email protected]> Gerrit-Reviewer: Subramanya Sastry <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
