Page MenuHomePhabricator

Default parameter values are not used when a parameter is explicitly set to null
Closed, InvalidPublic

Description

Author: dbenbenn

Description:
For example, the top of [[User:Dbenbenn/sandbox]] contains

{{User:Dbenbenn/sandbox2|size=}}

[[User:Dbenbenn/sandbox2]] is simply "{{{size|foo}}}". In the past, "foo" would
show. Now nothing does.

A real-life case where this causes a problem is in [[Template:Country
flagcountry]]. It currently uses

{{qif|test={{{size|}}}|then={{{size}}}|else=22x20px}}

and it has to, because it is called via [[Template:Country]], which passes the
"size" parameter forward via "size={{{size|}}}"


Version: 1.6.x
Severity: normal

Details

Reference
bz4708

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:02 PM
bzimport set Reference to bz4708.
bzimport added a subscriber: Unknown Object (MLST).

gangleri wrote:

Adding "blocks"
Bug 364: Optional parameters (and/or default parameter values) in templates

Please verify this dependency at the dependency tree for Bug 2376
http://bugzilla.wikimedia.org/showdependencytree.cgi?id=2376
and change it if necessary.

gangleri wrote:

Oops! Collision! Sorry!

omniplex wrote:

Empty is not the same as undefined, and defined is not the same as not empty,
I fail to see any "bug" here. Templates (q)if(n)def are pretenders, and poor
#if: is damned to emulate their oddities, but for a real test you can always
#ifeq:{{{x|+}}}|{{{x|-}}}|defined|undefined

I know undefined and empty are different concepts, but mediawiki is not a programming platform, it deals mainly with text content instead. It seems to me that assuming they're equal (as #if: currently does) would bring more good than evil.

On one hand, I can see several uses for leaving a parameter without a value (in an infobox, for example, for later filling -- that would greatly simplify the code in the template size, by removing all those ugly #if: tests).

On the other hand, I can't think of any reason one would want to explicitly set a parameter to an empty string; still, in that case, passing a whitespace (perhaps hardcoded as   or  ?) should suffice.

ayg wrote:

(In reply to comment #4)

On one hand, I can see several uses for leaving a parameter without a value (in
an infobox, for example, for later filling -- that would greatly simplify the
code in the template size, by removing all those ugly #if: tests).

Which #if tests could be removed? You'd still need to check if it's defined to know if you should render the row, typically.

On the other hand, I can't think of any reason one would want to explicitly set
a parameter to an empty string

You would if, for some reason, an empty value makes sense but is not the default. This is likely to occur in at least some cases.

still, in that case, passing a whitespace
(perhaps hardcoded as   or  ?) should suffice.

  and   are definitely not whitespace. They're entities, and are therefore explicitly *not* treated as whitespace. Unless you meant the corresponding Unicode characters, which would cause complete confusion. I don't see any way that this proposal would allow passing whitespace in the event you really did want it, which would be an unacceptable loss of flexibility.

On top of that, the change would most likely break thousands of templates across many wikis -- any significant behavior like this is likely to be relied upon by some people. So I'd be strongly inclined to WONTFIX.

Original request for behavior change was three years ago; current templates would be broken by the suggestion even if it was desirable which it's not clear that it is. Resolving as INVALID.