Help talk:Variable

From Meta, a Wikimedia project coordination wiki
Jump to: navigation, search

{{PAGENAME}} and Namespaces[edit]

Seems using the {{PAGENAME}} template does only work in the "Main" namespace. Is this a bug, or is tjhere an additional variable like CURRENTNS? --Katya 14:16, 31 January 2006 (UTC)

Check out NAMESPACE and FULLPAGENAME. -- Omniplex (w:t) 23:02, 4 April 2006 (UTC)


Is there a variable like {{PAGESIZE}}?

I do not think so. See also Help:Page size.--Patrick 22:39, 9 Aug 2004 (UTC)


There's a {{NUMBEROFIMAGES}} like variable? It would be nice to put in the main page :-) Joanjoc [1]

It would be great a {{NUMBEROFIMAGES}} variable !!


  • Is there any possibility to reference to the following day instead of the current. This would be very nice for calendar-use like 'what happens tomorrow'. --Der Mechatroniker 18:24, 18 Feb 2005 (UTC) Quick additional question: it would be also nice to have the days of the week by numbers instead of their names, such like 0 for mon, 1 for tue etc. Can anybody help me with this? --mecha 12:02, 19 Feb 2005 (UTC)

Is there really no variable for "short month name", i.e. Nov? I'd like to be able to generate a updating timestamp that looks like the normal timestamp, but I can't without that. wikipedia:User:JesseW 09:45, 20 Nov 2004 (UTC)

As far as I understand {{CURRENTTIME}} gives the server time. How to insert the local time as adjusted by personal settings? And is it possible to adjust the result by a set amount? E.g. {{CURRENTTIME}}+1. –Wintermute 21:12, 9 Feb 2005 (UTC)

{{USERNAME}} or {{CURRENTUSER}} ??[edit]

(The information in this section is for version 1.5 of media wiki. By Constantine 16:27, 23 November 2005 (UTC))

It would be useful to have a magic word which expands to the user viewing the wiki page. But there does not appear to be such a magic word. If you're willing to get your hands dirty (ie, edit PHP code), you can do this by making relatively simple edits to three PHP scripts...

in 'includes/MagicWord.php . . .

