Magic word if not found

Languages:

  • Bahasa Indonesia
  • Bân-lâm-gú
  • Deutsch
  • Deutsch (Sie-Form)
  • English
  • Esperanto
  • Nederlands
  • Tiếng Việt
  • Türkçe
  • Yorùbá
  • dansk
  • español
  • français
  • galego
  • italiano
  • magyar
  • norsk bokmål
  • polski
  • português
  • português do Brasil
  • română
  • slovenčina
  • suomi
  • svenska
  • čeština
  • беларуская (тарашкевіца)
  • ирон
  • русский
  • українська
  • اردو
  • العربية
  • بهاس ملايو
  • تۆرکجه
  • فارسی
  • हिन्दी
  • বাংলা
  • ไทย
  • 中文
  • 日本語
  • 粵語
  • 한국어

MediaWiki extensions

Magic words are a technique for mapping a variety of wiki text strings to a single ID that is associated with a function.
Both variables and parser functions use this technique.
All text mapped to that ID will be replaced with the return value of the function.
The mapping between the text strings and the ID is stored in the variable $magicWords in a file that can be loaded using $wgExtensionMessagesFiles[].

The default magic words are implemented in CoreParserFunctions.php.

How magic words work[edit]

Whenever MediaWiki finds text between double braces ({{XXX ...}}) it must decide whether XXX is a variable, parser function, or template. To do so, it asks a series of questions:

  1. Does it have an associated magic word ID? As a first step in resolving markup of the form {{XXX...}}, MediaWiki attempts to translate XXX to a magic word ID. The translation table is defined by $magicWords.
    • If no magic word ID is associated with XXX, XXX is presumed to be a template.
  2. Is it a variable? If a magic word ID is found, MediaWiki next checks to see if it has any parameters.
    • If no parameters are found, MediaWiki checks to see if the magic word ID has been declared as a variable ID. To check this, it retrieves the list of magic words serving by calling MagicWord::getVariableIDs(). This method gets its list of variable IDs from a hard coded list of variable IDs (see Help:Variables) and from a list of custom variable IDs provided by all functions attached to the hook MagicWordwgVariableIDs.
      • If the magic word ID has been classified as a variable, hooks MediaWiki calls the functions associated with the event name ParserGetVariableValueSwitch until one is found that recognizes the magic word and can return its value.
  3. Is it a parser function? If there are any parameters or if the magic word ID is missing from the list of variable magic word IDs, then MediaWiki assumes that the magic word is a parser function or template. If the magic word ID is found in the list of parser functions declared via a call to $wgParser->setFunctionHook($magicWordId, $renderingFunctionName), it is treated as a parser function and rendered using the function named $renderingFunctionName. Otherwise, it is presumed to be a template.

