MediaWIki API - How to parse wikitext that contains Lua templates?

Viewed 153

I'm using a wikipedia API (https://www.mediawiki.org/wiki/API:Parsing_wikitext) to get the content of a Wikipedia pages in wikitext format and then parse it manually.

Some pages that I wanted to parse data from, use Scribunto extension and Lua scripting, which is embedded to a page content in form of a {{#invoke:}} template. I saw an API for expanding templates (https://www.mediawiki.org/wiki/API:Expandtemplates) but I didn't have much success with it because url parameters have limited length so the invoke templates that I needed were too long and didn't fit.

Is there any other way to parse/expand those {#invoke}} templates? Is there a wikipedia API which allows us to get wikitext of page with already expanded content?

2 Answers

The MediaWiki API accepts data from the POST body of requests too. Put the long data in there instead.

Using the URL parameters ?action=raw&templates=expand would give you the expanded Wikitext, after the preprocessing of all templates, parser functions and Lua scripts, but before rendering the Wikitext to HTML (also before the full parsing of extension tags and their contents).

The URL parameter ?action=render, on the other hand, would give you the final HTML rendering of the page content, without the UI around.

Related