Help:魔术字

From MediaWiki.org
Jump to: navigation, search
This page is a translated version of the page Help:Magic words and the translation is 65% complete.

Other languages:
العربية • ‎تۆرکجه • ‎bosanski • ‎català • ‎čeština • ‎dansk • ‎Deutsch • ‎Zazaki • ‎English • ‎British English • ‎español • ‎euskara • ‎فارسی • ‎suomi • ‎français • ‎Frysk • ‎galego • ‎Bahasa Indonesia • ‎italiano • ‎日本語 • ‎ქართული • ‎한국어 • ‎Lëtzebuergesch • ‎मैथिली • ‎олык марий • ‎मराठी • ‎Nederlands • ‎polski • ‎پښتو • ‎português • ‎português do Brasil • ‎русский • ‎සිංහල • ‎slovenčina • ‎српски / srpski • ‎svenska • ‎தமிழ் • ‎Türkçe • ‎українська • ‎Tiếng Việt • ‎中文
PD 注意:当你编辑本页面时,你将表示同意以CC0协议授权你的贡献。你可以在公有领域帮助文档找到更多信息。
PD

魔术字是MediaWiki软件所识别的特定字符串,它们可以返回特定的值或触发其他的功能:比如时间、站点设置或是页面名称等等。本页所描述的均是标准魔术字的用法;开发人员请参考Manual:Magic words

魔术字有三种类型:

  • 状态开关:以两个下划线“__”为前后缀的大写单词,例如__FOO__
  • 变量:字符被两个大括号括起来,所有字母大写,例如{{FOO}}。用法与模板类似。

变量和解析器函数可以像模板一样使用subst:。无论这个魔术字是通过被引用的模板添加的或者被包含的系统信息中添加的,依赖页面的魔术字均将(默认)起作用或者返回当前页面的数据。

行为开关

状态开关可以控制页面的显示方式或其他行为。它往往用于排除或加入特定的页面内容。

