Template expansion via API fails


Author: volker.haas

The problem is that the expandtemplates API call returns with some unexpanded

Minimal Example:

API Call (without revision info of article...):


"expandtemplates": {

		"*": "blub<ref>{{Structurae|id=s0015184|title=Padma >Bridge|nolink=1}}, [[Padma Bridge|Report on the official hearing on construction >progress]]<\/ref>\n\n== References ==\n<div class=\"reflist >references->column-count references-column-count-2\" style=\"-moz-column-count: >2; -webkit-column-count: 2; column-count: 2; list-style-type: decimal;\">\n<references group=\"\"><\/references><\/div>"


This issue is criticial for the PDF rendering software (Extension:Collection and mwlib), since it now uses the API for expanding templates

Version: 1.21.x
Severity: critical
See Also:

bzimport added a project: MediaWiki-Parser.Via ConduitNov 22 2014, 1:16 AM
bzimport added a subscriber: wikibugs-l.
bzimport set Reference to bz46115.
bzimport created this task.Via LegacyMar 14 2013, 2:01 PM
hashar added a comment.Via ConduitMar 14 2013, 2:13 PM

With action=parse&prop=text&page=User:Voker.haas/TemplateExpansion


So I guess you want to use action=parse&prop=text&page= instead of action=expandtemplate.

bzimport added a comment.Via ConduitMar 15 2013, 1:22 PM

ralf_wikimedia wrote:

Does the above call expand templates and give me mediawiki markup? If not, that's not what we want...

hashar added a comment.Via ConduitMar 15 2013, 2:16 PM

Ah no, that render them :-] Sorry.

He7d3r added a comment.Via ConduitMar 16 2013, 12:53 PM

Compare this with the behavior described on bug 28616.

Anomie added a comment.Via ConduitApr 16 2013, 9:00 PM

The problem is that "expandtemplates" is a bit of a hack: it half-parses the wikitext to get new wikitext. But this half-parsing can't include calling tag hooks, because the tag hook returns HTML rather than wikitext. And it can't necessarily parse the text passed to the tag hook, because the tag hook might do almost anything with it (e.g. <syntaxhighlight> doesn't expand any templates, <ref> does, and it's theoretically possible to create a tag hook that would run inline Lua code or the like. So it just outputs the tag contents as-is.

It sometimes breaks in other ways, too. Consider, for example, what it does to something like "{{#tag:ref|Ref A<ref>Ref B</ref>}}".

Bug 28616 is similar: Special:ExpandTemplates half-parses the wikitext, and then parsed the half-parsed wikitext. This two-step parse can give different results.

bzimport added a comment.Via ConduitAug 23 2013, 8:42 AM

ralf_wikimedia wrote:

*** Bug 50090 has been marked as a duplicate of this bug. ***

bzimport added a comment.Via ConduitAug 23 2013, 8:43 AM

ralf_wikimedia wrote:

*** Bug 48872 has been marked as a duplicate of this bug. ***

TTO added a comment.Via ConduitAug 25 2013, 10:39 AM
  • Bug 53260 has been marked as a duplicate of this bug. ***

Add Comment

Column Prototype
This is a very early prototype of a persistent column. It is not expected to work yet, and leaving it open will activate other new features which will break things. Press "\" (backslash) on your keyboard to close it now.