Page MenuHomePhabricator

Consider linting/deprecating blank template parameter names
Open, Needs TriagePublic

Description

On https://www.mediawiki.org/wiki/Extension_talk:TemplateData#c-Jdforrester_(WMF)-20250919122700-Grufo-20250918210200 I was surprised to find out that Template:foo being {{{}}} with a call of {{ foo | = bar }} actually 'works'. This feels like an anti-feature, extremely surprising behaviour, and with no obvious reason to retain.

Should we decide that we want to eventually stop supporting this, and start linting these so they slowly get fixed?

Details

Event Timeline

Before changing anything, we should ask: What for? What will the current wikitext syntax gain from removing the empty-name parameter?

This has been a known wikitext feature for a long time. Besides the usual quirks like {{{|safesubst:}}}, it is the only way to create a template with a {{#switch:}}-like behavior, in which the empty-name parameter indicates a match with an empty string. E.g.:

{{My template
	| foo = Show this text if foo
	| bar = Show this text if bar
	| = Show this text if empty
}}

Before changing anything, we should ask: What for? What will the current wikitext syntax gain from removing the empty-name parameter?

In general, we are very slowly making wikitext syntax more consistent and less surprising without significantly reducing the kinds of structures that lack alternative forms and we judge are useful.

This has been a known wikitext feature for a long time. Besides the usual quirks like {{{|safesubst:}}},

That's an intriguing use-case.

it is the only way to create a template with a {{#switch:}}-like behavior, in which the empty-name parameter indicates a match with an empty string. E.g.:

{{My template
	| foo = Show this text if foo
	| bar = Show this text if bar
	| = Show this text if empty
}}

Can you explain why one would want to do that and not just use #switch?

we are very slowly making wikitext syntax more consistent and less surprising

Then wouldn't it look inconsistent and surprising, after we remove it, to realize that one single parsing function still allows it ({{#switch:}})?

Can you explain why one would want to do that and not just use #switch?

If it is a simple string match, of course, there is no reason to use anything other than {{#switch:}}. But it might be that {{My template}} does more complicate stuff – e.g. check the last editor of 20 pages; if it is the same editor call template XXX with nine parameters, in which both XXX and the nine parameters depend on the name of the last editor – e.g.:

{{My template|Page 1|Page 2|Page 3|Page 4|Page ...|Page 20
	| User Foo = Template AAA
	| User Bar = Template BBB
	| = Template No natch
}}

(In this example sequential parameters are reserved for page names)

Here is another use case of the empty-name parameter (see the {{unique coins}} template on enwiki):

{{#if:{{unique coins|{{{first|}}}|{{{second|}}}|{{{third|}}}|{{{fourth|}}}|{{{sixth|}}}|{{{seventh|}}}|{{{eight|}}}|{{{ninth|}}}|{{{tenth|}}}
	| = /
}}
	| show if at least one parameter is empty
	| show if no parameter is empty
}}

Doing the same without the empty-name parameter would be troublesome and computationally more expensive:

{{#if:{{#if:{{{first|}}}||!}}{{#if:{{{second|}}}||!}}{{#if:{{{third|}}}||!}}{{#if:{{{fourth|}}}||!}}{{#if:{{{sixth|}}}||!}}{{#if:{{{seventh|}}}||!}}{{#if:{{{eight|}}}||!}}{{#if:{{{ninth|}}}||!}}{{#if:{{{tenth|}}}||!}}
	| show if at least one parameter is empty
	| show if no parameter is empty
}}

Change #1343965 had a related patch set uploaded (by Osps7; author: Osama Eid):

[mediawiki/services/parsoid@master] Lint empty template parameter names

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

Implemented linting for empty template parameter names in Parsoid by detecting named parameters with empty names and recording a corresponding lint warning, while preserving the existing parsing behavior. Added a regression test covering {{test| = bar}}.

I feel like this lint is going to fire far too frequently to be useful. Before we add a lint, we should have a recommended rewrite for those places which are using this feature deliberately, The fact that named arguments can have a 'name' which is an empty string is *interesting* but not obviously a bug.

This has been a known wikitext feature for a long time. Besides the usual quirks like {{{|safesubst:}}},

That's an intriguing use-case.

Intriguing but unnecessary: it means substitution support can be broken in transclusions by e.g. {{Foo|=bar}} (which will also result in unwanted text being shown in the transclusion). A better method (which many English Wikipedia templates have been switched to) is some variant of safesubst:<noinclude/>.

Just to make it clear: why are we linting empty parameter names?

If the reasoning is something like “I feel that nobody will ever need this”—even though supporting it is naturally consistent with wikitext's syntax and Scribunto tables—shouldn't we apply the same reasoning to other unusual parameter names? Like |f3981##23= or |<>=?

What makes the empty parameter name different?