文字 描述 版本
表格内容
__NOTOC__ 隐藏目录(TOC)。
__FORCETOC__ 强制于默认位置(第一个章节标题上方,忽略__NOTOC__的设置)显示目录。
__TOC__ 在魔术字的位置插入目录(忽略__NOTOC__的设置)。如果这个魔术字在一个页面内被多次使用,目录将会被放置在首个__TOC__出现的位置。
编辑
__NOEDITSECTION__ 隐藏章节标题旁的编辑链接。这个特别有用,当章节标题在模板中被创建时,普通的编辑链接将用户带到编辑模板代码界面,这与用户的直觉不符。如果模板包括多个标题,有必要在每个标题后加上“__NOEDITSECTION__”。
__NEWSECTIONLINK__ 在非讨论页顶端“编辑页面”标签右侧加入一个按钮,用于在页面结尾加入新的章节(参见 在页面末尾加入新章节)。
1.7
__NONEWSECTIONLINK__ 移除讨论页顶端“编辑页面”右侧的加入新章节链接。
1.15
r47522
分类
__NOGALLERY__ 用于分类页面。不显示分类中所包含文件的缩略图,而以普通链接代替。
1.7
__HIDDENCAT__ 用于分类页面。加入后此分类成为隐藏分类,将不会显示在上级分类其及成员页面的分类列表中(可以通过参数设置中的选项强制显示)。
1.13
语言转换
__NOCONTENTCONVERT__
__NOCC__
在语言有不同变体时(如中文简体和繁体),不对当前页面进行字词转换。比如只显示中文,而不是显示大陆简体、台湾繁体、新加坡繁体和香港繁体。
__NOTITLECONVERT__
__NOTC__
在语言有不同变体时(如中文简体和繁体),不对当前页面进行标题转换(其他内容照常转换)。
其他
__START__ 无效。r1695被删除;r24784被彻底删除。
1.10
r1610
__END__ 明确表明文章的结尾,来防止Mediawiki删除文末的空格。从r19213停止使用。
1.1 – 1.8
__INDEX__ 允许搜索引擎检索本页(忽略$wgArticleRobotPolicies的参数设置,但无法忽略robots.txt)。服从$wgExemptFromUserRobotsControl的设定。
1.14
__NOINDEX__ 禁止搜索引擎检索本页(忽略$manual-wg-bot-policy的参数设置,但无法忽略robots.txt)。服从$wgExemptFromUserRobotsControl的设定。
1.14
r37973
__STATICREDIRECT__ 用于重定向页。当有人移动页面并勾选“Update any redirects that point to the original title”时,禁止MediaWiki更新本页的重定向。(需要变量$wgFixDoubleRedirects
1.13
r37928
__DISAMBIG__ 用于消歧义页,该页会被标记为消歧义页并显示于Special:消歧义页面,并且在Special:DisambiguationPageLinks中添加内部链接。参见Extension:Disambiguator 需要Extension:Disambiguator

变量

变量可以返回关于当前页面、wiki站点或日期的信息。变量的语法与模板类似。其中标记为“[高开销]”的变量会被软件记录,且在一个页面中可使用的总数会被限制。

如果某一模板名与变量名重复,软件会自动将其解释为变量(因此若要包含Template:PAGENAME,页面中需要写作{{Template:PAGENAME}})。在某些情况下,加入参数会强制软件将变量视作一个模板,如{{CURRENTDAYNAME|x}}将会包含Template:CURRENTDAYNAME,而是变量。

日期和时间

以下的变量返回当前的日期和时间,遵照用户的时区选项,默认为UTC时间。

在MediaWiki与浏览器缓存的影响下,这些变量显示的往往是被缓存的值,而非当前的时间。

日期和时间魔术字被格式化为相应的语种。自1.19版本开始,她们取决于,页面内容语言

变量 输出 描述 版本
{{CURRENTYEAR}} 2015
{{CURRENTMONTH}} 08 月(补足前导的0)
{{CURRENTMONTH1}} 8 月(无前导的0)
{{CURRENTMONTHNAME}} 8月 月份名称
{{CURRENTMONTHNAMEGEN}} 八月 月份 (属格)
{{CURRENTMONTHABBREV}} 8月 月份 (缩写)
1.5
{{CURRENTDAY}} 4 今天是几日 (不补齐)
{{CURRENTDAY2}} 04 今天是几日 (以 0 补齐)
1.6
{{CURRENTDOW}} 2 周内一日(无填充),0(即星期日)到6(即星期六)
{{CURRENTDAYNAME}} 星期二 周内一日(名称)
时间
{{CURRENTTIME}} 22:45 时间(24小时HH:mm格式)
{{CURRENTHOUR}} 22 时间 (24小时 以 0 补齐的数字)
其他
{{CURRENTWEEK}} 32 第几周(数字)
{{CURRENTTIMESTAMP}} 20150804224519 YYYYMMDDHHmmss时间戳
1.7

如下变量和上列变量功能相同,但是使用的是所在服务器的时间或者$wgLocaltimezone

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

“更详尽的时间格式,您可以在安装扩展:ParserFunctions后,使用#time parser function

技术元数据

注:历史版本变量返回的是与当前页面最近一次编辑有关的数据,即是当时您查看的是更旧版本的页面。

变量 输出 描述 版本
站点
{{SITENAME}} MediaWiki 维基网站的名称($wgSitename)。
{{SERVER}} //www.mediawiki.org 域名URL ($wgServer).
{{SERVERNAME}} www.mediawiki.org 子域名和域名(自版本1.17后不再取决于$wgServerName)。
{{DIRMARK}}
{{DIRECTIONMARK}}

输出这个wiki默认语言所使用的Unicode文本方向控制字符(从左到右书写的语言使用‎,反之使用‏),这在多方向文本中很有用。她取决于页面语言
1.7
r14442
{{SCRIPTPATH}} /w 脚本相对路径($wgScriptPath)。
{{STYLEPATH}} https://www.mediawiki.org/static/1.26wmf17/skins 样式相对路径($wgStylePath)。
1.16
{{CURRENTVERSION}} 1.26wmf17 (6bc083f) 这个维基站点的MediaWiki版本。
1.7
r14199
{{CONTENTLANGUAGE}}
{{CONTENTLANG}}
en
en
默认界面语言($wgLanguageCode)。
1.7
r14661
页面
{{PAGEID}} 191162 页面编号。
1.20
Gerrit change 9858
{{PROTECTIONLEVEL:操作}} 输出当前页面对于特定行为(比如edit,move)的保护级别(autoconfirm或sysop等)。若未保护则返回空字符串。
1.15
r45587
{{CASCADINGSOURCES}} [Expensive] Returns the sources of any cascading protection acting on the current page. Pages will not return their own title unless they transclude themselves.
1.23
Gerrit change 104999
最近一次编辑版本号
{{REVISIONID}} 1775495 唯一的版本ID
1.5
{{REVISIONDAY}} 21 最近一次编辑的日期(无前导0)。
1.8
{{REVISIONDAY2}} 21 最近一次编辑的日期(前导0)
1.8
{{REVISIONMONTH}} 07 最近一次编辑的月份(1.17+,版本有前导0,较早版本没有前导0)。
1.8
{{REVISIONMONTH1}} 7 最近一次编辑的月份(没有前导0)。
1.17
r66200
{{REVISIONYEAR}} 2015 最近一次编辑的年份
1.8
{{REVISIONTIMESTAMP}} 20150721000642 最近一次编辑的时间戳。
1.8
{{REVISIONUSER}} Matiia 最近一个对指定页面作出编辑的用户,或者当前正在对其编辑进行预览的用户。
1.15
r48149
{{REVISIONSIZE}} 66205 当前版本页面的大小(维基文本)。
1.22
Gerrit change 82650
影响页面内容。
{{DISPLAYTITLE:标题}} 设置当前页面标题的显示格式。变量值须与标题等值:只允许大小写变化和用下划线替换替换空格(这个设定可以通过$wgRestrictDisplayTitle改变)。可以通过$wgAllowDisplayTitle将其启用或禁用;在1.10+前默认禁用,之后的版本中默认启用。

可以使用第二个参数:“noerror”关闭使用多个本魔术字时导致错误信息提示。或“noreplace”如果displaytitle在前文已经设置,则关闭使用多个本魔术字时导致错误信息提示令displaytitle失效。

1.7

1.24
Gerrit change 144870

(以无错误提示、不替换为目的)
{{DEFAULTSORT:排序关键字}}
{{DEFAULTSORTKEY:排序关键字}}
{{DEFAULTCATEGORYSORT:排序关键字}}
{{DEFAULTSORT:排序关键字|noerror}}
{{DEFAULTSORT:|noreplace}}
在分类页面上使用,用来设置默认在分类中排序关键字。例如当你将<code><code><nowiki>{{DEFAULTSORT:Smith , John}}</nowiki>放到页面John Smith的结尾,该页面在分类页面上的列表中将默认排到“S”项下。可以使用第二个参数:“noerror”关闭使用多个本魔术字时导致错误信息提示。或“noreplace”如果defaultsort在前文已经设置,则关闭使用多个本魔术字时导致错误信息提示,令defaultsort失效。
1.10

1.19
r96767

(以无错误提示、不替换为目的)


统计

这些变量返回的数字往往包含分隔符(根据本地语言参数设置而可能是逗号或空格)。可以通过“:R”来返回无分隔号的数字(例如{{NUMBEROFPAGES}} → 407,003 and {{NUMBEROFPAGES:R}} → 407003)。

对于PAGESINCATEGORY等需要参数的变量则使用“|R”(例如{{PAGESINCATEGORY:Help}}{{PAGESINCATEGORY:Help|R}}{{PAGESINCATEGORY:Help|subcats}}{{PAGESINCATEGORY:Help|subcats|R}})。并且也适用于前述{{PAGESIZE:页面名称}}

返回数字的魔术字数字格式取决于内容语言的设定。自1.19,开始,取决于页面内容语言

变量 输出 描述 版本
{{NUMBEROFPAGES}} 407,003 维基页面数量
1.7
{{NUMBEROFARTICLES}} 29,581 内容名字空间中的页面个数。
{{NUMBEROFFILES}} 2,837 上传文件的个数。
1.5
{{NUMBEROFEDITS}} 1,868,603 维基编辑的数量
1.10
r21319
{{NUMBEROFVIEWS}} 页面浏览次数。通常对使用缓存的wiki无效。 在Gerrit change 150699被删除。
1.14 – 1.24
r42721
{{NUMBEROFUSERS}} 2,837,457 注册用户数量
1.7
{{NUMBEROFADMINS}} 175 管理员(sysop)用户数。
1.7
{{NUMBEROFACTIVEUSERS}} 1,126 活跃用户总数,其标准与Special:Statistics中的标准相同。
1.15
r47392
{{PAGESINCATEGORY:categoryname}}
{{PAGESINCAT:categoryname}}
100
100
[高开销]指定分类中的页面总数(包括子类和文件)。Category:Help 用来演示
1.13
r32932
{{PAGESINCATEGORY:分类名称|all}}
{{PAGESINCATEGORY:分类名称|pages}}
{{PAGESINCATEGORY:分类名称|subcats}}
{{PAGESINCATEGORY:|files}}
100
95
2
3
[高开销]返回指定分类的:
  • 所有页面数
  • 所有非分类页和非文件页数
  • 所有子分类页数
  • 所有文件页数
1.20
Gerrit change 12790
{{NUMBERINGROUP:用户组}}
{{NUMINGROUP:用户组}}
34
34
({{NUMBERINGROUP:bureaucrat}} used here)
特定用户群组中的用户总数
1.14
r40116
{{PAGESINNS:索引编号}}
{{PAGESINNAMESPACE:索引编号}}
未启用 [高开销]指定命名空间中的页面总数。(将“索引编号”替换成相关名字空间编号)。例如{{PAGESINNAMESPACE:14}}返回分类页面总数。{{PAGESINNS:0}}{{NUMBEROFARTICLES}}不同之处在于包括重定向页面和消除歧义页面。默认禁用,可以通过$wgAllowSlowParserFunctions设置启用。
1.7

页面名称

变量 输出 描述 版本
{{FULLPAGENAME}} Help:Magic words/zh 名字空间与完整页面标题(包括子页面级别)。
1.6
{{PAGENAME}} Magic words/zh 不包含名字空间的完整页面标题(包括子页面级别)。
{{BASEPAGENAME}} Magic words Page title of the page in the immediately superior subpage level without the namespace ("Title/foo" on "Help:Title/foo/bar").

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

1.7
{{SUBPAGENAME}} zh 子頁面標題 (例如 "Help:Title/foo/bar"中的"bar")
1.6
{{SUBJECTPAGENAME}}
{{ARTICLEPAGENAME}}
Help:Magic words/zh
Help:Magic words/zh
Full page name of the associated subject (e.g. article or file). Useful on talk pages.
1.7
{{TALKPAGENAME}} Help talk:Magic words/zh 关联讨论页的完整页面名称
1.7
{{ROOTPAGENAME}} Magic words Name of the root of the current page. Would return Title on page Help:Title/Foo/Bar
1.22

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

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 apostrophes ' or asterisks *, may produce unexpected results when handled with these magic words, e.g. {{PAGESINCATEGORY:{{PAGENAME}}}}. See bugs T16779, T18474, T37628, and T37746. One simple way to fix this is wrapping the pagename in #titleparts (parser function).

For example, if page name is "L'Aquila", the following code will produce the string "Numeric char encoding":

{{#switch:{{PAGENAME}}
| L'Aquila = No translation
| L = Not OK
| L&apos;Aquila = Entity escaping
| L&#39;Aquila = Numeric char encoding
}}

URL 編碼後的頁面名稱

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

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

名字空间

变量 输出 描述 版本
{{NAMESPACE}} Help 名字空间的名称
{{NAMESPACENUMBER}} 12 页面所在名字空间的ID
1.20
Gerrit change 4056
{{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}}
  • {{ARTICLESPACEE}}
  • {{TALKSPACEE}}

As of 1.15+, 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}}Template
  • {{SUBJECTSPACE:Template:Main Page}}Template
  • {{TALKSPACE:Template:Main Page}}Template talk

