Page MenuHomePhabricator

Unable to get template arguments through API
Closed, DeclinedPublic

Description

Author: christopher.down

Description:
Currently it is very difficult to parse templates externally. For example, if there is a template on a page with {{bots|deny=foo}}, a query to the "templates" prop shows that the "bots" template is on the page, but there is no way to get its attributes (both args and kwargs).

As such, it would be nice to have some API call where you both get the templates on a page and their attributes. As far as I can see this isn't currently implemented (apologies if I've missed it).


Version: 1.20.x
Severity: enhancement

Details

Reference
bz40664

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 12:53 AM
bzimport set Reference to bz40664.
bzimport added a subscriber: Unknown Object (MLST).

christopher.down wrote:

I should mention that the reason that this is particularly difficult is because the ability to nest templates probably requires a CFG to properly parse them without this. It would be much easier just to be able to get this from the API.

[ Confirming bug: valid feature request. ]

The api allows you to get the (xml) parsetree of the parser with

  • action=parse&prop=wikitext&generatexml=
  • action=expandtemplates
  • prop=revisions&rvprop=content&generatexml=

christopher.down wrote:

(In reply to comment #3)

The api allows you to get the (xml) parsetree of the parser with

  • action=parse&prop=wikitext&generatexml=
  • action=expandtemplates
  • prop=revisions&rvprop=content&generatexml=

Doesn't seem to work for me. I just get "Unrecognized value for parameter 'prop': revisions".

prop is part of action=query and it was rvgeneratexml= (my comment should only be a hint to the doc http://en.wikipedia.org/w/api.php), but see the query for the parse tree:

http://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&
prop=revisions&rvprop=content&rvgeneratexml=

You can also use Special:ExpandTemplates (has to check a option) to see the parse tree, maybe that is human readable and easy to understand the parse tree for various input.

christopher.down wrote:

I'm not seeing how having the XML parse tree helps this situation, unless I'm missing something. Even with Special:ExpandTemplates and the example that I gave, there would be no indication of the content of the arguments being passed.

In case I am not being clear enough about what I am requesting, the sort of exchange I'm looking for would be something like this:

Input:

...&title=Foo

The content on page Foo is the following:

xxx{{wibble|bar|baz=qux}}yyy{{a|b|c=d}}

Output:

<template title="wibble">
    <arg id=1>bar</arg>
    <arg title="baz">qux</arg>
</template>
<template title="a">
    <arg id=1>b</arg>
    <arg title="c">d</arg>
</template>

Yes, that is not so easy to use, but it contains the information:

Parse tree: (pretty printed by me)

<root>
xxx
<template>

<title>wibble</title>
<part><name index="1"/><value>bar</value></part>
<part><name>baz</name>=<value>qux</value></part>

</template>
yyy
<template>

<title>a</title>
<part><name index="1"/><value>b</value></part>
<part><name>c</name>=<value>d</value></part>

</template>
</root>

You have the name and the values of the template.
Only as alternative.

Anomie set Security to None.