Define a new PHP constant (I picked 129 arbitrarily) for a new "magic word" after line 57 (where all the other define() statements end:
define('MAG_CURRENTUSER',          129);
and just below that, in the $wgVariableIDs array, add the following within the balanced parenthesis:

in languages/Language.php . . .

Define the actual word which will become magical. (This determine what you will type inside double-curly-quotes.) Add this at about line 234 in the defintion of $wgMagicWordsEn. It goes inside the balanced parenthesis like all the other MAG_... items:

in includes/Parser.php . . .

Extend the wikitext parser to know what to do with the new magic word. Add this as the last case before the default: case around line 1930:
global $wgUser;
return $varCache[$index] = $wgUser->getName();

Once you've done that, you can use things like


to greet the current user. Or more powerful things like

twiddle your Monobook skin style  [[User:{{CURRENTUSER}}/monobook.css]]

to render a link to the viewing user's specific wiki page for adding custom CSS to the monobook skin.

The latter can be done with Special:Mypage/monobook.css.--Patrick 14:04, 10 August 2006 (UTC)

Hi Constantine,

'Edit: Ok, i forgot define the array in languages/Language.php'

if i make this i had an error:

Warning: array_slice(): The first argument should be an array in /wiki/languages/Language.php on line 2651
Warning: Invalid argument supplied for foreach() in /wiki/includes/MagicWord.php on line 329

It comes when i do:

:and just below that, in the $wgVariableIDs array, add the following within the balanced parenthesis:

Sorry for my English. Andy

  • I can't believe there is no built-in that does this? pfctdayelise 08:41, 28 April 2006 (UTC)
There is no built-in function to do it because it would mean we would be unable to cache the rendered output from each parse run. This would be akin to murdering the most popular sites running MediaWiki. The hack above will produce undefined behaviour when the parser cache is enabled, which is the default case. This has been explained before at least four times, but some people refuse to understand it. 00:51, 10 August 2006 (UTC)

Piped links[edit]

Is there an way of using piped links (i.e. with a different name) when the link is a construction of variables. I just find seeing all the long addresses really ugly ... butmy pipes never work. Uberpuppy 00:00, 17 Feb 2005 (UTC)

It seems to work fine, I added an example.--Patrick 09:43, 17 Feb 2005 (UTC)

Zero-pad inconsistency[edit]

{{CURRENTMONTH}} zero-pads, but {{CURRENTDAY}} does not. --Keith Tyler, 2005-04-01, 21:22.

Due to this inconsistency, {{CURRENTMONTH}} has little or no utility, since it's useless without the corresponding zero-padded day of month. Since almost no one could be using it due to this design mistake, I propose modifying the existing CURRENTMONTH variable so that it behaves consistently with the existing CURRENTDAY variable. I.e., remove the leading zero in {{CURRENTMONTH}}. Then create two new variables, named CURRENTMONTH2 and CURRENTDAY2, that give the month and day always as two-digit numbers. I also request that a new variable, {{CURRENTTIME2}}, be added to give current UTC time without seconds (i.e., hh:mm). This is urgently needed; see bugzilla 3453.
In the interim, on English wikipedia, I've added {{CURRENTMNTH}}, spelled as shown, to give current month number with no leading zero. CURRENTMNTH can be renamed to CURRENTMONTH after the above software changes are implemented. --Simian, 2005-10-17, 16:09 Z

I'm in need of that too, please help! Thanks

Last updated variable?[edit]

Is their a variable like {{LASTUPDATED}}?

Relative user namespace variable?[edit]

Is there some way to use the ns:2 varible for links like [[{{ns:2}}\monobook.css]]-SV so it will show your own (logged in) username in the tag? 23:20, 23 Apr 2005 (UTC)

Variable needed for false namespaces on wikibooks[edit]

Hi, I'm Kellen from wikibooks. We're in need a of a variable (or some other solution) similar to {{PAGENAME}} for false namespaces. On the Cookbook, we're using "Cookbook:" as a false namespace. We have set up a template Template:Recipe to include on each recipe page which will add a small bit of navigation and, more importantly, include each recipe in a category (so we can have an easily maintainable recipe index), specifically Category:Recipe. Our template currently uses [[Category:Recipe|{{PAGENAME}}]] to achieve this, but since each page is prefixed by "Cookbook:", everything is indexed under C. Having "Cookbook:" as a proper namespace would alleviate this problem, but in lieu of that, a variable which returns only the page name after the false namespace would be invaluable. If there is another easier solution, I'd be glad to hear it. Kellen 07:14, 2 Jun 2005 (UTC)

Filed a bug request here. Kellen 18:33, 2 Jun 2005 (UTC)

Link to Talk[edit]

Hi everybody, I'm a user of nl.wikipedia, and we would like to make a link in a template to the talkpage where the template is used. We found out that we can use [[overleg:{{PAGENAME}}]], where "overleg"means in Dutch "talk". But the problem is that the "Wikipedia:", "Gebruiker:" (user), "Help:"-part of the articlename is ignored by the template. And with a namespace articlename, there is a other template needed. With a not-namespace talk, the link should be: [[overleg:XXX]], but in a namespace it is: [[Overleg namespace:XXX]]. The problem is in the substitution of the double point after "overleg" by a spacebar. Is there a template whitch can be used in this kind of situation? Thnax a lot by forehand. Because I spend very little time at meta.wikimedia, pleace give a notice at My talkpage if you give a respons. Thanx a lot again! Effeietsanders 19:35, 24 July 2005 (UTC)

Difference between localurl and localurle[edit]

Reading the MediaWiki source code, it appears that localurle is simply localurl with htmlspecialchars applied. It seems to be designed for HTML sections, like pasting a link target into an attribute. Your mileage may vary. —cky 23:00, 26 August 2005 (UTC)

Spaces in user names[edit]

Is there a way to go directly to the block log for a user - when the link is NOT placed on their user page? I'm the maintainer of Wikipedia:Wikipedia:account suspensions, and this would be a really handy thing to put into a template:

--Ed Poor 02:14, 1 September 2005 (UTC)


Hi, I don't understand the meaning of {{CURRENTDOW}} (2)? And my translation tool is not able to help me... Can anyone explain it to me? --Habakuk 11:08, 14 September 2005 (UTC)

ok, its the day of the week, Monday=1, etc. --Habakuk 11:16, 14 September 2005 (UTC)

Number of Users?[edit]

Since the Special:Statistics page reports the number of users, why isn't there a variable, much like {{NUMBEROFARTICLES}}, that reports the number of users? BV's English Wiki Talk page / BlankVerse 11:40, 4 October 2005 (UTC)

{{CREATIONDATE}} ?[edit]

I would very much like to know if I am missing something, or there currently is no way to insert the creation date of a particular page? This would be extremely helpful in, say, the Wikicties:Template:Wikipedia page-copy notice (which is interested in the date the local copy is created, not the original). 19:35, 21 October 2005 (UTC)

I think there are no other variables than mentioned, so this is not possible, sorry.--Patrick 10:04, 22 October 2005 (UTC)
Darn, I saw this message in recent changes and got hopefull. I've been trying to do this for awhile now. There are a few "hacks" but none that suit my needs. Oh well :) «»Who?¿?WP 10:21, 22 October 2005 (UTC)


This is a meta-variable, a somewhat missing variable:

  |case: 1=Mon
  |case: 2=Tue
  |case: 3=Wed
  |case: 4=Thu
  |case: 5=Fri
  |case: 6=Sat
  |case: 0=Sun
  |default=No date

Which returns: Tue


Why isn't {{NUMBEROFFILES}} documented? [note: I did find it at Help:Magic words, where it says it's new for v.1.5.] BlankVerse 20:37, 6 December 2005 (UTC)

I added it.--Patrick 01:27, 7 December 2005 (UTC)


Where can I find documentation about {{Special}}? {{Special:Newpages/5}} results 5 rows of new pages. I found not all specialpages can be applied to {{Special}}. Borgx 09:56, 24 December 2005 (UTC)

I added that to Help:Special_page#Miscellaneous.--Patrick 01:40, 25 December 2005 (UTC)

List of interesting templates[edit]

Is there a list of... how should I call it... programable templates? I found some really nice templates which are very useful if you have the nerve for programing: Template:array, Template:for, Template:foreach, Template:call, Template:If_equal. I guess there must be some more of those. Is there a list of those? I particular, is there a template that generates a random number? :-D --Dijxtra 14:34, 5 January 2006 (UTC)

Magic Word ?= Variables[edit]

Just a thought....., how about merging "Magic Words" page into this page? (Or completely split them apart).

Seems some duplication/redundency/redundency here..

Should be somewhere striaght forward either way, if help is desired, I could dive into it, once decision has been made.

--IainDavidson 00:51, 31 January 2006 (UTC)

I suggest that in Help:Variable we continue to cover variables only, and not other magic words. If the other page has any content about variables not yet present here, that can be merged into this page. The other page can be renamed to Help:Magic word other than variable.--Patrick 01:08, 31 January 2006 (UTC)

Date variables[edit]


This works on the English Wikipedia, and the French Wikipediae has all sorts of extra variable goodies! -- 17:55, 27 March 2006 (UTC)

It's a template without parameter, like {{UTC}} = 2017-09-26 04:01 UTC
Variables like {{CURRENTDAY}} are no templates, there's no page Template:CURRENTDAY. But w:Template:CURRENTDATE exists, if you like it and want it also here copy it from w: -- Omniplex (w:t) 08:00, 4 May 2006 (UTC)

localurle and fullurle[edit]

Current examples of {{localurle}} and {{fullurle}} shows no difference from their counterparts example {{localurl}} and {{fullurl}}. Could you please give a better examples showing the difference between {{localurle}}/{{fullurle}} - {{localurl}}/{{fullurl}} Borgx 12:38, 14 April 2006 (UTC)

Also asked in w:VP/T, no example yet. -- Omniplex (w:t) 18:44, 15 April 2006 (UTC)
If they are the same as PAGENAME and PAGENAMEE, the difference is that the version with the extra "e" at the end will convert spaces in the names to underscores to allow links to work properly. Test the difference on pages that have spaces in the names. 04:15, 3 May 2006 (UTC)
Be bold and everything this test is directly on Help:Magic words and/or Help:Variable, localurl (no e) and fullurl (no e) already handle space to underscore, like localurle and fullurle. An example where they differ would be nice. -- Omniplex (w:t) 08:05, 4 May 2006 (UTC)


I was reading Constantine's edit from november. It was extremely helpful. Now i'm looking for a way to do the same thing but now display the person's real name from the user preferences field. From the form, i found the variable wpRealName, but i assume that it isn't global and just goes right into the database once entered. my question is, is there a way to make that a global variable so that i can use the same technique to make {{REALNAME}} a magic word?

--Prodaea 16:40, 17 April 2006 (UTC)

{{CURRENTTIME}} to CET[edit]

What variable should I use for getting CURRENTTIME in Central European Time? Thanx. Gubbubu 19:41, 25 April 2006 (UTC)

See w:Template:Utc.--Patrick 23:50, 25 April 2006 (UTC)

Thanx :-)). Gubbubu 07:03, 27 April 2006 (UTC)


It would be nice to have the {{CURRENTHOUR}} and {{CURRENTMIN}} variables :-) --Joanjoc 17:29, 28 April 2006 (UTC)

Includeonly subst magic...[edit]

I wanted to have a possiblity to automatically add a week of including some template and I thought this subst magic was great... Unfortunatly either there is something wrong or I just can't do it right. My test are here: User_talk:Nux/test. As I see it, the first version should work, but it is just shown as it would be in tag. Any ideas? --Nux talk | faster talk 01:04, 3 May 2006 (UTC)

What are you trying to do? It's not clear. 04:13, 3 May 2006 (UTC)
Either one uses different template versions for substitution and ordinary inclusion, or one uses a technique like Help:Substitution#Optional_substitution.--Patrick 09:58, 3 May 2006 (UTC)
What I really wanted to do is to add the time of edit of the article when some template was included. So I would expect that including {{User:Nux/test}} would give 23:01 rather then {{subst:CURRENTTIME}}. This would be nice in some templates that are to be expired on some date and you would see that just looking at it, rather then going to searching the history or making users insert the date. Nux talk | faster talk 23:01, 6 May 2006 (UTC)
That works, but you have to provide for the substitution at both levels (as mentioned above), substituting the variable, and substituting the template containing it.--Patrick 12:01, 7 May 2006 (UTC)
That's what I wanted to avoid, but thanks any way. Nux talk | faster talk 18:43, 7 May 2006 (UTC)

HowTo use a custom variable or Autonumbered Captions[edit]

Please help.

It is necessary in certan occassions to use custom variables in the text. For example, I have caption "Picture 1", after that in the text I add another image and caption in this case "Picture 2". After that "Picture 3", etc. Is it possible to have defined variable something like placing "Picture {{variablename}}" in the first place and "Picture {{variablename}}" on the second etc. Each time it will increase by one. Is is not only necessary for pictures, but for everything.

It is very usable, and one sort of autonumbered captions.

Constants depending on parameters[edit]

Patrick minted the new terms "colon function" and "predefined template". I like the former, better than my idea "pseudo-template" (already replaced). IMO "predefined template" is less useful, what is it, all variables plus all colon functions? Whatever it is, we should move NS, LOCALURL, FULLURL, LOCALURLE, and FULLURLE plus examples to Help:Colon function. stupid boy forgot to sign this, threee tildes will do: -- Omniplex (w:t)

The term "predefined template" for variables, parser functions, and other colon functions can be convenient when considering their common properties. Many variables do not have a colon.--Patrick 00:22, 12 May 2006 (UTC)
Actually no variable has a colon, the colon is a sign that something is a colon function. I guess that we could solve the puzzle of predefined templates sometimes handled as ordinary templates based on this observation, but admittedly the example {{ns:{{SITENAME}}}} is still beyond me. It has the same effect as {{ {{SITENAME}} }}, but I've no clue why. -- Omniplex (w:t) 01:15, 12 May 2006 (UTC)

I've already killed the third incarnation of a LC / UC / LCFIRST / UCFIRST table here, it's enough in Help:Magic words and Help:Colon function. -- Omniplex (w:t) 20:53, 11 May 2006 (UTC)


I've no clue what that's about and removed it. At the moment the formerly "unclear" CURRENTWEEK 1..52 vs. 1..54 converges at 1..53 here and also on Help:Magic words.

7*53 is 371 - do we have a category for "talk pages using parser functions"? Just kidding. Non-leap years have 365 days, 371-365 is 6. What's the problem with 2007-12-31?

You said it's a Monday, checking: 1, (0 = Sunday), okay, it's a Monday. And you said it has CURRENTWEEK 1, because it belongs to the first week in 2008. Why isn't it in week 53 of 2007? -- Omniplex (w:t) 20:51, 21 May 2006 (UTC)

See w:ISO_8601#Week_dates. A week has only one number, even if it contains days in two years.--Patrick 22:45, 21 May 2006 (UTC)
See also Help_talk:Magic_words#CURRENTWEEK.--Patrick 23:24, 21 May 2006 (UTC)

Copied / moved to Help talk:Magic words -- Omniplex (w:t) 18:54, 22 May 2006 (UTC)

Variables in a template[edit]

When used in a template, these variables refer to the page in which the template is included, not to the template page.

With subst they refer to the template, with noinclucde (e.g. template category) they refer to the template page, with includeonly to the including page, and otherwise to all pages with this template plus the template page itself. Useful for category sort keys, self-documenting templates, and tricky cases like H:f Template.

Maybe say "not only to the template page" or similar, as is it sounds as if variables are not evaluated on the template page, but that's not the case. -- Omniplex (w:t) 00:52, 23 May 2006 (UTC)

Ok, I rephrased it. I think it is accurate now.--Patrick 10:09, 23 May 2006 (UTC)


It seems, that this construct doesn't work insidе templates. I needed to display the timestamp of template inclusion, but the result was like {{subst:CURRENTTIMESTAMP}} with no substitution at all. Look here and here. Is anything wrong? --CodeMonk 04:09, 10 July 2006 (UTC)

You have to use {{subst:T1}}.--Patrick 08:53, 10 July 2006 (UTC)

Page existence determination[edit]

OK, I might have gotten lost somewhere along the line but I need to determine whether a page has been created or not (and thus determine whether it can be linked to) and I don't think there's a simply variable for that? so I'm trying to compare the page URL determined by the server to FULLURL|action=edit to see if the server is automatically sending it to an edit page. Is there an easier way to do this? Is it even possible to get the URL as determined by the server (which would be an edit page if the page didn't exist) by providing the article name? Can anybody point me in the right direction here? freshgavin TALK 00:41, 26 October 2006 (UTC)

I suppose you mean you want the server to do something depending on existence. See Help:Parser_functions#.23ifexist:.--Patrick 12:03, 26 October 2006 (UTC)
Ah damn, I missed that. Thanks! freshgavin TALK 01:13, 27 October 2006 (UTC)

HTTP Request Parameters[edit]

Is there a variable that'll let me access the query parameters of a GET or POST HTTP request? If not, is there another way to access said parameters? -- 21:24, 18 December 2006 (UTC)

ISO 8601 Week Numbering[edit]

This seems to lack full support for ISO 8601 Week Numbering, needed for both UTC and local civil time (LCT).

There needs to be variables for ISO Day, Week, Year numbers; and for clarity I suggest that their names should include ISO8601Week. Variables yielding yyyy-Www-d are inessential but could be helpful (and ones for yyyy-mm-dd).

Implementors should read ISO8601:2004, Wikipedia:ISO_8601, Wikipedia:Week_number very carefully before acting.

Days are 1..7 for Mon..Sun. Weeks are 01 to 52/53 and the leading zero must be provided. The Year Number (for Dec 29 to Jan 3) may differ from the Gregorian. Microsoft VB DatePart has errors for 3 days per 28 years and one day per 400 years -<> ff.

Variables for other forms of week and day numbering should exist with names alluding to whatever non-standard method is used, with a long-term view of deprecating and removing the existing ambiguous names.

ALL references to numeric day-of-week need an explanation in the form of Mon..Sun = 1..7 or similar.

All this applies to Wikis in all forms and languages; and consider "Date-computing templates". 11:06, 8 October 2007 (UTC)

{{CURRENTDAY}} - 1 ?[edit]

