|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
| {{Help contents back}} | | {{Help contents back}} |
| '''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. | | '''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. |
|
| |
|
| ==General information== | | |
| | |
| | == General information == |
| There are three types of magic words: | | There are three types of magic words: |
| *'''Behavior switches:''' uppercase words surrounded by double underscores, e.g. <tt><nowiki>__NOTOC__</nowiki></tt>, or keywords using parser function syntax
| |
| *'''Variables:''' uppercase words surrounded by double braces, e.g. <tt><nowiki>{{PAGENAME}}</nowiki></tt> (thus resembling [[Help:Templates|templates]])
| |
| *'''Parser functions:''' keywords (some beginning #) in double braces with parameters after a colon, e.g. <tt><nowiki>{{#expr:2+2}}</nowiki></tt>
| |
|
| |
|
| 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. | | * '''Behavior switches:''' uppercase words surrounded by double underscores, e.g. <nowiki>__NOTOC__</nowiki>, or keywords using parser function syntax |
| | * '''Variables:''' uppercase words surrounded by double braces, e.g. <nowiki>{{PAGENAME}}</nowiki> (thus resembling [[Help:Templates|templates]]) |
| | * '''Parser functions:''' keywords (some beginning #) in double braces with parameters after a colon, e.g. <nowiki>{{#expr:2+2}}</nowiki> |
| | 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. |
|
| |
|
| ==Behavior switches== | | |
| | |
| | == Behavior switches == |
| ''For documentation, refer to the [http://www.mediawiki.org/wiki/Help:Magic_words#Behavior_switches Behavior Switches] section of the MediaWiki page.'' | | ''For documentation, refer to the [http://www.mediawiki.org/wiki/Help:Magic_words#Behavior_switches Behavior Switches] section of the MediaWiki page.'' |
| *<tt><nowiki>__NOTOC__</nowiki></tt> (can appear anywhere in the wikitext; suppresses the table of contents)
| |
| *<tt><nowiki>__FORCETOC__</nowiki></tt> (can appear anywhere in the wikitext; makes a table of contents appear in its normal position above the first header)
| |
| *<tt><nowiki>__TOC__</nowiki></tt> (places a table of contents at the word's position)
| |
|
| |
|
| *<tt><nowiki>__NOEDITSECTION__</nowiki></tt> (hides the section edit links beside headings)
| |
| *<tt><nowiki>__NEWSECTIONLINK__</nowiki></tt> (adds a "+" link for adding a new section on a non-"Talk" page)
| |
| *<tt><nowiki>__NONEWSECTIONLINK__</nowiki></tt> (removes the "+" link on "Talk" pages)
| |
|
| |
|
| *<tt><nowiki>__NOGALLERY__</nowiki></tt> (on a category page, replaces thumbnails with normal links) | | * <nowiki>__NOTOC__</nowiki> (can appear anywhere in the wikitext; suppresses the table of contents) |
| *<tt><nowiki>__HIDDENCAT__</nowiki></tt> (on a category page, makes it a hidden category) | | * <nowiki>__FORCETOC__</nowiki> (can appear anywhere in the wikitext; makes a table of contents appear in its normal position above the first header) |
| *<tt><nowiki>__INDEX__</nowiki></tt> (tells search engines to index the page) | | * <nowiki>__TOC__</nowiki> (places a table of contents at the word's position) |
| *<tt><nowiki>__NOINDEX__</nowiki></tt> (tells search engines not to index the page) | | * <nowiki>__NOEDITSECTION__</nowiki> (hides the section edit links beside headings) |
| | * <nowiki>__NEWSECTIONLINK__</nowiki> (adds a "+" link for adding a new section on a non-"Talk" page) |
| | * <nowiki>__NONEWSECTIONLINK__</nowiki> (removes the "+" link on "Talk" pages) |
| | * <nowiki>__NOGALLERY__</nowiki> (on a category page, replaces thumbnails with normal links) |
| | * <nowiki>__HIDDENCAT__</nowiki> (on a category page, makes it a hidden category) |
| | * <nowiki>__INDEX__</nowiki> (tells search engines to index the page) |
| | * <nowiki>__NOINDEX__</nowiki> (tells search engines not to index the page) |
| | * <nowiki>{{DISPLAYTITLE:''title''}}</nowiki> (changes the displayed form of the page title) |
| | * <nowiki>{{DEFAULTSORT:''sortkey''}}</nowiki> (sets a default category sort key) |
|
| |
|
| *<tt><nowiki>{{DISPLAYTITLE:</nowiki>''title''<nowiki>}}</nowiki></tt> (changes the displayed form of the page title)
| | == Variables == |
| *<tt><nowiki>{{DEFAULTSORT:</nowiki>''sortkey''<nowiki>}}</nowiki></tt> (sets a default category sort key)
| | ''For documentation, refer to the [http://www.mediawiki.org/wiki/Help:Magic_words#Variables Variables] section of the MediaWiki page.'' |
|
| |
|
| ==Variables==
| |
| ''For documentation, refer to the [http://www.mediawiki.org/wiki/Help:Magic_words#Variables Variables] section of the MediaWiki page.''
| |
| *<tt><nowiki>{{FULLPAGENAME}}</nowiki></tt> (page title including namespace)
| |
| *<tt><nowiki>{{PAGENAME}}</nowiki></tt> (page title excluding namespace)
| |
| *<tt><nowiki>{{BASEPAGENAME}}</nowiki></tt> (page title excluding subpage and namespace)
| |
| *<tt><nowiki>{{SUBPAGENAME}}</nowiki></tt> (subpage part of title)
| |
| *<tt><nowiki>{{SUBJECTPAGENAME}}</nowiki></tt> (associated non-talk page)
| |
| *<tt><nowiki>{{TALKPAGENAME}}</nowiki></tt> (associated talk page)
| |
| *<tt><nowiki>{{NAMESPACE}}</nowiki></tt> (namespace of current page)
| |
| *<tt><nowiki>{{SUBJECTSPACE}}, {{ARTICLESPACE}}</nowiki></tt> (associated non-talk namespace)
| |
| *<tt><nowiki>{{TALKSPACE}}</nowiki></tt> (associated talk namespace)
| |
| * <tt><nowiki>{{FULLPAGENAMEE}}, {{NAMESPACEE}}</nowiki></tt> etc. (URL-encoded equivalents)
| |
|
| |
|
| | * <nowiki>{{FULLPAGENAME}}</nowiki> (page title including namespace) |
| | * <nowiki>{{PAGENAME}}</nowiki> (page title excluding namespace) |
| | * <nowiki>{{BASEPAGENAME}}</nowiki> (page title excluding subpage and namespace) |
| | * <nowiki>{{SUBPAGENAME}}</nowiki> (subpage part of title) |
| | * <nowiki>{{SUBJECTPAGENAME}}</nowiki> (associated non-talk page) |
| | * <nowiki>{{TALKPAGENAME}}</nowiki> (associated talk page) |
| | * <nowiki>{{NAMESPACE}}</nowiki> (namespace of current page) |
| | * <nowiki>{{SUBJECTSPACE}}, {{ARTICLESPACE}}</nowiki> (associated non-talk namespace) |
| | * <nowiki>{{TALKSPACE}}</nowiki> (associated talk namespace) |
| | * <nowiki>{{FULLPAGENAMEE}}, {{NAMESPACEE}}</nowiki> etc. (URL-encoded equivalents) |
| The above can all take a parameter, to operate on a page other than the current page. | | The above can all take a parameter, to operate on a page other than the current page. |
|
| |
|
| *<tt><nowiki>{{SITENAME}}</nowiki></tt> ({{SITENAME}})
| |
| *<tt><nowiki>{{SERVER}}</nowiki></tt> (<nowiki>http://en.wikipedia.org</nowiki>)
| |
| *<tt><nowiki>{{SERVERNAME}}</nowiki></tt> ({{SERVERNAME}})
| |
| *<tt><nowiki>{{SCRIPTPATH}}</nowiki></tt> ({{SCRIPTPATH}})
| |
| *<tt><nowiki>{{CURRENTVERSION}}</nowiki></tt> (current MediaWiki version)
| |
| *<tt><nowiki>{{REVISIONID}}</nowiki></tt> (latest revision to current page)
| |
| *<tt><nowiki>{{REVISIONDAY}}, {{REVISIONDAY2}}, {{REVISIONMONTH}}, {{REVISIONYEAR}}, {{REVISIONTIMESTAMP}}, {{REVISIONUSER}}</nowiki></tt> (date, time, editor at last edit)
| |
|
| |
|
| *<tt><nowiki>{{CURRENTYEAR}}, {{CURRENTMONTH}}, {{CURRENTMONTHNAME}}, {{CURRENTMONTHABBREV}}, {{CURRENTDAY}}, {{CURRENTDAY2}}, {{CURRENTDOW}}, {{CURRENTDAYNAME}}, {{CURRENTTIME}}, {{CURRENTHOUR}}, {{CURRENTWEEK}}, {{CURRENTTIMESTAMP}}</nowiki></tt> (current date/time variables) | | * <nowiki>{{SITENAME}}</nowiki> (Wikipedia of the Dark Jedi Brotherhood, an online Star Wars Club) |
| *<tt><nowiki>{{LOCALYEAR}}</nowiki></tt> etc. (as above, based on site's local time) | | * <nowiki>{{SERVER}}</nowiki> (http://en.wikipedia.org) |
| | * <nowiki>{{SERVERNAME}}</nowiki> (wiki.darkjedibrotherhood.com) |
| | * <nowiki>{{SCRIPTPATH}}</nowiki> (/code) |
| | * <nowiki>{{CURRENTVERSION}}</nowiki> (current MediaWiki version) |
| | * <nowiki>{{REVISIONID}}</nowiki> (latest revision to current page) |
| | * <nowiki>{{REVISIONDAY}}, {{REVISIONDAY2}}, {{REVISIONMONTH}}, {{REVISIONYEAR}}, {{REVISIONTIMESTAMP}}, {{REVISIONUSER}}</nowiki> (date, time, editor at last edit) |
| | * <nowiki>{{CURRENTYEAR}}, {{CURRENTMONTH}}, {{CURRENTMONTHNAME}}, {{CURRENTMONTHABBREV}}, {{CURRENTDAY}}, {{CURRENTDAY2}}, {{CURRENTDOW}}, {{CURRENTDAYNAME}}, {{CURRENTTIME}}, {{CURRENTHOUR}}, {{CURRENTWEEK}}, {{CURRENTTIMESTAMP}}</nowiki> (current date/time variables) |
| | * <nowiki>{{LOCALYEAR}}</nowiki> etc. (as above, based on site's local time) |
| | * <nowiki>{{NUMBEROFPAGES}}, {{NUMBEROFARTICLES}}, {{NUMBEROFFILES}}, {{NUMBEROFEDITS}}, {{NUMBEROFVIEWS}}, {{NUMBEROFUSERS}}, {{NUMBEROFADMINS}}, {{NUMBEROFACTIVEUSERS}}</nowiki> (statistics on English Wikipedia; add <nowiki>:R</nowiki> to return numbers without commas) |
| | |
| | == Parser functions == |
| | ''These are documented at the [http://www.mediawiki.org/wiki/Help:Magic_words main documentation page] unless otherwise stated.'' |
| | |
|
| |
|
| *<tt><nowiki>{{NUMBEROFPAGES}}, {{NUMBEROFARTICLES}}, {{NUMBEROFFILES}}, {{NUMBEROFEDITS}}, {{NUMBEROFVIEWS}}, {{NUMBEROFUSERS}}, {{NUMBEROFADMINS}}, {{NUMBEROFACTIVEUSERS}}</nowiki></tt> (statistics on English Wikipedia; add <tt>:R</tt> to return numbers without commas)
| |
|
| |
|
| ==Parser functions== | | === Metadata === |
| ''These are documented at the [http://www.mediawiki.org/wiki/Help:Magic_words main documentation page] unless otherwise stated.'' | | * <nowiki>{{PAGESIZE:''page name''}}</nowiki> (size of page in bytes) |
| | * <nowiki>{{PROTECTIONLEVEL:''action''}}</nowiki> (protection level for given action on the current page) |
| | * <nowiki>{{PAGESINCATEGORY:''categoryname''}}</nowiki> (number of pages in the given [[Help:Category|category]]) |
| | * <nowiki>{{NUMBERINGROUP:''groupname''}}</nowiki> (number of users in a specific group) |
| | Add <nowiki>|R</nowiki> to return numbers without commas. |
|
| |
|
| ===Metadata===
| |
| *<tt><nowiki>{{PAGESIZE:</nowiki>''page name''<nowiki>}}</nowiki></tt> (size of page in bytes)
| |
| *<tt><nowiki>{{PROTECTIONLEVEL:</nowiki>''action''<nowiki>}}</nowiki></tt> (protection level for given action on the current page)
| |
| *<tt><nowiki>{{PAGESINCATEGORY:</nowiki>''categoryname''<nowiki>}}</nowiki></tt> (number of pages in the given [[Help:Category|category]])
| |
| *<tt><nowiki>{{NUMBERINGROUP:</nowiki>''groupname''<nowiki>}}</nowiki></tt> (number of users in a specific group)
| |
|
| |
|
| Add <tt>|R</tt> to return numbers without commas.
| |
|
| |
|
| ===Formatting=== | | === Formatting === |
| *<tt><nowiki>{{lc:</nowiki>''string''<nowiki>}}</nowiki></tt> (convert to lower case) | | * <nowiki>{{lc:''string''}}</nowiki> (convert to lower case) |
| *<tt><nowiki>{{lcfirst:</nowiki>''string''<nowiki>}}</nowiki></tt> (convert first character to lower case) | | * <nowiki>{{lcfirst:''string''}}</nowiki> (convert first character to lower case) |
| *<tt><nowiki>{{uc:</nowiki>''string''<nowiki>}}</nowiki></tt> (convert to upper case) | | * <nowiki>{{uc:''string''}}</nowiki> (convert to upper case) |
| *<tt><nowiki>{{ucfirst:</nowiki>''string''<nowiki>}}</nowiki></tt> (convert first character to upper case) | | * <nowiki>{{ucfirst:''string''}}</nowiki> (convert first character to upper case) |
| *<tt><nowiki>{{formatnum:</nowiki>''unformatted num''<nowiki>}}</nowiki></tt> (format a number with comma separators; add <tt><nowiki>|</nowiki>R</tt> to unformat a number) | | * <nowiki>{{formatnum:''unformatted num''}}</nowiki> (format a number with comma separators; add <nowiki>|R</nowiki> to unformat a number) |
| *<tt><nowiki>{{#formatdate:</nowiki>''date''<nowiki>}}</nowiki></tt> (formats a date according to user preferences; a default can be given as a second parameter for users without date preference). | | * <nowiki>{{#formatdate:''date''}}</nowiki> (formats a date according to user preferences; a default can be given as a second parameter for users without date preference). |
| *<tt><nowiki>{{padleft:xyz|</nowiki>''stringlength''<nowiki>}}</nowiki></tt>, <tt><nowiki>{{padright:xyz|</nowiki>''stringlength''<nowiki>}}</nowiki></tt> (pad with zeros to the right or left; an alternative padding string can be given as a third parameter) | | * <nowiki>{{padleft:xyz|''stringlength''}}</nowiki>, <nowiki>{{padright:xyz|''stringlength''}}</nowiki> (pad with zeros to the right or left; an alternative padding string can be given as a third parameter) |
| *<tt><nowiki>{{plural:</nowiki>''n''|''is''<nowiki>|</nowiki>''are''<nowiki>}}</nowiki></tt> (produces alternative text according to whether ''n'' is greater than 1) | | * <nowiki>{{plural:''n''|''is''|''are''}}</nowiki> (produces alternative text according to whether ''n'' is greater than 1) |
| *<tt><nowiki>{{#time: format string | date/time object }}</nowiki></tt> (for date/time formatting; also <tt>#timel</tt> for local time. Covered at the [http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions extension documentation page].) | | * <nowiki>{{#time: format string | date/time object }}</nowiki> (for date/time formatting; also <nowiki>#timel</nowiki> for local time. Covered at the [http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions extension documentation page].) |
|
| |
|
| ===Paths=== | | === Paths === |
| *<tt><nowiki>{{localurl:</nowiki>''page name''<nowiki>}}</nowiki></tt>, <tt><nowiki>{{localurl:</nowiki>''page name''<nowiki>|</nowiki>''query string''<nowiki>}}</nowiki></tt> (relative path to the title) | | * <nowiki>{{localurl:''page name''}}</nowiki>, <nowiki>{{localurl:''page name''|''query string''}}</nowiki> (relative path to the title) |
| *<tt><nowiki>{{fullurl:</nowiki>''page name''<nowiki>}}</nowiki></tt>, <tt><nowiki>{{fullurl:</nowiki>''page name''<nowiki>|</nowiki>''query_string''<nowiki>}}</nowiki></tt> (absolute path to the title) | | * <nowiki>{{fullurl:''page name''}}</nowiki>, <nowiki>{{fullurl:''page name''|''query_string''}}</nowiki> (absolute path to the title) |
| *<tt><nowiki>{{filepath:</nowiki>''file name''<nowiki>}}</nowiki></tt> (absolute URL to a media file) | | * <nowiki>{{filepath:''file name''}}</nowiki> (absolute URL to a media file) |
| *<tt><nowiki>{{urlencode:</nowiki>''string''<nowiki>}}</nowiki></tt> (input encoded for use in URLs) | | * <nowiki>{{urlencode:''string''}}</nowiki> (input encoded for use in URLs) |
| *<tt><nowiki>{{anchorencode:</nowiki>''string''<nowiki>}}</nowiki></tt> (input encoded for use in URL section anchors) | | * <nowiki>{{anchorencode:''string''}}</nowiki> (input encoded for use in URL section anchors) |
| *<tt><nowiki>{{ns:</nowiki>''n''<nowiki>}}</nowiki></tt> (name for the namespace with index ''n''; use <tt><nowiki>{{nse:}}</nowiki></tt> for URL-encoded equivalent) | | * <nowiki>{{ns:''n''}}</nowiki> (name for the namespace with index ''n''; use <nowiki>{{nse:}}</nowiki> for URL-encoded equivalent) |
| *<tt><nowiki>{{#rel2abs:</nowiki> ''path'' <nowiki>}}</nowiki></tt> (converts a relative file path to absolute; see the extension documentation above) | | * <nowiki>{{#rel2abs: ''path'' }}</nowiki> (converts a relative file path to absolute; see the extension documentation above) |
| *<tt><nowiki>{{#titleparts: pagename | number of segments to return | first segment to return }}</nowiki></tt> (splits title into parts; see the extension documentation above) | | * <nowiki>{{#titleparts: pagename | number of segments to return | first segment to return }}</nowiki> (splits title into parts; see the extension documentation above) |
|
| |
|
| ===Conditional expressions=== | | === Conditional expressions === |
| These are covered at the extension documentation page (above). Some parameters are optional. | | These are covered at the extension documentation page (above). Some parameters are optional. |
| *<tt><nowiki>{{#expr:</nowiki> ''expression'' <nowiki>}}</nowiki></tt> (evaluates the given expression; see [http://en.wikipedia.org/wiki/Help:Calculation Help:Calculation] on Wookieepedia)
| |
| *<tt><nowiki>{{#if:</nowiki> ''test string'' | ''value if non-empty'' | ''value if empty'' <nowiki>}}</nowiki></tt> (selects one of two values based on whether the test string is empty)
| |
| *<tt><nowiki>{{#ifeq:</nowiki> ''string 1'' <nowiki>|</nowiki> ''string 2'' <nowiki>|</nowiki> ''value if equal'' <nowiki>|</nowiki> ''value if unequal'' <nowiki>}}</nowiki></tt> (selects one of two values based on whether the test strings are equal – numerically if applicable)
| |
| *<tt><nowiki>{{#iferror:</nowiki> ''test string'' <nowiki>|</nowiki> ''value if error'' <nowiki>|</nowiki> ''value if correct'' <nowiki>}}</nowiki></tt> (selects value based on whether the test string generates a parser error)
| |
| *<tt><nowiki>{{#ifexpr:</nowiki> ''expression'' <nowiki>|</nowiki> ''value if true'' <nowiki>|</nowiki> ''value if false'' <nowiki>}}</nowiki></tt> (selects value based on evaluation of expression)
| |
| *<tt><nowiki>{{#ifexist:</nowiki> ''page title'' | ''value if exists'' | ''value if doesn't exist'' <nowiki>}}</nowiki></tt> (selects value depending on whether a page title exists)
| |
| *<tt><nowiki>{{#switch: test | case1 = value for case 1 | ... | default }}</nowiki></tt> (provides alternatives based on the value of the test string)
| |
|
| |
|
| | |
| | * <nowiki>{{#expr: ''expression'' }}</nowiki> (evaluates the given expression; see [http://en.wikipedia.org/wiki/Help:Calculation Help:Calculation] on Wookieepedia) |
| | * <nowiki>{{#if: ''test string'' | ''value if non-empty'' | ''value if empty'' }}</nowiki> (selects one of two values based on whether the test string is empty) |
| | * <nowiki>{{#ifeq: ''string 1'' | ''string 2'' | ''value if equal'' | ''value if unequal'' }}</nowiki> (selects one of two values based on whether the test strings are equal – numerically if applicable) |
| | * <nowiki>{{#iferror: ''test string'' | ''value if error'' | ''value if correct'' }}</nowiki> (selects value based on whether the test string generates a parser error) |
| | * <nowiki>{{#ifexpr: ''expression'' | ''value if true'' | ''value if false'' }}</nowiki> (selects value based on evaluation of expression) |
| | * <nowiki>{{#ifexist: ''page title'' | ''value if exists'' | ''value if doesn't exist'' }}</nowiki> (selects value depending on whether a page title exists) |
| | * <nowiki>{{#switch: test | case1 = value for case 1 | ... | default }}</nowiki> (provides alternatives based on the value of the test string) |
| For the use of these functions in tables, see [http://en.wikipedia.org/wiki/Wikipedia:Conditional_tables Conditional tables]. | | For the use of these functions in tables, see [http://en.wikipedia.org/wiki/Wikipedia:Conditional_tables Conditional tables]. |
| | |
|
| |
|
| [[Category:DJB Help]] | | [[Category:DJB Help]] |