Page MenuHomePhabricator

templatesWithParams misses template where a parameter value has a curly brace
Closed, ResolvedPublic

Description

Investigating T240312: Error with curly braces in selector (eg when using subquery or UNION), I came down to pywikibot:

Reproduction steps:

import pywikibot

def main():
    site = pywikibot.Site(url="https://www.wikidata.org/wiki/")
    page_title = "User:Jean-Frédéric/T240312"
    page = pywikibot.Page(site, page_title)
    all_templates_with_params = page.templatesWithParams()
    print(all_templates_with_params)


if __name__ == "__main__":
    main()

Expected results:

[(Page('Template:Property dashboard'), ['grouping_property=P131'<snip>]), (Page('Template:Property dashboard end'), [])]

Actual results:

[(Page('Template:Property dashboard end'), [])]

Event Timeline

This is a known restriction of the parsing regex. to get the expected result please pip install mwparserfromhell. Here are the results:

Using parsing regex

>>> import pywikibot
>>> site = pywikibot.Site().data_repository()
>>> page = pywikibot.Page(site, 'User:Jean-Frédéric/T240312')
>>> temp = page.templatesWithParams()
>>> temp
[(Page('Template:Property dashboard end'), [])]
>>>

Using mwparserfromhell

>>> import pywikibot
>>> site = pywikibot.Site().data_repository()
>>> page = pywikibot.Page(site, 'User:Jean-Frédéric/T240312')
>>> temp = page.templatesWithParams()
>>> temp
[(Page('Template:Property dashboard'), ['grouping_property=P131', 'grouping_threshold=0', 'higher_grouping=wdt:P131', 'properties=P625,P18,P6375', 'property_threshold=0', 'selector_sparql=wdt:P17 wd:Q408; wdt:P31 ?type . { SELECT * WHERE { ?type wdt:P279 wd:Q7075 } }', 'stats_for_no_group=1']), (Page('Template:Property dashboard end'), [])]
>>>

Probably mwparserfromhell or wikitextparser should become mandatory for Pywikibot.

@Xqt Thanks for the swift answer! Installed mwparserfromhell and works like a charm. Thanks!