Help:Magic words: Difference between revisions

From Saintapedia
Jump to navigation Jump to search
Tag: Reverted
Tag: Manual revert
 
Line 291: Line 291:
__NEWSECTIONLINK__
__NEWSECTIONLINK__


[[Category:Help]][[Category:Help under review]]
[[Category:Help]]

Latest revision as of 23:12, 7 October 2024

Help
Getting Started
Picking a UsernameTeach Yourself Wiki
Policies and guidelines
Saintapedia:Copyrights
The Saintapedia Interface
Left NavigationToolbox Discussion/Talk PageEdit & HistorySearchLog in & Create an Account
Editing Saintapedia
Creating a new pageCreating your user page • Editors (Visual/Enhanced) • Editing toolbarCheat SheetMagic wordsTable of Contents
Links
Internal linkExternal linkInterWiki linkCategory link Reference links
Images and Media
File Upload Guidelines for SaintapediaHow to upload new versions of filesImage mapNaming Conventions for FilesUpload documents
Tracking Changes
Recent Edits on SaintapediaArticle historyReverting to an earlier versionWatchlistHow to add a page to your watchlist
Asking Questions
Using talk pagesHelp:CommentStreams
Resources and Lists
Categories InfoboxHelp:Templates
Account settings and maintenance
Change your preferences Confirm your email address
Technical information
The MediaWiki softwareParser functions
All topics
view · talk · edit

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:

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}}

Behavior switches

Please remember to use enhanced editor when adding these magic words. If you use VisualEditor, it will not work as noinclude is added around the text. For further 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)
  • __TOC__ (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 categoryWikipedia Logo.png)
  • __INDEX__ (tells search engines to index the page)
  • __NOINDEX__ (tells search engines not to index the page)
  • {{DISPLAYTITLE:title}} (changes the displayed formWikipedia Logo.png of the page title)
  • {{DEFAULTSORT:sortkey}} (sets a default category sort keyWikipedia Logo.png)

Variables

Date and time

The following variables return the current date and time in Time zoneWikipedia Logo.png Coordinated Universal Time (UTC).

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

The use of those variables cause pages to be cached for a more limited number of seconds. This is configured in MagicWordFactory.

Variable Output Description

Year

{{CURRENTYEAR}} 2025 Year
Month
{{CURRENTMONTH}} 01 Month (zero-padded number)
{{CURRENTMONTH1}} 1 Month (unpadded number)
{{CURRENTMONTHNAME}} January Month (name)
{{CURRENTMONTHNAMEGEN}} January Month (genitive form)
{{CURRENTMONTHABBREV}} Jan Month (abbreviation)

Day

{{CURRENTDAY}} 23 Day of the month (unpadded number)
{{CURRENTDAY2}} 23 Day of the month (zero-padded number)
{{CURRENTDOW}} 4 Day of the week (unpadded number), 0 (for Sunday) through 6 (for Saturday)
{{CURRENTDAYNAME}} Thursday Day of the week (name)

Time

{{CURRENTTIME}} 18:51 Time (24-hour HH:mm format)
{{CURRENTHOUR}} 18 Hour (24-hour zero-padded number)

Other

{{CURRENTWEEK}} 4 Week (number)
{{CURRENTTIMESTAMP}} 20250123185138

YYYYMMDDHHmmss timestamp

The following variables do the same as the preceding ones, but using the site's server config or $wgLocaltimezone.

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

For more thorough time formatting, or to output the current year and week with better compliance with ISO-8601, you may want to install Extension:ParserFunctionsMediawiki logo.svg to use the [[mediawikiwiki:Help:Extension:ParserFunctions#

  1. time|#time]] Mediawiki logo.svg parser function.

Parser functions

URL data

Parser function

Input → Output

Description

{{localurl:page name}}

{{localurl:page name

|query_string}}

{{localurl:MediaWiki}}
→ /wiki/MediaWiki
{{localurl:MediaWiki|printable=yes}}
→ /w/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://saintapedia.org/wiki/Category:Top_level

{{fullurl:Category:Top level|action=edit}}
https://saintapedia.org/w/index.php?title=Category:Top_level&action=edit
https:{{fullurl:s:Electra|action=edit}}
→ https:https://saintapedia.org/w/index.php?title=S:Electra&action=edit
https:{{fullurl:s:es:Electra|action=edit}}
→ https:https://saintapedia.org/w/index.php?title=S:es:Electra&action=edit

A protocol-relative path to the title. This will also resolve Interwiki prefixes. Note: Unbracketed (plain) protocol-relative links are not automagically linked.

{{canonicalurl:page name}}

{{canonicalurl:page name

|query_string}}

{{canonicalurl:interwiki:remote page name

|query_string}}

{{canonicalurl:Category:Top level}}
https://saintapedia.org/wiki/Category:Top_level

{{canonicalurl:Category:Top level|action=edit}}
https://saintapedia.org/w/index.php?title=Category:Top_level&action=edit

The absolute path to the title, using the canonical URL. This will also resolve interwiki prefixes.

{{filepath:file name}}

{{filepath:file name|nowiki}}

{{filepath:file name|thumbnail_size}}

{{filepath:Wiki.png}}

{{filepath:Wiki.png|nowiki}}

{{filepath:Example.svg|300}}

A protocol-relative path to the full size or thumbnail 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%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

Note that the default changed from <tvar|wiki>|WIKI</> to <tvar|query>|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.
Encoding
code 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 “#” symbol in a URL).

Full url

When linking to diffs, logs, etc., please use the {{fullurl}} parser function. Including the entire URL may cause users to switch between the secure and insecure servers, and the diffs of the page it is included in to widen the page substantially.

Examples

[{{fullurl:{{FULLPAGENAME}}|action=edit}}]
Links to edit this page: [1]
[{{fullurl:Special:Log|type=block&page=User:Jimbo_Wales}}]
Links to Jimbo's block log. [2]
[{{fullurl:{{FULLPAGENAME}}|oldid={{REVISIONID}}&diff=prev}}]
Link to the last edit of this page. [3]

This can be used as any URL, with text, or as a bare URL, in addition to as a [N] link as shown above.

Technical metadata of another page

Parser function Output
(for page MediaWiki)
Description
{{REVISIONID: page name }} 1721 [ Expensive] Unique revision ID of the last revision on the specified page*.
{{REVISIONDAY: page name }} 5 [ Expensive] Day of edit from the last revision of the specified page* (unpadded number).
{{REVISIONDAY2: page name }} 05 [ Expensive] Day of edit from the last revision of the specified page* (zero-padded number).
{{REVISIONMONTH: page name }} 09 [ Expensive] Month of edit from the last revision specified page* (zero-padded number as <tvar |1>1.17+</>, unpadded number in prior versions).
{{REVISIONMONTH1: page name }} 9 [ Expensive] Month of edit from the last revision of the specified page* (unpadded number).
{{REVISIONYEAR: page name }} 2024 [ Expensive] Year of edit from the last revision of the specified page*.
{{REVISIONUSER: page name }} Tom [ Expensive] The username from the last revision on the specified page*.
  • When the given param is equal to the current title of the parser, the parser function will yield the previous versions on preview and on substitution, that includes empty strings when used on page creation but using the values from the current version for page view, including viewing old revisions. In this case it is a non-expensive parser function.

External links

The most comprehensive resource for information on MediaWiki's "Magic words" can be found on:

Heading text