Jump to content

User:AlanM1/Variables

From Wikipedia, the free encyclopedia


Variables

[edit]

From Help:Magic words#Variables. These all take an optional parameter to operate on a page other than the current one. Append an "E" for equivalents encoded for use in MediaWiki URLs (e.g {{PAGENAMEE}}, {{NAMESPACEE}}).

Template Result Descrip
{{FULLPAGENAME}} User:AlanM1/Variables Page title including namespace
{{PAGENAME}} AlanM1/Variables Page title excluding namespace
{{BASEPAGENAME}} AlanM1 Page title excluding current subpage and namespace
effectively the parent page without the namespace.
{{SUBPAGENAME}} Variables Subpage part of title
{{SUBJECTPAGENAME}} User:AlanM1/Variables Associated non-talk page
{{ARTICLEPAGENAME}} User:AlanM1/Variables
{{TALKPAGENAME}} User talk:AlanM1/Variables Associated talk page
{{NAMESPACE}} User Namespace of current page
{{SUBJECTSPACE}} User Associated non-talk namespace
{{ARTICLESPACE}} User
{{TALKSPACE}} User talk Associated talk namespace

These do not take a parameter:

Template Result Descrip
{{SITENAME}} Wikipedia Site name
{{SERVER}} //en.wikipedia.org Server
{{SERVERNAME}} en.wikipedia.org Server name
{{SCRIPTPATH}} /w Script path
{{CURRENTVERSION}} 1.44.0-wmf.25 (964d7fd) Current MediaWiki version
{{REVISIONID}} - Latest revision to current page
{{REVISIONDAY}} 6 Date, time, editor at last edit
{{REVISIONDAY2}} 06
{{REVISIONMONTH}} 12
{{REVISIONYEAR}} 2020
{{REVISIONTIMESTAMP}} 20201206155956
{{REVISIONUSER}} SporkBot
{{CURRENTYEAR}} 2025 Current date/time variables
{{CURRENTMONTH}} 04
{{CURRENTMONTHNAME}} April
{{CURRENTMONTHABBREV}} Apr
{{CURRENTDAY}} 25
{{CURRENTDAY2}} 25
{{CURRENTDOW}} 5
{{CURRENTDAYNAME}} Friday
{{CURRENTTIME}} 22:19
{{CURRENTHOUR}} 22
{{CURRENTWEEK}} 17
{{CURRENTTIMESTAMP}} 20250425221908
{{LOCALYEAR}} 2025 Site local date/time variables
{{LOCALMONTH}} 04
{{LOCALMONTHNAME}} April
{{LOCALMONTHABBREV}} Apr
{{LOCALDAY}} 25
{{LOCALDAY2}} 25
{{LOCALDOW}} 5
{{LOCALDAYNAME}} Friday
{{LOCALTIME}} 22:19
{{LOCALHOUR}} 22
{{LOCALWEEK}} 17
{{LOCALTIMESTAMP}} 20250425221908
{{NUMBEROFPAGES}} 63,007,953 Statistics on English Wikipedia
Add |R to return numbers without commas
{{NUMBEROFARTICLES}} 6,986,438
{{NUMBEROFFILES}} 936,842
{{NUMBEROFEDITS}} 1,282,633,631
{{NUMBEROFUSERS}} 49,047,323
{{NUMBEROFADMINS}} 846
{{NUMBEROFACTIVEUSERS}} 118,057

Parser functions

[edit]

From Help:Magic words#Parser functions. These are fully documented at the Meta magic words page or ParserFunctions Extension documentation unless otherwise stated. {{{0}}} (arg0) is the arg after the colon, before the pipe before {{{1}}} (arg1).

Metadata

[edit]

Add |R (i.e. {{{1}}}=R) to return numbers without commas.

Template Result Descrip
{{PAGEID}} 37960895 Unique page identifier number
{{PAGESIZE:User:AlanM1/Variables}} 13,342 Size of page {{{0}}} in bytes
{{PROTECTIONLEVEL:edit}} Protection level for action {{{0}}} on the current page
{{PAGESINCATEGORY:Wikipedia features}} 96 Number of pages in category {{{0}}}
{{NUMBERINGROUP:checkuser}} 54 Number of users in group {{{0}}}

Formatting

