Arlolra has uploaded a new change for review. https://gerrit.wikimedia.org/r/175944
Change subject: Support {{REVISIONID}} ...................................................................... Support {{REVISIONID}} Bug: T73306 Change-Id: I2396709a93c42e951b3d0ef2ba054924efbf3c43 --- M lib/ext.core.TemplateHandler.js M tests/parserTests-blacklist.js M tests/parserTests.js M tests/parserTests.txt 4 files changed, 19 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/44/175944/1 diff --git a/lib/ext.core.TemplateHandler.js b/lib/ext.core.TemplateHandler.js index fc194b8..eedaa8b 100644 --- a/lib/ext.core.TemplateHandler.js +++ b/lib/ext.core.TemplateHandler.js @@ -20,6 +20,7 @@ PreprocessorRequest = api.PreprocessorRequest, Util = require('./mediawiki.Util.js').Util, DU = require('./mediawiki.DOMUtils.js').DOMUtils, + JSUtils = require('./jsutils.js').JSUtils, async = require('async'); // define some constructor shortcuts @@ -280,14 +281,20 @@ name = this.manager.env.conf.wiki.magicWords[property.slice(0, -1)]; } - // special case for {{!}} magic word - if ( name === "!" ) { + var simpleMagicWords = JSUtils.mapObject({ + "!": "|", + "revisionid": String(this.manager.env.page.id) + }); + + if ( simpleMagicWords.has(name) ) { + + // special case for {{!}} magic word // If we're not at the top level, return a table cell. This is always - // be the case. Either {{!}} was tokenized as a td, or it is tokenized + // the case. Either {{!}} was tokenized as a td, or it is tokenized // as template but the recursive call to fetch its content returns a // single | in an ambiguous context which will again be tokenized as td. - if ( !this.atTopLevel ) { + if ( name === "!" && !this.atTopLevel ) { return [new TagTk("td")]; } @@ -297,8 +304,8 @@ wrappedObjectId: this.manager.env.newObjectId() }; - this.resolveTemplateTarget(state, "!"); - var toks = this.getEncapsulationInfo(state, ["|"]); + this.resolveTemplateTarget(state, name); + var toks = this.getEncapsulationInfo(state, [simpleMagicWords.get(name)]); toks.push(this.getEncapsulationInfoEndTag(state)); var argInfo = this.getArgInfo(state); toks[0].dataAttribs.tmp.tplarginfo = JSON.stringify(argInfo); diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js index 754daac..1e66145 100644 --- a/tests/parserTests-blacklist.js +++ b/tests/parserTests-blacklist.js @@ -88,7 +88,6 @@ add("wt2html", "Magic Word: {{PAGENAME}}", "<p about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,12,0,0],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"PAGENAME\",\"function\":\"pagename\"},\"params\":{},\"i\":0}}]}'>User:Ævar Arnfjörð Bjarmason</p>"); add("wt2html", "Magic Word: {{PAGENAMEE}}", "<span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,13,null,null],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"PAGENAMEE\",\"function\":\"pagenamee\"},\"params\":{},\"i\":0}}]}'></span>"); add("wt2html", "Magic Word: {{PAGENAMEE}} with metacharacters (bug 26781)", "<span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,13,null,null],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"PAGENAMEE\",\"function\":\"pagenamee\"},\"params\":{},\"i\":0}}]}'></span>"); -add("wt2html", "Magic Word: {{REVISIONID}}", "<p data-parsoid='{\"dsr\":[0,14,0,0]}'><span typeof=\"mw:Transclusion mw:Placeholder\" about=\"#mwt1\" id=\"mwt1\" data-parsoid='{\"dsr\":[0,14,null,null],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"REVISIONID\",\"href\":\"./Template:REVISIONID\"},\"params\":{},\"i\":0}}]}'>Warning: Page/template fetching disabled, and no cache for Template:REVISIONID</span></p>"); add("wt2html", "Magic Word: {{STYLEPATH}}", "<p data-parsoid='{\"dsr\":[0,13,0,0]}'><span typeof=\"mw:Transclusion mw:Placeholder\" about=\"#mwt1\" id=\"mwt1\" data-parsoid='{\"dsr\":[0,13,null,null],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"STYLEPATH\",\"href\":\"./Template:STYLEPATH\"},\"params\":{},\"i\":0}}]}'>Warning: Page/template fetching disabled, and no cache for Template:STYLEPATH</span></p>"); add("wt2html", "Case-sensitive magic words, when cased differently, should just be template transclusions", "<p data-parsoid='{\"dsr\":[0,63,0,0]}'><span typeof=\"mw:Transclusion mw:Placeholder\" about=\"#mwt1\" id=\"mwt1\" data-parsoid='{\"dsr\":[0,16,null,null],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"CurrentMonth\",\"href\":\"./Template:CurrentMonth\"},\"params\":{},\"i\":0}}]}'>Warning: Page/template fetching disabled, and no cache for Template:CurrentMonth</span>\n<span typeof=\"mw:Transclusion mw:Placeholder\" about=\"#mwt2\" id=\"mwt2\" data-parsoid='{\"dsr\":[17,31,null,null],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"currentday\",\"href\":\"./Template:Currentday\"},\"params\":{},\"i\":0}}]}'>Warning: Page/template fetching disabled, and no cache for Template:Currentday</span>\n<span typeof=\"mw:Transclusion mw:Placeholder\" about=\"#mwt3\" id=\"mwt3\" data-parsoid='{\"dsr\":[32,47,null,null],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"cURreNTweEK\",\"href\":\"./Template:CURreNTweEK\"},\"params\":{},\"i\":0}}]}'>Warning: Page/template fetching disabled, and no cache for Template:CURreNTweEK</span>\n<span typeof=\"mw:Transclusion mw:Placeholder\" about=\"#mwt4\" id=\"mwt4\" data-parsoid='{\"dsr\":[48,63,null,null],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"currentHour\",\"href\":\"./Template:CurrentHour\"},\"params\":{},\"i\":0}}]}'>Warning: Page/template fetching disabled, and no cache for Template:CurrentHour</span></p>"); add("wt2html", "Namespace 1 {{ns:1}}", "<p about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,8,0,0],\"pi\":[[]]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"ns:1\",\"function\":\"ns\"},\"params\":{},\"i\":0}}]}'>1</p>"); @@ -1228,7 +1227,6 @@ add("html2wt", "Magic Word: {{PAGENAME}} with metacharacters (bug 26781)", "<nowiki>*RFC 1234 http://example.com/</nowiki>\n"); add("html2wt", "Magic Word: {{PAGENAMEE}}", "%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason\n"); add("html2wt", "Magic Word: {{PAGENAMEE}} with metacharacters (bug 26781)", "<nowiki>*RFC_1234_http://example.com/</nowiki>\n"); -add("html2wt", "Magic Word: {{REVISIONID}}", "1337\n"); add("html2wt", "Magic Word: {{SCRIPTPATH}}", "/\n"); add("html2wt", "Magic Word: {{STYLEPATH}}", "/skins\n"); add("html2wt", "Magic Word: {{SERVER}}", "http://example.org\n"); diff --git a/tests/parserTests.js b/tests/parserTests.js index cfa9224..5dcf28f 100755 --- a/tests/parserTests.js +++ b/tests/parserTests.js @@ -1641,6 +1641,9 @@ // to be basically empty, since the parserTests environment is very bare. this.env = env; + // expected in: "Magic Word: {{REVISIONID}}" + this.env.page.id = 1337; + if (booleanOption( options.quiet )) { var logger = new ParsoidLogger(env); logger.registerLoggingBackends(["fatal", "error"], parsoidConfig); diff --git a/tests/parserTests.txt b/tests/parserTests.txt index b2807cc..33bd260 100644 --- a/tests/parserTests.txt +++ b/tests/parserTests.txt @@ -8510,9 +8510,11 @@ Magic Word: {{REVISIONID}} !! wikitext {{REVISIONID}} -!! html +!! html/php <p>1337 </p> +!! html/parsoid +<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"REVISIONID","href":"./Template:Revisionid"},"params":{},"i":0}}]}'>1337</p> !! end !! test -- To view, visit https://gerrit.wikimedia.org/r/175944 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2396709a93c42e951b3d0ef2ba054924efbf3c43 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Arlolra <abrea...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits