Jump to content

Help talk:ParserFunctions

From Meta, a Wikimedia project coordination wiki
This is an archived version of this page, as edited by Jerome Charles Potts (talk | contribs) at 19:28, 9 November 2008 (→‎ISO 8601 duration: new section). It may differ significantly from the current version.

Latest comment: 15 years ago by Jerome Charles Potts in topic ISO 8601 duration

Archives: /Archive1

Bugs

Some known bugs (not necessarily limited to parser functions) are mentioned on the subject page, see also:
  1. substall 2777 = Optional substitution,
  2. corrupted defaults 5678 = ParserFunctions/5678,
  3. DIV and MOD 6068 = Help talk:Calculation,
  4. incorrect MOD results 6356 = ParserFunctions/MOD10000.

#time

I'm not sure why this is happening:

If I enter {{ #time: d M Y | 2007-10-08 }} I get 07 Oct 2007; I'm always one day behind, yet {{ #time: c | 2007-10-08 }} gives the correct date (2007-10-08T00:00:00+01:00). Anyone any clues as to what's happening here?

Sushiguru 21:02, 8 October 2007 (UTC)Reply


I found a workaround for this issue:

When I add a timezone statement as described in help page like {{ #time: d M Y | 20080425 -0000}} the date is displayed correctly. In my case the timezone setting have to be negative because a positive setting will show the date one day behind. With a negative timezone setting the day is displayed correctly. 141.30.103.214 07:36, 28 April 2008 (UTC)Reply

#Time

I am tring to use the #Time statement {{ #time: Y }} but I do see any result. The statement is not executed. The statements {{#expr: (30 + 7) * 7 }} and {{ #if: 1=1 | Yes | No }} are exectuted well, so the installation of ParserFunction should be correct. What can be the problem? --Bernard 10:15, 28 January 2007 (UTC)Reply

#time language

{{ #time: U | 4 March 2007 }} gives : 1172966400 , its ok.
But {{ #time: U | 4 марта 2007 }} gives : Error: Invalid time. - it is not right :( Berserkerus 16:08, 31 March 2008 (UTC)Reply

HTML Rendering Issues

I'm sure this is not specific to ParserFunctions, but others MUST have encountered this, the table tags that are conditionally added in a template (the stuff in the #if statements) is being rendered awkwardly. Instead of:

<tr><td colspan="2" align="center">

I am instead getting:

&lt;tr&gt;&lt;td colspan="2" align="center"&gt;

Does anyone know how to prevent this from happening? I just need to figure out where and why those characters are being substituted.

See below Talk:ParserFunctions#Solution_to_Tables_Problems --Dr DBW 21:23, 5 December 2006 (UTC)Reply

Further HTML (Tables) Problems

I have been trying to use the #if expression within tables, in a similar manner to the Template:Taxobox on the Wikipedia. Using the wikitext for tables, with the pipe character simple doesn't work how I want it to, even when using the exclaimation mark template.

Using the exclaimation marks works, correctly displaying a row if a parameter is displayed, and leaving the row out if that parameter isn't. The problem is that the text has a different format to the rest of the text on the page and it does not wrap within a cell, forcing the table to go to the width to accommodate the length of the line within the cell. Any ideas on solution around that or what is causing it to do that? Can't see with the Wikipedia code what is causing it for them to display correctly.

The other alternative I was trying out was to simple use HTML coding for the table instead. And that fails totally to work when used in conjunction with the #if expression. Any HTML code that is contained within the #if is not rendered / translated correctly, it is simply left as text and you see Cell contents. I have been looking around for awhile now in as many different places as I could, and can't see any mention why this happens and the possible solution to that issue. Appears that anything within the #if is considered as text only, not as any code / formatting instructions. This is also pointed out on these pages that I have manage to find in further searching:

--Dr DBW 21:01, 5 December 2006 (UTC)Reply

Solution to Tables Problems

Yah, think I have found the solution. New it would be out there somewhere. Missed the fact that there are achives of this discussion page, and it is on there. See here:

The solution is to enable $wgUseTidy. This is actually mentioned on the content page here for ParserFunctions:

YES this solution works and there is nothing additional to install. Simply add $wgUseTidy = true; to your LocalSettings.php file. --Dr DBW 21:22, 5 December 2006 (UTC)Reply

OK, knew there would be a reason that it is mentioned on the ParserFunctions#Tables page that it is a last resort. Everything seems to work fine after I installed it and couldn't find any issues. I got a note from another user, saying they tried it and it messed up their main page. I hadn't seen that, are using the CologneBlue skin. Checked the Main Page of my wiki today, and the coding is messed up. Effected is the images generated by the RandomImage extension. Some of the opening and closing tags of the code is generated as & gt; and then things fail. The code was working fine before enabling $wgUseTidy. --Dr DBW 20:57, 6 December 2006 (UTC)Reply
Have now worked out that it is a problem with displaying images, all images. Not just the RandomImage extension. So now all images within my wiki don't display correctly. I don't really know where I should be posting this problem now, so I have put full details on the MediaWiki site on the discussion page for $wgUseTidy: here: Manual talk:$wgUseTidy Any suggestions, am I putting this in the best location? --Dr DBW 00:02, 8 December 2006 (UTC)Reply
I have now worked out the Tidy only messes up the code generated by the gallery function or RandomImage extension. All other images displayed on pages is fine. Appears that those two components generate something that Tidy doesn't know how to handle correctly.--Dr DBW 22:21, 19 December 2006 (UTC)Reply
I am still having problems with having Tidy activated and messing up some of the code. Anyone have any suggestions on what can do, who can ask, any sense of what should be trying, who I should be bugging, anything? ;-) --Dr DBW 23:00, 8 February 2007 (UTC) Also appears that my indentations aren't working here, strange ....Reply
Upgraded to 1.9.3 and the problem still occurs --Dr DBW 23:47, 27 February 2007 (UTC)Reply
The issue with $UseTidy has been solved. See [[1]], appears that Tidy requires a configuration file (default on server either isn't valid or not present). --Dr DBW 03:43, 13 March 2007 (UTC)Reply

MediaWiki rendering versus Tidy

a‎ ‎ ‎ ‎ ‎ ‎z

Gangleri · Th · T 04:19, 15 April 2006 (UTC)Reply
Gangleri, I know this behaviour very well. This has nothing to do with ParserFunctions. This is current general behaviour of template inclusion. I've been circumventing the resulting newline by arranging it like this:
a{{ #ifeq: comparison text 1 | comparison text 2 | equal text | }}{{
    #ifeq: comparison text 1 | comparison text 2 | equal text | }}{{ 
    #ifeq: comparison text 1 | comparison text 2 | equal text | }}{{
    #ifeq: comparison text 1 | comparison text 2 | equal text | }}{{
    #ifeq: comparison text 1 | comparison text 2 | equal text | }}{{
    #ifeq: comparison text 1 | comparison text 2 | equal text | }}z
I write this just to report how I solve that problem in my everyday wikiwork.
Another very common problem that has occured quite often ist that when people add a <noinclude> to templates like en:template:cite web they tend do add that on a new line, which produces a new line in the output of the inclusion. This happens a lot when people add interwiki links to templates. This is especially a pain when done wrong on a high use template. And an even greater pain when such a template is protected and this fault is done by an admin and I can't fix it due to the protection of the template (but that is a wiki-politics question which has nothing to do with the dev side of the wiki world). However, I'm not sure if the adding of the \ will significantly improve the situation as this is another construct from the "programmers" world and sure difficult to understand for the non-programmer editors.
I just write here about my experience. And I am not sure about what to do to improve the situation. As for the \ if there are no solid arguments against it, it might be help.
However, I even suspect that part of the fear that editors feel when they start editing these kind of themplates is caused by this "surprising" newline behaviour. I have already asked myself if this shouldn't simply trimmed away from the output. But before doing this, some thorough thinking and investigation would be in order. But it might help lower the barrier for editing templates containing conditional code significantly. If anybody can point me to a case were trimming away the newlines would hurt, please let me know. --Ligulem 08:04, 15 April 2006 (UTC)Reply
Thanks Ligulem! It looks quite practical in LTR and a simple RTL example looks like this:
א{{ #ifeq: {{{יאָר}}} | 2006 | אַקטועל | }}ת
א{{ #ifeq: {{{יאָר}}} | 2006 | אַקטועל | }}{{
    #ifeq: {{{יאָר}}} | 2006 | אַקטועל | }}{{
    #ifeq: {{{יאָר}}} | 2006 | אַקטועל | }}{{
    #ifeq: {{{יאָר}}} | 2006 | אַקטועל | }}ת
The longer the statements are the more time you need to write / read / understand it. Gangleri · Th · T 12:10, 15 April 2006 (UTC)Reply
about 'noinclude' and 'includeonly': Again it is a metter of practice. Personaly I feel that
<noinclude>wikitext noinclude_1
wikitext noinclude_1_continued</noinclude>wikitext common_part
wikitext common_part_continued<includeonly>wikitext includeonly
wikitext includeonly_continued</includeonly><noinclude>wikitext noinclude_2
wikitext noinclude_2_continued</noinclude>
could be / should be written as
<noinclude>\
wikitext noinclude_1
wikitext noinclude_1_continued\
</noinclude>\
wikitext common_part
wikitext common_part_continued\
<includeonly>\
wikitext includeonly
wikitext includeonly_continued\
</includeonly>\
<noinclude>\
wikitext noinclude_2
wikitext noinclude_2_continued\
</noinclude>
It is easier to read, mark / copy the blocks and would be much easier to edit if both LTR and RTL characters are used. Gangleri · Th · T 11:51, 15 April 2006 (UTC)Reply

You can always use blockquote-tag, inside such tag, newlines are ignored (but then you have to add newlines by your self and hange thew margin to inherit etc.... 81.235.249.75 20:29, 15 April 2006 (UTC)Reply

Problems with #time

I've just installed the extension, and everything works fine except #time functions. If I include any of these, I just get an entirely blank page returned. I'm using Mediawiki version 1.6.8. Has anyone else had this problem? 161.72.11.196 16:33, 25 October 2006 (UTC)Reply

Nobody answered you, but I've just hit the same issue, and worked round it. You need Tim Starling's fix (see #New features, 1.7 compatibility above), including the third file which he didn't mention. --ColinFine 17:00, 15 January 2007 (UTC)Reply

ifexist created WantedPages in MediaWiki 1.10

I'm currently busy finding how and why there are WantedPages created with page names I am probing with "ifexist". This occured after having MediaWiki 1.10alpha installed, also on 1.10 (final). Problem to see here.

For episode links, there can be three types of writing because of disambiguation: "Episode-Name (Episode)", "Episode-Name (SER)" (SER can be DS9, TNG, ENT,...), or plain "Episode-Name". Even without linking to the episode, there are Wanted Pages lists created for all kinds of writing which renders this list to be useless. This is where the magic is: Template:EpLink. Anyone with similar problems or solutions? -- Florian K 08:25, 7 June 2007 (UTC)Reply

I made an addition to Help:ParserFunctions#Code_execution. It also gives a workaround.--Patrick 09:36, 7 June 2007 (UTC)Reply
this problem still exists as of today (2007-11-18). the double #if "trick" in Help:ParserFunctions#Code_execution does not work for this, only for template or category calls, because in this case the "link" is being added to the parser link list by the ifexist function on a lower level.
i've traced it down to the line $parser->mOutput->addLink( $title, $id ); that was added by tstarling in revision 19892 on Mon Feb 12 10:24:23 2007 UTC with the reason Register a link on #ifexist. Otherwise this breaks cache coherency..
i can find no reasoning for this change. all it is doing is checking if the target exists, and outputting one of two user supplied text blocks. it is not making a link to target, nor does it display a link to target anywhere in the scope of this functions code so why does the target need to be added to the link list?
--Uberfuzzy 10:05, 18 November 2007 (UTC)Reply
Have you tried removing that bit o' code and seeing what happens? Does anything break? —Sledged (talk) 19:17, 19 November 2007 (UTC)Reply

Installed, but #if still not recognized?

Hi, I've tried installing ParserFunctions at my wiki, but when I try a template which makes use of #if, it doesn't seem to be responding properly. Anyone knows what could be the problem? According to http://rommedahlen.dk/wiki/index.php?title=Speciel:Version Speciel:Version] it is installed. --Lhademmor 15:59, 23 February 2007 (UTC)Reply

What if you don't use a template but just on a page? --Dr DBW 03:03, 27 February 2007 (UTC)Reply
I'm having the same problem as Lhademmor on my Wiki. The #if function is used a lot in the Infoboxes, which are very useful; has anyone figured out why sometimes this does this? Is an additional extension or something needed?--Azurite 09:14, 29 July 2007 (UTC)Reply

Exactly the same problem here on MediaWiki version 1.11. Downloaded the ParserFunction pages to the specified folder, amended LocalSettings.php, but Special:Version still says nothing about ParserFunctions being installed. Main purpose of installing is to get #if working. Am I missing something obvious? 137.191.225.18 14:50, 10 December 2007 (UTC)Reply

Same problem again. I have MediaWiki 1.6. I have php4 and downloaded the older versions of the files for ParserFunctions. The infobox templates I had copied into my wiki show up as a complete mess along with a bunch of #if references. They were no affected by installing ParserFunctions.Corsulian 06:57, 29 December 2007 (UTC)Reply

Using #if or #ifexist...not to sure...

I am wondering what to use, if applicble to use (I've seen it used on Memory Alpha...). I use the code below for a character template, and want to know what would i use, and how I would use it (I don't seem to understand how it is written, and example here would give me a better idea). I've tried to adapt what I saw on Memory Alpha, but it didn't seem to work, so, what I'd like to know is...how do I do this?

<includeonly>{| align="right" border="1"
|-
| colspan="2" align="center" | '''{{{name}}}'''<br/>[[Image:{{{image1name}}}|{{{image1size}}}px]]
|-
| '''Name:'''
| {{{name}}}
|-
| '''Affiliation:'''
| {{{affiliation}}}
|-
| '''Rank:'''
| {{{rank}}}
|-
| '''Homeworld:'''
| {{{homeworld}}}
|-
| '''Species:'''
| {{{species}}}
|-
| '''Gender:'''
| {{{gender}}}
|-
| '''Date of Birth:'''
| {{{dateofbirth}}}
|-
| '''Age:'''
| {{{age}}}
|-
| '''Height:'''
| {{{height}}}
|-
| '''Weight:'''
| {{{weight}}}
|-
| '''Status:'''
| {{{status}}} <small>({{{statusyear}}})</small>
|}</includeonly>

--CaptainBrooks 23:51, 19 August 2007 (UTC)Reply

If you're asking how to hide empty values, try this:
| '''Name:''' || {{#if:{{{name|}}}|{{{name}}}|}}
(or put whatever after the last |, like a question mark--?) —Eep² 02:26, 20 August 2007 (UTC)Reply

This doesn't work, I copies the code and placed it like you did, and I get...."{{#if:" in the area that would be filled in if I filled it in, and a new column is made, where I get "}}" Any ideas what I could be doing wrong? Man, my fustration right now is through the roof.--CaptainBrooks 02:51, 20 August 2007 (UTC)Reply

Perhaps you try to use it on a wiki where ParserFunctions is not installed.--Patrick (talk) 08:48, 20 August 2007 (UTC)Reply

How do you tell if ParserFunctions arer installed or not? That makes a differnence on what will work or not?--CaptainBrooks 21:14, 20 August 2007 (UTC)Reply

Special:Version.--Patrick (talk) 23:54, 20 August 2007 (UTC)Reply

Apparently, there are no extensions at all, all I see on there is "This wiki is powered by MediaWiki, copyright (C) 2001-2006

Verbiage removed Noel (talk) 21:04, 13 March 2008 (UTC)Reply

   * MediaWiki: 1.8.4
   * PHP: 5.1.6 (cgi)
   * MySQL: 4.1.22-standard"

Does that mean that I don't have ParserFunctions installed?--CaptainBrooks 17:36, 21 August 2007 (UTC)Reply

Alright, I didn't even had paserfunctions installed apparently. Long story short, I installed the stuff, set the permissions and... it still does not work. Any ideas? --CaptainBrooks 02:11, 15 September 2007 (UTC)Reply

installs, but doesn't parse

Greetings I've read everything here, and then some. I just can't get #switch to work. I'm using

  • MediaWiki: 1.10.1
  • PHP: 5.1.6 (apache2handler)
  • MySQL: 5.0.27

on special:version it says it's installed, and I've made sure I'm using the current versions, I even tried the old versions, the wiki just won't do anything with it. Any ideas would be wonderfully appreciated. ThePoet444 14:51, 21 August 2007 (UTC)Reply

Hi, please try asking that over at MediaWiki's official website, or on #mediawiki on IRC. Thunderhead 11:52, 21 August 2007 (UTC)Reply
Searching Mediawiki leads me back here, so I'm stuck back at phase one. It seems there's something in this program that doesn't like the latest version of the wiki software, and I'm curious as to what. It's also bad form to go to the mediawiki site and say "hey, this third party extension doesn't work, can you help?" They'll point me back here. This talk page and the main page is the home of these functions, or so everything searching tells me. Perhaps I missed something? ThePoet444 14:51, 21 August 2007 (UTC)Reply
Having done more research, it seems Mediawiki has not moved this function over yet, so asking there on a page that doesn't exist yet is also silly. being an amateur coder, I haven't been much help trying to track this error down, but if I had to guess I would say that Parser.php isn't recognizing the ParserFunctions file, despite the fact it is installed as Special:Versions sees it. Any help would be wonderful. ThePoet444 10:36, 25 August 2007 (UTC)Reply
Can you give a markup/output example of what it's doing? —Sledged (talk) 02:55, 4 October 2007 (UTC)Reply

Unable to Install

Can't install..

Just in case this answers any of the problems above {or below - JNC} ....
... if everything seems to go okay but Special:Version does not register the installation, make sure you are using the correct version. For Mediawiki_1.11.0 and above you need the trunk version http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/ParserFunctions/

Cannot instal the extension

Hello,

I have a problem with the ParserFunctions extension. My MediaWiki runs on version 1.7.1 with Php 5.0 and I used the standard method to install the extension: Copy Expr.php and ParserFunctions.php in the extension directoy and write the command: require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" ); in LocalSettings.php

Unfortunately, when I open my wiki, lots of error messages appear and it doesn't work any more! How can I do to install correctly the Parser Functions? Without them, it is very difficult to build good templates...

Thank you for your help.

It sounds like you've installed it correctly, what are the errors that come up? does it show up in Special:Version?
You wrote: "Copy Expr.php and ParserFunctions.php in the extension directoy" Did you create a ParserFunctions subdirectory to put them in? --217.230.63.66 10:10, 8 June 2007 (UTC)Reply

Unable To Install 7

After I install ParserFunctions my wiki shows as a blank page in both IE and Firefox. What I did:

  1. Download Expr.php and ParserFunctions.php
  2. Put both into extensions/ParserFunctions
  3. Add to LocalSettings (at the bottom, directly above "?>"):
    require_once( "extensions/ParserFunctions/ParserFunctions.php" );

I'm running MediaWiki: 1.9.3, PHP: 5.2.1 (apache2handler), MySQL: 5.0.37-community-nt-log. If I comment out the a.m. line in LocalSettings the wiki works fine! I've doublechecked spelling of both LocalSettings and file names/path. I'm clueless. The only thing that is "special" about my setup is the fact that I'm running MediaWiki on a Windows Vista machine. Does that make any difference for ParserFunctions.php? Any help would be appreciated. Tetris L --217.230.63.66 10:21, 8 June 2007 (UTC)Reply

I just tried the php<5 (older versions of php prior to php5) version of Expr.php and ParserFunctions.php and it works fine with these, so my install setup really is okay. It must have to do with the latest version not being compatible with my system. Tetris L --217.230.63.66 10:31, 8 June 2007 (UTC)Reply
Further investigation: I can use the php5 version of Expr.php, and it'll still work, but I have to use the php<5 version of ParserFunctions.php. Weird. I'm definetly running php5. Tetris L --217.230.63.66 10:36, 8 June 2007 (UTC)Reply
Note: Registered. 217.230.63.66 is me. --Tetris L 11:18, 8 June 2007 (UTC)Reply

Unable to Install 8

I tried just a basic install, but instead of working correctly, every page on my wiki now puts out:

array( 0, 'expr' ), 'if' => array( 0, 'if' ), 'ifeq' => array( 0, 'ifeq' ), 'ifexpr' => array( 0, 'ifexpr' ), 'iferror' => array( 0, 'iferror' ), 'switch' => array( 0, 'switch' ), 'default' => array( 0, '#default' ), 'ifexist' => array( 0, 'ifexist' ), 'time' => array( 0, 'time' ), 'timel' => array( 0, 'timel' ), 'rel2abs' => array( 0, 'rel2abs' ), 'titleparts' => array( 0, 'titleparts' ), ); /** * Farsi-Persian */ $words['fa'] = array( 'expr' => array( 0, 'حساب', 'expr' ), 'if' => array( 0, 'اگر', 'if' ), 'ifeq' => array( 0, 'اگرمساوی', 'ifeq' ), 'ifexpr' => array( 0, 'اگرحساب', 'ifexpr' ), 'switch' => array( 0, 'گزینه', 'switch' ), 'default' => array( 0, '#پیش‌فرض', '#default' ), 'ifexist' => array( 0, 'اگرموجود', 'ifexist' ), 'time' => array( 0, 'زمان', 'time' ), 'rel2abs' => array( 0, 'نسبی‌به‌مطلق', 'rel2abs' ), ); /** * Hebrew */ $words['he'] = array( 'expr' => array( 0, 'חשב', 'expr' ), 'if' => array( 0, 'תנאי', 'if' ), 'ifeq' => array( 0, 'שווה', 'ifeq' ), 'ifexpr' => array( 0, 'חשב תנאי', 'ifexpr' ), 'iferror' => array( 0, 'תנאי שגיאה', 'iferror' ), 'switch' => array( 0, 'בחר', 'switch' ), 'default' => array( 0, '#ברירת מחדל', '#default' ), 'ifexist' => array( 0, 'קיים', 'ifexist' ), 'time' => array( 0, 'זמן', 'time' ), 'timel' => array( 0, 'זמןמ', 'timel' ), 'rel2abs' => array( 0, 'יחסי למוחלט', 'rel2abs' ), 'titleparts' => array( 0, 'חלק בכותרת', 'titleparts' ), ); /** * Indonesian */ $words['id'] = array( 'expr' => array( 0, 'hitung', 'expr' ), 'if' => array( 0, 'jika', 'if' ), 'ifeq' => array( 0, 'jikasama', 'ifeq' ), 'ifexpr' => array( 0, 'jikahitung', 'ifexpr' ), 'switch' => array( 0, 'pilih', 'switch' ), 'default' => array( 0, '#baku', '#default' ), 'ifexist' => array( 0, 'jikaada', 'ifexist' ), 'time' => array( 0, 'waktu', 'time' ), 'rel2abs' => array( 0, 'rel2abs' ), 'titleparts' => array( 0, 'bagianjudul', 'titleparts' ), ); # English is used as a fallback, and the English synonyms are # used if a translation has not been provided for a given word return ( $lang == 'en' || !isset( $words[$lang] ) ) ? $words['en'] : array_merge( $words['en'], $words[$lang] ); } 戼⁲㸯㰊㹢慆慴牥潲㱲戯㨾†慃汬琠湵敤楦敮⁤畦据楴湯†晥慰獲牥畦据楴湯睳牯獤⤨椠戼䔾尺慸灭屰瑨潤獣硜浡灰浜摥慩楷楫敜瑸湥楳湯屳慐獲牥畆据楴湯屳慐獲牥畆据楴湯⹳桰㱰戯‾湯氠湩⁥戼㔾㌱⼼㹢戼⁲㸯

Could somebody help! I just installed version 1.11 last week and everything seemed to be working fine. We're running: MediaWiki: 1.11.0, PHP: 5.2.5 (apache2handler), & MySQL: 5.0.51. Mountiandew1986 23:32, 22 January 2008 (UTC)Reply

Unable to Install 9

Recently upgraded from an older version of the ParserFunctions to the latest trunk and for some reason the functions stopped working even through the extension is listed as being installed in the version special page. Using the latest stable MW, 1.12.

By not working I mean every parser I try to use comes out unprocessed. Any ideas? -- Tufloc

Requests and proposals

MOD and DIV

Please comment mediazilla:6068 if I got it wrong, for a copy or discussion here see Help talk:Calculation. -- Omniplex (w:t) 03:06, 24 May 2006 (UTC)Reply

Patch has been created and is awaiting commitment. — Ambush Commander(Talk) 23:24, 16 June 2006 (UTC)Reply
Please look at Mediazilla for additional comments about your proposed patch (which breaks the compatibility). I propose introducing new operators instead, and leave "round" and "div" unchanged. Also I propose making the new "trunc" operator binary (like it is for "round"). See formula details and the rationale behind this in mediazilla:6068. When #expr were introduced, div and mod operators were really poorly designed, taking the existing poor design of the corresponding operators of PHP. But we must continue to live with that.
Various fixes have been proposed in the PHP development project, but all have been rejected for compatibility reasons with various PHP applications (not only MediaWiki). PHP designers have decided not to fix it, and consistently send people to the PHP supported math module instead. So the best is to stop using PHP's mod and div operators in newer Wiki operators based on functions found of this PHP math module. 86.221.90.101 21:46, 8 November 2006 (UTC)Reply

Request for string functions

Despite the great #expr function, I think string handling functions are also important and helpful to Wikipedia's editors. After looking into those PHP string functions which are really helpful, I suppose maybe the following are some:

  1. chr
  2. count_chars
  3. ltrim
  4. number_format
  5. ord
  6. rtrim
  7. str_ireplace
  8. str_pad
  9. str_repeat
  10. str_replace
  11. str_shuffle
  12. str_split
  13. str_word_count
  14. strcasecmp
  15. strchr
  16. strcmp
  17. strcoll
  18. strcspn
  19. strip_tags
  20. stripos
  21. stristr
  22. strlen
  23. strpbrk
  24. strpos
  25. strrchr
  26. strrev
  27. strripos
  28. strrpos
  29. strspn
  30. strstr
  31. strtok
  32. strtr
  33. substr_compare
  34. substr_count
  35. substr_replace
  36. substr
  37. trim
  38. ucfirst (implemented)
  39. ucwords
  40. wordwrap

I suppose this won't be a hard job, but just a normal form of function in ParserFunctions.php. If Tim thinks this is too difficult to implement, I just advise Tim to implement a few of them. Only a few will give much convenience for editors. Upssdr 05:47, 15 April 2006 (UTC)Reply

If this is done, I strongly suggest using the ANSI C function names rather than PHPs bastardized names. :P Some of these use ANSI C names, some of them, like strcasecmp, use new names (strcasecmp appears to be identical to ANSI C's stricmp). —Locke Coletc 06:56, 15 April 2006 (UTC)Reply
Ternary operator, C names, string operators, etc.: If we really want slang let's add it, not reinvent it. -- Omniplex (w:t) 00:12, 16 April 2006 (UTC)Reply
I don't follow: we're not reinventing anything, just suggesting functionality be exposed. —Locke Coletc 02:04, 16 April 2006 (UTC)Reply
Why I suggest these PHP functions is because they are easy to develop. No matter whether they're bastardized or ugly or disliked by you, they're always easy for Tim. Upssdr 03:40, 16 April 2006 (UTC) Also MediaWiki is not ANSI C++ compiler. UpssdrReply
That's nice. That has absolutely nothing to do with what I said. —Locke Coletc 09:07, 16 April 2006 (UTC)Reply
He's referring to the fact that it's not always a clear switch between the PHP behavior and C++ behavior. The worst thing we could do is a name a PHP function C++ style when it actually deviates in behavior. — Ambush Commander(Talk) 06:58, 22 June 2006 (UTC)Reply

I don't intend on implementing any functions which have a worst-case performance of O(N^2) or worse in the input size. Any such function would constitute a DoS vulnerability. This rules out str_replace and friends, str_pad, str_repeat, strspn and friends, and probably others, unless their time and memory usage can be appropriately limited. Since there's no array type, I can't see the point in implementing functions which act on or return arrays, such as count_chars and str_split. -- Tim Starling 10:57, 17 April 2006 (UTC)Reply

OK. Despite the O(n^2) and O(m*n) functions, there are still a few functions which is absolutely O(n) and contribute nothing to DoS vulnerability. Upssdr 05:52, 19 April 2006 (UTC)Reply

strlen & substr

These are the most important and basic string handling function. Upssdr 05:52, 19 April 2006 (UTC)Reply

I strongly support the addition of these two functions, if nothing else. --Algorithm 23:35, 30 April 2006 (UTC)Reply
I strongly support the addition of these two functions, and nothing else. --Alfakim 16:25, 27 May 2006 (UTC)Reply
One of the See Also entries is to StringFunctions. See that. (SEWilco 00:29, 28 May 2006 (UTC))Reply

There is an easy way to calculate the length of a string with the magic word padright. For example, a template with the folowing contents gives the length of the given string with a maximum of 10 characters:

{{#switch: {{{1}}}
|{{padright:{{{1}}}|10|*}} = 10
|{{padright:{{{1}}}|9 |*}} = 9 
|{{padright:{{{1}}}|8 |*}} = 8 
|{{padright:{{{1}}}|7 |*}} = 7 
|{{padright:{{{1}}}|6 |*}} = 6 
|{{padright:{{{1}}}|5 |*}} = 5 
|{{padright:{{{1}}}|4 |*}} = 4 
|{{padright:{{{1}}}|3 |*}} = 3 
|{{padright:{{{1}}}|2 |*}} = 2 
|{{padright:{{{1}}}|1 |*}} = 1 
}}

JePe 01:49, 20 November 2006 (UTC)Reply

The idea is very good, but there are problems. It fails when fed non-ASCII characters. The following example
{{#switch: inglés
|{{padright:inglés|10|*}} = 10
|{{padright:inglés|9 |*}} = 9 
|{{padright:inglés|8 |*}} = 8 
|{{padright:inglés|7 |*}} = 7 
|{{padright:inglés|6 |*}} = 6 
|{{padright:inglés|5 |*}} = 5 
|{{padright:inglés|4 |*}} = 4 
|{{padright:inglés|3 |*}} = 3 
|{{padright:inglés|2 |*}} = 2 
|{{padright:inglés|1 |*}} = 1 
}}
 

evaluates to 6 instead of 6.

I suppose this is a bug with padright:, but I know too little about the mechanics behind it to properly report it. Taragui 15:26, 12 December 2006 (UTC)Reply

That is probably because the symbol 'é' is a unicode character, so it's two bytes (to give 65536 possibilities), so the function treats it as two chars instead of 1. Also, I have created en:Template:Strlen based on this method (that will only work when feed ASCII chars. Polonium 17:36, 2 January 2007 (UTC)Reply
I guessed as much. However, I don't think that would be the intended behaviour for padright:, as width is measured in characters, not in bytes. I simply hoped someone more knowledgeable than me on the mechanichs of PHP would file the bug. Faute de mieux, I'll do so myself. Taragui 13:34, 12 January 2007 (UTC)Reply
Are there any objections to installing strlen and substr (native support, not the strlen hack described above). They would be useful and are DOS safe. Please raise any objections to these 2 functions (not other ones) here. Polonium 20:35, 12 January 2007 (UTC)Reply
I support adding these two. I also note that StringFunctions claims that all its members are O(n), and that at least one search-type function would be useful too.--69.79.73.143 17:52, 13 January 2007 (UTC)Reply

Request: Additional Functions

Loop Functions

Damnedmage 11:23, 24 June 2006 (UTC)Reply

When I found the parser functions, I fell in love. All that's left, now, is the ability to do repeats. Thus do I request the following parser functions:

#do
#for
#foreach
#loop
#until
#while
#wend
What would you use it for? Wiki is not a programming language! Platonides 21:04, 25 June 2006 (UTC)Reply
Why shouldn't it be? :) #if and #switch make it a pseudo-programming language! I see no reason an extension for these shouldn't be added. Mostly, though, I want to be able to do repeating rows. I do a lot of table-work in my Wiki dealing with tables of 20 rows that often hold specific mathematical information that could be calculated if I could build the table all at once, rather than having to build it one row at a time. :) --Damnedmage 16:47, 7 July 2006 (UTC)Reply
Not to mention if you have a template that puts together a table whose length is dependant on parameters. —Sledged 22:35, 23 October 2006 (UTC)Reply

I've made a template which has input structure like this

{{works
|author =
|work_1 =
|work_2 =
|work_3 =
|work_4 =
|work_5 =
}}

Because of that I support to request for #for parser function. Nein 17:16, 19 November 2006 (UTC)Reply

The big issue with these is puttting the server into a huge loop.  I do support adding a "for" function however. 204.62.68.23 21:18, 16 December 2006 (UTC)Reply
Have made an extension to allow some limited looping functionality, see mw:Extension:LoopFunctions, dunno if it would ever be included into pedia :) AzaToth 02:39, 17 December 2006 (UTC)Reply
Here is a foreach loop. it takes a text, pattern, replacement (from preg family) and input and output separators. it separates the text, then uses preg_replace and then joins it. e.g., {{ #foreach: one,two,three,thirteen| /th(.*)ee/ | [[xx${1}yy]] }} will give one,two,xxryy,xxirtyyn. Ittayd 07:54, 2 January 2007 (UTC)Reply
    public function foreach2Hook(&$parser, $text, $pattern, $replacement, $insep = ',', $outsep = ',' ) {
               $text = trim($text);
               $pattern = trim($pattern);
               $replacement = trim($replacement);
               $insep = trim($insep);
               $outsep = trim($outsep);

               $text = $parser->unstrip($text, $parser->mStripState);
               $localParser = new Parser();
               $output = $localParser->parse($text, $parser->mTitle, $parser->mOptions, false);
               $text = $output->getText();

               #return "got: text=$text,pattern=$pattern,replacement=$replacement,";
               $variables = explode($insep, $text);
               $result = preg_replace($pattern, $replacement, $variables);
               #return "" . $variables[0] . '=>' . $result[0] . "";   
               $result = implode($outsep, $result);
               return $result;
    }

The main problem with any LoopFunction is that it could be used for DOS attacks. For example, a vandal could enter {{#repeat:HAHA|9999999999}} or anything along those lines. The mass repetition of the string "HAHA" would overload and crash the servers. I actually support adding LoopFunctions, but they would have to be limited somehow (maybe a output maximum of 1.2 megabytes could work). Polonium 17:31, 2 January 2007 (UTC)Reply

Template limits already exist, so I so reason why "loop limits" could not be implemented for LoopFunctions. Polonium 20:16, 20 January 2007 (UTC)Reply

Advanced Math

I want to make templates that do math as part of their rendering. The #expr: function already does some of this, but I have been working for a while on gettign a square root - it hasn't worked very well. I suggest adding the basic scientific calculator functions such as exponentation (squar root simply being an exponent of .5) and trigonometric functions. The loop implementation would be a very inefficient substitute for this. 204.62.68.23 21:18, 16 December 2006 (UTC)Reply

See MathStatFunctions. Polonium 17:33, 2 January 2007 (UTC)Reply
As for a function that finds the square root, I have created a template that finds the square root of a number on en-wiki. See en:Template:Root. Polonium 15:31, 5 January 2007 (UTC)Reply
See also category:recursive conversion templates. I have tried to write one for the ex in wikiversity:en:, but I have encounted the problem that very large numbers are output as exponenets (something like 1234e5). Hillgentleman 15:48, 18 November 2007 (UTC)Reply

Request: Variables

This is probably needed much more when trying to make an super-inteligent template, which parses the name of a sub-sub-page (e.g. /page/subpage/sub-subpage) and includes other templates/images accoring to what the sub-parts of the entire path are. While doing so I often calculated the same thing again and again. So I came to an idea of storing values in temporary variables. An easy examaple:

 {{#set:a|1}}
 {{#set:b|2}}

 {{#expr: {{#var:a}} + {{#var:b}} }}

Is it possible to implement such support? (considering that a template that uses a specific variable name may be used in a template that uses the same variable name) --jsimlo 10:02, 22 July 2006 (UTC)Reply

Some motivation from real life:

{{#set:first| {{#pos:{{PAGENAME}}|/}} }}
{{#set:second| {{#pos:{{PAGENAME}}|/| {{#expr: {{#var:first}} + 1 }} }} }}
{{#set:third| {{#pos:{{PAGENAME}}|/| {{#expr: {{#var:second}} + 1 }} }} }}

Navigation:
[[{{#sub:{{PAGENAME}}| 0 | {{#var:first}} }}]],
[[{{#sub:{{PAGENAME}}| 0 | {{#var:second}} }}]],
[[{{#sub:{{PAGENAME}}| 0 | {{#var:third}} }}]],

Vs.:

Navigation:
[[{{#sub:{{PAGENAME}}|0|{{#pos:{{PAGENAME}}|/}} }}]],
[[{{#sub:{{PAGENAME}}|0|{{#pos:{{PAGENAME}}|/|{{#expr:{{#pos:{{PAGENAME}}|/}}+1}} }} }}]],
[[{{#sub:{{PAGENAME}}|0|{{#pos:{{PAGENAME}}|/|{{#expr:{{#pos:{{PAGENAME}}|/|{{#expr:{{#pos:{{PAGENAME}}|/}}+1}} }}+1}}

--jsimlo 10:15, 22 July 2006 (UTC)Reply

Try the variables extension. —Sledged 15:46, 24 October 2006 (UTC)Reply

Request #time-parameter o - ISO-8601 year number

In PHP-date there's a "o" parameter "ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)"[2]. Is it possible to add this? See also The Mathematics of the ISO 8601 Calendar for an ecxelent explanation.

Then it's possible to denote the ISO 8601 YYYY-Ww-D format: 2024-W26-1

Nsaa 13:32, 17 October 2006 (UTC)Reply

I didn't want to add a PHP 5.1 dependency just yet, that's why I left it out. Presumably we could simulate it, but I didn't think anyone would want it that badly. Was I wrong? -- Tim Starling 02:08, 18 October 2006 (UTC)Reply
In most of Europe people uses the ISO weeks, but not together with the year (most people doesn't realize the difference between the gregorian year and the ISO year - I've corrected a lot of PL/SQL stements from YYYYIW to IYYYIW ... IYYY denotes the ISO year in PL/SQL). Although I hope it's possible to implement further down the road. Here's the bug reported in PHP [3]. Nsaa 20:16, 18 October 2006 (UTC)Reply
Found a solution using Template:Isoyear like
this:{{isoyear|{{#time:Y}}|{{#time:n}}|{{#time:j}}}}{{#time:-\WW-N}}
and this gives: 2024-W26-1
I'm asuming the calculation in the ISOYear template is correct. Regards Nsaa 14:57, 10 November 2006 (UTC)Reply

StringFunctions

Please install the StringFunctions and DynamicFunctions. I often work on templates (at Wikipedia), and these functions would be very useful for some things. As they already exist, they should be installed.

StringFunctions is poorly protected against DoS attacks. DynamicFunctions appears to disable the cache on any page where it appears, thus it is unacceptable for Wikimedia. Features on Wikimedia which require access to these variables should preferably be implemented on the client side, in JavaScript. -- Tim Starling 02:00, 18 October 2006 (UTC)Reply
Ok, then no DynamicFunctions, but why not simply limit the length of a StringFunction string to 1024 bytes or something like that to stop DOS attacks? 72.139.119.165 19:41, 18 October 2006 (UTC)Reply
StringFunctions could be installed, but only ones which are completely O(n) (linear increase with string size) could be accepted because ones that increase exponentially could be used in DOS attacks (unless they are somehow limited, as suggested above). I support adding the substr and strlen functions because other functions could be made from them, they are DOS-safe, and very useful. Since DynamicFunctions break the cache, they cannot be installed on the MediaWiki servers. Polonium 15:37, 3 January 2007 (UTC)Reply

Variables

Are there any good reasons not to install the VariablesExtension? If not, the extension should be installed. Polonium 15:29, 5 January 2007 (UTC)Reply

Request #ifregex

Here's a simple one (patterend after #ifeq):

        function ifregex( &$parser, $pattern = '', $search = '', $then = '', $else = '' ) {
                if ( ereg( $pattern, $search ) ) {
                        return $then;
                } else {
                        return $else;
                }
        }

Maybe also do a #ifregexi (case insensitive). WsW 11:03, 15 April 2007 (UTC)Reply

formatnum:

See Bug 10454

First, the formatnum: parser function won't introduce separators as expected in the decimal part. For example, {{formatnum:0.1234567}} should render "0.123,456,7". This may be a localisation issue, but the option to format decimals in this way should at least be offered.

Secondly, formatnum: expects its input in a specific format, which is incongruous once localised. For example, French wikipedia templates that mix formatnum: parameters with non-formatnum: ones will force the user to specify the first ones with a period, the second ones with a comma. There should be an option (or an alternate parser function) that expects the input to be already localised, as far as the decimal separator goes.

For example, {{formatnum:123456.789012}} should give "123,456.789,012" under English localisation, "123 456,789 012" under French. But what most French contributors will want to write is "{{formatnum:123456,789012}}".

Urhixidur 15:18, 7 July 2007 (UTC)Reply

String Expressions

I would love to see additional string expressions such as "alphabetical > orthographical" so that I can make a self-sorting tables or lists. If this exists please tell me where I can find info. ~RayLast «Talk!» 17:15, 1 March 2008 (UTC)Reply


Other

Switch and equal signs

Maybe no bug, but interesting, apparently #switch: doen't support equal signs at all in compared values. It's of course possible to match urlencode-d values, and #ifeq: can handle equal signs. Another observation, #ifeq: (and probably also #switch) support numerical comparisons also for numbers in exponential format, see Help:Calculation#Comparisons. -- Omniplex (w:t) 06:50, 6 June 2006 (UTC)Reply

I ALSO have the same problem : http://encyclopedia.meta99.com/wiki/Cats Warning: Missing argument 2 for wfParserFunctionsLanguageGetMagic() in /home/httpd/vhosts/encyclopedia.meta99.com/httpdocs/extensions/ParserFunctions/ParserFunctions.php on line 144

Incorrect in #time

{{#time:H|12:00:00 -0100}} gives 13 instead of 11-- 14:53, 8 September 2006 (UTC)Reply

This is expected, it is just the way strtotime works. -0100 means "the preceding time specification was in the timezone -01:00 UTC". The function then converts it to UTC by adding one hour. -- Tim Starling 09:22, 30 September 2006 (UTC)Reply
Thank you for your answer. Well, I see, but I don't think it is very good because, for example, {{#time:H:i:s|-0100}} has no relation to the timezone -0100 UTC.-- 06:16, 13 October 2006 (UTC)Reply
I can see no explanation in the documentation of what should be the format of the time parameter. I would have expected that

{#time:H|12:00:00 -0100}}

gives just 12 (that is, the hour in the given timezone). Or is implied (but not described in the documentation) that all time are converted to UTC before printing it with the format specified? What we are suppose to think the following code

{#time:H e|12:00:00 -0100}}

is going to produce? (according to [4] e should print the timezone identifier (added in PHP 5.1.0)).
Is the time always converted to UTC or it is converted to the local timezone? (if different from UTC)
Again I have to said that the origin of ambiguities is that it is not defined the format of the parameter time. In the documentation at [5] (where it is called timestamp) it is said that it is an int not a string of character string. Below in the same documentation it is said that to generate this parameter form a string the function strtotime() should be use. So what happens when the mediawiki function #time is called? The second parameter (time) is passed to strtotime first? And this made time expressed as "12:00:00 -0100" to be silent convert to "13:00:00 UTC" (if local timezone is UTC)? (well perhaps I am too lazy, I could look up in the code, if I only have learnt php). -- AnyFile 10:24, 26 September 2007 (UTC)Reply

Year 2038 problem

I seem that Y2038 appears now.

  • {{#time:r|2038-1-19 03:14:07}} -> Tue, 19 Jan 2038 03:14:07 +0000
  • {{#time:r|2038-1-19 03:14:08}} -> Tue, 19 Jan 2038 03:14:08 +0000

--cpro 10:19, 27 September 2006 (UTC)Reply

This is a limitation in PHP's strtotime(), and also in date() for format characters which use it. I have no intention to fix it. -- Tim Starling 09:25, 30 September 2006 (UTC)Reply

Problem with #switch

When i use the #switch function, i get this error message:

Warning:  array_slice(): The first argument should be an array in/home/www/***/w/languages/Language.php on line 858
Warning:  Invalid argument supplied for foreach() in /home/www/***/w/includes/MagicWord.php on line 183

I use the "old" version, because i have PHP 4.

Anyone knows what is wrong? --193.90.237.253 14:15, 20 December 2006 (edit) (undo)

I have the same problem and it seems the suggestion from Talk:ParserFunctions/Archive_3#Notable_error_in_1.6.8 works. --Flominator 07:08, 21 March 2007 (UTC)Reply

New features, 1.7 compatibility

I've added extra format characters to #time, namely NwzWtLaAgGhcrU and the extension xN. I've also bundled a copy of sprintfDate with the extension, so it will now work with MW 1.7. -- Tim Starling 06:08, 25 September 2006 (UTC)Reply

Thanks for the terrific work you've done with this extension. However, I'm still experiencing two problems:
  1. Any HTML inside an #if statement (Infobox tables copied from Wikipedia, for example) seems to be converted to preformatted text.
  2. It completely breaks MW 1.7 when running concurrently with the Cite extension.
These errors have been mentioned here and elsewhere, but they don't seem to be widespread. Not sure why we're having these problems. I'm forced to run PHP5 as a CGI module on my server; could that be to blame? Any other thoughts? Thanks --Akabaka 20:23, 1 October 2006 (UTC)Reply

I got around your problem number 2 by copying a newer version of Hooks.php: http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/Hooks.php?revision=16282 However, I am still experiencing the issue with HTML inside #ifs being converted to "html entities". Did anyone have luck with running those on 1.7.1? Svemir Brkic 03:00, 9 October 2006 (UTC)Reply

Oops, I guess I should really read the instructions. As it suggests when "all else fails," adding the line $wgUseTidy=true; to my LocalSettings file did the trick. No more preformatted table code! Hooray! --Akabaka 20:58, 26 October 2006 (UTC)Reply

Tim Starling's fix seems to need a third file: SprintfDateCompat.php. I would add it to the list of links on the main page, but I've now got thoroughly confused as to what is neeeded for different versions of MW and different versions of PHP, so I'd probably add it in the wrong place. --ColinFine 16:34, 15 January 2007 (UTC)Reply

And SprintfDateCompat.php is inconsistent with PHP4. Oh joy. --ColinFine 16:52, 15 January 2007 (UTC)Reply

Relating to the SprinfDateCompat.php fix, if the system does not have class SprintfDateCompat or method sprintfDate or the file SprintfDateCompat.php, it crashes. Line 209 of ParserFunctions.php should check for file existence first and gracefully fail rather than crashing by attempting to load a nonexistent file.

To make SprintfDateCompat.php PHP4 compatible, simply remove the "static" keywords from lines 203 and 204.

Defining a parameter

Hello there, I want to use boolean parameters (as a flag): either there or absent. In this manner I want to set it like this:

{{zh|kurz|c=香港|p=Xiānggǎng}}

Obviously that doesn't work, and I have to add the equal sign to make it do so:

{{zh|kurz=|c=香港|p=Xiānggǎng}}

The testing I do is:

{{#ifeq: {{{kurz| }}}|{{{kurz|u}}} …

Is that the only way? Is it this way on purpose? Thanks for any clues. --Chrislb 21:44, 20 October 2006 (UTC)Reply

To use "kurz" (or any other non-empty string) instead of "kurz=", I would use an unnamed parameter: {{#if: {{{1| }}}| ….--Patrick 22:54, 20 October 2006 (UTC)Reply
I see the difference now. This solution doesn't work for me, as I already have several parameters (all named). As I see it's MediaWiki's implementation to treat "kurz=" as an empty parameter and "kurz" as a unnamed parameter with the content "kurz".
As I have several parameters I have to hold on to the named version: requesting to use the flag as first parameter (and then unnamed would work) might be to restrictive (users might screw it up and place it last instead). And as the numbers of parameters can vary in my template even checking the count of parameters is no solution...
Any other hints? Thanks for yours Patrick, it opened my eyes a bit for the understanding of MediaWikis handling.
Hmm, while typing this it comes to my mind that I can check with all given parameters for the value "kurz", though I can't check if it's for an unnamed variable or a named one, so {{zh|kurz}} will be the same as {{zh|p=kurz}}. Or is there a way to check that the variable for the given value is unnamed? --Chrislb 13:38, 21 October 2006 (UTC)Reply
{{{1}}} means the first unnamed parameter, the value can be provided after the named parameters. If there are more unnamed parameters, then you can check each for the value "kurz".--Patrick 00:21, 22 October 2006 (UTC)Reply
Oh, I didn't know that. Thanks, I think that's what I need. It should be the only unnamed one. I wonder why I didn't find that piece of information in the documentation. Maybe I'm blind. You really helped me. Thanks again. --Chrislb 21:09, 22 October 2006 (UTC)Reply

Inserting commas

We have an infobox that converts area in km2 to sq mi. For this to work, the input is not allowed to contain commas and the output does not contain commas - so it looks a bit messy. Is there any way around this? - 131.174.21.230 14:50, 9 November 2006 (UTC)Reply

For output you can use formatnum, see Help:Magic_words#Formatting.--Patrick 02:01, 10 November 2006 (UTC)Reply
Fantastic! Just the thing. Thanks! - 84.169.242.33 09:33, 10 November 2006 (UTC)Reply

Colors using #

While fiddleing with en:Template:Infobox mineral I stumbled upon a problem with colors written using #xxxxxx and #if in tables. I tried to do (template variables already eliminated):

{|
|- align=center style="background-color:{{#if:  |  |  #ff0000}}"
! colspan=2 align=center | a name
|}

gives:

  1. ff0000"
a name

With the #if eliminated:

{|
|- align=center style="background-color:#ff0000"
! colspan=2 align=center | a name
|}

gives:

a name


If I use named web colors it works:

{|
|- align=center style="background-color:{{#if:  |   |  red }}"
! colspan=2 align=center | a name
|}

gives:

a name

How can I use html hex colors in #if constructs in tables? --Ligulem 16:45, 18 November 2006 (UTC)Reply

Type like this:

{|
|- align=center style="background-color:{{#if: | |{{#color:#ff0000}}}}"
! colspan=2 align=center | a name
|}

Wich will result in:

{|
|- align=center style="background-color:rgb(255,0,0)"
! colspan=2 align=center | a name
|}

after adding this code to the ParserFunction.php:

 function colorHook( &$parser, $color='') {
 if(strpos($color, '#') !== false) {
 $hex = preg_replace('#[^A-Fa-f0-9]#', '', $color);
 switch(strlen($color)) {
 case 3:
 $r = hexdec($hex[0].$hex[0]);
 $g = hexdec($hex[1].$hex[1]);
 $b = hexdec($hex[2].$hex[2]);
 return "rgb($r,$g,$b)";
 case 6:
 $r = hexdec($hex[0].$hex[1]);
 $g = hexdec($hex[2].$hex[3]);
 $b = hexdec($hex[4].$hex[5]);
 return "rgb($r,$g,$b)";
 default:
 return $color;
 }
 } else {
 return $color;
 }
 }

and hooking it up properly. AzaToth 21:02, 18 November 2006 (UTC)Reply

Also:

{|
|- align=center style="background-color:#{{#if:  |  |  ff0000}}"
! colspan=2 align=center | a name
|}

gives:

a name

Patrick 01:48, 19 November 2006 (UTC)Reply

Sure, yes. But that would require the user specifying the color in hex for *all* calls of en:Template:Infobox mineral. Ideally the calls should be allowed to say "boxbgcolor = #ff0000" and "boxbgcolor = red". I just wonder why the parsing software interprets the # as being like at the beginning of a line (and thus emitting a numbered list). Nevertheless, thanks to both of you for responding. --Ligulem 09:45, 19 November 2006 (UTC)Reply

I think I found a workaround: Don't use wiki-table syntax:

<table>
<tr align=center style="background-color:{{#if:  |  |  #ff0000}}">
<th colspan=2 align=center>a name</th></tr>
</table>

gives:

a name

--Ligulem 17:13, 20 November 2006 (UTC)Reply

You can still use the wiki-table syntax. You just have to throw an empty nowiki tag in front of the #:

{|
|- align=center style="background-color:{{#if:  |  |  <nowiki/>#ff0000}}"
! colspan=2 align=center | a name
|}

gives:

a name

Sledged 17:51, 15 December 2006 (UTC)Reply

{|
|- align=center style="background-color:{{#if:  |  |  #ff0000}}"
! colspan=2 align=center | a name
|}

gives:

a name

It looks the same as the first example, but it isn't. ;) JePe 21:09, 15 December 2006 (UTC)Reply

Working with math tag

Is there any way around to work the parser function to work with math tag, for example instead of typing an atom symbol of with math, it can be done with just {{atom|name=He|number=2|mass=4|charge=2+}}. I've tried to made it with CSS, but now work perfectly. With LaTex (math), it doesn't work because math environment doesn't pass the variable. Nein 17:27, 19 November 2006 (UTC)Reply

When is #ifexist evaluated?

I'm thinking of writing an #ifexist statement that automatically adds a template to a page if another page is deleted or missing. Is this possible? Kimchi.sg 12:51, 28 November 2006 (UTC)Reply

Yes, see en:Template:Todo AzaToth 16:28, 28 November 2006 (UTC)Reply

Infobox_Company template

I am trying to make use of the Infobox_Company template on my site, but it is not rendering out correctly, I was told to install these parserfunctions, which I did, but still doesn't look right. I have a 1.8.2 MW install. Here's a link to the page: [6] . It's not rendering the table info like

<tr><th style="text-align:right; padding-right:0.75em;">Key people</th><td>Wayne C Fox (Chairman)
Richard W Nesbitt 

Just hoping someone can see what I did wrong. I appreciate any assistance. Thanks Rovo79 22:58, 30 November 2006 (UTC)Reply

I do not know the answer, but it seems a setting regarding HTML in wikitext needs to be changed to allow td-tags etc. even if not within table-tags, because this seems to be checked within #if instead of for the full wikitext after evaluating #if.--Patrick 13:13, 1 December 2006 (UTC)Reply
See above Talk:ParserFunctions#Solution_to_Tables_Problems --Dr DBW 21:27, 5 December 2006 (UTC)Reply

Logical and/or question

Sorry if this is the wrong place to post this, but I have a question I'm hoping someone can help with. Is there any way to do boolean and/or with parameters and #if, short of using nested if blocks? For instance,

{{#if {{{param1|}}} or {{{param2|}}}|then case|else case}}

Any help would be much appreciated. 67.168.181.152 10:19, 6 December 2006 (UTC)Reply

{{{param1|}}} is a string, not a boolean, so you cannot apply and/or on it. You can on a Boolean such as {{#if|{{{param1|}}}|1|0}}.--Patrick 10:54, 6 December 2006 (UTC)Reply
However, [(string1 is non-empty) or (string2 is non-empty)] can conveniently be checked by checking whether the concatenation is non-empty:
{{#if:{{{param1|}}}{{{param2|}}}|then case|else case}}
Patrick 12:41, 6 December 2006 (UTC)Reply

Bug when using colon in #ifeq:

If I use the following parser code in a category sub-page, e.g. Category:Test/subpage:

[[{{#ifeq: {{NAMESPACE}} | Category |:}}{{NAMESPACE}}:{{BASEPAGENAME}}]]

I would expect a link back to the root page (Category:Test):

Category:Test (wiki code: [[:Category:Test]])

Instead I get:

 [[

    Category:Test]] 

Which, in wiki code is :

[[
:Category:Test]] 

In other words, a newline is inserted before the colon, causing it to be treated as a blockquote.

This may also affect the other functions, and other symbols, e.g. *.

Logged as bugzilla:8199.

--HappyDog 14:54, 9 December 2006 (UTC)Reply

As a workaround you can use the escape sequence for a colon: &#58;
then the result is what you may predict. JePe 00:20, 10 December 2006 (UTC)Reply
Unfortunately, that doesn't seem to work. Please see mw:Template:Languages/Lang to see the page where the problem exists - it is quite a complicated template (called from mw:Template:Languages). See how it currently appears on a category page at mw:Category:Help. --HappyDog 01:58, 11 December 2006 (UTC)Reply
It is to complicated to test it there. But I think if you place the links within the parserfunction instead of the parserfunctions within the link, it shall work:
{{#ifeq: {{NAMESPACE}} | Category
| [[:{{NAMESPACE}}:{{BASEPAGENAME}}]] 
| [[{{NAMESPACE}}:{{BASEPAGENAME}}]] 
}}
Another possibility for this specific case is to avoid the the test for the category-namespace and place a colon for every link. That's possible for every namespace and you don't see the colon in the resulting link. JePe 12:38, 11 December 2006 (UTC)Reply
I'll try that. I believe I was doing that before, and added the test case because it wasn't working properly, but perhaps I was solving the wrong problem. --HappyDog 19:44, 11 December 2006 (UTC)Reply
Interestingly, I hard-coded the colon and the same problem exists (see [7]). Therefore the problem may not be with the #ifeq: function at all, but with the way parserfunctions are handled in general. Any thoughts? --HappyDog 19:48, 11 December 2006 (UTC)Reply
As suggested above I have put the links inside, that seems to work.--Patrick 00:29, 9 January 2007 (UTC)Reply
I thought I had tried that, but either I didn't get it right or there has been a code update since then as it didn't work. The new template code works fine now, but I should point out that the bug is not fixed, just worked around. Our reason for needing a fix has now been removed, so I won't be actively monitoring this, but it would be good if problem could be fixed properly sometime. Good luck! --HappyDog 01:28, 9 January 2007 (UTC)Reply

Possible bug in ParserFunctions version on en.wikipedia.org

Could someone please have a look at en:Template talk:Year in other calendars#Japanese calendar is back? I'm pretty sure the behavior I'm seeing is some kind of state leak bug. My second comment in that section points to three revisions of en:Template talk:Japanese year that demonstrate the odd behavior. Please contact me at en:User talk:Mike Dillon if you have any questions. Mike Dillon 19:23, 10 December 2006 (UTC)Reply

There is a more targeted test at en:User:Mike Dillon/Sandbox#Japanese dates involving only en:Template:Nengo and en:Template:Japanese era. It seems to be related to the use of en:Template:! in the case values of #switch, but that's just a guess at this point. Mike Dillon 20:36, 10 December 2006 (UTC)Reply

It seems some limitation on how much can be on one page. I don't know what the bottleneck is, perhaps the amount of wikitext after resolving the templates, or something like that.--Patrick 00:20, 11 December 2006 (UTC)Reply
Is there any way I can help diagnose the problem, or should I start looking for workarounds? I did notice that there is a difference in behavior when previewing the "Japanese dates" section on my sandbox versus viewing the whole page, so you may be right that it is related to size or call count. That being said, there are tons of ParserFunctions calls in the "Generic infobox" section on my sandbox (above "Japanese dates") and it doesn't seem that the preview of just the "Japanese dates" section would trigger the problem given that some of the ParserFunctions calls in that section work when viewing the full sandbox page. I hope my explanation wasn't too confusing, but I haven't been able to make heads or tails of the problem. I haven't yet resorted to "use the source Luke", since I'm not exactly sure which versions are deployed on English Wikipedia. Mike Dillon 01:38, 11 December 2006 (UTC)Reply
Apparently one cannot call w:Template:Japanese era, which has 36 switches, more than 931 times, so 33,512 switches on one page, directly or indirectly, are still allowed, a little more are not.--Patrick 13:28, 11 December 2006 (UTC)Reply
In an mxn array like w:Template:Japanese era you have m+1 switches; in a case like this where n<m you can reduce this to n+1 by putting #switch {{{2}}} first.--Patrick 13:02, 11 December 2006 (UTC)Reply
I don't know if this is a limit for #switch specifically, or if it is due to template limits (basically, the sum of the size of the source code of all templates on a page cannot exceed 2 MB). Polonium 00:41, 16 January 2007 (UTC)Reply
Yes, that's it, I think.--Patrick 09:59, 16 January 2007 (UTC)Reply
I tried putting 40000 switch statements on a page on a page in my userspace, but I could not load it (firefox gave a read timeout error because it took so too long to send the data, and the page was not created). I don't see any reason why you need 1000's of parser functions on a page. Polonium 01:04, 16 January 2007 (UTC)Reply

Data structures: returning multiple values

I am working on an improvement to the Clade template on en.. which would allow subclades to be contained in a single containing table (for alignment) rather than creating subtables. I need the (optional) subclade templates to be able to hand back two pieces of information to the master template - their wikitext and their row span (to calculate a total row span). I cannot see an easy way to do this. Obviously, string functions would make it easy; as would VariablesExtension (assigning variables from within the subclade templates then using them outside). I've also tried using the various tricks based on "reparsing" the text the subclade passes back (either as a template call with some variables already assigned, that is, something like partial-function-application; or as a pair of variable assignments, as in the nonworking "1=a|2=b" example), but it seems that once passed back as a result this is forever after treated as a "static string" and never reparsed (so I can't use it as in the hist5 example or the polygon example above, which both have static data in a template and not dynamic data returned by a template). Is there any way to accomplish what I'm trying to do? Or, if not, are string functions and/or VariableExtension on their way or have they been ruled as unsuitable for Wikipedia?

Meanwhile, I can require the user to precalculate rowspans, or call an extra template with identical variables to calculate it for them - but neither is ideal.

By the way, the hist5 example needs simplifying and explaining. --Homunq 15:22, 8 January 2007 (UTC)Reply

There is currently no active movement to install variables, but there are no serious objections as far as I know to the concept. Go to bugzilla and file a bug report to have them installed. As for StringFunctions, there are concerns that they could be used for DOS attacks, but the functions strlen and substr are linear and therefore make this objection moot. See bugzilla:6455 (proposal to install them, not rejected but currently inactive). Polonium 22:11, 8 January 2007 (UTC)Reply

| character

{{ #if: <condition> | <then text> | <else text> }}

I want to have a "|" character in <then text>. What should I do so that it is not treated as a separator between <then text> and <else text>? --194.141.30.140 17:01, 15 February 2007 (UTC)Reply

See Template:!.--Patrick 00:50, 16 February 2007 (UTC)Reply

Using links in expressions

I'm trying to make a template that turns a string into a link if the argument results in an article that exists, otherwise just inserts text. I'm using the following template presently, but while the correct text appears, it's not actually a link; instead I just see the text that should be a clickable link. I've confirmed that it's not the "doesn't exist" text appearing. Any ideas?

<span style="border: 1px solid #818151; background-color: #FFFFE1; font-size: 9px; vertical-align: text-top;">New in {{#ifexist: Firefox {{{1}}} for developers|[[Firefox {{{1}}} for developers{{!}}Firefox {{{1}}}]]|Firefox {{{1}}}}}</span>

You can see an example of what's going on on our staging server.

The idea is that if you use the template, specifying a version number for which a "Firefox X for developers" page exists, the little "new in" badge should be a clickable link to that article; otherwise it should just be plain text. Sheppy 21:09, 16 March 2007 (UTC)Reply

It working just fine, or at least it's working the way it's supposed to. The end result is that you have a wiki-link to the page you're already viewing, so it's bolded instead of hyper-linked. —Sledged (talk) 21:45, 16 March 2007 (UTC)Reply
I'm a moron. Forgot that it was on the same page. Ignore my stupidness. Sheppy 21:56, 16 March 2007 (UTC)Reply

time

If on March 30th {{ #time: m/Y | -1 months }} gives 03/2007 (1 month ago) I think that there is something completely wrong.

It is odd, but understandable, because 30 February does not exist.--Patrick 23:45, 29 March 2007 (UTC)Reply
i really think that answer must be Febuary 28th or (29th depends of year) - 80.235.43.61 23:26, 5 April 2007 (UTC)Reply
Same here too, i have {{#time: n | +1 month}} on January, 31st. The result is March but it should be February. I know why this is caused, but i do not know how to solve this problem. Does anyone have a clue?
Thanks in advance, kind regards
TurboKanne
I am having the same problem, it is currently, October 30th, 2008 and i have a listing that increments by one each month:
* [[...{{#time: Y"/"F | +6 month}}|{{#time: F Y | +6 month}}]]  (April)
* [[...{{#time: Y"/"F | +5 month}}|{{#time: F Y | +5 month}}]]  (MARCH)
* [[...{{#time: Y"/"F | +4 month}}|{{#time: F Y | +4 month}}]]  (MARCH)   <=== This one is the problem
* [[...{{#time: Y"/"F | +3 month}}|{{#time: F Y | +3 month}}]]  (January
* [[...{{#time: Y"/"F | +2 month}}|{{#time: F Y | +2 month}}]]  (December)
* [[...{{#time: Y"/"F | +1 month}}|{{#time: F Y | +1 month}}]]  (November)
Can this all be caused simply because Febuaray does not go past the 28 (29) and it is currently a 30th day on a month? --99.229.54.183 20:18, 30 October 2008 (UTC)Reply
Figgured out a fix(ish). Basically, if the current day is 29 or over, it will increment only 3 days (or 3 days and x months). This will force it to the next month. If you are trying to do accurate-to-the-day entries, you'll probably have to nest #ifexpr's for day 30 and 31. --99.229.54.183 15:24, 31 October 2008 (UTC)Reply
* {{#ifexpr: {{CURRENTDAY}}>=29 | [[...{{#time: Y"/"F | +3 days +5 month}}|{{#time: F Y | +3 days +5 month}}]] | [[...{{#time: Y"/"F | +6 month}}|{{#time: F Y | +6 month}}]]}}
* {{#ifexpr: {{CURRENTDAY}}>=29 | [[...{{#time: Y"/"F | +3 days +4 month}}|{{#time: F Y | +3 days +4 month}}]] | [[...{{#time: Y"/"F | +5 month}}|{{#time: F Y | +5 month}}]]}}
* {{#ifexpr: {{CURRENTDAY}}>=29 | [[...{{#time: Y"/"F | +3 days +3 month}}|{{#time: F Y | +3 days +3 month}}]] | [[...{{#time: Y"/"F | +4 month}}|{{#time: F Y | +4 month}}]]}}
* {{#ifexpr: {{CURRENTDAY}}>=29 | [[...{{#time: Y"/"F | +3 days +2 month}}|{{#time: F Y | +3 days +2 month}}]] | [[...{{#time: Y"/"F | +3 month}}|{{#time: F Y | +3 month}}]]}}
* {{#ifexpr: {{CURRENTDAY}}>=29 | [[...{{#time: Y"/"F | +3 days +1 month}}|{{#time: F Y | +3 days +1 month}}]] | [[...{{#time: Y"/"F | +2 month}}|{{#time: F Y | +2 month}}]]}}
* {{#ifexpr: {{CURRENTDAY}}>=29 | [[...{{#time: Y"/"F | +3 days }}|{{#time: F Y | +3 days}}]] | [[...{{#time: Y"/"F | +1 month}}|{{#time: F Y | +1 month}}]]}}

Table problems:

Hi i am working with the if statements in a table so that way if something is not there, that one part of the row will not show up. i have the code like this.

<TABLE BORDER=1 WIDTH=25% ALIGN="right" COLS=2>
{{#if: {{{System1|}}}|<TR><TD COLSPAN=2 ALIGN=center>'''{{{System1}}}'''</TD></TR>}}
</TABLE>

and instead of being part of the table. all it shows is:

<tr><td colspan="2" align="center">'''{{{System1}}}'''</td></tr>

Is there something that I am doing wrong?163.118.3.59 18:13, 5 April 2007 (UTC)Reply

The MediaWiki parser can't handle tables having parts in different templates or parser-functions. --Nad 02:21, 18 April 2007 (UTC)Reply
This does not seem true, we have e.g. Template:!.--Patrick (talk) 23:22, 9 January 2008 (UTC)Reply
i have the same problem, i copied the code from a template and it works there. in the sourcecode all < are written as &lt;. --213.23.168.170 11:42, 9 January 2008 (UTC)Reply
It is not clear whether is meant:
Things work fine on Meta, but not on my wiki.
or
The problem occurs also on Meta. (If so, give link to attempt.)
The code above seems to work fine here.Patrick (talk) 23:20, 9 January 2008 (UTC)Reply

Use of #ifexist in MediaWiki namespace

I'm trying to add an #ifexist function to the MediaWiki:Pagemovedtext so should a page exist at "Talk:$1/Comments" ($1 is the old page title), it would return a message to inform people that they need to move this page manually (with a link to Special:Movepage), but it doesn't seem to be working for my tests. Please see n:User:Zachary/Sandbox for the text I am trying to use. Please advise. Zachary talk 10:30, 25 April 2007 (UTC)Reply

Test Username

Is there a way to test whether or not a username exists? —Sledged (talk) 19:13, 25 May 2007 (UTC)Reply

No, only whether the user page exists, and whether the user talk page exists, I think.--Patrick 00:19, 26 May 2007 (UTC)Reply

titleparts

Where's the coverage of {{#titleparts}}? 155.69.160.147 09:20, 19 June 2007 (UTC)Reply

I added it.--Patrick 10:17, 19 June 2007 (UTC)Reply
If I want {{#titleparts}} to also consider whitespace's/underscores, what should I do? [8]-- 212.68.222.69 00:01, 26 August 2007 (UTC)Reply

#if:

Can somebody explain this? It contains {{#if:yes|x|{{User:Doron/bug2}}}} appearing 60 times, which should display 60 x's (or, at least, that's what I'd expect), but the last few fail and produce some junk. My only explanation is that the wiki software expands both the "then" and the "else" expressions before picking one of them according to the #if condition (rather than first evaluating the condition and then expanding only the relevant expression). In this case this would mean that although the condition should lead to the expansion of just x's, the parser would also try to expand User:Doron/bug2, which itself also contains lots of #if's with a very large redundant expansion of the alternative expression, ultimately leading to some sort of overflow. Is this correct?--Doron 09:02, 21 June 2007 (UTC)Reply

Well??? Is anybody watching this talk page at all?--Doron 11:00, 11 July 2007 (UTC)Reply

Your surmise is correct: this is entirely normal and is documented here. Take a look at the HTML source for that page ("View Source" in your browser). You will see that the expansion limit for your nested templates has been breached. This would explain why it is not working as you hoped. HTH HAND —Phil | Talk 11:12, 11 July 2007 (UTC)Reply

#if not compatible with AND operator?

I have been trying to use something like {{#if {{{param|}}}|true|false}} in a template, and it works fine. But when I try to add a second parameter and try to use the -and- operator, i.e. like this {{#if {{{param1|}}} and {{{param2|}}}|true|false}} it no longer works. Is only #expr compatible with the and operator? If that's the case, can I test for the existence/non-emptiness of two parameters with #expr? Thanks for your help! - Manu3d 23:26, 6 July 2007 (UTC)Reply

"and" works for #expr and #ifexpr only. You can use nested ifs: make the "true" part itself also conditional.--Patrick 10:03, 7 July 2007 (UTC)Reply

String to Number

I'm using the StringFunction #explode to get numbers from a timecode string that looks like this: 01:30:22:18. The #explode function however returns strings. How can I convert those strings into numbers, so that I can use them with #expr? Thanks for your help! - Manu3d 19:00, 17 July 2007 (UTC)Reply

#expr does not distinguish between e.g. the number 30 and the string 30.--Patrick talk 23:47, 17 July 2007 (UTC)Reply

Rounding down

How do I make it round down? The command "round 0" makes it round to the nearest whole number, up or down.

See Help:Modulo_and_round#Round.--Patrick talk 06:16, 20 July 2007 (UTC)Reply

#if single parameter

I'm trying to do this but it's just not working. What'm I doing wrong?

[[Wikipedia: {{#if:{{{1|}}}|{{{1}}}{{!}}{{{1}}}|{{PAGENAME}}}}]]

What I want is for the template to do [[Wikipedia:{{PAGENAME}}]] if no parameter is passed and [[Wikipedia:{{{1}}}|{{{1}}}]] (must repeat parameter after pipe or MediaWiki won't interpret the markup with just a pipe for some reason--bug: [[Wikipedia:ParserFunctions|]]) if a parameter is passed. -Eep² 10:00, 5 August 2007 (UTC)Reply

No, it's not including the "Wikipedia: " part when the parameter is specified... -Eep² 21:47, 5 August 2007 (UTC)Reply
I think the OP meant: why is [[Wikipedia: {{#if:{{{1|}}}|{{{1}}}{{!}}|{{PAGENAME}}}}]] not working. I.e., essentially, why [[Wikipedia:{{#if:x|abc{{!}}}}]] gives [[Wikipedia:abc|]]. Apparently the pipe-trick expansion is done before parser function expansion.--Patrick (talk) 06:46, 6 August 2007 (UTC)Reply
Actually, this is explained by the fact that non-substituted expansion of templates etc. is always done after the possible automatic conversion of wikitext. So if pipe-trick code is produced by non-substituted parser function expansion it does not work.--Patrick (talk) 07:19, 6 August 2007 (UTC)Reply
That's part of the problem but Hill is right in that I was specifying a pipe when I didn't want one. -Eep² 06:51, 6 August 2007 (UTC)Reply

HTML tags in #if

I wrote the following template

{{#if:{{{classe}}}|<div class="{{{classe}}}">|<div>}}{{{contenuto|Testo da includere}}}</div>

but

{{MyTemplate|classe=test|contenuto=MyPage}}

instead of generating

<div class="test">MyPage</div>

it generates

<div class="test"></div>
MyPage</div>

Why? --Dejudicibus 13:55, 28 August 2007 (UTC)Reply

The <div> often messes things up when implemented with PFs. Try an alternate configuration of the classes and PFs. AnonymousDissident 06:25, 15 September 2007 (UTC)Reply
It may be tidy prematurely closing tags you've opened. Instead of using
{{#if:{{{classe}}}|<div class="{{{classe}}}">|<div>}}{{{contenuto|Testo da includere}}}</div>
Try nesting the parser function inside the div tag:
<div {{#if:{{{classe|}}}|class="{{{classe}}}"}}>{{{contenuto|Testo da includere}}}</div>
Sledged (talk) 00:14, 4 October 2007 (UTC)Reply

HTML < and > escaped to lt and gt

Hi, I have installed latest wikimedia 1.10.1 with the ParserFunctions extension to get Templates.

But it seems that sometimes the < and > are escaped to lt and gt when they shoulf not.

One Example is the clear Template with a

 <div style="clear:both;" /> 

other examples include Templates that are splited.

Those templates work on Wikipedia but not if you were installing wikimedia 1.10.1 with Parser Extensions.

Is there another extension to install ?

82.246.25.153 17:35, 3 September 2007 (UTC)Reply

I have the same issue
This is in many of the infobox templates in wikipedia embedded in a <table> tag and (obviously) works fine:
{{#if: {{{editor|}}} | <tr><th>Editor</th><td>{{{editor}}}</td></tr>}}
However when I try it the angle brackets around the <tr> and <th> tags are changed to &lt; and &gt; in the html
but other tags such as <b> are unaffected - they remain as is. I assume this is an artefact of how Sanitizer.php treats different tags.
anyone got any ideas how come it works in wikipedia but not elsewhere?? many thanks!
Paul07481 17:17, 30 November 2007 (UTC)Reply

the behavior changes if '$wgUseTidy=true;' is specified in LocalSettings.php because a different hunk of code is executed in Sanitizer.php. Try that and see if it stops escaping the angle brackets on some html tags.

HTML escaping solution

I had this problem too. Adding '$wgUseTidy=true;' to the end of the LocalSettings.php (as mentioned above) solved the problem. I guess the default behaviour is for MediaWiki to expand HTML returned by the parser functions. 86.162.23.79 09:45, 3 August 2008 (UTC)Reply

#TIME problems

I am on mediawiki 1.9.2 when I type {{#time: Y F | August 2007}} i correctly get August 2007, but when I type {{#time: Y F | June 2007}} i get May 2007, what is going on, I have tried adding date (1) but still get same issue ??? Many thanks --Markw21 15:06, 11 September 2007 (UTC)Reply

Question About the Source Code

	function &getExprParser() {
		if ( !isset( $this->mExpr ) ) {
			if ( !class_exists( 'ExprParser' ) ) {
				require( dirname( __FILE__ ) . '/Expr.php' );
				ExprParser::addMessages();
			}
			$this->mExprParser = new ExprParser;
		}
		return $this->mExprParser;
	}

Shouldn't the part that reads:

$this->mExpr

instead read:

$this->mExprParser

Sledged (talk) 05:32, 12 September 2007 (UTC)Reply

Delimiter-separated lists into links

How can I get a comma-separated list (like "climb, dive, grab edge, jump, pick up, pull, push, roll, run, shimmy, shoot, sidestep, swim, vault, walk") in a template field into separate article links ("climb, dive, grab edge, "...)? Using StringFunctions with ParserFunctions, I tried nesting the {{#replace:}} in an {{#if:}} but StringFunctions doesn't render it if I try something like {{#if:{{{actions|}}}|[[{{#replace:{{{actions}}}{{!}}, {{!}}]], [[}}]]|?}} but it doesn't work (with the {{!}} or a |). The result is [[{{{actions}}}|, |]], [[}}]] (as-is in plaintext with no parameter replacement or formatting). —Eep² 07:51, 12 September 2007 (UTC)Reply

OK, I got some help here but there's still an issue with no space after a comma and a trailing comma at the end. Anyone? —Eep² 09:41, 17 September 2007 (UTC)Reply

Question regarding ParserFunctions #if

I'm attempting to do:

If

then Value: {{{value}}}
  else if 1
  then Value: 1
  else if 2
  then Value: 2
else Value: Undefined

That's the gist of it. The alternatives are uglier. It looks as though parser functions can do this, but I don't see how.

Please contact me at hewhocutsdown with the server gmail.com

Thank you

The #ifexist evaluation appears on the Special:Whatlinkshere as a link

The page where {{#ifexist:foo}} appears is listed on Special:Whatlinkshere/foo (as a page which links to foo). I don't know if it is a bug, or a (strange) requested feature.

Demonstration : I put {{#ifexist:ironietest}} on that message => see Special:Whatlinkshere/ironietest.

--ironie talk 12:17, 16 September 2007 (UTC) If someone could ask the bugzilla thing for me...Reply

The chapter "Code execution" gives some answers : "In the case of conditional parser functions (if, ifeq, ifexist, ifexpr, switch), the wikitext for each case (then-part, else-part, etc.) is internally "executed"/"processed"/"evaluated"..." --ironie talk 12:36, 16 September 2007 (UTC)Reply
I think it is not deliberate, but a consequence of how the code is currently organized.--Patrick (talk) 23:01, 16 September 2007 (UTC)Reply
Which raises the question I asked here. —Sledged (talk) 02:32, 17 September 2007 (UTC)Reply

if output messed up

This template results in the if rows showing up as text and not actual rows. How can I fix it? I even copied the exact code structure from Template:Infobox CVG.

{| cellspacing=0 style="border: 1px solid" border rules=cols
<!--________________________________________________Environment________________________________________________-->
|- style="background:#778" valign=top
! colspan=2 | [[:cat:environment|Environment]]
|- valign=top
| '''# [[level]]s''' || {{#if:{{{#levels|}}}|[[{{{#levels}}}]]|?}}
|- style="background:#797b86" valign=top
| '''[[:cat:locations|Locations]]''' || {{#if:{{{#levels|}}}|[[{{{#levels}}}]]|?}}
|- valign=top
| '''[[cutscene|Cutscenes]]''' || {{#if:{{{locations|}}}|[[{{{locations}}}]]|?}}
|- style="background:#797b86" valign=top
| '''[[:cat:damage|Damage<br><small>(traps/hazards)</small>]]''' || {{#if:{{{damage|}}}|[[{{{damage}}}]]|?}}
|- valign=top
| colspan=2 | '''[[:cat:interaction|Interaction]]'''
{{#if:{{{break|}}}|<tr valign=top><th align=right>[[break]]</th><td>[[{{{break}}}]]</td></tr>}}<!--
-->{{#if:{{{burn|}}}|<tr valign=top><th align=right>[[burn]]</th><td>[[{{{burn}}}]]</td></tr>}}<!--
-->{{#if:{{{close|}}}|<tr valign=top><th align=right>[[close]]</th><td>[[{{{close}}}]]</td></tr>}}<!--
-->{{#if:{{{drop|}}}|<tr valign=top><th align=right>[[drop]]</th><td>[[{{{drop}}}]]</td></tr>}}<!--
-->{{#if:{{{open|}}}|<tr valign=top><th align=right>[[open]]</th><td>[[{{{open}}}]]</td></tr>}}<!--
-->{{#if:{{{pick up|}}}|¦- valign=top\n! align=right ¦[[pick up]]¦¦[[{{{pick up}}}]]}}<!--
-->{{#if:{{{pull|}}}|<tr valign=top><th align=right>[[pull]]</th><td>[[{{{pull}}}]]</td></tr>}}<!--
-->{{#if:{{{push|}}}|<tr valign=top><th align=right>[[push]]</th><td>[[{{{push}}}]]</td></tr>}}<!--
-->{{#if:{{{ride|}}}|<tr valign=top><th align=right>[[ride]]</th><td>[[{{{ride}}}]]</td></tr>}}<!--
-->{{#if:{{{shoot|}}}|<tr valign=top><th align=right>[[shoot]]</th><td>[[{{{shoot}}}]]</td></tr>}}<!--
-->{{#if:{{{throw|}}}|<tr valign=top><th align=right>[[throw]]</th><td>[[{{{throw}}}]]</td></tr>}}<!--
-->{{#if:{{{turn on/off|}}}|<tr valign=top><th align=right>[[turn on/off]]</th><td>[[{{{turn on/off}}}]]</td></tr>}}<!--
-->{{#if:{{{interaction other|}}}|<tr valign=top><th align=right>other</th><td>[[{{{interaction other}}}]]</td></tr>}}
|- style="background:#797b86" valign=top
| '''[[puzzle|Puzzles]]''' || {{#if:{{{puzzles|}}}|[[{{{puzzles}}}]]|?}}
|}

Eep² 09:46, 17 September 2007 (UTC)Reply

Still having trouble with this...anyone? —Eep² 21:53, 26 September 2007 (UTC)Reply
I don't recommend mixing wiki- and HTML-syntax when it comes to tables. Take the line that reads:
{{#if:{{{break|}}}|<tr valign=top><th align=right>[[break]]</th><td>[[{{{break}}}]]</td></tr>}}<!--
And replace it with:
{{#if:{{{break|}}}|{{!}}- valign=top
! align=right ! [[break]]
{{!}} [[{{{break}}}]]
<nowiki/>}}<!--
Note that "{{!}}" is a call to a template whose only includeable (for lack of a better word) content is the pipe character ("|"). Also the trailing nowiki tag in the parser function is there to keep the parser from stripping the line break. Do a similar replacement with all the other lines. —Sledged (talk) 01:57, 4 October 2007 (UTC)Reply

Date comparison

Is there any decent way to compare dates? For example, how do I test whether a given date is before or after today's date? --Jonathan Kovaciny 21:55, 15 October 2007 (UTC)Reply

With U (seconds since January 1 1970 00:00:00 GMT):
  • {{#time:U}} gives 1719221486 [10]
  • "{{#time:U|17-10-2007}}" gives "1192579200" [11]

Patrick (talk) 00:40, 16 October 2007 (UTC)Reply

Using a table under the if tag

If I want to use the expression "if" and if someone uses the appropriate paramter, I want a table to appear. If the parameter isn't used, I don't want the table to appear. How do I do this if | is one of the parameters to make a table? (i.e. {| and |} ).

Help would be appreciated! --lincalinca 03:36, 17 October 2007 (UTC)Reply

On many wikis you can use the template {{!}} to get a pipe: "|" ( <-- I used the template there so you can see it works here ). If the wiki you are on doesn't have it, consider creating it by cpopying it from here. That's what I use when I need pipes. Perhaps that doesn't answer your question though... ++Lar: t/c 04:39, 17 October 2007 (UTC)Reply
Note that you can always use <table> <tr> <td> ... ∴ Alex Smotrov 22:33, 17 October 2007 (UTC)Reply

How to convert strings to numbers to use 0 for calculations?

Is there a possibility to convert strings (out of an inline query with smw) into numbers to make calculations with the { {#expr:...}} function? The preceding unsigned comment was added by 88.64.117.218 (talk • contribs) 21:38, 27 October 2007 (UTC)

#if or #ifeq

I am trying to make an advanced infobox but having trouble parsing information given. Hopefully this explanation works, because I can't think of any other way to word it.

As an example, I am curretnly using:

{{#ifeq:{{lc:{{{aarwheelsA1A-2|}}}}}|yes|, <tr><th>[[AAR wheel arrangement|AAR wheel arr.]]</th><td>[[AAR wheel arrangement#A1A-2|A1A-2]]</td></tr> }}
{{#ifeq:{{lc:{{{aarwheelsA1A-3|}}}}}|yes|, <tr><th>[[AAR wheel arrangement|AAR wheel arr.]]</th><td>[[AAR wheel arrangement#A1A-3|A1A-3]]</td></tr>}}
{#ifeq:{{lc:{{{aarwheelsA1A-A1A|}}}}}|yes|,<tr><th>[[AAR wheel arrangement|AAR wheel arr.]]</th><td>[[AAR wheel arrangement#A1A-A1A|A1A-A1A]]</td></tr>}}

But, I would rather use something like this:

{{#ifeq:{{lc:{{{aarwheels|}}}}}|A1A-2|, <tr><th>[[AAR wheel arrangement|AAR wheel arr.]]</th><td>[[AAR wheel arrangement#A1A-2|A1A-2]]</td></tr> }}
{{#ifeq:{{lc:{{{aarwheels|}}}}}|A1A-3|, <tr><th>[[AAR wheel arrangement|AAR wheel arr.]]</th><td>[[AAR wheel arrangement#A1A-3|A1A-3]]</td></tr>}}
{{#ifeq:{{lc:{{{aarwheels|}}}}}|A1A-A1A|,<tr><th>[[AAR wheel arrangement|AAR wheel arr.]]</th><td>[[AAR wheel arrangement#A1A-A1A|A1A-A1A]]</td></tr>}}

These are just a few of the possibilities in this string. I have a dozen or so of these variables to sort.

Basic goal: If X = A print link to article A If X = B print link to article B If X = C print link to article C etc, etc,

Hope my mumbles make some sort of sense. :) --DP67 (talk/contribs) 23:51, 10 December 2007 (UTC)Reply

  • When you apply lc the result can never be A1A-2 etc.
  • #switch seems more convenient
Patrick (talk) 01:24, 11 December 2007 (UTC)Reply
Thanks! So if I read properly the code should look something like this..
{{#switch: {{{builder}}}
| blw = <tr><th>Builder</th><td>[[Baldwin Locomotive Works]] (BLW)</td></tr>
| clc = <tr><th>Builder</th><td>[[Canadian Locomotive Company]] (CLC)</td></tr>
| emd = <tr><th>Builder</th><td>[[Electro-Motive Diesel]] (EMD)</td></tr>
| fm = <tr><th>Builder</th><td>[[Fairbanks-Morse]] (FM)</td></tr>
| ge = <tr><th>Builder</th><td>[[GE Transportation Systems]] (GE)</td></tr>
| gmd = <tr><th>Builder</th><td>[[General Motors Diesel|General Motors Electro-Motive Division]] (GMD)</td></tr>
| gm-emd = <tr><th>Builder</th><td>[[Electro-Motive Diesel]] (GM-EMD)</td></tr>
| hamilton = <tr><th>Builder</th><td>[[Lima-Hamilton Locomotive Works]] (LHLW)</td></tr>
| lima = <tr><th>Builder</th><td>[[Lima-Hamilton Locomotive Works]] (LLW)</td></tr>
| mlw = <tr><th>Builder</th><td>[[Montreal Locomotive Works]] (MLW)</td></tr>
| <!-- Default Blank -->
}}

Is that correct?? --DP67 (talk/contribs) 23:31, 11 December 2007 (UTC)Reply

Well,
That does work, only it drops the value given into the aricle as well as in the infobox where it is supposed to be. If I can make it stop dropping the text in the wrong place it will work.. --DP67 (talk/contribs) 23:46, 11 December 2007 (UTC)Reply
I don't understand what you mean, if this switch is in the inbox the output is only there.

--Patrick (talk) 01:55, 12 December 2007 (UTC)Reply

Ahh! I fixed it.. It's working now.. !Mucho gracias! Patrick for all the help! --DP67 (talk/contribs) 06:16, 12 December 2007 (UTC)Reply

problem with ifexist and parameter

I have the following source: (Test exist, tseT doesn't exist)

*{{subst:#ifexist:Test|1 2 3 4|5 6 7 8}}
*{{subst:#ifexist:tseT|1 2 3 4|5 6 7 8}}
*{{subst:#ifexist:Test|1 2 {{{1|3}}} 4|5 6 {{{1|7}}} 8}}
*{{subst:#ifexist:tseT|1 2 {{{1|3}}} 4|5 6 {{{1|7}}} 8}}
*{{subst:#ifexist:Test|1 2 {{{2|3}}} 4|5 6 {{{2|7}}} 8}}
*{{subst:#ifexist:tseT|1 2 {{{2|3}}} 4|5 6 {{{2|7}}} 8}}
*{{subst:#ifexist:Test|1 2 {{{3|3}}} 4|5 6 {{{3|7}}} 8}}
*{{subst:#ifexist:tseT|1 2 {{{3|3}}} 4|5 6 {{{3|7}}} 8}}
----
*{{#ifexist:Test|1 2 3 4|5 6 7 8}}
*{{#ifexist:tseT|1 2 3 4|5 6 7 8}}
*{{#ifexist:Test|1 2 {{{1}}} 4|5 6 {{{1}}} 8}}
*{{#ifexist:tseT|1 2 {{{1}}} 4|5 6 {{{1}}} 8}}
*{{#ifexist:Test|1 2 {{{2}}} 4|5 6 {{{2}}} 8}}
*{{#ifexist:tseT|1 2 {{{2}}} 4|5 6 {{{2}}} 8}}
*{{#ifexist:Test|1 2 {{{3}}} 4|5 6 {{{3}}} 8}}
*{{#ifexist:tseT|1 2 {{{3}}} 4|5 6 {{{3}}} 8}}

The result:

  • 1 2 3 4
  • 5 6 7 8
  • 1 2 1 2 3 4 4
  • 5 6 1 2 3 4 8
  • 1 2 5 6 7 8 4
  • 5 6 5 6 7 8 8
  • 1 2 3 4
  • 5 6 7 8

  • 1 2 3 4
  • 5 6 7 8
  • 1 2 {{{1}}} 4
  • 5 6 {{{1}}} 8
  • 1 2 {{{2}}} 4
  • 5 6 {{{2}}} 8
  • 1 2 {{{3}}} 4
  • 5 6 {{{3}}} 8

What can I do, to use numeric parameter "1" or "2" in ifexist?

An undefined parameter without default does not seem useful, for the other case see the workaround at Help:Substitution#Corrupted_default_value.--Patrick (talk) 01:11, 23 December 2007 (UTC)Reply
Thank you. I think the section can help me. It's not a bug, it's a feature. Der Umherirrende 12:16, 23 December 2007 (UTC)Reply

Super-nested parser functions

I've been dealing with some pretty hefty nested blocks for information generation, and I was just wondering if anyone had a better way of going about things. A good example is as follows:

For generating an address I've been using one big fat ugly line of nested goodness:

{{#ifeq:{{{BC Street Address|}}}||{{#ifeq:{{{BC City|}}}||{{#ifeq:{{{BC State|}}}||{{#ifeq:{{{BC Zip|}}}|||** '''Address''': }}|** '''Address''': }}|** '''Address''': }}|** '''Address''': }}{{#ifeq:{{{BC Street Address|}}}||{{#ifeq:{{{BC City|}}}||{{#ifeq:{{{BC State|}}}||{{#ifeq:{{{BC Zip|}}}|||{{{BC Zip}}}}}|{{#ifeq:{{{BC Zip|}}}||{{{BC State}}}|{{{BC State}}} {{{BC Zip}}}}}}}|{{#ifeq:{{{BC State|}}}||{{#ifeq:{{{BC Zip|}}}||{{{BC City}}}|{{{BC City}}} {{{BC Zip}}}}}|{{#ifeq:{{{BC Zip|}}}||{{{BC City}}}, {{{BC State}}}|{{{BC City}}}, {{{BC State}}} {{{BC Zip}}}}}}}}}|{{#ifeq:{{{BC City|}}}||{{#ifeq:{{{BC State|}}}||{{#ifeq:{{{BC Zip|}}}||{{{BC Street Address}}}|{{{BC Street Address}}}, {{{BC Zip}}}}}|{{#ifeq:{{{BC Zip|}}}||{{{BC Street Address}}}, {{{BC State}}}|{{{BC Street Address}}}, {{{BC State}}} {{{BC Zip}}}}}}}|{{#ifeq:{{{BC State|}}}||{{#ifeq:{{{BC Zip|}}}||{{{BC Street Address}}}, {{{BC City}}}|{{{BC Street Address}}}, {{{BC City}}} {{{BC Zip}}}}}|{{#ifeq:{{{BC Zip|}}}||{{{BC Street Address}}}, {{{BC City}}}, {{{BC State}}}|{{{BC Street Address}}}, {{{BC City}}}, {{{BC State}}} {{{BC Zip}}}}}}}}}}}

In order to write that line of code, I had to write out the following and then condense it:

{{#ifeq:{{{BC Street Address}}}|| /if no address
  {{#ifeq:{{{BC City}}}|| /if no city
    {{#ifeq:{{{BC State}}}|| /if no state
      {{#ifeq:{{{BC Zip}}}|| /if no zip
        Print nothing
      | /if zip
        {{{BC Zip}}} /print zip
      }}
    | /if state
      {{#ifeq:{{{BC Zip}}}|| /if no zip
        {{{BC State}}} /Print state
      | /if zip
        {{{BC State}}} {{{BC Zip}}} /Print state zip
      }}
    }}
  | /if city
    {{#ifeq:{{{BC State}}}|| /if no state
      {{#ifeq:{{{BC Zip}}}|| /if no zip
        {{{BC City}}} /print city
      | /if zip
        {{{BC City}}} {{{BC Zip}}} /Print city zip
      }}
    | /if state
      {{#ifeq:{{{BC Zip}}}|| /if no zip
        {{{BC City}}}, {{{BC State}}} /Print city, state
      | /if zip
        {{{BC City}}}, {{{BC State}}} {{{BC Zip}}} /Print city, state zip
      }}
    }}
  }}
| /if street address
  {{#ifeq:{{{BC City}}}|| /if no city
    {{#ifeq:{{{BC State}}}|| /if no state
      {{#ifeq:{{{BC Zip}}}|| /if no zip
        {{{BC Street Address}}} /print street
      | /if zip
        {{{BC Street Address}}} {{{BC Zip}}} /Print street, zip
      }}
    | /if state
      {{#ifeq:{{{BC Zip}}}|| /if no zip
        {{{BC Street Address}}}, {{{BC State}}} /Print street, state
      | /if zip
        {{{BC Street Address}}}, {{{BC State}}} {{{BC Zip}}} /Print street, state zip
      }}
    }}
  | /if city
    {{#ifeq:{{{BC State}}}|| /if no state
      {{#ifeq:{{{BC Zip}}}|| /if no zip
        {{{BC Street Address}}}, {{{BC City}}} /print street, city
      | /if zip
        {{{BC Street Address}}}, {{{BC City}}} {{{BC Zip}}} /Print street, city zip
      }}
    | /if state
      {{#ifeq:{{{BC Zip}}}|| /if no zip
        {{{BC Street Address}}}, {{{BC City}}}, {{{BC State}}} /Print street, city, state
      | /if zip
        {{{BC Street Address}}}, {{{BC City}}}, {{{BC State}}} {{{BC Zip}}} /Print street, city, state zip
      }}
    }}
  }}
}}

This is essentially going through every possible combination and writing out the result. It seems very redundant, but it seems almost necessary due to the fact that separators (commas) are there or not there depending on surrounding content. Is there a cleaner way to do this? I feel like I may be doing something dumb and not noticing. This is a really simple example of the amount of nesting I'm doing; more variables involved in one output line is a huge increase in the number of possible combinations... it gets much worse!

Thanks in advance! Andrew 207.154.64.19 22:47, 4 January 2008 (UTC)Reply

Refuses to Parse

I'm running MediaWiki 1.11.0, but previously had 1.10.0 installed and the same issue occured. This is on Ubuntu gutsy with php5.2.3-1ubuntu6.2 (apache2handler) and MySQL 5.0.45-Debian_1ubuntu3.1-log.

I'm doing my best to use Wikipedia's Navbox/Tnavbar templates, but it doesn't parse any of the #if or #ifeq statements. Furthermore, it leaves a hanging or (sometimes both) after the vde. It also has a bunch of unparsed table HTML before the template uses in the /doc, which I assume is supposed to be included in the template call, hidden when you click [hide] and shown when you click [show] (this option doesn't even appear the bars).

For example, before one of the navbars on Template:Navbox/doc I get this chunk:

<tr><td rowspan="4" style="vertical-align:middle; padding-right:7px; width:0%;">{{{imageleft}}}</td><td colspan="1" style="text-align:center;width:100%;font-size:95%;border-style:inset; border-width:2px;">{{{list1}}}</td><td rowspan="4" style="vertical-align:middle; padding-left:7px; width:0%;">{{{image}}}</td></tr><tr><td colspan="1" style="text-align:center;width:100%;font-size:95%;background:#f7f7f7;border-style:inset; border-width:2px;">{{{list2}}}</td></tr><tr><td colspan="1" style="text-align:center;width:100%;font-size:95%;border-style:inset; border-width:2px;">{{{list3}}}</td></tr><tr><td colspan="1" style="text-align:center;width:100%;font-size:95%;background:#f7f7f7;border-style:inset; border-width:2px;">{{{list4}}}</td></tr>

After which it shows me the navbar, which is correctly formatted except for that the vde is large and not mini, as it should be had it correctly parsed the #ifeq that changes it into its smaller form.

I can't figure out why this is happening (obviously). I've tried hunting down what extensions Wikipedia has, but there's no list. Trying to retrieve the dumps from Wikipedia to see if I simply copied something wrong has proven useless; apparently, the files I've downloaded have been broken every single time, and furthermore, they're 3 GB, when I only want the templates (and really only a small number of them).

EDIT: I did test out just creating tables with HTML and that worked fine, so my wiki is parsing that much, but when it comes to ParserFunctions...

#if not functioning improperly in en wikipedia

in wikipedia i have a template that uses {{#if:{{{2}}}|{{{2}}}|else this}}

when called without the parameter {{{2}}} it used to display "else this"

however now it simply displays {{{2}}} even though the parameter is not called. e.g.:

{{mytemplate|param1}} displays {{{2}}} instead of "else this" - it was working fine. suddenly it doesnt work now.

{{mytemplate|param1|param2}} functions correctly and displays "param2"

The template relied on a bug that has been fixed. Simply use {{{2|else this}}} instead.--Patrick (talk) 10:40, 25 January 2008 (UTC)Reply
Got it. Thanks :)

Question about the #if example given in the article?

In the given example;

{{ #if:  {{{parameter|}}} | Parameter is defined and not the empty string. | Parameter is undefined, or empty  }}

What is the function or purpose of the pipe that follows the 'parameter' ({{{parameter|}}})? What is this doing here, and how does it affect the result? Cheers --Dmb 21:33, 25 January 2008 (UTC)Reply

The pipe is the "if undefined" parameter fallback. For example, say you have a template that uses the page name in the text, but lets you optionally supply your own, eg:
Wiktionary has an article about {{{1|{{PAGENAME}}}}
If called with a parameter, it is used as {{{1}}}, if not, the page's name is used. For #if, it required (or rather, is pointless without) to have a null fallback, which serves as the 'false' case, as #if checks against nullity. Splarka 04:38, 26 January 2008 (UTC)Reply

Question about #time

What parameters do I need to use to get #time to spit out what day (Mon, Tue, etc.) it is on the first of a particular month in the current year? I've seen {{#time:D|{{#time:Y}}-{{{month}}}-01 +1 second}} used but I don't know how to input the month I want. Mufka 23:30, 25 February 2008 (UTC)Reply

Got it to work using {{#time:D|{{CURRENTYEAR}}0101}} Mufka 03:32, 26 February 2008 (UTC)Reply

Nesting #if problem

I have an #if statement that isn't working properly, I thought I fixed it by using AND, but that didn't work.

 {{#if:{{{1|}}} AND {{{2|}}} AND {{{3}}}|[[{{{1}}}]], [[{{{2}}}]], and [[{{{3}}}]]|
 {{#if:{{{1|}}} AND {{{2|}}}|[[{{{1}}}]] and [[{{{2}}}]]|
 [[{{{1}}}]]
 }}
 }}

Any thoughts? - LA @ 14:45, 28 February 2008 (UTC)Reply

AND is applied to truth values 1 and 0, which are in this case produced by {{#if:{{{1|}}}|1|0}} etc.--Patrick (talk) 17:20, 28 February 2008 (UTC)Reply

special:Allmessages#msg_pfunc_max_ifexist_category

Dear friends; please see special:Allmessages#msg_pfunc_max_ifexist_category and special:Allmessages#msg_pfunc_ifexist_warning. Please see

w:en:category:Pages with too many ifexist calls
test:category:Pages with too many ifexist calls
a list about topics related to MediWiki language prefixes etc.

question: special:Allmessages#msg_pfunc_ifexist_warning is not shown there ... What are the exact values for « $1 » and « $2 » ? Best regards
‫·‏לערי ריינהארט‏·‏Th‏·‏T‏·‏email me‏·‏‬ 13:36, 6 March 2008 (UTC)Reply

Unpredictability of Sci Notation Output using expr

Sometimes the output is in Sci notation & sometimes it is not. Is it the time of day? the server that processes the code?

Below are roundings of constants 6,655,046,294.9 and of 33,200,000

  • rounded to nearest billion: 7000000000 || 0
  • rounded to nearest 100-million: 6700000000 || 0
  • rounded to nearest 10-million: 6660000000 || 30000000
  • rounded to nearest million: 6655000000 || 33000000
  • rounded to nearest 100-thousand: 6655000000 || 33200000
  • rounded to nearest 10-thousand: 6655050000 || 33200000
  • rounded to nearest thousand: 6655046000 || 33200000
  • rounded to nearest hundred: 6655046300 || 33200000
  • rounded to nearest ten: 6655046290 || 33200000
  • rounded to nearest integer: 6655046295 || 33200000
  • NOT rounded at all: 6655046294.9 || 33200000

HERE is the output I got one time

  • rounded to nearest billion: 7.0E+9 || 0
  • rounded to nearest 100-million: 6.7E+9 || 0
  • rounded to nearest 10-million: 6.66E+9 || 3.0E+7
  • rounded to nearest million: 6.655E+9 || 3.3E+7
  • rounded to nearest 100-thousand: 6.655E+9 || 3.32E+7
  • rounded to nearest 10-thousand: 6655050000 || 3.32E+7
  • rounded to nearest thousand: 6655046000 || 3.32E+7
  • rounded to nearest hundred: 6655046300 || 3.32E+7
  • rounded to nearest ten: 6655046290 || 3.32E+7
  • rounded to nearest integer: 6655046295 || 3.32E+7
  • NOT rounded at all: 6655046294.9 || 3.32E+7

HERE is the output less than a minute later

  • rounded to nearest billion: 7000000000 || 0
  • rounded to nearest 100-million: 6700000000 || 0
  • rounded to nearest 10-million: 6660000000 || 30000000
  • rounded to nearest million: 6655000000 || 33000000
  • rounded to nearest 100-thousand: 6655000000 || 33200000
  • rounded to nearest 10-thousand: 6655050000 || 33200000
  • rounded to nearest thousand: 6655046000 || 33200000
  • rounded to nearest hundred: 6655046300 || 33200000
  • rounded to nearest ten: 6655046290 || 33200000
  • rounded to nearest integer: 6655046295 || 33200000
  • NOT rounded at all: 6655046294.9 || 33200000

I thought it might have to do with how ROUND works, but the last row does not use ROUND --JimWae 07:08, 7 March 2008 (UTC)Reply

The problem seems to be that various server types are used, and that MediaWiki just takes the raw results from the php functions installed on these servers, without formatting them uniformly. Also, even formatnum does not help with this, it only adds commas. See also Help:Calculation#Numbers_as_output.--Patrick (talk) 10:13, 7 March 2008 (UTC)Reply

5 zeroes and expr

I think I've identified the condition that SOMETIMES produces the result. Having 5 zeroes at end seems to be the issue.

    • { {#expr: 12300000} } => 1.23E+7 (sometimes)
    • { {#expr: 123400000} } => 1.234E+8 (sometimes)
    • { {#expr: 1234500000} } => 1.2345E+9 (sometimes)
    • { {#expr: 12345600000} } => 1.23456E+10 (sometimes)
    • { {#expr: 123456700000} } => 1.234567E+11 (sometimes)
    • { {#expr: 1230000} } => 1230000 (always)
    • { {#expr: 12340000} } => 12340000 (always)
    • { {#expr: 123450000} } => 123450000 (always)
    • { {#expr: 1234560000} } => 1234560000 (always)
    • { {#expr: 12345670000} } => 12345670000 (always)
  • --JimWae 01:25, 11 March 2008 (UTC)Reply

Workaround

Here's a useful workaround - source code looks like this:

{ {formatnum:{ {#expr:(6706992932 + 218495.91 * 75 ) /100000000 round 0}}00000000}}


Places
rounded
to
result "textified" formatted
none 6,723,380,125.25
0 6,723,380,125
1 6,723,380,130 6723380130 6,723,380,130
2 6,723,380,100 6723380100 6,723,380,100
3 6,723,380,000 6723380000 6,723,380,000
4 6,723,380,000 6723380000 6,723,380,000
5 6,723,400,000 6723400000 6,723,400,000
6 6,723,000,000 6723000000 6,723,000,000
7 6,720,000,000 6720000000 6,720,000,000
8 6,700,000,000 6700000000 6,700,000,000
9 7,000,000,000 7000000000 7,000,000,000

--JimWae 06:39, 19 September 2008 (UTC)Reply

Short way to produce a boolean for argument existence?

I see code like:

{{#if|{{{1|}}}|1|0}}

a lot (to give a boolean indicating whether argument 1 is present or not). Is there any shorter way to do this? If not, is there any chance of getting a builtin function added to do this? (I don't want to waste time posting something on Bugzilla if this isn't gonna fly...) Jnc 03:23, 8 March 2008 (UTC)Reply

That should be {{#if:{{{1|}}}|1|0}}. It is the shortest way. A function directly producing a boolean (also for ifeq, ifexist, iferror) would be nice, but not very important. A function for {{#ifeq:{{{1|+}}}|{{{1|-}}}|1|0}} (empty counts as defined) would be more useful, since this is rather cumbersome.--Patrick (talk) 07:58, 8 March 2008 (UTC)Reply
Thanks. Good point about the 'defined' test. Well, if I get energetic I'll file something on Bugzilla! Noel (talk) 21:14, 13 March 2008 (UTC)Reply

[RESOLVED] How to include?

I feel dumb! I installed the extension ("For the MediaWiki 1.12 series, use the branched version"), it shows up on Special:Version but when I add {{ #time: d M Y | 2008-04-08 }} or some other easy example on some article it only displays in plain text. --Subfader

Ok got it working by moving require... above all other require... nontheless it was confusing cos usually i get a blank page when an extension is not working... --77.135.31.171 16:52, 10 April 2008 (UTC)Reply

Problem with #ifexist

I've installed the ParserFunctions extension under MediaWiki 1.11.0 and it shows on the Special:Version page.

The #time functions seems to work

{{#ifexpr: 10>9 | yes | no }} gives yes

BUT

{{#ifexist: Special:Version | yes | no }} gives no

I've also tested it with other page names and it always gives "no". Any ideas what's wrong? --194.201.250.209 15:49, 9 April 2008 (UTC)Reply

  • Inside incrementIfexistCount there's a variable $wgExpensiveParserFunctionLimit that never appears to be initialized causing this function to always return false. One lazy workaround would be to add: $wgExpensiveParserFunctionLimit = 100; after the variable declaration assuming you wanted to only allow 100 ifexists to be processed when rendering any given article. --68.44.203.246 15:01, 2 May 2008 (UTC)Reply

#ifexist not working with pf 1.1.1 in MW 1.2

"#ifexist:" is not working in my wiki as you can see:

I have this configuration:

  • MW 1.12.0
  • ParserFunctions 1.1.1 r41321

I have also installed:

  • SMW 1.2
  • SF 1.2.6
  • reCaptcha

Other parser functions are working fine.

--Dvdgmz 08:11, 29 September 2008 (UTC)Reply

[RESOLVED] if external link

I'm trying to add a code that reciognizes if a parameter is a local file or an external link.
Tried {{#ifexist: File:{{{1}}}|internal|external}} but it doesn't recognize File:{{{1}}} Any idea how else I coul do it? --77.135.31.171 17:21, 10 April 2008 (UTC)Reply

Solved, worked on website, not on localhost! --77.135.31.171 18:20, 10 April 2008 (UTC)Reply

Reorganize

I propose a division into math functions and logical functions. That is, the expr thing that Tim Starling created contains common arithmetic operators. Let's not hide them under a bushel. --Ed Poor 17:36, 17 April 2008 (UTC)Reply

expr also does logical functions.--Patrick (talk) 22:05, 17 April 2008 (UTC)Reply

#ifeq and unicode

I am comparing the unicode value of an Arabic character (#x062a) with the same character input by keyboard ت and I get the wrong result. The following produces NO, which is not the case:

{{#ifeq:&#x062a;|ت|YES|NO}}

Result: YES

Thanks. Hakeem.gadi 18:03, 21 May 2008 (UTC)Reply

Presumably this is because MediaWiki doesn't decode the character entities but just passes them straight to the browser. Test case: {{#ifeq:&gt;|>|YES|NO}} = YES. (Oh, and I fixed the display issue you had with the code example.) --Ilmari Karonen 22:07, 21 May 2008 (UTC)Reply

#ifexist for images?

ifexist does not seem to support images and I would like to use it to create a simple template to handle images uploaded with uppercase and lowercase file extensions:

{{#ifexist:Image:{{{1}}}.jpg
|[[Image:{{{1}}}.jpg|{{{2}}}|{{{3}}}]]
|[[Image:{{{1}}}.JPG|{{{2}}}|{{{3}}}]]
}}

But the #ifexist here always returns false, even when the ".jpg" version of the image exists. Any suggestions?

It should work. Note, however, that this tests whether the image description page exists; if you want to test for the existence of the image itself, try {{#ifexist:Media:{{{1}}}.jpg}}.
Testing with Image:Example.png from Commons:
{{#ifexist:Image:Example.png|yes|no}} → no
{{#ifexist:Media:Example.png|yes|no}} → yes
{{#ifexist:Media:Example.PNG|yes|no}} → no
--Ilmari Karonen 05:11, 4 June 2008 (UTC)Reply
Thanks. I tried this but it still return false for both cases. The Media link I used in the ifexist statement works if I just copy/paste it, so I know the file is there and the link is correct. Perhaps it is because I am still using MediaWiki 1.10? I will look into upgrading and see if that solves it.
--e 17:28, 4 June 2008 (UTC)
It doesn't work for me either and I use MW 1.12
--e 14:09, 5 June 2008 (CEST)

Need help with use of parser function

I've designed a userbox called {{w:User:UBX/University Challenge}}. I'd like to be able to automatically put user pages that the userbox is used on into categories, but not other pages such as talk pages. I therefore used a parser function like this:

{{#if:{{NAMESPACE}}=User | [[Category:Wikipedians interested in University Challenge]]}}

However, it doesn't seem to work. If the userbox is placed on other types of pages (for example, "w:Wikipedia talk:WikiProject BBC"), those pages still get put into the category. Any idea why the parser function is not working, or what I can do to solve this problem? — Cheers, JackLee talk 19:33, 6 June 2008 (UTC)Reply

Use ifeq.--Patrick (talk) 00:10, 7 June 2008 (UTC)Reply

Media Wiki 1.13 Alpha

HI all,

I installed parser functions but when i refresh the page i get a HTTP 500 Internal Server Error. Any Ideas? I'm runnig Wiki from DWebPro (All in one webserver) using PHP 5.2.4 Prom3th3an 12:25, 13 June 2008 (UTC)Reply

I solved it, I swapped servers (Im now using XAMPP instead of DWebPro) and it works fine. My advice for anyone is not to use DEWEBPRO with ParserFunctions

"Trunc" unrecognised

I'm trying to use the "trunc" function, but MediaWiki keeps returning the following error:

Expression error: Unrecognised word "trunc"

Here is the code I try to use:

{{ #expr:trunc1.2}}

Other functions seem to parse, but not trunc. Am running MW 1.11.0, and believe I'm running the appropriate version of ParserFunctions for my version of MW. Seems to be very little info out there regarding this function.

Thoughts? Pfurrie 14:45, 17 June 2008 (UTC)Reply

It is very new.--Patrick (talk) 01:43, 22 June 2008 (UTC)Reply

#if:

I think this page really does lack examples, and I can't find any links to more examples, so i'm going to ask this here. I'm not sure how to explain in words, so here's what i want: want a template called "wobble" to be called as such:

{{wobble|a|c}}

and give the result "a is yes, b is no, c is yes"

This should happen regardless of what order the parameters are being called in (eg {{wobble|c|a}} would give the same result)

How would i go about getting this effect? 92.21.92.169 10:04, 21 June 2008 (UTC)Reply

"a is {{#ifexpr:{{#ifeq:{{{1}}}|a|1|0}} or {{#ifeq:{{{2}}}|a|1|0}} or {{#ifeq:{{{3}}}|a|1|0}}|yes|no}}, b is ..".--Patrick (talk) 01:40, 22 June 2008 (UTC)Reply
Thanks Patrick :) 92.21.92.169 07:57, 22 June 2008 (UTC)Reply

Minus sign

Is there a way to change the minus sign that appears for a negative result of #expr: from "-" to "−"? Because that is the actual minus sign, whereas the first is just a dash. For example, {{#expr:4-7}} results in -3, while it should result in −3. Artyom 21:12, 6 July 2008 (UTC)Reply

"−" is never used in programming languages as the character does not exist in ASCII, hence the need for the character entity. 76.251.237.156 04:06, 16 July 2008 (UTC)Reply

Recursion

How do you do recursion in templates? Even if it's not possible, I think it should be explained/mentioned here. 76.251.237.156 04:02, 16 July 2008 (UTC)Reply

Wow. What a nightmare. I don't understand why a regular scripting language isn't used instead of all this nonsense. 76.251.237.156 05:06, 16 July 2008 (UTC)Reply

#titleparts in template pages

If I use {{#titleparts:...}} in templates, sometimes it reads the template name as input value and so gives a wrong output, instead of reading in that page name where the template has beeen edited in.

Huwikibooks Example: HGFc template and the page Halmazrendszerek geometriája/Feladatok. In that page the template creates H4 class section titles but they are ineditable, when you click on their "szerkesztés" (edit) functions (not the "edit page" button, but the H4 editing lines) , the link navigates to the template edit window (wrong) instead of the page. Concrete example: http://hu.wikibooks.org/wiki/Halmazrendszerek_geometri%C3%A1ja/Feladatok#Sectiontitle. Please, if someone answer me, leave a short message on my HuWB talkpage. Thx. Gubbubu 09:01, 25 July 2008 (UTC)Reply

Day counting

Is there any simple way to let ParserFunctions count the days between two dates, where the last date is not necessarily today?

If your thinking about a countdown function: yes, it's possible. See e.g. no:Template:Nedtelling. --EivindJ 20:01, 11 August 2008 (UTC)Reply

#ifeq: question

Ok...I'm creating a template which, when called, has a parameter, firstBody, which might or might not have a value assigned. I want the template to appear differently if a value is or is not assigned. So, on the template's page, I have entered: {{#ifeq: {{{firstBody|}}} ||<!-- }} before a block of text I don't want to appear if no value is assigned and: {{#ifeq: {{{firstBody|}}} || --> }} at the end. So far, no matter if a value is assigned, it comments out all the text. For the pages in question go here for the template, and here for where it is used (it's the first hidden box on the top right side of page). Thank you, in advance, for any help you can render. 138.162.0.41 19:03, 11 August 2008 (UTC)Reply

Have you tried using "display:none"? Hillgentleman 19:11, 11 August 2008 (UTC)Reply
I'll try that, but not confident that will work either. I ended up taking out all the <!-- and --> and put messages in their place, but even this way, when the template is used, the section is always commented out (or, it's not recognizing the code and so is ignoring everything inbetween the two sections)...138.162.0.43 19:14, 11 August 2008 (UTC)Reply
Scratch the above...I must have done something wrong earlier. When I get rid of the 'comment out' sections, it does show back up, but the text that I have in there when {{{firstBody}}} is true, never shows up. 138.162.0.44 19:20, 11 August 2008 (UTC)Reply
I fixed some minor things in your code, but I aint sure what your problem is or whether or not the problem still exists (as a matter of fact, I haven't understood your problem properly at all). Note the important fact that the second field is returned if field one is true and third field if field one is false (many people think opposite for some reason). Feel free to explain your problem further, maybe I can help. --EivindJ 20:00, 11 August 2008 (UTC)Reply
The problem I've been having is getting the second hide section to not show up on my user page if firstBody has not been declared. For example, I commented out the firstBody variable on my page but the section still shows up, now it's just blank. Actually, I may need to back up my dispay:none a bit higher in the code (like right above the second table declaration). Anyway, thank you all for the help - if I still wasn't clear, please feel free to leave more messages here. 209.33.14.48 00:49, 12 August 2008 (UTC)Reply

Well, I thought I had it whooped. I changed the template so that the part that I wanted to show up if firstBodyTrue = 1 is now on a seperate page. I then included this new template into the code ({{#ifeq: {{{firstBodyTrue|}}} | 1 | {{User:Choytw/Hidden_With_UsageTemplate}} || }}...which performs perfectly when firstBodyTrue equals something other than 1 (like 0 for false). But when I change firstBodyTrue back to 1, all I get is the header without any formatting or body. I'm assuming it is because the new template is two pages removed? (included on the final template with the final template then being included on the userpage)...starting to get frustrating lol. If anyone else want to take a look at it, the links are above. The new template is here. 209.33.14.48 02:47, 12 August 2008 (UTC)Reply

Ok, I did some more fixing on the code, but haven't got time to really try and understand how these templates hang together (sorry!). What I don't understand is, what is supposed to show up below the "USAGE" header? --EivindJ 09:53, 12 August 2008 (UTC)Reply
No worries at all. If I was paying you, I'd be ticked...but beggars can't be choosers  ;-). As for what is supposed to show up, it's the variable 'firstBody'. If you want to see how it's 'supposed' to look when firstBodyTrue = 1, go down my userpage to the next show/hide section. When you show/hide that one, at the very bottom is a description. As for the templates, I couldn't get #ifeq to work unless I put the code I wanted to be conditional in the true spot ({{#ifeq: variable one | test against this | template was put here | nothing here }}</nowiki}}. I tried using display:none in the if else section, but it never seemed to work. I had to used a template because when I tried putting the code in the section now holding the template, it wouldn't code the data right (half the code would show up when viewing the template). So long story short, I took out the condition code of template 1 (User:Choytw/Hidden_With_Usage2) and put it in its own template (User:/Choytw/Hidden_With_UsageTemplate). I then inserted this new template back into the #ifeq formula in template one (User:Choytw/Hidden_With_Usage2) and then put template one on my userpage (<nowiki>{{User:Choytw/Hidden_With_Usage2|parameters here}} but the new template (User:Choytw/Hidden_With_UsageTemplate) isn't getting in information stored in the variables on my userpage. 209.33.14.48 13:48, 12 August 2008 (UTC)Reply

Question

Hi, is there a way (using ParserFunctions?) to modify strings? I mean, given a template TEMPLATE with variable VARIABLE=hello {{TEMPLATE|VARIABLE=hello}}, I'd like to return "hella", "hell", "Pello", "Helo" (depending on the template). Thanks!--Xtv 12:35, 3 September 2008 (UTC)Reply

#time - define week?

Hi, how can I define the week for a time output? I would like to let a template find out which date the first day of a week has. --217.91.74.27 15:09, 11 September 2008 (UTC)Reply

{{#time:l j F Y|{{#ifexpr:{{#time:W}} - {{{1|1}}} > 0|-{{#expr:{{#time:W}} - {{{1|1}}}}}|+{{#expr:{{{1|1}}} -{{#time:W}}}}}} weeks +{{#expr:8 - {{#time:N}}}} days}}
Put that in a template. Should always return the date of the Monday of the specified week for the current year. Splarka 08:05, 12 September 2008 (UTC)Reply
Thanks! --217.91.74.27 11:39, 18 September 2008 (UTC)Reply

Help with expr

If I try to use mod I get this error:


Fatal error: Call to undefined function wfloadextensionmessages() in /home/a5668505/public_html/wiki/mediawiki-1.9.3/extensions/Expr.php on line 36

vertical alignment problem using #if in table

I have some tests of using a template I have developed to display variable number of images. http://www.elviscostello.info/wiki/index.php/User:JohnE#More_Artwork_format_tests

Under Custom Artwork heading, I step through 1,2,3, ... images. There is excess blank lines for 1 & 2 images. Also there is bad alignment of images for 2 & 3 images.

The template I have created is at: http://www.elviscostello.info/wiki/index.php/Template:BootlegArtwork

This in turn uses template: http://www.elviscostello.info/wiki/index.php/Template:BootlegArtworkSingle

Any ideas why I am having the above problems, please. Thanks, JohnE


Still can't sort this out. Does anybody have any idea why this puts in extra <br /> for 1,2 and 3 parameters but not for 4 or 5? Here is the calling lines:
 {{BootlegArtwork|Bootleg 2007-05-02 West Hollywood|front}}   <==== adds br
 {{BootlegArtwork|Bootleg 2007-05-02 West Hollywood|front|back}}      <==== adds br
 {{BootlegArtwork|Bootleg 2007-05-02 West Hollywood|front|back|disc1}} <=== adds br
 {{BootlegArtwork|Bootleg 2007-05-02 West Hollywood|front|front1|back|disc1}}  <====doesn't add br
 {{BootlegArtwork|Bootleg 2007-05-02 West Hollywood|front|front1|back|disc1|disc2}}  <====doesn't add br
Here is the Template: BootlegArtwork:
 ::{|
 |- 
 {{ #if: {{{2|}}} | ! {{BootlegArtworkSingle |{{{1}}}|{{{2}}}}} | }}
 {{ #if: {{{3|}}} | ! {{BootlegArtworkSingle |{{{1}}}|{{{3}}}}} | }}
 {{ #if: {{{4|}}} | ! {{BootlegArtworkSingle |{{{1}}}|{{{4}}}}} | }}
 {{ #if: {{{5|}}} | ! {{BootlegArtworkSingle |{{{1}}}|{{{5}}}}} | }}
 {{ #if: {{{6|}}} | ! {{BootlegArtworkSingle |{{{1}}}|{{{6}}}}} | }}
 |}
And here is the called Template: BootlegArtworkSingle:
[[Image:{{{1}}} {{{2}}}.jpg|500x60px]]
Possibly try it like this:
::{|
|- 
{{#if:{{{2|}}}|
! {{BootlegArtworkSingle |{{{1}}}|{{{2}}}}}
}}{{#if:{{{3|}}}|
! {{BootlegArtworkSingle |{{{1}}}|{{{3}}}}}
}}{{#if:{{{4|}}}|
! {{BootlegArtworkSingle |{{{1}}}|{{{4}}}}}
}}{{#if:{{{5|}}}|
! {{BootlegArtworkSingle |{{{1}}}|{{{5}}}}}
}}{{#if:{{{6|}}}|
! {{BootlegArtworkSingle |{{{1}}}|{{{6}}}}}
}}
|}
That way, the newlines exist only inside the true branch of each #if, so skipping parameters keeps them from inserting blank lines. Splarka 06:59, 13 October 2008 (UTC)Reply
Thanks so much. It got me on the right track. Really appreciate it. - JohnE

Template to display variable number of similar images

I want to create a template to display a different number of images that are defined when the template is called. Note that numbering may or may not be contiguous, and the list could be any length.

e.g. images to display
abcdef01.jpg
abcdef02.jpg
abcdef05.jpg
abcdef06.jpg
abcdef07.jpg
abcdef10.jpg
abcdef11.jpg

I wanted to call this using this:

 {{ImageDisplay|abcdef|01|02|05|06|11}}

Then ImageDisplay template is something like this, but need to have a way of displaying each image that is listed in the call to the template.:

 {{[[Image:{{{1}}}{{{2}}}.jpg|500x60px]]}}

Any thoughts on how to achieve this, please?

Perhaps use Template:For.--Patrick (talk) 22:09, 21 September 2008 (UTC)Reply
Wow, yes this does the trick. Thanks a lot.
Here is what I came up with:
{{for| |call=PhotoSingle|pc1n=1|pc1v=2005-01-22 Copenhagen|pv=2|11|12|13|14|15|16|17|18}}
I now want to remove the complication of the "for" template from other users, and just call another template and pass it the base filename and the serial numbers of the photos:
{{Photos|2005-01-22 Copenhagen|11|12|13|14|15|16|17|18}}
The problem is that only the 11 serial number is passed in this case. How do I pass "11|12|13|14|15|16|17|18" as a parameter?
Maybe a more fundamental question is how can I remove the complication of the "for" template from the user, so that they just have to enter a template name and the various numbers of parameters required for it. I am probably missing something.
One could make a customized version of Template:For, with a custom name (like Photos), and with some of the parameters replaced by fixed values, e.g. replace {{{call}}} by PhotoSingle, then the call of Photos does not require "call=PhotoSingle". Template:For/aux does not have to be adapted.--Patrick (talk) 12:42, 13 October 2008 (UTC)Reply

the epoch

  • {{#time:c | @0 }} = "Error: invalid time"
  • {{#time:c | @1 }} = "1970-01-01T00:00:01+00:00"
  • {{#time:c | @-1 }} = "Error: invalid time"

From the GNU tar manual, and GNU Shishi ref. manual:

GNU and most other POSIX-compliant systems support such times as an extension to POSIX, using negative counts, so that ‘@-1’ represents 1969-12-31 23:59:59 utc.

Nag, nag, nag. Their code is free(GPL), isn't it? --Jerome Charles Potts 19:26, 9 November 2008 (UTC)Reply

ISO 8601 duration

How about a #time:P as shorthand for #time:PY\Yn\Mj\DTG\Hi\MsS ?

Thanks in advance? --Jerome Charles Potts 19:28, 9 November 2008 (UTC)Reply