[edit]
Template Result Descrip
{{lc:STRING}} string Convert {{{0}}} to lower-case
{{lcfirst:STRING}} sTRING Convert first character of {{{0}}} to lower case
{{uc:string}} STRING Convert {{{0}}} to upper case
{{ucfirst:string}} String Convert first character of {{{0}}} to upper case
{{formatnum:1234567}} 1,234,567 Format {{{0}}} with comma separators
{{formatnum:1,234,567|R}} 1234567 Unformat {{{0}}} with comma separators
{{#formatdate:7 October 2012|default_format}} October 7, 2012 Formats date in {{{0}}} according to user's preference. If no preference set, {{{1}}} (default_format) (one of mdy, dmy, ymd, ISO 8601) is used.
{{padleft:string|8}} 00string Pad {{{0}}} with zeros to the right or left; an alternative padding string can be given as {{{2}}}; the alternative padding string may be truncated if its length does not evenly divide by the required number of characters (i.e. the result is always {{{1}}} chars long)
{{padleft:string|8|/}} //string
{{padright:string|8}} string00
{{padright:string|8|/}} string//
{{plural:1|is|are}} is Returns {{{1}}} if {{{0}}} is 1, {{{2}}} if {{{0}}} is greater than 1
{{plural:3|is|are}} are
{{#time:format_string|date_time_object}} Format {{{1}}} date/time according to {{{0}}} format string (see mw:Help:Extension:ParserFunctions#.23time extension documentation page)
{{#timel:format_string|date_time_object}} Like #time, but for local time.
{{gender:username|masculine|female|neutral}} neutral Produces alternative text according to the gender specified by the given user in his/her preferences
{{#tag:tagname|content}} <tagname ''parameter1''="'value1'" ''parameter2''="'value2'"> content </tagname> Equivalent to an HTML tag or pair of tags; can be used for nesting references

Paths

[edit]
Template Result Descrip
{{localurl:AlanM1/Variables}}
{{localurl:AlanM1/Variables|query string}}
/wiki/AlanM1/Variables
/w/index.php?title=AlanM1/Variables&query string
Relative path to the title
{{fullurl:AlanM1/Variables}}
{{fullurl:AlanM1/Variables|query_string}}
//en.wikipedia.org/wiki/AlanM1/Variables
//en.wikipedia.org/w/index.php?title=AlanM1/Variables&query_string
Absolute path to the title, without a protocol prefix
{{canonicalurl:AlanM1/Variables}}
{{canonicalurl:AlanM1/Variables|query_string}}
https://en.wikipedia.org/wiki/AlanM1/Variables
https://en.wikipedia.org/w/index.php?title=AlanM1/Variables&query_string
Absolute path to the title, with a protocol prefix
{{filepath:file name}} Absolute URL to a media file
{{urlencode:string}} string Input encoded for use in URLs
{{anchorencode:string}} string Input encoded for use in URL section anchors
{{ns:n}}
{{nse:n}}
{{ns:n}}
{{nse:n}}
Name for the namespace with index n; use for the equivalent encoded for MediaWiki URLs
{{#rel2abs:path}} path Converts a relative file path to absolute; see the extension documentation
{{#titleparts:pagename|number of segments to return|first segment to return}} Pagename Splits title into parts; see the extension documentation

Conditional expressions

[edit]

These are covered at the extension documentation page. Some parameters are optional.

Template Result Descrip
{{#expr: expression}} Expression error: Unrecognized punctuation character "'". Evaluates the given expression; see Help:Calculation
{{#if: test string|value if non-empty|value if empty}} value if non-empty Selects one of two values based on whether the test string is empty
{{#ifeq: string 1|string 2|value if equal|value if unequal}} value if unequal Selects one of two values based on whether the test strings are equal – numerically if applicable
{{#iferror: test string|value if error|value if correct}} value if correct Selects value based on whether the test string generates a parser error
{{#ifexpr: expression|value if true|value if false}} Expression error: Unrecognized punctuation character "'". Selects value based on evaluation of expression
{{#ifexist: page title|value if exists|value if doesn't exist}} value if doesn't exist Selects value depending on whether a page title exists
{{#switch: test|...|default}} default Provides alternatives based on the value of the test string

Note that with #if: expressions, a variable like {{{1}}} always requires a final pipe: . If it is absent, then whenever the parameter 1 is absent, instead of leaving the field blank the software will use the actual text {{{1}}} and the field will never be empty.

For the use of these functions in tables, see Conditional tables.