how can I get previous day?--Vssun 10:28, 12 October 2007 (UTC)

  • Today is 2017-09-26; yesterday was 2017-09-25.Hillgentleman 23:02, 20 November 2007 (UTC)

Current User??[edit]

Is there a variable to display the username of whoevers logged in. I want my userpage to display: "Hello [name of user], welcome to my userpage!" Is this possible? Much appreciated. --Noahcs 21:18, 20 November 2007 (UTC)

Total number of wiki page views[edit]

There's an option to make this show up in the Statistics page of a site using the wiki software. Just curious what the Magic word and/or code is for displaying this in any page you like. Not seeing it written down anywhere. -- 09:47, 28 December 2007 (UTC)

Localizing {{CURRENTDAY}}, {{CURRENTYEAR}} variables[edit]

Is there any way to localize the {{CURRENTDAY}}, {{CURRENTYEAR}} variables so that the output uses Burmese numerals on the Myanmar Wikipedia instead of English numbers? Thanks.--Hintha 22:46, 23 July 2008 (UTC)


At the end of this section the REVISIONID variable is stated to be useless (at least in revision 996859 of that page). I disagree. Consider a page with auto-numbered items, for example: a test plan. As the test plan evolves over time, items may get renumbered. If that page is referenced from another page or an outside (e.g. bug tracking) system, it becomes impossible to identify items by number. For example, testcase 4.1 on one version of that page might be renumbered to 5.3 in a later version. Another example: the link at the beginning of this paragraph could appear meaningless if that section in the main article were to be refactored.

Solution: include the REVISIONID on the page itself, and include the REVISIONID in external references. Then it can easily be seen if the page being viewed is the same version, and if not, the history can be used to locate the older page (since the REVISIONID shows at the end of each URL in the history). The REVISIONID of the page you are currently viewing is: 4006365

Alternately, the URL itself can be used as the external reference, as it contains the REVISIONID as well as being a hyperlink:

The above can be copied from the topmost (current) timestamp hyperlink in the "history" tab. A disadvantage of the above is the brittleness of the left side of the URL, since relocating the wiki would then break these links. Another (minor GUI) disadvantage is the addition of the "diff" links at the top of pages loaded using "oldid" in the URL.

Unfortunately the following does not work (it would have been useful in the first paragraph above):

  [[Help:Variable&oldid=996859#Depending_on_page|this section]]

I consider the lack of a REVISIONID during preview to be only a minor inconvenience. That could easily be improved with a code tweak that substitutes a placeholder like "######" during preview.

Mcepek 14:22, 13 January 2009 (UTC)

PAGENAME, titleparts and categories[edit]

I'm trying to create a template that:

  • Auto-categorizes the including page
  • Sorts on the page name, but with a leading sub-page element stripped (e.g. "A/B/C" becomes "B/C")

What I have so far is something like:

<noinclude>[[Category: {{{catname|General}}} | {{{catsort|{{#titleparts: {{subst:PAGENAME}} | 0 | 2 }} }}} ]]</noinclude>

This fails because of the inclusion/substitution order, but for the life of me, I can't get the right ordering of <noinclude>...</noinclude> and subst: that works for this. Can someone help me out, here and either point me to somewhere that #titleparts is used with PAGENAME in a template or show me an example that's otherwise known to work? Thanks. -Harmil 20:48, 12 October 2009 (UTC)

New variables[edit]

Is there any way to create new variables? Something like {{let:myname|Leonidas}}, and then use {{myname}} and see it replaced by Leonidas? Albmont 21:07, 23 June 2010 (UTC)

There is mw:Extension:VariablesExtension, but not on this wiki.--Patrick (talk) 23:51, 23 June 2010 (UTC)

Use of odd/even referencing prevents namespace flexibility[edit]

The use of namespace IDs to identify talk and subject pages prevents flexibility in naming and defining custom namespaces. Consider a (semantic) wiki with 3 discrete groups of pages under a single namespace, e.g. 100 = project, 101 = project_talk and 102 = project_data (this could be for security - a public namespace, one visible to all but edits only by registered users, the last private). The Help talk and Help references work for this, but the next project with the same structure won't work. This screws up most intra-wiki links and skins that I've been able to test.

Is it possible to go back to defining the Help talk as Help_TALK, not as a numerical namespace reference?