Parameter must not be a namespace name:

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

其他

变量 输出 描述 版本
{{!}} | Used to include a pipe character as part of a template argument or table cell contents. Before this was added as a magic word, many wikis implemented this by creating Template:! with | as the content.
1.24
Gerrit change 136234

解析器函数

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. For those see Help:扩展:ParserFunctions.

其他页面的技术元数据

解析器函数 输出
(用于MediaWiki
描述 版本
{{PAGEID: 页面名称 }} 1 [Expensive] Returns the page identifier of the specified page*.
1.23
Gerrit change 76534
{{PAGESIZE: 頁面名稱 }}
{{PAGESIZE: 頁面名稱 |R}}
157
157
[Expensive] Returns the byte size of the specified page. Use "|R" to get raw (unformatted) numbers.
1.13
r33551
{{PROTECTIONLEVEL:操作 | 页面名称}} sysop [Expensive] Outputs the protection level (e.g. "autoconfirmed", "sysop") for a given action (e.g. "edit", "move") on the specified page. Returns an empty string if not protected.
1.21
r44683
{{CASCADINGSOURCES:

page name}}

[Expensive] Returns the sources of any cascading protection acting on the specified page. Pages will not return their own title unless they transclude themselves.
1.23
Gerrit change 104999
{{REVISIONID: 页面名称 }} 1446376 [Expensive] Unique revision ID of the last revision on the specified page*.
1.23
Gerrit change 76534
{{REVISIONDAY: 页面名称 }} 16 [Expensive] Day of edit from the last revision of the specified page* (unpadded number).
1.23
Gerrit change 76534
{{REVISIONDAY2: 页面名称 }} 16 [Expensive] Day of edit from the last revision of the specified page* (zero-padded number).
1.23
Gerrit change 76534
{{REVISIONMONTH: 页面名称 }} 03 [Expensive] Month of edit from the last revision of the specified page* (zero-padded number as of 1.17+, unpadded number in prior versions).
1.23
Gerrit change 76534
{{REVISIONMONTH1: 页面名称 }} 3 [Expensive] Month of edit from the last revision of the specified page* (unpadded number).
1.23
Gerrit change 76534
{{REVISIONYEAR: 页面名称 }} 2015 [Expensive] Year of edit from the last revision of the specified page*.
1.23
Gerrit change 76534
{{REVISIONTIMESTAMP: 页面名称 }} 20150316021645 [Expensive] Timestamp as of time of edit on the specified page*.
1.23
Gerrit change 76534
{{REVISIONUSER: 页面名称 }} Ruy Pugliesi [Expensive] The username from the last revision on the specified page*.
1.23
Gerrit change 76534
*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.

URL数据

解析器函数 输入 → 输出 描述 版本
{{localurl:page name}}
{{localurl:page name
|query_string}}
{{localurl:MediaWiki}}
→ /wiki/MediaWiki
{{localurl:MediaWiki|printable=yes}}
→ /w/index.php?title=MediaWiki&printable=yes
至標題的相對路徑。
{{fullurl:page name}}
{{fullurl:page name
|query_string}}

{{fullurl:interwiki:remote page name
|query_string}}
{{fullurl:Category:Top level}}
→ //www.mediawiki.org/wiki/Category:Top_level

{{fullurl:Category:Top level|action=edit}}
→ //www.mediawiki.org/w/index.php?title=Category:Top_level&action=edit
https:{{fullurl:s:Electra|action=edit}}
https://en.wikisource.org/wiki/Electra?action=edit
https:{{fullurl:s:es:Electra|action=edit}}
https://en.wikisource.org/wiki/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.
1.5
{{canonicalurl:page name}}
{{canonicalurl:page name
|query_string}}

{{canonicalurl:interwiki:remote page name
|query_string}}
{{canonicalurl:Category:Top level}}
https://www.mediawiki.org/wiki/Category:Top_level

{{canonicalurl:Category:Top level|action=edit}}
https://www.mediawiki.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.
1.18
{{filepath:file name}}
{{filepath:file name|nowiki}}
{{filepath:file name|thumbnail_size}}
{{filepath:Wiki.png}}
→ //upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png

{{filepath:Wiki.png|nowiki}}
→ //upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png
{{filepath:Example.svg|300}}
→ //upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/300px-Example.svg.png

A protocol-relative path to the full size or thumbnail (1.18+) of a media file.
1.12
r25854

1.18
r80813
{{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 |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.
字符編碼
code 空格
 none  + 
QUERY  + 
 WIKI  _ 
 PATH %20
1.7
r14273
(or
1.17
r64726

1.17
r64726

1.17
r64726
)
{{anchorencode:字符串}} {{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.6
r16279

名字空间

{{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". On a wiki where the content language is French, {{ns:Fichier}} is also valid, but {{ns:Datei}} (the localisation of "File" in German) is 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.

内容名字空间 讨论名字空间
用法 输出 用法 输出
{{ns:-2}} / {{ns:Media}} Media {{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}} Project
Varies between wikis
{{ns:5}} / {{ns:Project talk}} Project talk
{{ns:6}} / {{ns:File}} or {{ns:Image}} File {{ns:7}} / {{ns:File talk}} or {{ns:Image 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

Don't confuse localised namespaces with custom namespaces.

格式化

用法 输入 → 输出 说明 版本
{{formatnum:unformatted number}}

{{formatnum:formatnum-formatted number|R}}
{{formatnum:unformatted number|NOSEP}}

  • 简单:
    • {{formatnum:987654321.654321}}
      → 987,654,321.654321
    • {{formatnum:987,654,321.654321|R}}
      → 987654321.654321
  • 高级:
    • {{formatnum:{{formatnum:987654321.654321}}|R}}
      → 987654321.654321 (於任意語言)
    • {{formatnum:00001}}
      → 00,001
    • {{formatnum:987654321.654321 |NOSEP}}
      → 987654321.654321
    • Examples with Bengali locale:
      • {{formatnum:987654321.654321}}
        → ৯৮,৭৬,৫৪,৩২১.৬৫৪৩২১
      • {{formatnum:987654321.654321 |NOSEP}}
        → ৯৮৭৬৫৪৩২১.৬৫৪৩২১
      • {{formatnum:৯৮,৭৬,৫৪,৩২১.৬৫৪৩২১ |R}}
        → 987654321.654321

不被支持的:
{{formatnum:{{formatnum:987.654.321}}}}
→ 987 654 321 (e.g. with Italian locale)


Examples of wrong input (unreliable output), with or without |R:
{{formatnum:987,654.321|R}} (the least broken)
{{formatnum:987.654,321|R}}
{{formatnum:987 654,321|R}}
{{formatnum:987&nbsp;654,321|R}}

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, according to the wiki's default locale.

The |R parameter can be used to reverse the behavior, for use in mathematical situations: it's reliable and should be used only to deformat numbers which are known to be formatted exactly as formatnum formats them with the wiki's locale.
The NOSEP ("no separators") parameter means that no group / decimal separators are changed; formatnum will only transform the digits themselves in languages which don't use the Hindu–Arabic numeral system. NOSEP can also prevent non-standard digit groupings you wouldn't expect.

Warning Warning: Leading zeroes are not removed, you can use {{#expr:00001}} instead if you have 扩展:ParserFunctions installed.

Warning Warning: If you don't input numbers in the exact format required, don't expect any reliable output, especially on non-English wikis.


If you really need to format (according the wiki's locale) a number in unknown input format, you could try and use formatnum two times (but not if it can have a decimal group, or its separator will be eaten or the number won't be formatted). Be aware that this is more a hack than a regular way to proceed, thus the output may be not reliable.

1.7

1.13
r32012

{{#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}}
12月 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 hereinbefore, "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.

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
r48249
{{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
{{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.

Only the first character of the third parameter is used in versions up to 1.12, but by version 1.15 all the characters are used.

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.
1.8

See also: Extension:StringFunctions.

本地化

Here are the magic words which are used as main localisation tools. Other magic words will often depend on the wiki's locale and configuration or on the chosen language: see in particular #Date and time, #Formatting, #Miscellaneous. More magic words are added by the 扩展:翻译.

The usage of these magic words can be very complex, and the documentation is currently incomplete; there's some more info on PLURAL, GRAMMAR, GENDER.

用法 输入 → 输出 描述 版本
{{plural:2|is|are}} {{plural:0|is|are}} → are
{{plural:1*1|is|are}} → is
{{plural:21 mod 10|is|are}} → are
{{plural:{{#expr:21 mod 10}}|is|are}} → is
{{plural:1|is|are}} → is
{{plural:2|is|are}} → are
(用于俄语
{{PLURAL:5|1=Категория|Категории}}  → Категории


{{PLURAL:3|страница|страницы|страниц}} → страницы
{{PLURAL:5|страница|страницы|страниц}} → страниц

Outputs the singular form (second parameter) if the first parameter is an expression equalling one; the plural form (third parameter) otherwise. Its functioning is language-dependent.
Some language codes (ab, av, ba, bxr, ce, crh_cyrl, cv, inh, koi, krc, kv, lbe, lez, mhr, mrj, myv, ru, tt_cyrl, tyv, udm, xal) used 3 plural forms (updated 01.2014):
  • Form 1: 1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, …
  • Form 2: 0, 5, 6, 7,8,...18, 19, 100, 1000, 10000, 100000, 1000000, …
  • Form 3: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44, 52, 53, 54, 62, 102, 1002, …
{{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 $wgGrammarForms.
1.7
{{gender:username|text for every gender}}

{{gender:Username|male text|female text|text for unspecified}}
{{gender:|male text|female text|text for unspecified}}
{{gender:.|male text|female text|text for unspecified}}

(Depends on the named user's gender) A switch for the gender set in Special:Preferences.

Note: The first example is basically a no-op
Note: If 3rd parameter is omitted and user hasn't defined his/her gender, then text if user is male is returned.
A blank username field ({{gender:|) means the current user.
A dot username (.) means the default user gender on this wiki.

1.15
r46247
{{int:信息名称}} {{int:edit}}Edit
(Depends on user language; try: frja)
Internationalizes (translates) the given interface (MediaWiki namespace) message into the user language. For msgnw and other transclusion magic words, see the Transclusion modifiers section.

Note that this can damage / confuse cache consistency in MediaWiki 1.17 and earlier, see bug 14404.

{{int:editsectionhint|MediaWiki}} {{int:editsectionhint|MediaWiki}}Edit section: MediaWiki You may also use parameters with translations.
Parameters are designated in messages with: $1, $2, $3, etc.
For example, here is the message for editsectionhint: Edit section: $1
In this example, MediaWiki replaces $1.

Transclusion modifiers

{{Page name|optional params}} usually transcludes another page, by default from the Template:namespace. These magic words modify that behavior.

杂项