Page MenuHomePhabricator

Parameter auto-detection picks up other syntax elements
Closed, ResolvedPublic1 Estimated Story PointsBUG REPORT

Description

Example API call: https://en.wikipedia.org/wiki/Special:ApiSandbox#action=templatedata&format=json&includeMissingTitles=1&lang=en&titles=Template%3ANavbox%20element%20isotopes&formatversion=2

The API auto-detects two parameters: state, which is fine, and !}} style="border-spacing:1px;display:block;overflow:auto;width:100%;margin:0 !important"\n{{!}}- style="line-height:125%; vertical-align:top;"\n! style="text-align:right; width:3%; background:transparent" {{!}}. Yes, that's reported as the parameter name.

Detailed analysis

It is entirely impossible to use these sequences in a parameter name:

  • | separates different parameters. There is no way to escape this or any of the following in a parameter name.
  • = ends a parameter's name, and starts the value. At least when calling a template. The situation here is a little weird. It appears like attempting to use a parameter like {{{a=b}}} in a template is valid syntax. But it's (almost, see below) impossible to call this parameter. Attempting to do so will create bad wikitext that calls a parameter a instead of a=b.
  • {{ and {{{ start another syntax element, and }} and }}} end one.

It appears like it's technically possible to use the following sequences in a parameter name:

  • Single { and }.
  • \n, i.e. the parameter name is a multi-line string.

However, this is extremely unlikely. We can pretty much guarantee there is something weird going on. Either the auto-detection made a mistake. Or the template is just broken. No sane template programmer would ever use curly braces in a parameter name. They would be constantly confused with syntax. Same with newlines in the middle of a parameter name. I have never seen anything like that in the 15+ years I deal with wikitext. And I touched a lot of templates, from a lot of users. Let's assume these are errors and not offer them as auto-detected parameters.

Event Timeline

thiemowmde set the point value for this task to 1.

Change 717276 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/extensions/TemplateData@master] Fix parameter auto-detection picking up syntax elements

https://gerrit.wikimedia.org/r/717276

Change 717276 merged by jenkins-bot:

[mediawiki/extensions/TemplateData@master] Fix parameter auto-detection picking up syntax elements

https://gerrit.wikimedia.org/r/717276

It appears like attempting to use a parameter like {{{a=b}}} in a template is valid syntax. But it's impossible to call this parameter.

Actually, it’s possible. Either by including a template in the parameter name (e.g. {{test|a{{=}}b=x}}, where Template:= contains a single equal sign), or for example using Scribunto—its expandTemplate takes its parameter as a Lua table, thus there’s no ambiguity, and frame:expandTemplate{ title = 'Test', args = { ['a=b'] = 'x' } } does return x if Template:Test’s content is {{{a=b}}}. However, it’s not less insane than putting newlines or braces in template names, so I agree that such parameter-like things shouldn’t be auto-detected as parameters, false positives are way more likely than true positives.

Wow, thanks a lot for the additional information. I updated the task description accordingly, for future reference.