Topic on Extension talk:Scribunto

Is that possible to get raw wikitext by Lua?

6
Cirno.Tim (talkcontribs)

I find out frame.args will receive parsed wikitext, so how to get raw wikitext without using <nowiki> tag?

Mr. Stradivarius (talkcontribs)

You can get the unparsed wikitext of an entire page using title:getContent(). I don't think there's a way to get unparsed wikitext of just the template arguments.

Tacsipacsi (talkcontribs)

It’s definitely impossible at the moment, and I don’t even think it would be possible at all to implement it in Scribunto: by design, the MediaWiki parser only allows getting expanded (parsed) contents of template/parser function arguments.

FeRDNYC (talkcontribs)

If you think about it, it's kind of a logistical impossibility — how can a module possibly ask the parser to supply anything without first... well... parsing it? The wikitext containing the {{#invoke:... }} has to be parsed for the interpreter to even identify that a Lua module is being called; which one, specifically; and how the remainder of the text up to the closing }} represents any arguments to the call.

The <nowiki>...</nowiki> feature exists specifically because that IS the method of telling the parser, "hands off this chunk of content, I want it to be preserved in an unparsed state as it moves through the parse tree" — or to put it another way, to "get raw wikitext". Without those tags, you're gonna get the results of the parser doing its job on whatever it finds.

It'd require direct modifications to the wikitext parser itself, for it to also store and make available the unparsed version of the child content at each node in the parse tree without needing to use <nowiki>...</nowiki>.

Tim Starling (WMF) (talkcontribs)

Maybe you should read the code before so confidently declaring it impossible. It seems pretty straightforward to me.

Arguments (apart from the first argument which has the module name) are stored as a node in a parse tree. You can recover the original wikitext by calling PPFrame::expand() on the node with the PPFrame::RECOVER_ORIG flag. Reversibility is a strong requirement for the preprocessor due to its use in pre-save transform. When you save wikitext, the preprocessor is taking it apart, expanding subst tags, and then putting it back together again.

We could add say frame:getRawArgument() which would pass a flag up to LuaEngine::getExpandedArgument(). Then add a flags parameter to PPFrame::getArgument() and call it with RECOVER_ORIG.

Maybe request it in Phabricator if you want something like this.

Pppery (talkcontribs)
Reply to "Is that possible to get raw wikitext by Lua?"