Template expansion via API fails
OpenPublic

Description

Author: volker.haas

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

Minimal Example:
http://en.wikipedia.org/w/index.php?title=User:Volker.haas/TemplateExpansion&oldid=544039610

API Call (without revision info of article...):
https://en.wikipedia.org/w/api.php?action=expandtemplates&format=jsonfm&text={{User:Volker.haas/TemplateExpansion}}

Result:

{
"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

http://en.wikipedia.org/wiki/Special:ApiSandbox#action=parse&format=json&page=User%3AVolker.haas%2FTemplateExpansion&prop=text

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.EditedVia ConduitMar 16 2013, 12:53 PM

Compare this with the behavior described on T30616: Special:ExpandTemplates - Preview seems to be parsed twice.

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. ***
Aklapper added a subscriber: Aklapper.Via WebMon, Apr 13, 2:26 PM

Is this really still high priority (priority not changed for two years) now that PDF rendering is done by OCG?

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.