Last modified: 2010-05-15 15:37:28 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 2615 - Add an "IFDEF" operator for template inclusion
Add an "IFDEF" operator for template inclusion
Product: MediaWiki
Classification: Unclassified
Templates (Other open bugs)
All All
: Normal enhancement with 2 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
Depends on:
Blocks: 2376
  Show dependency treegraph
Reported: 2005-06-29 19:57 UTC by ABCD
Modified: 2010-05-15 15:37 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Description ABCD 2005-06-29 19:57:37 UTC
It would be nice if there were to be an IFDEF-like method for template parameter


Parameter #1 is {{{ifndef:1|not}}} defined{{{ifdef:1|, and is set to: {{{1}}}}}}.
Comment 1 Brion Vibber 2005-06-29 20:50:29 UTC
See also bug 364.
Comment 2 David A. Wheeler 2005-10-19 16:28:30 UTC
It would be VERY nice to have an ifdef-like method, particularly for citations.
 The citation templates are exploding with so many variants you can't keep track
of them. (One template if there's an author and date... a different one if no
date... etc. etc. etc.).

Just have a "default" isn't enough, because you often want OTHER text but ONLY
if a given template parameter is defined.  Suggested syntax:

{{{?name ...replaceable text... }}}
  If "name" is defined, then use "replaceable text" (which may have
  normal text, template parameter references, and so on)
  If "name" is undefined, it has 0 length.

{{{!name ... replaceable text...}}}
  The inverse of "?".  If name is NOT defined, then use "replaceable text"...
  if name IS defined, then it has 0 length.
  Combining the two gives you an if...else, but you don't have to
  put them in the same place.

--- David A. Wheeler
Comment 3 Zoran Obradovic 2005-11-25 15:26:11 UTC
The funny thing is that we already have ifndef: {{{A|B}}} is equivalent to
ifndef(A) then "B", as long as A is either undefined or empty, i.e. something
like either {{pictureframe}} or {{pictureframe|notitle=}}.

This is, of course, cumbersome, as are extensions of syntax everybody is
proposing. What I think would be better to extend the {{{arg}}} syntax to 3
forms, the first two of which already exist:

{{{A}}} = print A 
{{{A|B}}} = ifdef A print A else print B, where B can be empty
{{{A|B|C}}} = ifdef A print B else print C, where both B and C can be empty

That would be a natural extension of the current syntax: it would make {{{A}}} a
shorthand for {{{A|A|A}}}, and {{{A|B}}} a shorthand for {{{A|A|B}}}.
Comment 4 lɛʁi לערי ריינהארט 2005-11-25 17:11:19 UTC

There are two similar requirements which differ by object type.

{{{A|B|C}}} = ifdef A print B else print C, where both B and C can be empty
I suppose that *A* in this case is regarded as a *parameter*.

at bug 2299 comment 5
( )
*A* is a *page* in the database; *exists* was used not *defined*;

IFEXISTS [[{{NAMESPACE}}:{{PAGENAME}}/archive]] THEN <code> where code could be
IFNOTEXISTS [[{{NAMESPACE}}:{{PAGENAME}}/to do/priority]] THEN <code>
Comment 5 lɛʁi לערי ריינהארט 2005-11-25 18:21:19 UTC
In common dayly language there are two meanings which can be associated with
"IFDEF" in connection with template parameters

a) If "parameter is present" when the template is called
at one page you write {{template_a|PARAMETER_IS_PRESENT=foo}}
at another {{template_a}}

b) if the parameter has a value other then the empty string (eventualy being NULL)

It is not easy to say whay "IFDEF" should be.
Comment 6 Ilmari Karonen 2006-01-07 20:43:03 UTC
"IFDEF" should probably have the meaning (a) above, to be consistent with the
way parameter defaults work.  A plain "IF" could, if desired, be used for
meaning (b).
Comment 7 Carl Fürstenberg 2006-01-07 21:53:23 UTC
The problem with your proposals is that you can't have | as an argument, so you
won't be able to create a row in a wikitable. I made a simple logic code,
perhaps using the "if-part of it as a extension?) 

See for your self:

The way it works is to ignore the wiki-code, and act as a preprocessor, using
{#..#} as definition, and as default | is delimiter per arguments, but can be
overrided by placing [delimiter] aftyer the first #, for example
Comment 8 Ilmari Karonen 2006-01-07 22:48:14 UTC
(In reply to comment #7)
> The problem with your proposals is that you can't have | as an argument, so you
> won't be able to create a row in a wikitable.

Is there a reason why "{{ifdef:foo | Some|Wiki|markup|with|vertical|bars.}}"
could not be made to work as expected?  I'm not familiar enough with MediaWiki
internals myself, but it shouldn't be impossible, should it?  Even if some code
automatically splits on "|", couldn't the fragments just be concatenated again?

Note You need to log in before you can comment on or make changes to this bug.