By convention:

  • The magic words called variables are capitalised, case-sensitive and do not have space characters.
  • Parserfunctions are prefixed with a hash sign ({{#), are case insensitive and do not include space characters.

This is however a convention and one not consistently applied (for historic reasons).

  • Variables do not have space characters, but some translations of variables in other languages DO have spaces
  • Variables generally are capitalised and case-sensitive, but some parser functions also use this convention.
  • Some parser functions start with a hash sign, but some do not.

Where possible you should follow the conventions when defining or translating magic words.
Magic words are higher in priority than templates, so any magic word defined, will block the usage of that defined name as a template.

Following the conventions avoids adding more and more potential collisions.

Defining magic words[edit]

For magic words to do their magic we must define two things:

  • a mapping between wiki text and a magic word ID
  • a mapping between a magic word ID and some php function that interprets the magic word.

Mapping wiki text to magic word IDs[edit]

The variable $magicWords is used to associate each magic word ID with a language-dependent array that describes all the text strings that mapped to the magic word ID.
Important: This only sets up the back end i18n mapping, you still have to write other code to make MediaWiki use the magic word for anything.
Also, make sure that you initialize $magicWords as an empty array before adding language-specific values or you will get errors when trying to load the magic word and will need to rebuild your localization cache before it will work.

The first element of this array is an integer flag indicating whether or not the magic word is case sensitive. The remaining elements are a list of text that should be associated with the magic word ID. If the case sensitive flag is 0, any case variant of the names in the array will match. If the case sensitive flag is 1, only exact case matches will be associated with the magic word ID.
Thus the format is $magicWords['en'] = [ 'InternalName' => [ 0, 'NameUserTypes', 'AdditionalAliasUserCanType' ] ];

This association is created by $magicWords in a file registered using $wgExtensionMessagesFiles[].

In the example below, a Spanish MediaWiki installation will associate the magic word ID ‘MAG_CUSTOM’ with «personalizado», «custom», «PERSONALIZADO», «CUSTOM» and all other case variants.
In an English MediaWiki only «custom» in various case combinations will be mapped to ‘MAG_CUSTOM’:

File Example.i18n.magic.php:

<?php

$magicWords = [];

$magicWords['en'] = [
	'MAG_CUSTOM' => [ 0, 'custom' ],
];

$magicWords['es'] = [
	'MAG_CUSTOM' => [ 0, 'personalizado' ],
];

In part of the extension.json file:

"ExtensionMessagesFiles": {
	"ExampleMagic": "Example.i18n.magic.php"
}

Note that «ExampleMagic» is a different to the key you would use for a plain internationalization file (normally just the title of the extension, i.e. «Example»). «Magic» has been appended deliberately so one does not overwrite the other.

In inline PHP[edit]

You can associate magic words inline in PHP rather than through a i18n file.
This is useful when defining hooks in LocalSettings.php but should not be done in extensions.

MediaWikiMediaWikiServices::getInstance()->getContentLanguage()->mMagicExtensions['wikicodeToHtml'] = ['MAG_CUSTOM', 'custom'];

Associating a magic word ID with a PHP function[edit]

The mechanism for associating magic word IDs with rendering functions depends on whether the magic word will be used as a parser function or a variable. For more information, please see:

  • Manual:Parser functions
  • Manual:Variables

Localisation[edit]

See Help:Magic words#Localisation for help.

You can read more on definition and usage of magic words for localisation at Manual:Messages API, Manual:Language#Namespaces; Avoid {{SITENAME}} in messages.

Behavior switches (double underscore magic words)[edit]

Behavior switches are a special type of magic word. They can be recognized by their use of double underscores (rather than double braces).
Example:
__NOTOC__

These magic words typically do not output any content, but instead change the behavior of a page and/or set a page property.
These magic words are listed in MagicWordFactory::mDoubleUnderscoreIDs and also at Help:Magic words#Behavior switches.
The effect of most standard behavior switches is defined in Parser::handleDoubleUnderscore().
If no specific effect is defined, the magic word will simply set a page property in the page_props table.
This can also be checked later by testing if $parser->getOutput()->getPageProperty( 'MAGIC_WORD' ) is null or the empty string

Custom behavior switch[edit]

Here is an example extension implementing a custom __CUSTOM__ behaviour switch

custom/extension.json — This is minimal, a real extension would fill out more fields.

{
	"name": "Custom",
	"type": "parserhook",
	"AutoloadClasses": {
		"MyHooks": "MyHooks.php"
	},
	"Hooks": {
		"GetDoubleUnderscoreIDs": [
			"MyHooks::onGetDoubleUnderscoreIDs"
		],
		"ParserAfterParse": [
			"MyHooks::onParserAfterParse"
		]
	},
	"ExtensionMessagesFiles": {
		"CustomMagic": "custom.i18n.php"
	},
	"manifest_version": 1
}

custom/custom.i18n.php

<?php
$magicWords = [];
$magicWords['en'] = [
	'MAG_CUSTOM' => [ 0, '__CUSTOM__' ],
];

custom/MyHooks.php

<?php
class MyHooks {
	public static function onGetDoubleUnderscoreIDs( &$ids ) {
		$ids[] = 'MAG_CUSTOM';
	}

	public static function onParserAfterParse( Parser $parser, &$text, StripState $stripState ) {
		if ( $parser->getOutput()->getPageProperty( 'MAG_CUSTOM' ) !== null ) {
			// Do behavior switching here ...
			// e.g. If you wanted to add some JS, you would do $parser->getOutput()->addModules( 'moduleName' );
		}
	}
}

See also[edit]

  • Help:Magic words — List of Variables like {{PAGENAME}} and {{SERVER}}

I want to have a magic word IS_APPROVED which returns «is-approved» if a Mediawiki page version is approved and returns «» if the page version is not approved. The page is approved via the ApprovedRevs extension which simply adds a pair (pageid,versionid) to a table in the MySQL database to indicate the version approval.

Does such a magic word already exist?

asked Apr 14, 2015 at 18:44

oks's user avatar

1

api.php?action=query&meta=siteinfo&siprop=magicwords will give you the list of magic words available on a wiki (documentation, English Wikipedia example). As for figuring out if anyone has ever written an extension providing a magic word for a certain function, well, Google is your friend… As the manual on variables explains, MagicWordwgVariableIDs is a good search keyword as any extension providing variables must subscribe to that hook.

answered Apr 15, 2015 at 7:45

Tgr's user avatar

TgrTgr

1,2697 silver badges9 bronze badges

Magic words are strings of text that MediaWiki associates with a return value or function, such as time, site details, or page names. This page is about usage of standard magic words; for a technical reference, see Manual:Magic words.

There are three general types of magic words:

  • Behavior switches: these are uppercase words surrounded by double underscores, e.g. __FOO__
  • Variables: these are uppercase words surrounded by double braces, e.g. {{FOO}}. As such, they look a lot like templates.
  • Parser functions: these take parameters and are either of the form {{foo:...}} or {{#foo:...}}. See also Help:Extension:ParserFunctions.

Page-dependent magic words will affect or return data about the current page (by default), even if the word is added through a transcluded template or included system message.

Contents

  • 1 Behavior switches
  • 2 Variables
    • 2.1 Date and time
    • 2.2 Technical metadata
    • 2.3 Statistics
    • 2.4 Page names
    • 2.5 Namespaces
  • 3 Parser functions
    • 3.1 URL data
    • 3.2 Namespaces
    • 3.3 Formatting
    • 3.4 Miscellaneous

Behavior switches

A behavior switch controls the layout or behaviour of the page and can often be used to specify desired omissions and inclusions in the content.

Word Description Versions
Table of contents
__NOTOC__ Hides the table of contents (TOC).
__FORCETOC__ Forces the table of content to appear at its normal position (above the first header).
__TOC__ Places a table of contents at the word’s current position (overriding __NOTOC__). If this is used multiple times, the table of contents will appear at the first word’s position.
Editing
__NOEDITSECTION__ Hides the section edit links beside headings.
__NEWSECTIONLINK__ Adds a link («+» by default) beside the «edit» tab for adding a new section on a non-talk page (see Adding a section to the end). 1.7+
__NONEWSECTIONLINK__ Removes the link beside the «edit» tab on pages in talk namespaces. 1.15+
Categories
__NOGALLERY__ Used on a category page, replaces thumbnails in the category view with normal links. 1.7+
__HIDDENCAT__ Used on a category page, hides the category from the lists of categories in its members and parent categories (there is an option in the user preferences to show them). 1.13+
Language conversion
__NOCONTENTCONVERT__
__NOCC__
On wikis with language variants, don’t perform any content language conversion (character and phase) in article display; for example, only show Chinese (zh) instead of variants like zh_cn, zh_tw, zh_sg, or zh_hk.
__NOTITLECONVERT__
__NOTC__
On wikis with language variants, don’t perform language conversion on the title (all other content is converted).
Other
__START__ No effect.
__END__ Explicitly marks the end of the article, to prevent MediaWiki from removing trailing whitespace. Removed in 19213. 1.1 — 1.8
__INDEX__ Tell search engines to index the page (overrides $wgArticleRobotPolicies, but not robots.txt). 1.14+
__NOINDEX__ Tell search engines not to index the page (ie, do not list in search engines’ results). 1.14+
__STATICREDIRECT__ On redirect pages, don’t allow MediaWiki to automatically update the link when someone moves a page and checks «Update any redirects that point to the original title». 1.13+

Variables

Variables return information about the current page, wiki, or date. Their syntax is similar to templates. Variables marked as «[expensive]» are tracked by the software, and the number that can be included on a page is limited.

If a template name conflicts with a variable, the variable will be used (so to transclude the template Template:PAGENAME you would need to write {{Template:PAGENAME}}). In some cases, adding parameters will force the parser to invoke a template; for example, {{CURRENTDAYNAME|x}} transcludes Template:CURRENTDAYNAME not the variable.

Date and time

The following variables return the current date and time in UTC.

Due to MediaWiki and browser caching, these variables frequently show when the page was cached rather than the current time.

Variable Output Description Versions
Year
{{CURRENTYEAR}} 2023 Year
Month
{{CURRENTMONTH}} 04 Month (zero-padded number)
{{CURRENTMONTHNAME}} April Month (name)
{{CURRENTMONTHNAMEGEN}} April Month (genitive form)
{{CURRENTMONTHABBREV}} Apr Month (abbreviation) 1.5+
Day
{{CURRENTDAY}} 14 Day of the month (unpadded number)
{{CURRENTDAY2}} 14 Day of the month (zero-padded number) 1.6+
{{CURRENTDOW}} 5 Day of the week (unpadded number)
{{CURRENTDAYNAME}} Friday Day of the week (name)
Time
{{CURRENTTIME}} 08:49 Time (24-hour HH:mm format)
{{CURRENTHOUR}} 08 Hour (24-hour zero-padded number)
Other
{{CURRENTWEEK}} 15 Week (number)
{{CURRENTTIMESTAMP}} 20230414084905 YYYYMMDDHHmmss timestamp 1.7+

The following variables do the same as the above, but using the site’s server config or $wgLocaltimezone.

  • {{LOCALYEAR}}
  • {{LOCALMONTH}}
  • {{LOCALMONTHNAME}}
  • {{LOCALMONTHNAMEGEN}}
  • {{LOCALMONTHABBREV}}
  • {{LOCALDAY}}
  • {{LOCALDAY2}}
  • {{LOCALDOW}}
  • {{LOCALDAYNAME}}
  • {{LOCALTIME}}
  • {{LOCALHOUR}}
  • {{LOCALWEEK}}
  • {{LOCALTIMESTAMP}}
For more thorough time formatting, you may want to install Extension:ParserFunctions to use the #time parser function

Technical metadata

Revision variables return data about the latest edit to the current page, even if viewing an older version of the page.

Variable Output Description Versions
Site
{{SITENAME}} eLinux.org The wiki’s site name ($wgSitename).
{{SERVER}} https://elinux.org domain URL ($wgServer)
{{SERVERNAME}} elinux.org domain name (No longer dependent on $wgServerName as of version 1.17)
{{DIRMARK}}
{{DIRECTIONMARK}}

Outputs a unicode-directional mark that matches the wiki’s default language’s direction (&lrm; on left-to-right wikis, &rlm; on right-to-left wikis), useful in text with multi-directional text. 1.7+
{{SCRIPTPATH}} relative script path ($wgScriptPath)
{{STYLEPATH}} /skins relative style path ($wgStylePath) 1.16+
{{CURRENTVERSION}} 1.31.0 (c6f0a38) The wiki’s MediaWiki version. 1.7+
{{CONTENTLANGUAGE}}
{{CONTENTLANG}}
en
en
The wiki’s default interface language ($wgLanguageCode) 1.7+
Latest revision to current page
{{REVISIONID}} 31723 Unique revision ID 1.5+
{{REVISIONDAY}} 20 Day edit was made (unpadded number) 1.8+
{{REVISIONDAY2}} 20 Day edit was made (zero-padded number) 1.8+
{{REVISIONMONTH}} 01 Month edit was made (zero-padded number as of 1.17+, unpadded number in prior versions) 1.8+
{{REVISIONYEAR}} 2011 Year edit was made 1.8+
{{REVISIONTIMESTAMP}} 20110120181248 Timestamp as of time of edit 1.8+
{{REVISIONUSER}} Wmat The username of the user who made the most recent edit to the page, or the current user when previewing an edit 1.15+
{{PAGESIZE:page name}}
{{PAGESIZE:page name|R}}
35,238
35238
[expensive] Returns the byte size of the specified page. Use «|R» to get raw numbers. 1.13+
{{PROTECTIONLEVEL:action}} protection level Outputs the protection level (e.g. ‘autoconfirm’, ‘sysop’) for a given action (e.g. ‘edit’, ‘move’) on the current page or an empty string if not protected. 1.15+
Affects page content
{{DISPLAYTITLE:title}} Format the current page’s title header. The value must be equivalent to the default title: only capitalization changes and replacing spaces with underscores. It can be disabled or enabled by $wgAllowDisplayTitle; disabled by default before 1.10+, enabled by default thereafter. 1.7+
{{DEFAULTSORT:sortkey}}
{{DEFAULTSORTKEY:sortkey}}
{{DEFAULTCATEGORYSORT:sortkey}}
Used for categorizing pages, sets a default category sort key. For example if you put {{DEFAULTSORT:Smith, John}} at the end of John Smith, the page would be sorted under «S» by default in categories. 1.10+

Statistics

Numbers returned by these variables normally contain separators (commas or spaces, depending on the local language), but can return raw numbers with the «:R» flag (for example, {{NUMBEROFPAGES}} → 29,155 and {{NUMBEROFPAGES:R}} → 29155). Use «|R» for magic words that require a parameter like PAGESINCATEGORY (for example {{PAGESINCATEGORY:Help}} and {{PAGESINCATEGORY:Help|R}}). Also applicable to {{PAGESIZE:page name}} above.

Variable Output Description Versions
Entire wiki
{{NUMBEROFPAGES}} 29,155 Number of wiki pages. 1.7+
{{NUMBEROFARTICLES}} 3,112 Number of pages in content namespaces.
{{NUMBEROFFILES}} 8,610 Number of uploaded files. 1.5+
{{NUMBEROFEDITS}} 120,996 Number of page edits. 1.10+
{{NUMBEROFVIEWS}} Template:NUMBEROFVIEWS Number of page views. Usually useless on a wiki using caching. 1.14+
{{NUMBEROFUSERS}} 6,788 Number of registered users. 1.7+
{{NUMBEROFADMINS}} 4 Number of users in the sysop group. 1.7+
{{NUMBEROFACTIVEUSERS}} 36 Number of active users, based on the criteria used in Special:Statistics. 1.15+
{{PAGESINCATEGORY:categoryname}}
{{PAGESINCAT:Help}}
60
60
[expensive] Number of pages in the given category. 1.13+
{{NUMBERINGROUP:groupname}}
{{NUMINGROUP:groupname}}
4
4
({{NUMBERINGROUP:bureaucrat}} used here)
Number of users in a specific group. 1.14+
{{PAGESINNS:index}}
{{PAGESINNAMESPACE:index}}
not enabled Number of pages in the given namespace (replace index with the relevant namespace index). For instance, {{PAGESINNAMESPACE:14}} will output the number of category pages. {{PAGESINNS:0}} differs from {{NUMBEROFARTICLES}} in that the former includes redirects and disambiguation pages. Disabled by default, enable with $wgAllowSlowParserFunctions. 1.7+

Page names

Variable Output Description Versions
{{FULLPAGENAME}} Help:Magic words Namespace and page title. 1.6+
{{PAGENAME}} Magic words Page title.
{{BASEPAGENAME}} Magic words Page title excluding the current subpage and namespace («Title/foo» on «Title/foo/bar»).

For more complex splitting, use {{#titleparts:}} from ParserFunctions extension.

1.7+
{{SUBPAGENAME}} Magic words The subpage title («foo» on «Title/foo»). 1.6+
{{SUBJECTPAGENAME}} Help:Magic words The namespace and title of the associated content page. 1.7+
{{TALKPAGENAME}} Help talk:Magic words The namespace and title of the associated talk page. 1.7+

The {{BASEPAGENAME}} and {{SUBPAGENAME}} magic words only work in namespaces that have subpages enabled. See Manual:$wgNamespacesWithSubpages for information on enabling subpages.

The following are equivalents encoded for use in MediaWiki URLs (i.e. spaces replaced with underscores and some characters percent-encoded):

  • {{FULLPAGENAMEE}}
  • {{PAGENAMEE}}
  • {{BASEPAGENAMEE}}
  • {{SUBPAGENAMEE}}
  • {{SUBJECTPAGENAMEE}}
  • {{TALKPAGENAMEE}}

As of 1.15+, these can all take a parameter, allowing specification of the page to be operated on, instead of just the current page:

  • {{PAGENAME:Template:Main Page}}Main Page
Warning Warning: Page titles containing certain characters, such as single quotes (‘) or asterisks *, may produce unexpected results when handled with these magic words, e.g. {{PAGESINCATEGORY:{{PAGENAME}}}}. See bugs 14779, 16474.

Namespaces

Variable Output Description Versions
{{NAMESPACE}} Help Name of the page’s namespace
{{SUBJECTSPACE}}
{{ARTICLESPACE}}
Help
Help
Name of the associated content namespace 1.7+
{{TALKSPACE}} Help talk Name of the associated talk namespace 1.7+

The following are equivalents encoded for use in MediaWiki URLs (spaces replaced with underscores and some characters percent-encoded):

  • {{NAMESPACEE}}
  • {{SUBJECTSPACEE}}
  • {{TALKSPACEE}}

As of 1.15+, these can take a page name parameter and will return the namespace of the page name parameter, instead of the current page’s:

  • {{NAMESPACE:Template:Main Page}}Template
  • {{SUBJECTSPACE:Template:Main Page}}Template
  • {{TALKSPACE:Template:Main Page}}Template talk

Parser functions

Parser functions are very similar to variables, but take one or more parameters (technically, any magic word that takes a parameter is a parser function), and the name is sometimes prefixed with a hash to distinguish them from templates.

This page only describes parser functions that are integral to the MediaWiki software. Other parser functions may be added by MediaWiki extensions such as the ParserFunctions extension. For those see Help:Extension:ParserFunctions.

URL data

Parser function Input → Output Description Versions
{{localurl:page name}}
{{localurl:page name|query_string}}
{{localurl:MediaWiki}} → /MediaWiki
{{localurl:MediaWiki|printable=yes}} → /index.php?title=MediaWiki&printable=yes
The relative path to the title.
{{fullurl:page name}}
{{fullurl:page name|query_string}}
{{fullurl:interwiki:remote page name|query_string}}
{{fullurl:Category:Top level}} → https://elinux.org/Category:Top_level

{{fullurl:Category:Top level|action=edit}} → https://elinux.org/index.php?title=Category:Top_level&action=edit

The absolute path to the title. This will also resolve Interwiki prefixes. 1.5+
{{filepath:file name}}
{{filepath:file name|nowiki}}
{{filepath:Wiki.png}} → https://elinux.org/images/b/bc/Wiki.png
{{filepath:Wiki.png|nowiki}} → https://elinux.org/images/b/bc/Wiki.png
The absolute URL to a media file. 1.12+
{{urlencode:string}} (or {{urlencode:string|QUERY}})
{{urlencode:string|WIKI}}
{{urlencode:string|PATH}}
{{urlencode:x y z á é}} (or {{urlencode:x y z á é|QUERY}}) → x+y+z+%C3%A1+%C3%A9
{{urlencode:x y z á é|WIKI}} → x_y_z_%C3%A1_%C3%A9
{{urlencode:x y z á é|PATH}} → x%20y%20z%20%C3%A1%20%C3%A9
The input encoded for use in URLs. 1.7+ (or 1.17+)
1.17+
1.17+
{{anchorencode:string}} {{anchorencode:x y z á é}} → x_y_z_.C3.A1_.C3.A9 The input encoded for use in URL section anchors (after the ‘#’ symbol in a URL). 1.8+

Namespaces

{{ns:}} returns the localized name for the namespace with that index. {{nse:}} is the equivalent encoded for MediaWiki URLs. It does the same, but it replaces spaces with underscores, making it usable in external links.

Content namespaces Talk namespaces
Usage Output Usage Output
{{ns:-2}} or {{ns:Media}} Media
{{ns:-1}} or {{ns:Special}} Special
{{ns:0}} or {{ns:}} {{ns:1}} or {{ns:Talk}} Talk
{{ns:2}} or {{ns:User}} User {{ns:3}} or {{ns:User talk}} User talk
{{ns:4}} or {{ns:Project}} eLinux.org {{ns:5}} or {{ns:Project talk}} eLinux.org talk
{{ns:6}} or {{ns:File}} or {{ns:Image}} File {{ns:7}} or {{ns:File talk}} or {{ns:Image talk}} File talk
{{ns:8}} or {{ns:MediaWiki}} MediaWiki {{ns:9}} or {{ns:MediaWiki talk}} MediaWiki talk
{{ns:10}} or {{ns:Template}} Template {{ns:11}} or {{ns:Template talk}} Template talk
{{ns:12}} or {{ns:Help}} Help {{ns:13}} or {{ns:Help talk}} Help talk
{{ns:14}} or {{ns:Category}} Category {{ns:15}} or {{ns:Category talk}} Category talk

Formatting

Usage Input → Output Description Version
{{lc:string}} {{lc:DATA CENTER}} → data center The lowercase input. 1.5+
{{lcfirst:string}} {{lcfirst:DATA center}} → dATA center The input with the very first character lowercase. 1.5+
{{uc:string}} {{uc:text transform}} → TEXT TRANSFORM The uppercase input. 1.5+
{{ucfirst:string}} {{ucfirst:text TRANSFORM}} → Text TRANSFORM The input with the very first character uppercase. 1.5+
{{formatnum:unformatted num}}
{{formatnum:formatted num|R}}
{{formatnum:987654321.654321}}
→ 987,654,321.654321
{{formatnum:987,654,321.654321|R}}
→ 987654321.654321
The input with decimal and decimal group separators, and localized digit script, according to the wiki’s default locale. The |R parameter can be used to unformat a number, for use in mathematical situations. 1.7+
1.13+

{{#dateformat:date}}
{{#formatdate:date}}
{{#dateformat:date|format}}
{{#formatdate:date|format}}

{{#dateformat:25 deC 2009|ymd}}
2009 DeC 25 (your pref), 2009 DeC 25 (default)
{{#formatdate:dec 25,2009|dmy}}
25 Dec 2009 (your pref), 25 Dec 2009 (default)
{{#dateformat:2009-12-25|mdy}}
December 25, 2009 (your pref), December 25, 2009 (default)
{{#formatdate:2009 dec 25|ISO 8601}}
2009-12-25 (your pref), 2009-12-25 (default)
{{#dateformat:25 decEmber|mdy}}
DecEmber 25 (your pref), DecEmber 25 (default)

Note: In the example above, «your pref» refers to your date preference on the current MediaWiki wiki only.

Formats an unlinked date based on user «Date format» preference, and adds metadata tagging it as a formatted date. For logged-out users and those who have not set a date format in their preferences, dates can be given a default: mdy, dmy, ymd, ISO 8601 (all case sensitive). If only the month and day are given, only mdy and dmy are valid. If a format is not specified or is invalid, the input format is used as a default. If the supplied date is not recognized as a valid date (specifically, if it contains any metadata such as from a nested use of these or a similar template), it is rendered unchanged, and no (additional) metadata is generated.
Warning Warning: Although the ISO 8601 standard requires that dates be in the Gregorian calendar, the ISO parameter in this function will still format dates that fall outside the usual Gregorian range (e.g. dates prior to 1583). Also, the magic word cannot properly convert between negative years (used with ISO 8601) and years BC or years BCE (used in general writing).
1.15+
{{padleft:xyz|stringlength}}
{{padleft:xyz|strlen|char}}
{{padleft:xyz|strlen|string}}
{{padleft:xyz|5}} → 00xyz
{{padleft:xyz|5|_}} → __xyz {{padleft:xyz|5|abc}} → abxyz {{padleft:xyz|2}} → xyz
{{padleft:|1|xyz}} → x (first character of the string)
Inserts a string of padding characters (character chosen in third parameter; default ‘0’) of a specified length (second parameter) next to a chosen base character or variable (first parameter). The final digits or characters in the base replace the final characters in the padding; i.e. {{padleft:44|3|0}} produces 044. The padding string may be truncated if its length does not evenly divide the required number of characters.
bug (fixed in r45734): multibyte characters are interpreted as two characters, which can skew width. These also cannot be used as padding characters.
1.8+
{{padright:xyz|stringlength}}
{{padright:xyz|strlen|char}}
{{padright:xyz|strlen|string}}
{{padright:xyz|5}} → xyz00

{{padright:xyz|5|_}} → xyz__
{{padright:xyz|5|abc}} → xyzab
{{padright:xyz|2}} → xyz
{{padright:|1|xyz} → x

Identical to padleft, but adds padding characters to the right side.
{{plural:2|is|are}} {{plural:1|is|are}} → is
{{plural:2|is|are}} → are
Outputs the correct given pluralization form (parameters except first) depending on the count (first parameter). Plural transformations are used for languages like Russian based on «count mod 10».
{{grammar:N|noun}} Outputs the correct inflected form of the given word described by the inflection code after the colon (language-dependent). Grammar transformations are used for inflected languages like Polish. See also Manual:$wgGrammarForms. 1.7+

Miscellaneous

Usage Output Description Version
{{int:message name}}
{{int:edit}}Edit
(depends on user language, try: fr •ja)
Internationalizes (translates) the given interface (MediaWiki namespace) message into the user language. Note that this can damage/confuse cache consistency, see bug 14404.
{{#language:language code}}
{{#language:ar}}
{{#language:th}}
language code
العربية
ไทย
The native name for the given language code, in accordance with ISO 639. 1.7+
{{#special:special page name}}
{{#special:userlogin}}
Special:Special page name
Special:UserLogin
The localized name for the given canonical Special: page. 1.9+
{{#tag:tagname
|content
|parameter1=value1
|parameter2=value2
}}
(depends on parser tag) Alias for XML-style parser or extension tags, but parsing wiki code. Inner content can be passed as first parameter, and attributes as subsequent ones:

<tagname attribute1value1» attribute2value2«> content </tagname >{{#tag:tagname|content|attribute1=value1|attribute2=value2}}

Warning : You must write {{#tag:tagname||attribute1=value1|attribute2=value2}} to pass an empty content.

1.12+
{{gender:username
|return text if user is male
|return text if user is female
|return text if user hasn't defined their gender}}
(depends on the named user’s gender) A switch for the gender set in Special:Preferences 1.15+
Language: English

Magic words are strings of text that MediaWiki associates with a return value or function, such as time, site details, or page names.

There are three general types of magic words:

  • Behavior switches: these are uppercase words surrounded by double underscores, e.g. __FOO__
  • Variables: these are uppercase words surrounded by double braces, e.g. {{FOO}}. As such, they look a lot like templates.
  • Parser functions: these take parameters and are either of the form {{foo:...}} or {{#foo:...}}. See also Help:Extension:ParserFunctions.

Page-dependent magic words will affect or return data about the current page (by default), even if the word is added through a transcluded template or included system message.

Behavior switches

A behavior switch controls the layout or behavior of the page and can often be used to specify desired omissions and inclusions in the content.

Word Description
Table of contents
__NOTOC__ Hides the table of contents (TOC).
__FORCETOC__ Forces the table of content to appear at its normal position (above the first header).
__TOC__ Places a table of contents at the word’s current position (overriding __NOTOC__). If this is used multiple times, the table of contents will appear at the first word’s position. It is possible to suppress the auto-generated section numbers, if the proper class exists locally at MediaWiki:Common.css, defined as .tocnumber { display: none; }.
Editing
__NOEDITSECTION__ Hides the section edit links beside headings.
__NEWSECTIONLINK__ Adds a link «+» beside the «edit» tab for adding a new section on a non-talk page (see Adding a section to the end (meta.wikimedia.org)).
__NONEWSECTIONLINK__ Removes the link beside the «edit» tab on pages in talk namespaces.
Categories
__NOGALLERY__ Used on a category page, replaces thumbnails in the category view with normal links.
__HIDDENCAT__ Used on a category page, hides the category from the lists of categories in its members and parent categories (there is an option in the user preferences to show them).
Language conversion
__NOCONTENTCONVERT__
__NOCC__
On wikis with language variants, don’t perform any content language conversion (character and phase) in article display; for example, only show Chinese (zh) instead of variants like zh_cn, zh_tw, zh_sg, or zh_hk.
__NOTITLECONVERT__
__NOTC__
On wikis with language variants, don’t perform language conversion on the title (all other content is converted).
Other
__START__ No effect.
__INDEX__ Tell search engines to index the page (overrides $wgArticleRobotPolicies, but not robots.txt).
__NOINDEX__ Tell search engines not to index the page (ie, do not list in search engines’ results).
__STATICREDIRECT__ On redirect pages, don’t allow MediaWiki to automatically update the link when someone moves a page and checks «Update any redirects that point to the original title».

Variables

Variables return information about the current page, wiki, or date. Their syntax is similar to templates. Variables marked as «[expensive]» are tracked by the software, and the number that can be included on a page is limited.

If a template name conflicts with a variable, the variable will be used (so to transclude the template «PAGENAME» you would need to write {{Шаблон:PAGENAME}}). In some cases, adding parameters will force the parser to invoke a template; for example, {{CURRENTDAYNAME|x}} transcludes «{{Template:CURRENTDAYNAME}}«, not the variable.

Date and time

The following variables return the current date and time in UTC.

Due to MediaWiki and browser caching, these variables frequently show when the page was cached rather than the current time. The date and time magic words are formatted in the english language.

Variable Output Description
Year
{{CURRENTYEAR}} 2023 Year
Month
{{CURRENTMONTH}} 04 Month (zero-padded number)
{{CURRENTMONTHNAME}} апрель Month (name)
{{CURRENTMONTHNAMEGEN}} апреля Month (genitive form)
{{CURRENTMONTHABBREV}} апр Month (abbreviation)
Day
{{CURRENTDAY}} 14 Day of the month (unpadded number)
{{CURRENTDAY2}} 14 Day of the month (zero-padded number)
{{CURRENTDOW}} 5 Day of the week (unpadded number)
{{CURRENTDAYNAME}} пятница Day of the week (name)
Time
{{CURRENTTIME}} 08:49 Time (24-hour HH:mm format)
{{CURRENTHOUR}} 08 Hour (24-hour zero-padded number)
Other
{{CURRENTWEEK}} 15 Week (number)
{{CURRENTTIMESTAMP}} 20230414084901 YYYYMMDDHHmmss timestamp

The following variables do the same as the above, but using the site’s server config or $wgLocaltimezone.

  • {{LOCALYEAR}}
  • {{LOCALMONTH}}
  • {{LOCALMONTHNAME}}
  • {{LOCALMONTHNAMEGEN}}
  • {{LOCALMONTHABBREV}}
  • {{LOCALDAY}}
  • {{LOCALDAY2}}
  • {{LOCALDOW}}
  • {{LOCALDAYNAME}}
  • {{LOCALTIME}}
  • {{LOCALHOUR}}
  • {{LOCALWEEK}}
  • {{LOCALTIMESTAMP}}
For more thorough time formatting, you may want to use the #time parser function.

Technical metadata

Note: Revision variables return data about the latest edit to the current page, even if viewing an older version of the page.

Variable Output Description
Site
{{SITENAME}} Ай да Linux Wiki The wiki’s site name ($wgSitename).
{{SERVER}} https://aidalinux.ru domain URL ($wgServer)
{{SERVERNAME}} aidalinux.ru domain name
{{DIRMARK}}
{{DIRECTIONMARK}}

Outputs a unicode-directional mark that matches the wiki’s default language’s direction (&lrm; on left-to-right wikis, &rlm; on right-to-left wikis), useful in text with multi-directional text.
{{SCRIPTPATH}} /wiki relative script path ($wgScriptPath)
{{STYLEPATH}} /wiki/skins relative style path ($wgStylePath)
{{CURRENTVERSION}} 1.35.1 The wiki’s MediaWiki version.
{{CONTENTLANGUAGE}}
{{CONTENTLANG}}
ru
ru
The wiki’s default interface language ($wgLanguageCode)
Latest revision to current page
{{REVISIONID}} 368 Unique revision ID
{{REVISIONDAY}} 24 Day edit was made (unpadded number)
{{REVISIONDAY2}} 24 Day edit was made (zero-padded number)
{{REVISIONMONTH}} 12 Month edit was made (zero-padded number)
{{REVISIONMONTH1}} 12 Month edit was made (unpadded number)
{{REVISIONYEAR}} 2011 Year edit was made
{{REVISIONTIMESTAMP}} 20111224181336 Timestamp as of time of edit
{{REVISIONUSER}} Langator The username of the user who made the most recent edit to the page, or the current user when previewing an edit
{{PAGESIZE:page name}}
{{PAGESIZE:page name|R}}
35 966
35966
[expensive] Returns the byte size of the specified page. Use «|R» to get raw numbers.
{{PROTECTIONLEVEL:action}} protection level Outputs the protection level (e.g. ‘autoconfirmed’, ‘sysop’) for a given action (e.g. ‘edit’, ‘move’) on the current page or an empty string if not protected.
Affects page content
{{DISPLAYTITLE:title}} Format the current page’s title header. The value must be equivalent to the default title: only capitalization changes and replacing spaces with underscores are allowed.
{{DEFAULTSORT:sortkey}}
{{DEFAULTSORTKEY:sortkey}}
{{DEFAULTCATEGORYSORT:sortkey}}
Used for categorizing pages, sets a default category sort key. For example if you put {{DEFAULTSORT:Update, BIOS}} at the end of BIOS Update, the page would be sorted under «U» by default in categories.

Statistics

Numbers returned by these variables normally contain separators (commas or spaces, depending on the local language), but can return raw numbers with the «:R» flag (for example, {{NUMBEROFPAGES}} → 1778 and {{NUMBEROFPAGES:R}} → 1778). Use «|R» for magic words that require a parameter like PAGESINCATEGORY (for example {{PAGESINCATEGORY:Help}} and {{PAGESINCATEGORY:Help|R}}). Also applicable to {{PAGESIZE:page name}} above.

The number magic words are formatted in the english language.

Variable Output Description
Entire wiki
{{NUMBEROFPAGES}} 1778 Number of wiki pages.
{{NUMBEROFARTICLES}} 29 Number of pages in content namespaces.
{{NUMBEROFFILES}} 22 Number of uploaded files.
{{NUMBEROFEDITS}} 22 852 Number of page edits.
{{NUMBEROFVIEWS}} Шаблон:NUMBEROFVIEWS Number of page views. Usually useless on a wiki using caching.
{{NUMBEROFUSERS}} 17 768 Number of registered users.
{{NUMBEROFADMINS}} 2 Number of users in the sysop group.
{{NUMBEROFACTIVEUSERS}} 0 Number of active users, based on the criteria used in Special:Statistics.
{{PAGESINCATEGORY:categoryname}}
{{PAGESINCAT:Help}}
31
31
[expensive] Number of pages in the given category.
{{NUMBERINGROUP:groupname}}
{{NUMINGROUP:groupname}}
2
2
({{NUMBERINGROUP:bureaucrat}} used here)
Number of users in a specific group.

Page names

Variable Output Description
{{FULLPAGENAME}} Справка:Magic words Namespace and page title.
{{PAGENAME}} Magic words Page title.
{{BASEPAGENAME}} Magic words Page title excluding the current subpage and namespace («Title/foo» on «Title/foo/bar»).

For more complex splitting, use {{#titleparts:}} from ParserFunctions extension.

{{SUBPAGENAME}} Magic words The subpage title («foo» on «Title/foo»).
{{SUBJECTPAGENAME}} Справка:Magic words The namespace and title of the associated subject page.
{{TALKPAGENAME}} Обсуждение справки:Magic words The namespace and title of the associated talk page.

The {{BASEPAGENAME}} and {{SUBPAGENAME}} magic words only work in namespaces that have subpages enabled.

The following are equivalents encoded for use in MediaWiki URLs (i.e. spaces replaced with underscores and some characters percent-encoded):

  • {{FULLPAGENAMEE}}
  • {{PAGENAMEE}}
  • {{BASEPAGENAMEE}}
  • {{SUBPAGENAMEE}}
  • {{SUBJECTPAGENAMEE}}
  • {{TALKPAGENAMEE}}

These can all take a parameter, allowing specification of the page to be operated on, instead of just the current page:

  • {{PAGENAME:Template:Main Page}}Main Page

Предупреждение: Page titles containing certain characters, such as single quotes (') or asterisks (*), may produce unexpected results when handled with these magic words, e.g. {{PAGESINCATEGORY:{{PAGENAME}}}}. See bugs 14779, 16474.

Note that {{PAGENAME}}, {{PAGENAMEE}} and {{urlencode:}} have distinct implementations. See Manual:PAGENAMEE encoding for details.

Namespaces

Variable Output Description
{{NAMESPACE}} Справка Name of the page’s namespace
{{SUBJECTSPACE}}
{{ARTICLESPACE}}
Справка
Справка
Name of the associated content namespace
{{TALKSPACE}} Обсуждение справки Name of the associated talk namespace

The following are equivalents encoded for use in MediaWiki URLs (spaces replaced with underscores and some characters percent-encoded):

  • {{NAMESPACEE}}
  • {{SUBJECTSPACEE}}
  • {{TALKSPACEE}}

These can take a full-page-name parameter and will return the requested namespace associated with that page, instead of with the current page:

  • {{NAMESPACE:Template:Main Page}}Шаблон
  • {{SUBJECTSPACE:Template:Main Page}}Шаблон
  • {{TALKSPACE:Template:Main Page}}Обсуждение шаблона

Parameter must not be a namespace name:

  • {{SUBJECTSPACE:Help talk}} → ‘

Parser functions

Parser functions are very similar to variables, but take one or more parameters (technically, any magic word that takes a parameter is a parser function), and the name is sometimes prefixed with a hash to distinguish them from templates.

This page only describes parser functions that are integral to the MediaWiki software. Other parser functions are added by the ParserFunctions extension. For those see Help:Extension:ParserFunctions.

URL data

Parser function Input → Output Description
{{localurl:page name}}
{{localurl:page name|query_string}}
{{localurl:MediaWiki}} → /w/MediaWiki
{{localurl:MediaWiki|printable=yes}} → /wiki/index.php?title=MediaWiki&printable=yes
The relative path to the title.
{{fullurl:page name}}
{{fullurl:page name|query_string}}
{{fullurl:interwiki:remote page name|query_string}}
{{fullurl:Category:Top level}} → https://aidalinux.ru/w/%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%8F:Top_level

{{fullurl:Category:Top level|action=edit}} → https://aidalinux.ru/wiki/index.php?title=%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%8F:Top_level&action=edit

The absolute path to the title. This will also resolve Interwiki prefixes.
{{filepath:file name}}
{{filepath:file name|nowiki}}
{{filepath:Wiki.png}}

{{filepath:Wiki.png|nowiki}}
{{filepath:Example.svg|300}}

The absolute URL to the full size of a media file.
{{urlencode:string}} (or {{urlencode:string|QUERY}})
{{urlencode:string|WIKI}}
{{urlencode:string|PATH}}
{{urlencode:x y z á é}} (or {{urlencode:x y z á é|QUERY}}) → x+y+z+%C3%A1+%C3%A9
{{urlencode:x y z á é|WIKI}} → x_y_z_%C3%A1_%C3%A9
{{urlencode:x y z á é|PATH}} → x%20y%20z%20%C3%A1%20%C3%A9

Note that the default changed from |WIKI to |QUERY in 1.17; this may break templates that rely on this function.

The input encoded for use in URLs. Note that there is no urldecode function like there is in the obsolete Extension:StringFunctions.
{{anchorencode:string}} {{anchorencode:x y z á é}} → x_y_z_.C3.A1_.C3.A9 The input encoded for use in URL section anchors (after the ‘#’ symbol in a URL).

Namespaces

{{ns:}} returns the current localized name for the namespace with that index, canonical name, or local alias. Thus {{ns:6}}, {{ns:File}}, and {{ns:Image}} (an old name for the File namespace) all return «Файл». On a wiki where the content language was French, {{ns:Fichier}} would also be valid, but {{ns:Datei}} (the localisation of «File» into German) would not.

{{nse:}} is the equivalent encoded for MediaWiki URLs. It does the same, but it replaces spaces with underscores, making it usable in external links.

Content namespaces Talk namespaces
Usage Output Usage Output
{{ns:-2}} or {{ns:Media}} Медиа
{{ns:-1}} or {{ns:Special}} Служебная
{{ns:0}} or {{ns:}} {{ns:1}} or {{ns:Talk}} Обсуждение
{{ns:2}} or {{ns:User}} Участник {{ns:3}} or {{ns:User talk}} Обсуждение участника
{{ns:4}} or {{ns:Project}} Ай да Linux Wiki {{ns:5}} or {{ns:Project talk}} Обсуждение Ай да Linux Wiki
{{ns:6}} or {{ns:File}} or {{ns:Image}} Файл {{ns:7}} or {{ns:File talk}} or {{ns:Image talk}} Обсуждение файла
{{ns:8}} or {{ns:MediaWiki}} MediaWiki {{ns:9}} or {{ns:MediaWiki talk}} Обсуждение MediaWiki
{{ns:10}} or {{ns:Template}} Шаблон {{ns:11}} or {{ns:Template talk}} Обсуждение шаблона
{{ns:12}} or {{ns:Help}} Справка {{ns:13}} or {{ns:Help talk}} Обсуждение справки
{{ns:14}} or {{ns:Category}} Категория {{ns:15}} or {{ns:Category talk}} Обсуждение категории

Formatting

Usage Input → Output Description
{{lc:string}} {{lc:DATA CENTER}} → data center The lowercase input.
{{lcfirst:string}} {{lcfirst:DATA center}} → dATA center The input with the very first character lowercase.
{{uc:string}} {{uc:text transform}} → TEXT TRANSFORM The uppercase input.
{{ucfirst:string}} {{ucfirst:text TRANSFORM}} → Text TRANSFORM The input with the very first character uppercase.
{{formatnum:unformatted num}}
{{formatnum:formatted num|R}}
{{formatnum:987654321.654321}}
→ 987 654 321,654321
{{formatnum:987,654,321.654321|R}}
→ 987.654.321.654321
{{formatnum:00001}}
→ 00 001
The input with decimal and decimal group separators, and localized digit script, according to the wiki’s default locale. The |R parameter can be used to unformat a number, for use in mathematical situations.

Предупреждение: Leading zeroes are not removed, you can use {{#expr:00001}} instead.

{{#dateformat:date}}
{{#formatdate:date}}
{{#dateformat:date|format}}
{{#formatdate:date|format}}

{{#dateformat:25 deC 2009|ymd}}
→ 25 deC 2009 (your pref), 2009 DeC 25 (default)
{{#formatdate:dec 25,2009|dmy}}
→ dec 25,2009 (your pref), 25 Dec 2009 (default)
{{#dateformat:2009-12-25|mdy}}
декабрь 25, 2009 (your pref), December 25, 2009 (default)
{{#formatdate:2009 dec 25|ISO 8601}}
→ 2009 dec 25 (your pref), 2009-12-25 (default)
{{#dateformat:25 decEmber|mdy}}
→ 25 decEmber (your pref), DecEmber 25 (default)

Note: In the example above, «your pref» refers to your date preference on the current MediaWiki wiki only.

Formats an unlinked date based on user «Date format» preference, and adds metadata tagging it as a formatted date. For logged-out users and those who have not set a date format in their preferences, dates can be given a default: mdy, dmy, ymd, ISO 8601 (all case sensitive). If only the month and day are given, only mdy and dmy are valid. If a format is not specified or is invalid, the input format is used as a default. If the supplied date is not recognized as a valid date (specifically, if it contains any metadata such as from a nested use of these or similar templates), it is rendered unchanged, and no (additional) metadata is generated.

Предупреждение: {{{1}}}

Although the ISO 8601 standard requires that dates be in the Gregorian calendar, the ISO parameter in this function will still format dates that fall outside the usual Gregorian range (e.g. dates prior to 1583). Also, the magic word cannot properly convert between negative years (used with ISO 8601) and years BC or years BCE (used in general writing).

{{padleft:xyz|stringlength}}
{{padleft:xyz|strlen|char}}
{{padleft:xyz|strlen|string}}
{{padleft:xyz|5}} → 00xyz
{{padleft:xyz|5|_}} → __xyz {{padleft:xyz|5|abc}} → abxyz {{padleft:xyz|2}} → xyz
{{padleft:|1|xyz}} → x (first character of the string)
Inserts a string of padding characters (character chosen in third parameter; default ‘0’) of a specified length (second parameter) next to a chosen base character or variable (first parameter). The final digits or characters in the base replace the final characters in the padding; i.e. {{padleft:44|3|0}} produces 044. The padding string may be truncated if its length does not evenly divide the required number of characters.
{{padright:xyz|stringlength}}
{{padright:xyz|strlen|char}}
{{padright:xyz|strlen|string}}
{{padright:xyz|5}} → xyz00

{{padright:xyz|5|_}} → xyz__
{{padright:xyz|5|abc}} → xyzab
{{padright:xyz|2}} → xyz
{{padright:|1|xyz}} → x

Identical to padleft, but adds padding characters to the right side.
{{plural:2|is|are}} {{plural:0|is|are}} → are
{{plural:1*1|is|are}} → is
{{plural:21 mod 10|is|are}} → is
{{plural:{{#expr:21 mod 10}}|is|are}} → is
{{plural:1|is|are}} → is
{{plural:2|is|are}} → are
(for Polish):
{{plural:2|milion|miliony|milionów}} → miliony
Outputs the singular form (second parameter) if the first parameter is an expression equalling one; the plural form (third parameter) otherwise. Plural transformations are used for languages like Russian based on «count mod 10». You should not expect this to handle fractions (like 44.5) — see bug 28128.
{{grammar:N|noun}} Outputs the correct inflected form of the given word described by the inflection code after the colon (language-dependent). Grammar transformations are used for inflected languages like Polish. See also Manual:$wgGrammarForms.

see also: Extension:StringFunctions

Miscellaneous

Usage Output Description
{{int:message name}}
{{int:edit}}Править
(depends on user language, try: fr •ja)
Internationalizes (translates) the given interface (MediaWiki namespace) message into the user language. Note that this can damage/confuse cache consistency, see bug 14404.
{{#language:language code}}

{{#language:ar}}

language code
العربية
The full name of the language for the given language code: native name by default. Codes are mostly in accordance with ISO 639.
{{#special:special page name}}
{{#special:userlogin}}
Служебная:Special page name
Служебная:Вход
The localized name for the given canonical Special: page.
{{#tag:tagname
|content
|parameter1=value1
|parameter2=value2
}}
(depends on parser tag) Alias for XML-style parser or extension tags, but parsing wiki code. Inner content can be passed as first parameter, and attributes as subsequent ones:

<tagname attribute1value1» attribute2value2«> content </tagname >{{#tag:tagname|content|attribute1=value1|attribute2=value2}}

Warning : You must write {{#tag:tagname||attribute1=value1|attribute2=value2}} to pass an empty content.
No space is permitted between the | and the attribute name.

{{gender:username
|return text if user is male
|return text if user is female
|return text if user hasn't defined their gender}}
(depends on the named user’s gender) A switch for the gender set in Special:Preferences

Note: If 3rd parameter is omitted and user hasn’t defined his/her gender, then text if user is male is returned.

«WP:MAGIC» redirects here. For help on the automatic transformation of wikitext, see Help:Magic. For the WikiProject on stage magic and illusions, see WikiDevi:WikiProject Magic.

Shortcuts:

  • H:MW
  • WP:MAGIC

Magic words (which include parser functions, variables and behavior switches) are features of wikitext that enable various instructions to be given to the MediaWiki software (for example, to suppress or position the table of contents), or else serve to produce variable output, as is often required in templates.

A quick reference for magic words can be found on this page. For more complete and updated documentation, refer to the following pages on the MediaWiki site:

  • mw:Help:Magic words for all standard magic words, including the «standard» parser functions
  • mw:Help:Extension:ParserFunctions for some additional parser functions, including conditional expressions

General information

There are three types of magic words:

  • Behavior switches: uppercase words surrounded by double underscores, e.g. __NOTOC__, or keywords using parser function syntax
  • Variables: uppercase words surrounded by double braces, e.g. {{PAGENAME}} (thus resembling templates)
  • Parser functions: keywords (some beginning #) in double braces with parameters after a colon, e.g. {{#expr:2+2}}

Some magic words are case-insensitive, but not all. White space is stripped from the start and end of keywords and parameters, as in template syntax.

Page-dependent magic words will affect or return data about the current page, even if the word is added through a transcluded template or included system message.

It is possible to substitute parser functions and variables in the same way that templates are substituted (using the subst: keyword). This causes their current value (as evaluated at the time of substitution) to be written into the wikitext.

Behavior switches

For documentation, refer to the Behavior Switches section of the MediaWiki page.

  • __NOTOC__ (can appear anywhere in the wikitext; suppresses the table of contents)
  • __FORCETOC__ (can appear anywhere in the wikitext; makes a table of contents appear in its normal position above the first header)
  • {{TIDTOC}} (places a table of contents at the word’s position)
  • __NOEDITSECTION__ (hides the section «edit» links beside all headings on the page) (use <h2> tags to hide the edit link for one header only)
  • __NEWSECTIONLINK__ (adds a «+» link for adding a new section on a non-«Talk» page)
  • __NONEWSECTIONLINK__ (removes the «+» link on «Talk» pages)
  • __NOGALLERY__ (on a category page, replaces thumbnails with normal links)
  • __HIDDENCAT__ (on a category page, makes it a hidden category)
  • __INDEX__ (tells search engines to index the page)
  • __NOINDEX__ (tells search engines not to index the page)
  • __STATICREDIRECT__ (On redirect pages, don’t allow MediaWiki to automatically update the link when someone moves a page and checks «Update any redirects that point to the original title», also used to tell interwikibots that this redirect might be seen as an article)
  • {{DISPLAYTITLE:title}} (changes the displayed form of the page title)
  • {{DEFAULTSORT:sortkey}} (sets a default category sort key)
  • {{noexternallanglinks}} to suppress all Wikidata automatic interlanguage links. Equivalent to {{noexternallanglinks:*}}. Links for individual languages can be suppressed by specifying language codes in a pipe-separated list, e.g. {{noexternallanglinks:fr|es|ja}}. See mw:Extension:Wikibase Client#noexternallanglinks.

Variables

For documentation, refer to the Variables section of the MediaWiki page.

  • {{FULLPAGENAME}} (page title including namespace)
  • {{PAGENAME}} (page title excluding namespace)
  • {{BASEPAGENAME}} (page title excluding current subpage and namespace — effectively the parent page without the namespace.)
  • {{SUBPAGENAME}} (subpage part of title)
  • {{SUBJECTPAGENAME}}, {{ARTICLEPAGENAME}} (associated non-talk page)
  • {{TALKPAGENAME}} (associated talk page)
  • {{NAMESPACE}} (namespace of current page)
  • {{SUBJECTSPACE}}, {{ARTICLESPACE}} (associated non-talk namespace)
  • {{TALKSPACE}} (associated talk namespace)
  • {{FULLPAGENAMEE}}, {{NAMESPACEE}} etc. (equivalents encoded for use in MediaWiki URLs)

The above can all take a parameter, to operate on a page other than the current page.

  • {{SITENAME}} (WikiDevi.Wi-Cat.RU)
  • {{SERVER}} (https://wikidevi.wi-cat.ru)
  • {{SERVERNAME}} (wikidevi.wi-cat.ru)
  • {{SCRIPTPATH}} ()
  • {{CURRENTVERSION}} (current MediaWiki version)
  • {{REVISIONID}} (latest revision to current page)
  • {{REVISIONDAY}}, {{REVISIONDAY2}}, {{REVISIONMONTH}}, {{REVISIONYEAR}}, {{REVISIONTIMESTAMP}}, {{REVISIONUSER}} (date, time, editor at last edit)
  • {{CURRENTYEAR}}, {{CURRENTMONTH}}, {{CURRENTMONTHNAME}}, {{CURRENTMONTHABBREV}}, {{CURRENTDAY}}, {{CURRENTDAY2}}, {{CURRENTDOW}}, {{CURRENTDAYNAME}}, {{CURRENTTIME}}, {{CURRENTHOUR}}, {{CURRENTWEEK}}, {{CURRENTTIMESTAMP}} (current date/time variables)
  • {{LOCALYEAR}} etc. (as above, based on site’s local time)
  • {{NUMBEROFPAGES}}, {{NUMBEROFARTICLES}}, {{NUMBEROFFILES}}, {{NUMBEROFEDITS}}, {{NUMBEROFVIEWS}}, {{NUMBEROFUSERS}}, {{NUMBEROFADMINS}}, {{NUMBEROFACTIVEUSERS}} (statistics on English WikiDevi; add :R to return numbers without commas)

Parser functions

Shortcut:

  • WP:PF

These are fully documented at the Meta magic words page or ParserFunctions Extension documentation unless otherwise stated.

Metadata

  • {{PAGEID}} (unique page identifier number)
  • {{PAGESIZE:page name}} (size of page in bytes)
  • {{PROTECTIONLEVEL:action}} (protection level for given action on the current page)
  • {{PENDINGCHANGELEVEL}} (level of pending changes protection on the current page)
  • {{PAGESINCATEGORY:categoryname}} (number of pages in the given category)
  • {{NUMBERINGROUP:groupname}} (number of users in a specific group)

Add |R to return numbers without commas.

Formatting

  • {{lc:string}} (convert to lower case)
  • {{lcfirst:string}} (convert first character to lower case)
  • {{uc:string}} (convert to upper case)
  • {{ucfirst:string}} (convert first character to upper case)
  • {{formatnum:unformatted num}} (format a number with comma separators; add |R to unformat a number)
  • {{#formatdate:date|format}} (formats a date according to user preferences; a default can be given as an optional case-sensitive second parameter for users without date preference; can convert a date from an existing format to any of dmy, mdy, ymd or ISO 8601 formats, with the user’s preference overriding the specified format)
  • {{padleft:xyz|stringlength}}, {{padright:xyz|stringlength}} (pad with zeros to the right or left; an alternative padding string can be given as a third parameter; the alternative padding string may be truncated if its length does not evenly divide the required number of characters)
  • {{plural:n|is|are}} (produces alternative text according to whether n is greater than 1)
  • {{#time:format string|date/time object}} (for date/time formatting; also #timel for local time. Covered at the extension documentation page.)
  • {{gender:username|masculine|feminine|neutral}} (produces alternative text according to the gender specified by the given user in his/her preferences)
  • {{#tag:tagname|content|parameter1=value1|parameter2=value2}} (equivalent to an HTML tag or pair of tags; can be used for nesting references)

Paths

  • {{localurl:page name}}, {{localurl:page name|query string}} (relative path to the title)
  • {{fullurl:page name}}, {{fullurl:page name|query_string}} (absolute path to the title, without a protocol prefix)
  • {{canonicalurl:page name}}, {{canonicalurl:page name|query_string}} (absolute path to the title, with a protocol prefix)
  • {{filepath:file name}} (absolute URL to a media file)
  • {{urlencode:string}} (input encoded for use in URL query strings: like+this)
    • {{urlencode:string|PATH}} (input encoded for use in URL paths: like%20this)
    • {{urlencode:string|WIKI}} (input encoded for use as MediaWiki page names: like_this)
  • {{anchorencode:string}} (input encoded for use in MediaWiki URL section anchors)
  • {{ns:n}} (name for the namespace with index n; use {{nse:}} for the equivalent encoded for MediaWiki URLs)
  • {{#rel2abs: path }} (converts a relative file path to absolute; see the extension documentation)
  • {{#titleparts: pagename | number of segments to return | first segment to return }} (splits title into parts; see the extension documentation)

Conditional expressions

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

  • {{#expr: expression }} (evaluates the given expression; see Help:Calculation)
  • {{#if: test string | value if non-empty | value if 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 }} (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 }} (selects value based on whether the test string generates a parser error)
  • {{#ifexpr: expression | value if true | value if false }} (selects value based on evaluation of expression)
  • {{#ifexist: page title | value if exists | value if doesn’t exist }} (selects value depending on whether a page title exists)
  • {{#switch: test | case1 = value for case 1 | … | 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: {{{1|}}}. 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.

Other

  • {{#babel: babelcode1 | babelcode2 | ... }} (replacement for the {{babel}} template; see Extension:Babel)
  • {{#coordinates: arg1 | arg2 | ... }} (see Extension:GeoData)
  • {{#invoke: module | function | arg1 | arg2 | ... }} (calls a function located in a Scribunto module; see WikiDevi:Lua)

See also

  • mw:Internationalisation
  • Adding parser functions
  • CoreParserFunctions.php
  • wikEd, a MediaWiki editor with syntax highlighting for templates and parser functions
  • v
  • t
  • e

WikiDevi Templates.

Network Template Pages
  • WikiDevi Templates
  • Hardware Specific
  • Embedded system
  • Adapter
  • USB hub
Template Quiklinks
  • Forms
  • WikiDevi:Forms
  • Infobox Embedded System
  • Infobox Brand Specific
  • Infobox
  • WikiaInfobox
  • Side by side
Editing Helpers
  • Magic words
  • MediaWiki:Edittools
  • Most used code
  • Message Notices
  • Box examples
  • Generic DD-WRT serial recovery
Working…
  • Sandbox
  • Other Crap
  • File message boxes
  • Interwiki Links
  • Linksys USB100TX v3
  • Widget:AmazonRS
  • HTML Codes Table
Licensing
  • DarkShadow/GFDL-self
  • GFDL
  • GFDL-self
  • PD-USGov-FCC
  • Licenses
Messages Templates
  • WikiDevi template messages
  • Template messages
  • Wikidevi see also
  • WDTOC

These are templates to make pages on this wiki. Just create the page, then copy and paste the template. Let me know if i need to change some via my talk page.   DarkShadow   talk    contribs  



13 Years Ago



sravan953



0 Tallied Votes



5K
Views

This code snippet allows you to know whether a word/sentence you have entered is a ‘Magic Word’ or not.

A ‘Magic Word’ is a word which has at any position two consecutive letters. This can be achieved by taking the ASCII values of the characters.

For example, if I enter «all the best», the program will return that is Magic Word since in the end ‘s’ and ‘t’ are consecutive(ASCII value of ‘t’=ASCII value of ‘s’+1).

import java.io.*;
class magic_word
{
static void magic()throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter a word: ");
        String s=br.readLine();
        int counter=0;
        for(int i=0;i<s.length()-1;i++)
            {
                char a=s.charAt(i);
                char b=s.charAt(i+1);
                int x=(int)a;
                int y=(int)b;
                if(y==x+1)
                    {
                        System.out.println("Magic word!");
                        counter++;
                        break;
                    }
                }
                if(counter==0)
                    {
                        System.out.println("Not a Magic word");
                    }
                }
            }

Wiki Help Gotoarrow.png Tables and templates Gotoarrow.png Magic words

Help-content.png This help article will guide you as you edit in the Wiki. See Contributor Help for more help articles.
Much of the information on this page explains options for users who wish to create templates with advanced features. Most users will only be interested in some of the behavior switches listed below.

Magic words (which include parser functions, variables and behavior switches) are features of wikitext that enable various instructions to be given to the MediaWiki software (for example, to suppress or position the table of contents), or else serve to produce variable output, as is often required in templates.

A quick reference for magic words can be found on this page. For more complete and updated documentation, refer to following pages on the MediaWiki site:

  • mw:Help:Magic words for all standard magic words, including the «standard» parser functions
  • mw:Help:Extension:ParserFunctions for some additional parser functions, including conditional expressions

General information[edit | edit source]

There are three types of magic words:

Behavior switches — uppercase words surrounded by double underscores, e.g. __NOTOC__, or keywords using parser function syntax
Variables — uppercase words surrounded by double braces, e.g. {{PAGENAME}} (thus resembling templates)
Parser functions — keywords (some beginning #) in double braces with parameters after a colon, e.g. {{#expr:2+2}}

Some magic words are case-insensitive, but not all. Whitespace is stripped from the start and end of keywords and parameters, as in template syntax. Page-dependent magic words will affect or return data about the current page, even if the word is added through a transcluded template or included system message. It is possible to substitute parser functions and variables in the same way that templates are substituted (using the subst: keyword). This causes their current value (as evaluated at the time of substitution) to be written into the wikitext.

Behavior switches[edit | edit source]

For documentation, refer to the mw:Behavior Switches section of the MediaWiki page.

Word Description
__TOC__ (places a table of contents at the word’s position)
__NOTOC__ (can appear anywhere in the wikitext; suppresses the table of contents)
__FORCETOC__ (can appear anywhere in the wikitext; makes a table of contents appear in its normal position above the first header)
__NOEDITSECTION__ (hides the section edit links beside headings)
__NEWSECTIONLINK__ (adds a «+» link for adding a new section on a non-«Talk» page)
__NONEWSECTIONLINK__ (removes the «+» link on «Talk» pages)
__NORICHEDITOR__ (prevents the FCK editor from being used to edit a page)
__NOGALLERY__ (on a category page, replaces thumbnails with normal links)
__HIDDENCAT__ (on a category page, makes it a hidden category)
__INDEX__ (tells search engines to index the page)
__NOINDEX__ (tells search engines not to index the page)
{{DISPLAYTITLE:title}} (changes the displayed form of the page title)
{{DEFAULTSORT:sortkey}} (sets a default category sort key)

Variables[edit | edit source]

For documentation, refer to the mw:Variables section of the MediaWiki page.

Variable Output Description
{{FULLPAGENAME}} Help:Magic words (page title including namespace)
{{PAGENAME}} Magic words (page title excluding namespace)
{{BASEPAGENAME}} Magic words (page title excluding subpage and namespace)
{{SUBPAGENAME}} Magic words (subpage part of title)
{{SUBJECTPAGENAME}} Help:Magic words (associated non-talk page)
{{TALKPAGENAME}} Help talk:Magic words (associated talk page)
{{NAMESPACE}} Help (namespace of current page)
{{SUBJECTSPACE}}, {{ARTICLESPACE}} Help
Help
(associated non-talk namespace)
{{TALKSPACE}} Help talk (associated talk namespace)
{{FULLPAGENAMEE}}, {{NAMESPACEE}} Help:Magic words,
Help
etc. (URL-encoded equivalents)

The above can all take a parameter, to operate on a page other than the current page.

Variable Output Description
{{SITENAME}} FamilySearch Wiki Site name
{{SERVER}} https://www.familysearch.org Server
{{SERVERNAME}} www.familysearch.org Server name
{{SCRIPTPATH}} /en/wiki Script path
{{CURRENTVERSION}} 1.35.8 (current MediaWiki version)
{{REVISIONID}} 4297064 (latest revision to current page)
{{REVISIONDAY}}, {{REVISIONDAY2}}, {{REVISIONMONTH}}, {{REVISIONYEAR}}, {{REVISIONTIMESTAMP}}, {{REVISIONUSER}} 12, 12,
03, 2021,
20210312180323, Batsondl
(date, time, editor at last edit)
{{CURRENTYEAR}}, {{CURRENTMONTH}}, {{CURRENTMONTHNAME}}, {{CURRENTMONTHABBREV}}, {{CURRENTDAY}}, {{CURRENTDAY2}}, {{CURRENTDOW}}, {{CURRENTDAYNAME}}, {{CURRENTTIME}}, {{CURRENTHOUR}}, {{CURRENTWEEK}}, {{CURRENTTIMESTAMP}} 2023, 04
April
Apr, 14
14, 5
Friday, 08:49
08, 15
20230414084902
(current date/time variables)
{{LOCALYEAR}} 2023 etc. (as above, based on site’s local time)
{{NUMBEROFPAGES}}, {{NUMBEROFARTICLES}}, {{NUMBEROFFILES}}, {{NUMBEROFEDITS}}, NUMBEROFVIEWS, {{NUMBEROFUSERS}}, {{NUMBEROFADMINS}}, {{NUMBEROFACTIVEUSERS}} 327,623, 100,114
73,146, 5,055,254
NUMBEROFVIEWS, 4,551,023
26
307
(statistics on FamilySearch Wiki; add :R to return numbers without commas)
{{CURRENTMONTHNAMEGEN}} April See notes below.

Namespaces[edit | edit source]

Variable Output
{{ns:1}} Talk
{{ns:2}} User
{{ns:3}} User talk
{{ns:4}} FamilySearch Wiki
{{ns:5}} FamilySearch Wiki talk
{{ns:6}} File
{{ns:7}} File talk
{{ns:8}} MediaWiki
{{ns:9}} MediaWiki talk
{{ns:10}} Template
{{ns:11}} Template talk
{{ns:12}} Help
{{ns:13}} Help talk
{{ns:14}} Category
{{ns:15}} Category talk

Parser functions[edit | edit source]

These are documented at the mw:main documentation page unless otherwise stated.

Metadata[edit | edit source]

Parser function Description
{{PAGESIZE:page name}} (size of page in bytes)
{{PROTECTIONLEVEL:action}} (protection level for given action on the current page)
{{PAGESINCATEGORY:categoryname}} (number of pages in the given category)
{{NUMBERINGROUP:groupname}} (number of users in a specific group)

Add |R to return numbers without commas.

Formatting[edit | edit source]

Parser function Description
{{lc:string}} (convert to lower case)
{{lcfirst:string}} (convert first character to lower case)
{{uc:string}} (convert to upper case)
{{ucfirst:string}} (convert first character to upper case)
{{formatnum:unformatted num}} (format a number with comma separators; add |R to unformat a number)
{{#formatdate:date}} (formats a date according to user preferences; a default can be given as a second parameter for users without date preference); however, please note that the community voted against the concept of date-autoformatting in the March 2009 RfC, and that there is considerable opposition to the use of this parser function.
{{padleft:xyz|stringlength}}, {{padright:xyz|stringlength}} (pad with zeros to the right or left; an alternative padding string can be given as a third parameter)
{{plural:n|is|are}} (produces alternative text according to whether n is greater than 1)
{{#time: format string | date/time object }} (for date/time formatting; also #timel for local time. Covered at the mw:extension documentation page.)

Paths[edit | edit source]

Parser function Description
{{localurl:page name}}, {{localurl:page name|query string}} (relative path to the title)
{{fullurl:page name}}, {{fullurl:page name|query_string}} (absolute path to the title)
{{filepath:file name}} (absolute URL to a media file)
{{urlencode:string}} (input encoded for use in URLs)
{{anchorencode:string}} (input encoded for use in URL section anchors)
{{ns:n}} (name for the namespace with index n; use {{nse:}} for URL-encoded equivalent)
{{#rel2abs: path }} (converts a relative file path to absolute; see the mw:extension documentation)
{{#titleparts: pagename | number of segments to return | first segment to return }} (splits title into parts; see the mw:extension documentation)

Conditional expressions[edit | edit source]

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

Parser function Description
{{#expr: expression }} (evaluates the given expression; see Help:Calculation)
{{#if: test string | value if non-empty | value if 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 }} (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 }} (selects value based on whether the test string generates a parser error)
{{#ifexpr: expression | value if true | value if false }} (selects value based on evaluation of expression)
{{#ifexist: page title | value if exists | value if doesn’t exist }} (selects value depending on whether a page title exists)
{{#switch: test | case1 = value for case 1 | … | default }} (provides alternatives based on the value of the test string)

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

See also[edit | edit source]

Help-content.png Questions?
Visit the Get Help to receive help with contributing to the Wiki.
  • mw:Internationalisation
  • mw:Adding parser functions
  • CoreParserFunctions.php
  • wikEd, a MediaWiki editor with syntax highlighting for templates and parser functions

v  d  e

Help-content.png   Contributor Help   Help-content.png

Getting Started

Help:Search the Wiki • Wiki Basics • Editing • Genealogical Terms

Browsing the Wiki

Navigation • Help:Search the Wiki • Advanced Searching • Help:Search the Wiki

User Page and Preferences

User Pages • User Page Guidelines • User Talk Pages • Talk Pages • Talk Page Guidelines • Your User Sandbox • Navigation • Page History • Preferences • Signatures • Skins •  • Page Changes • Diffs • Watchlist • How to Turn Notifications On

Resources and Lists

Request a New Help Article • Special Pages • Style Guide • Abbreviations • Editing With Wikitext • Finding an ISBN Number • Formatting • Wikitext Cheatsheet • Wiki Terminology

Guiding Principles and Policies

FamilySearch Wiki:Purpose, Policies, and Procedures • Wiki Policies • Conditions of Use • FamilySearch Wiki:Purpose, Policies, and Procedures

Community Center

Newsletter

Technical Info

Wiki Maintenance • Technical Information

Questions?

Ask a Question • Request Training • Report a Problem

v  d  e

Contributor Help:Editing

General Editing

Basic Editing: Editing a Page • Copy and Paste Into a Wiki Page • Edit Summary • The Editing Tool • Sections • Table of Contents • Protected Pages • Page History • Adding Links
Advanced Editing: Advanced Editing with Wikitext • Copy Documents Into the Wiki • Copy Spreadsheets Into the Wiki
Editing Tools: Wiki Cheatsheet • Wiki Terminology • Abbreviations • Wiki Markup
Practice Editing: Practice in Your Sandbox • Simple Edits You Can Make

Creating a Page

Page Naming • Creating a Page • Create a Page Linked from an Existing Page • Create a Page Not Linked from an Existing Page • Creating Sections
Advanced: Deleting a Page • Namespaces • Creating a Society Page • Subpages • Archiving a Talk Page

Links and Citations

Links: Adding Links • Create An Internal LInk • Create An External Link • Advanced Linking
Citations: Adding Citations • Sources Consulted

Images and Files

Images: Selecting images • Submitting Images • Images • Adding images to Articles • How to Edit and Resize Images • Using FS Library Images • Image Maps
Files: Copy Documents Into the Wiki • Managing Files

Tables and Templates

Tables: Basic Tables • Advanced Tables • Historical Population Charts • Infoboxes • Navboxes • Quick Date Boxes
Templates: Quick Guide to Templates • Templates • Maintenance Templates • Resource badges • Contributor Userboxes • External Searches • Magic Words

Renaming and Redirecting

Renaming a Page • Redirecting a Page • Help:How to Split Articles • Adding a Page to the Correct Namespace

Categorizing

How to Categorize a Page • Advanced Categorization

__NORICHEDITOR__

Geographylogo.png In other languages: English | português |

Magic words are special strings of text that MediaWiki associates with a return value or function. This page explains the standard magic words on the Scratch Wiki.

There are three general types of magic words:

  • Behavior switches: these are usually uppercase words surrounded by double underscores, e.g. «__BAR__«.
  • Variables: these are uppercase words surrounded by double braces, e.g. «{{BAZ}}«. As such, they are commonly confused with templates.
  • Parser functions: these take parameters and are either of the form «{{foo:...}}» or «{{#foo:...}}«

Variables and parser functions can use subst:, just like templates. Page-dependent magic words will affect or return data about the current page (by default), even if the word is added through a transcluded template or included system message.

Note Note: Parameters that are underlined are optional; parameters that are in italics are mandatory.

Behavior switches

A behavior switch controls the layout or behavior of the page and can often be used to specify desired omissions and inclusions in the content.

Word Description
Table of Contents
__NOTOC__ Hides the table of contents
__FORCETOC__ Forces the table of contents to appear at its normal position (before the first header), overriding __NOTOC__
__TOC__ Places the table of contents at the word’s position (overriding __NOTOC__). If used multiple times, the table of contents appears at the first word’s position.
Editing
__NOEDITSECTION__ Hides the section edit links beside headings. This is especially useful where a heading is created from within a template: the normal wiki section-edit would in this case edit the template code, which is normally counterintuitive to the user. Use of this in a template will extend the effect to that template, the pages it’s included on, and any other templates included on the same page.
__NEWSECTIONLINK__ Adds a link under «Edit» to add a new section to the end on a non-talk page.
__NONEWSECTIONLINK__ Removes the link under «Edit» to add a new section on talk pages.
Categories
__NOGALLERY__ Used on a category page, replaces thumbnails with normal links.
__HIDDENCAT__ Used on a category page, hides the category from the lists of categories in its members and parent categories.
Search engine indexing
__INDEX__ Tells search engines to index the page (does not override robots.txt).
__NOINDEX__ Tells search engines not to index the page (i.e. prevents the page from showing up in search results).

Variables

Variables return information about the current page, date, or wiki. Their syntax is similar to that of templates. Variables here marked as [expensive] can only have a limited number of them put on a page.

If a template name conflicts with a variable, the variable will be used; i.e. to transclude the template one would have to include the Template: namespace). However, in some cases passing parameters to the variable will transclude the template instead (e.g. {{CURRENTDAYNAME|foo}} transcludes Template:CURRENTDAYNAME, not the variable).

Date and time

These variables return the current date and time in UTC.

Due to browser caching, these variables often show the cached time instead of the actual time.

Word Output Description
Year
{{CURRENTYEAR}} 2023 Year
Month
{{CURRENTMONTH}} 04 Month (zero-padded number)
{{CURRENTMONTH1}} 4 Month (unpadded number)
{{CURRENTMONTHNAME}} April Month (name)
{{CURRENTMONTHNAMEGEN}} April Month (genitive form)
{{CURRENTMONTHABBREV}} Apr Month (abbreviation)
Day
{{CURRENTDAY}} 2 Day of the month (unpadded number)
{{CURRENTDAY2}} 02 Day of the month (zero-padded number)
{{CURRENTDOW}} 0 Day of the week (unpadded number), 0 (for Sunday) through 6 (for Saturday)
{{CURRENTDAYNAME}} Sunday Day of the week (name)
Time
{{CURRENTTIME}} 01:08 Time (24-hour HH:mm format)
{{CURRENTHOUR}} 01 Hour (24-hour zero-padded number)
Other
{{CURRENTWEEK}} 13 Week (number)
{{CURRENTTIMESTAMP}} 20230402010848 YYYYMMDDHHmmss timestamp

The following variables do the same thing as above but they show the site’s server config.

  • {{LOCALYEAR}}
  • {{LOCALMONTH}}
  • {{LOCALMONTH1}}
  • {{LOCALMONTHNAME}}
  • {{LOCALMONTHNAMEGEN}}
  • {{LOCALMONTHABBREV}}
  • {{LOCALDAY}}
  • {{LOCALDAY2}}
  • {{LOCALDOW}}
  • {{LOCALDAYNAME}}
  • {{LOCALTIME}}
  • {{LOCALHOUR}}
  • {{LOCALWEEK}}
  • {{LOCALTIMESTAMP}}

Technical metadata

Note Note: Revision variables return data about the latest edit to the current page, even if viewing an older version of the page.

Word Output Description
{{SITENAME}} Scratch Wiki The wiki’s site name
{{SERVER}} https://en.scratch-wiki.info Domain URL
{{SERVERNAME}} en.scratch-wiki.info Subdomain and domain name
{{DIRMARK}}
{{DIRECTIONMARK}}

Outputs a Unicode directional mark that matches the wiki’s default language direction, useful in text with multi-directional text
{{SCRIPTPATH}} /w Relative script path
{{STYLEPATH}} /w/skins Relative style path
{{CURRENTVERSION}} 1.39.1 The wiki’s MediaWiki version
{{CONTENTLANGUAGE}}
{{CONTENTLANG}}
en
en
The wiki’s default interface language
Page
{{PAGEID}} 772 Returns the page identifier
{{PROTECTIONLEVEL:action}} Returns the protection level (e.g. «autoconfirmed» or «EWplus») for a given action (e.g. «edit» or «move») on the current page. Returns an empty string if not protected
Latest revision to current page
{{REVISIONID}} 263438 Unique revision ID
{{REVISIONDAY}} 3 Day edit was made (unpadded number)
{{REVISIONDAY2}} 03 Day edit was made (zero-padded number)
{{REVISIONMONTH}} 10 Month edit was made (zero-padded number)
{{REVISIONMONTH1}} 10 Month edit was made (unpadded number)
{{REVISIONYEAR}} 2020 Year edit was made
{{REVISIONTIMESTAMP}} 20201003001136 Timestamp as of time of edit
{{REVISIONUSER}} Groko13 The last editor of the page, or the current user when previewing an edit
{{REVISIONSIZE}} 31228 The size (in bytes of wikitext) of the current revision of the page
Affects page content
{{DISPLAYTITLE:title|noreplace}} Formats the current page’s title header. Changes to the actual title are not allowed besides changing capitalization on the first letter (not including the namespace), style, or replacing underscores with spaces.
It can take a parameter of noreplace to make the word do nothing if another instance of itself already exists on the page
{{DEFAULTSORT:sortkey}}
{{DEFAULTSORTKEY:sortkey}}
{{DEFAULTCATEGORYSORT:sortkey}}
{{DEFAULTSORT:sortkey|noreplace}}
Used for categorizing pages, sets a default category sort key. For example if you put {{DEFAULTSORT:Smith , John}} at the end of John Smith, the page would be sorted under «S» by default in categories. It can take a second argument of noreplace to make the word do nothing if another instance of itself already exists on the page

Statistics

Numbers returned by these variables normally contain separators (commas, dots or spaces, depending on the local language) but can return raw numbers with the «:R» flag (for example, {{NUMBEROFPAGES}}→22,985 and {{NUMBEROFPAGES:R}}→22985).

Use «|R» for magic words that require a parameter like PAGESINCATEGORY (for example {{PAGESINCATEGORY:Help}} and {{PAGESINCATEGORY:Help|R}}, or {{PAGESINCATEGORY:Help|subcats}} and {{PAGESINCATEGORY:Help|subcats|R}}). Also applicable to {{PAGESIZE:page name}} hereinbefore.

Word Output Description
{{NUMBEROFPAGES}} 22,985 Number of wiki pages
{{NUMBEROFARTICLES}} 2,135 Number of articles. An «article»:

  • Is in mainspace
  • Is not a redirect
  • Has at least one link to another page
{{NUMBEROFFILES}} 3,875 Number of uploaded files
{{NUMBEROFEDITS}} 322,526 Number of wiki edits
{{NUMBEROFUSERS}} 2,379 Number of registered users
{{NUMBEROFADMINS}} 28 Number of users in the sysop group
{{NUMBEROFACTIVEUSERS}} 112 Number of active users (users with an action in the last month)
{{PAGESINCATEGORY:categoryname}}
{{PAGESINCAT:categoryname}}
66
66
[Expensive] Number of pages (including subcategories and files) in a given category. (Category:Help used for demonstration)
{{PAGESINCATEGORY:categoryname|all}}
{{PAGESINCAT:categoryname|pages}}
{{PAGESINCATEGORY:categoryname|subcats}}
{{PAGESINCAT:categoryname|files}}
66
66
0
0
[Expensive] Respectively, the number of

  • all pages
  • ordinary pages (excluding subcategories and files)
  • subcategories or
  • files

in a given category. (Category:Help used for demonstration)

{{NUMBERINGROUP:groupname}}
{{NUMINGROUP:groupname}}
18
18
(groupname bureaucrat used here)
Number of users in a given usergroup

Page names

Word Output Description
{{FULLPAGENAME}} Help:Magic words Namespace and full page title (including all subpage levels)
{{PAGENAME}} Magic words Full page title (including all subpage) without namespace
{{BASEPAGENAME}} Magic words Page title of the page in the immediately superior subpage level without the namespace («Title/foo» on «Help:Title/foo/bar»)
{{SUBPAGENAME}} Magic words The subpage title («bar» on «Help:Title/foo/bar»)
{{SUBJECTPAGENAME}}
{{ARTICLEPAGENAME}}
Help:Magic words
Help:Magic words
Full page name of the associated subject (e.g. article or file). Useful on talk pages
{{TALKPAGENAME}} Help talk:Magic words Full page name of the associated talk page; basically inverse of the above.
{{ROOTPAGENAME}} Magic words Name of the root of the current page. Would return Title on page Help:Title/Foo/Bar

The {{BASEPAGENAME}} and {{SUBPAGENAME}} magic words only work in namespaces that have subpages enabled.

URL encoded page names

The following are equivalents encoded for use in MediaWiki URLs (i.e. spaces replaced with underscores and some characters HTML escaped using numeric character encoding):

  • {{FULLPAGENAMEE}}
  • {{PAGENAMEE}}
  • {{BASEPAGENAMEE}}
  • {{SUBPAGENAMEE}}
  • {{SUBJECTPAGENAMEE}}
  • {{ARTICLEPAGENAMEE}}
  • {{TALKPAGENAMEE}}
  • {{ROOTPAGENAMEE}}

Namespaces

Word Output Description
{{NAMESPACE}} Help Name of the page’s namespace
{{NAMESPACENUMBER}} 12 ID of the page’s namespace
{{SUBJECTSPACE}}
{{ARTICLESPACE}}
Help
Help
Name of the associated content namespace
{{TALKSPACE}} Help talk Name of the associated talk namespace

The following are equivalents encoded for use in MediaWiki URLs (spaces replaced with underscores and some characters percent-encoded):

  • {{NAMESPACEE}}
  • {{SUBJECTSPACEE}}
  • {{ARTICLESPACEE}}
  • {{TALKSPACEE}}

These can take a full-page-name parameter and will return the requested namespace associated with that page, instead of with the current page:

  • {{NAMESPACE:Scratch Wiki Home}}(pages in mainspace will return empty)
  • {{NAMESPACE:Template:E}}Template
  • {{SUBJECTSPACE:Template:E}}Template
  • {{TALKSPACE:Template:E}}Template talk

Parameter must not be a namespace name:

  • {{SUBJECTSPACE:Help talk}}(Empty)

Other

Word Output Description
{{!}} | Used to include a pipe character as part of a template argument or table cell contents.

Parser functions

Main page: Help:ParserFunctions

Parser functions are very similar to variables but take one or more parameters (technically, any magic word that takes a parameter is a parser function), and the name is sometimes prefixed with a hash to distinguish them from templates.

Technical metadata of another page

Parser function Output (for page Scratch Wiki Home) Description
{{PAGESIZE:page name|R}} 2,356 [Expensive] Returns the amount of bytes (of wikitext) in the specified page

If an extra parameter R is specified, numbers are returned unformatted (e.g. 132030 instead of 132,030)

{{PROTECTIONLEVEL:action|page name}} sysop [Expensive] Returns the protection level (e.g. «autoconfirmed», «EWplus») for a given action (e.g. «edit», «move») on the specified page. Returns an empty string if not protected.

URL data

Parser function Input → Output Description
{{localurl:page name|query string}} {{localurl:Scratch Wiki Home}}→/wiki/Scratch_Wiki_Home
{{localurl:Scratch Wiki Home|printable=yes}}→/w/index.php?title=Scratch_Wiki_Home&printable=yes
The relative path to the title
{{fullurl:page name|query string}} {{fullurl:Category:Help}}→https://en.scratch-wiki.info/wiki/Category:Help
{{fullurl:Category:Help|action=edit}}→https://en.scratch-wiki.info/w/index.php?title=Category:Help&action=edit
A protocol-relative path to the title
{{canonicalurl:page name|query string}} {{canonicalurl:Category:Help}}→https://en.scratch-wiki.info/wiki/Category:Help The absolute path to the title, using the canonical URL
{{filepath:file name|thumbnail size}} {{filepath:Happy Giga.jpg}}→https://en.scratch-wiki.info/w/images/Happy_Giga.jpg
{{filepath:Happy Giga|100}}→https://en.scratch-wiki.info/w/images/thumb/Happy_Giga.jpg/100px-Happy_Giga.jpg
A protocol-relative path to the full size or thumbnail of a media file
{{urlencode:string|FORMAT STRING}} {{urlencode:x:y/z á é}} or {{urlencode:x:y/z á é|QUERY}}→x%3Ay%2Fz+%C3%A1+%C3%A9
{{urlencode:x:y/z á é|WIKI}}→x:y/z_%C3%A1_%C3%A9
{{urlencode:x:y/z á é|PATH}}→x%3Ay%2Fz%20%C3%A1%20%C3%A9
The input encoded for use in an URL.

Format Space
none +
QUERY +
WIKI _
PATH %20
{{anchorencode:string}} {{anchorencode:x y z á é}}→x_y_z_á_é The input encoded for use in URL section anchors (after the # in an URL)

Namespaces

{{ns:}} returns the current localized name for the namespace with that index, canonical name, or local alias. Thus {{ns:6}}, {{ns:File}}, and {{ns:Image}} (an old name for the File namespace) all return «File».

{{nse:}} is the equivalent encoded for MediaWiki URLs. It does the same, but it replaces spaces with underscores, making it usable in external links.

Content namespaces Talk namespaces
Usage Output Usage Output
{{ns:-2}} {{ns:Media}} Media
(no talk page)
{{ns:-1}} {{ns:Special}} Special
(no talk page)
{{ns:0}} {{ns:}} {{ns:1}} {{ns:Talk}} Talk
{{ns:2}} {{ns:User}} User {{ns:3}} {{ns:User talk}} User talk
{{ns:4}} {{ns:Project}} {{ns:Scratch Wiki}} Scratch Wiki {{ns:5}} {{ns:Project talk}} {{ns:Scratch Wiki talk}} Scratch Wiki talk
{{ns:6}} {{ns:File}} File {{ns:7}} {{ns:File talk}} File talk
{{ns:8}} {{ns:MediaWiki}} MediaWiki {{ns:9}} {{ns:MediaWiki talk}} MediaWiki talk
{{ns:10}} {{ns:Template}} Template {{ns:11}} {{ns:Template talk}} Template talk
{{ns:12}} {{ns:Help}} Help {{ns:13}} {{ns:Help talk}} Help talk
{{ns:14}} {{ns:Category}} Category {{ns:15}} {{ns:Category talk}} Category talk

Formatting

Usage Input → Output Description
{{formatnum:unformatted number|R}} {{formatnum:65536.2}}→65,536.2
{{formatnum:1,048,576.3|R}}→1048576.3
Takes an unformatted number (arab, no group separators and . as decimal separator) and outputs it in the localized digit script and formatted with decimal and decimal group separators.
The parameter |R basically reverses the process. It takes a number formatted exactly the same way formatnum would and transforms it into a raw number for mathematical uses.
{{#dateformat:date|format}}
{{#formatdate:date|format}}
{{#dateformat:2 may 2017|ymd}}2017 May 2 (your preference); 2017 May 2 (default)
{{#formatdate:2017 may 2|mdy}}May 2, 2017 (your preference); May 2, 2017 (default)
«Your preference» refers to the date format set in your user preferences.
Formats an unlinked date based on user «date format» preference, and adds metadata tagging it as a formatted date. For logged-out users and those who have not set a date format in their preferences, dates can be given a default: mdy, dmy, ymd, ISO 8601 (all case sensitive). If only the month and day are given, only mdy and dmy are valid. If a format is not specified or is invalid, the input format is used as a default. If the supplied date is not recognized as a valid date (specifically, if it contains any metadata such as from a nested use of these or similar templates), it is rendered unchanged, and no (additional) metadata is generated
{{lc:string}} {{lc:BLOCK}}→block Returns the lowercase form of the input
{{lcfirst:string}} {{lcfirst:BLOck}}→bLOck Returns the input with the first letter lowercase
{{uc:string}} {{uc:block}}→BLOCK Returns the uppercase form of the input
{{ucfirst:string}} {{ucfirst:bloCK}}→BloCK Returns the input with the first letter uppercase
{{padleft:xyz|string length|char}}
{{padleft:xyz|string length|string}}
{{padleft:xyz|5}}→00xyz
{{padleft:xyz|5|_}}→__xyz
{{padleft:xyz|5|abc}}→abxyz
{{padleft:xyz|2}}→xyz
{{padleft:|1|xyz}}→x (first character of string)
Inserts a string of padding characters (character chosen in third parameter; default «0») of a specified length (second parameter) next to a chosen base character or variable (first parameter). The final digits or characters in the base replace the final characters in the padding; i.e. {{padleft:44|3|0}} produces 044. The padding string may be truncated if its length does not evenly divide the required number of characters.
{{padright:xyz|string length|char}}
{{padright:xyz|string length|string}}
{{padright:xyz|5}}→xyz00
{{padright:xyz|5|_}}→xyz__
{{padright:xyz|5|abc}}→xyzab
{{padright:xyz|2}}→xyz
{{padright:|1|xyz}}→x
Identical to padleft but adds padding characters to the right side

Localization

Usage Input → Output Description
{{plural:which|singular|plural}} {{plural:0|is|are}}→are
{{plural:1|is|are}}→is
{{plural:2|is|are}}→are
{{plural:-1|is|are}}→is
Returns the singular form (second parameter) if which (first parameter) is a number with an absolute value equal to one. Returns the plural form (third parameter) otherwise. Any number (including decimals and negative numbers) are accepted, and a limited number of expressions is also accepted
{{grammar:inflection|word}} {{grammar:N|explode}}→explode Returns the correctly inflected form of the given word. Inflections are in short form (e.g. N for noun or ADJ for adjective)
{{gender:username|text for every gender}}
{{gender:username|male text|female text|text for unspecified}}
{{gender:mres|them}}→them
{{gender:mres|him|her|them}}→them
A switch for the gender set in Special:Preferences.
Note Note: If text for unspecified is not specified and the user’s gender is unspecified, male text is returned

Transclusion modifiers

Usage Description
{{:xyz}} A bare colon is not a template modifier but the prefix for the main namespace. Since transclusion defaults to the Template namespace, you would use for example, {{:UTC}} (vs. {{UTC}}) to include the text of the main namespace article UTC rather than Template:UTC
{{msg:xyz}}
{{raw:xyz}}
Even if there is a magic word named «xyz», use template:xyz unless the template doesn’t exist (equivalent to {{Template:xyz}}). Normally, magic words have priority when there is a conflict
{{msgnw:xyz}} The content of Template:Xyz is transcluded inside <nowiki> tags
{{subst:xyz}} The tag is changed into the content of Template:Xyz; see Template usage

Miscellaneous

Usage Output Description
{{#special:special page name}}
{{#special:userlogin}}
Special:Special page name
Special:UserLogin
The localized name for the given canonical Special: page
{{#speciale:special page name}}
{{#speciale:userlogin}}
Special:Special_page_name
Special:UserLogin
The localized and URL-encoded name for the given canonical Special: page

Like this post? Please share to your friends:
  • Make a sentence using the word into
  • Magic word i love you
  • Lustmord the word as power
  • Make a sentence using the word give up
  • Magic meaning of the word