添加的内容 删除的内容
标签:消歧义链接 |
无编辑摘要 标签:消歧义链接 |
||
第1行: | 第1行: | ||
{{NoteTA |
|||
<noinclude> |
|||
|G1 = IT |
|||
<languages/> |
|||
|G2 = MediaWiki |
|||
}} |
|||
nsp=0扩展提供11个額外的[[Special:MyLanguage/Parser functions|解析器函数]]以补充MediaWiki固有的“魔术字”。 |
|||
{{操作指南|H:PF|H:FUNC}} |
|||
⚫ | |||
{{not|Help:魔术字}} |
|||
'''解析器函数'''是一个MediaWiki扩展,由[[mw:Extension:ParserFunctions]]提供。 |
|||
⚫ | |||
此扩展提供的所有解析器函数均采用以下形式: |
此扩展提供的所有解析器函数均采用以下形式: |
||
:<code><nowiki>{{</nowiki>'''#函数名''': ''参数1'' | ''参数2'' | ''参数3''... <nowiki>}}</nowiki></code> |
:<code><nowiki>{{</nowiki>'''#函数名''': ''参数1'' | ''参数2'' | ''参数3''... <nowiki>}}</nowiki></code> |
||
各函数名都对大小写不敏感。语句中的空格、换行等空白字符将被省略。 |
|||
{{PD Help Page}} |
|||
== #expr == |
== #expr == |
||
{| class="wikitable" style="float: |
{| class="wikitable" style="float:right; width:30%; margin-{{dir|{{pagelang}}|right|left}}:1em" |
||
|- |
|- |
||
! |
! 类型 |
||
! |
! 运算符号 |
||
|- |
|- |
||
| 分组(括弧) |
|||
| style="word-spacing: 0.5em; font-weight: bold;" | <code>( )</code> |
| style="word-spacing: 0.5em; font-weight: bold;" | <code>( )</code> |
||
|- |
|- |
||
| 数字 |
|||
| <code>'''1234.5'''</code> <code>'''e'''</code> (2.718) <code>'''pi'''</code> (3.142) |
| <code>'''1234.5'''</code> <code>'''e'''</code> (2.718) <code>'''pi'''</code> (3.142) |
||
|- |
|- |
||
| |
| | |
||
| 二进制运算符 <code>'''e'''</code> 一元 <code>'''+'''</code>,<code>'''-'''</code> |
| 二进制运算符 <code>'''e'''</code> 一元 <code>'''+'''</code>,<code>'''-'''</code> |
||
|- |
|- |
||
| 一元 |
|||
| style="word-spacing: 0.5em; font-weight: bold;" | <code>not ceil trunc floor abs exp ln sin cos tan acos asin atan</code> |
| style="word-spacing: 0.5em; font-weight: bold;" | <code>not ceil trunc floor abs exp ln sin cos tan acos asin atan</code> |
||
|- |
|- |
||
| |
| rowspan="3" | 二进制 |
||
| style="word-spacing: 0.5em; font-weight: bold;" | <code>^</code> |
| style="word-spacing: 0.5em; font-weight: bold;" | <code>^</code> |
||
|- |
|- |
||
第35行: | 第41行: | ||
| style="word-spacing: 0.5em; font-weight: bold;" | <code>+ -</code> |
| style="word-spacing: 0.5em; font-weight: bold;" | <code>+ -</code> |
||
|- |
|- |
||
| 取整 |
|||
| style="word-spacing: 0.5em; font-weight: bold;" | <code>round</code> |
| style="word-spacing: 0.5em; font-weight: bold;" | <code>round</code> |
||
|- |
|- |
||
| |
| rowspan="3" | 逻辑 |
||
| style="word-spacing: 0.5em; font-weight: bold;" | <code>= != <> > < >= <=</code> |
| style="word-spacing: 0.5em; font-weight: bold;" | <code>= != <> > < >= <=</code> |
||
|- |
|- |
||
第90行: | 第96行: | ||
--> |
--> |
||
}} |
}} |
||
{{ |
{{memo-inline|1=如果你想要进行基于日期时间的计算(如检测当前日期时间是否超过指定日期时间),首先用<nowiki>{{#time: xNU }}</nowiki>将日期时间转换为距1970年1月1日的秒数,再对秒数进行加减运算。}} |
||
<span id="Rounding"></span> |
<span id="Rounding"></span> |
||
第100行: | 第106行: | ||
{| class="wikitable" |
{| class="wikitable" |
||
! |
! 案例 |
||
! |
! 结果 |
||
! |
! 舍入方式 |
||
|- |
|- |
||
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> 1/3 round 5 }}</code> || {{#expr: 1/3 round 5 }} || 最终的数字小于5,所以没有明显的取整发生 (0.333333… → 0.33333) |
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> 1/3 round 5 }}</code> || {{#expr: 1/3 round 5 }} || 最终的数字小于5,所以没有明显的取整发生 (0.333333… → 0.33333) |
||
第118行: | 第124行: | ||
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> '''trunc''' 1234.5678 }}</code> || {{#expr: trunc 1234.567 }} || 小数部分被全部舍弃(截断) |
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> '''trunc''' 1234.5678 }}</code> || {{#expr: trunc 1234.567 }} || 小数部分被全部舍弃(截断) |
||
|- |
|- |
||
! colspan=3 |
! colspan=3 四舍五入至最近的整数 |
||
|- |
|- |
||
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> 1/3 '''round 0''' }}</code> || {{#expr: 1/3 round 0 }} || 向下取整至0 |
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> 1/3 '''round 0''' }}</code> || {{#expr: 1/3 round 0 }} || 向下取整至0 |
||
第132行: | 第138行: | ||
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> -3/4 '''round 0''' }}</code> || {{#expr: -3/4 round 0 }} || 向下取整至-1 |
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> -3/4 '''round 0''' }}</code> || {{#expr: -3/4 round 0 }} || 向下取整至-1 |
||
|- |
|- |
||
! colspan=3 |
! colspan=3 使用ceil和floor向上或向下取整 |
||
|- |
|- |
||
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> '''ceil('''1/3''')''' }}</code> || {{#expr: ceil(1/3) }} || 向上取整至1 |
| <code style="white-space:nowrap;"><nowiki>{{#expr:</nowiki> '''ceil('''1/3''')''' }}</code> || {{#expr: ceil(1/3) }} || 向上取整至1 |
||
第395行: | 第401行: | ||
:<code><nowiki>{{#rel2abs:</nowiki> ../../../../quok | {{ns:12}}:Foo/bar/baz <nowiki>}}</nowiki></code> → '''{{#rel2abs: ../../../../quok | {{ns:12}}:Foo/bar/baz }}''' |
:<code><nowiki>{{#rel2abs:</nowiki> ../../../../quok | {{ns:12}}:Foo/bar/baz <nowiki>}}</nowiki></code> → '''{{#rel2abs: ../../../../quok | {{ns:12}}:Foo/bar/baz }}''' |
||
<span lang="en" dir="ltr" class="mw-content-ltr">For a similar group of functions see also [[ |
<span lang="en" dir="ltr" class="mw-content-ltr">For a similar group of functions see also [[Help:魔术字#URL data|Help:Magic words#URL data]].</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">Built-in parser functions include: 'localurl:', 'fullurl:', 'anchorencode:' etc.</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">Built-in parser functions include: 'localurl:', 'fullurl:', 'anchorencode:' etc.</span> |
||
第623行: | 第629行: | ||
{{Anchor|time|TIME}} |
{{Anchor|time|TIME}} |
||
== #time == |
== #time == |
||
{| class="wikitable plainlinks" style="float: |
{| class="wikitable plainlinks" style="float: right; font-size: 90%; line-height: normal; margin-{{dir|{{pagelang}}|right|left}}: 1em; width: 40%;" |
||
|- |
|- |
||
! |
! 代码 |
||
! |
! 描述 |
||
! |
! 当前输出<br /><small class="noprint">([{{fullurl:Help:Extension:ParserFunctions{{#translation:}}|action=purge}} 刷新此页面的缓存]以更新)</small> |
||
|- |
|- |
||
! |
! colspan="3"| 年 |
||
|- |
|- |
||
| style="text-align: center;" | <code>Y</code> |
| style="text-align: center;" | <code>Y</code> |
||
第649行: | 第655行: | ||
| colspan="3" style="font-size: 88%;" |<references group="note"/> |
| colspan="3" style="font-size: 88%;" |<references group="note"/> |
||
|- |
|- |
||
! |
! colspan="3"| 月 |
||
|- |
|- |
||
| style="text-align: center;" | <code>n</code> |
| style="text-align: center;" | <code>n</code> |
||
第671行: | 第677行: | ||
| style="line-height: 1.6;" | 波兰语:<br /><code style="font-size: 85%;"><nowiki>{{#time:F Y|June 2010|pl}}</nowiki></code> → {{#time:F Y|June 2010|pl}}<br />(主格)<br /><code style="font-size: 85%;"><nowiki>{{#time:d xg Y|20 June 2010|pl}}</nowiki></code> → {{#time:d xg Y|20 June 2010|pl}}<br />(所有格) |
| style="line-height: 1.6;" | 波兰语:<br /><code style="font-size: 85%;"><nowiki>{{#time:F Y|June 2010|pl}}</nowiki></code> → {{#time:F Y|June 2010|pl}}<br />(主格)<br /><code style="font-size: 85%;"><nowiki>{{#time:d xg Y|20 June 2010|pl}}</nowiki></code> → {{#time:d xg Y|20 June 2010|pl}}<br />(所有格) |
||
|- |
|- |
||
! |
! colspan="3"| 一年或一个月内的第几天 |
||
|- |
|- |
||
| style="text-align: center;" | <code>j</code> |
| style="text-align: center;" | <code>j</code> |
||
第685行: | 第691行: | ||
| style="text-align: center;" | {{#time:z}} |
| style="text-align: center;" | {{#time:z}} |
||
|- |
|- |
||
! |
! colspan="3"| 周,以及周内的第几天 |
||
|- |
|- |
||
| style="text-align: center;" | <code>W</code> |
| style="text-align: center;" | <code>W</code> |
||
第707行: | 第713行: | ||
| style="text-align: center;" | {{#time:l}} |
| style="text-align: center;" | {{#time:l}} |
||
|- |
|- |
||
! |
! colspan="3"| 小时 |
||
|- |
|- |
||
| style="text-align: center;" | <code>a</code> |
| style="text-align: center;" | <code>a</code> |
||
第733行: | 第739行: | ||
| style="text-align: center;" | {{#time:H}} |
| style="text-align: center;" | {{#time:H}} |
||
|- |
|- |
||
! |
! colspan="3"| 分钟和秒钟 |
||
|- |
|- |
||
| style="text-align: center;" | <code>i</code> |
| style="text-align: center;" | <code>i</code> |
||
第747行: | 第753行: | ||
| style="text-align: center;" | {{#time:U}} |
| style="text-align: center;" | {{#time:U}} |
||
|- |
|- |
||
! id="TimeZone" |
! id="TimeZone" colspan="3"| 时区(截至[[MediaWiki_1.22/Roadmap|1.22wmf2]]) |
||
|- |
|- |
||
| style="text-align: center;" | <code>e</code> |
| style="text-align: center;" | <code>e</code> |
||
第773行: | 第779行: | ||
| style="text-align: center;" | {{#time:Z}} |
| style="text-align: center;" | {{#time:Z}} |
||
|- |
|- |
||
! |
! colspan="3"| 杂项 |
||
|- |
|- |
||
| style="text-align: center;" | <code>t</code> |
| style="text-align: center;" | <code>t</code> |
||
第787行: | 第793行: | ||
| style="font-size: 75%;" | {{#time:r}} |
| style="font-size: 75%;" | {{#time:r}} |
||
|- |
|- |
||
! |
! colspan="3" | 非公历(格里历)历法 |
||
|- |
|- |
||
! {{hl3}} colspan="3" | 伊斯兰教历法 |
! {{hl3}} colspan="3" | 伊斯兰教历法 |
||
第881行: | 第887行: | ||
| {{#time:xtY}} |
| {{#time:xtY}} |
||
|- |
|- |
||
! |
! colspan="3" | 标记 |
||
|- |
|- |
||
| style="text-align: center;" | <code>xn</code> |
| style="text-align: center;" | <code>xn</code> |
||
第899行: | 第905行: | ||
|} |
|} |
||
该解析器函数接收一个(公历的)日期或者时间,并根据给定的语法将其格式化。可以指定日期/时间对象,默认则为[[ |
该解析器函数接收一个(公历的)日期或者时间,并根据给定的语法将其格式化。可以指定日期/时间对象,默认则为[[Help:魔术字#Date and time|魔术字]]Help:魔术字#Date and time的当前值——也就是说,页面最后被渲染为HTML时的时间。 |
||
:<code><nowiki>{{#time:</nowiki> ''format string'' <nowiki>}}</nowiki></code> |
:<code><nowiki>{{#time:</nowiki> ''format string'' <nowiki>}}</nowiki></code> |
||
第1,015行: | 第1,021行: | ||
}} |
}} |
||
4位數字總是被解讀為年分,而不是小時和分鐘: |
4位數字總是被解讀為年分,而不是小時和分鐘: |
||
:<syntaxhighlight lang="moin" inline>{{#time: Y m d H:i:s | 1959 }}</syntaxhighlight> → '''{{#time: Y m d H:i:s | 1959 }}''' |
:<syntaxhighlight lang="moin" inline>{{#time: Y m d H:i:s | 1959 }}</syntaxhighlight> → '''{{#time: Y m d H:i:s | 1959 }}''' |
||
第1,120行: | 第1,126行: | ||
: 不会执行从HTML到纯文本的其他转换,因此即使HTML标签在页面标题中无效,在此初始步骤中也会保持不变。 |
: 不会执行从HTML到纯文本的其他转换,因此即使HTML标签在页面标题中无效,在此初始步骤中也会保持不变。 |
||
{{ |
{{memo-inline| 1= |
||
MediaWiki的一些魔术字或解析器函数(例如<code><nowiki>{{</nowiki>PAGENAME<nowiki>}}</nowiki></code>和类似)会返回用多余的HTML编码的字符串,即使其自身的输入参数不是HTML编码的: |
MediaWiki的一些魔术字或解析器函数(例如<code><nowiki>{{</nowiki>PAGENAME<nowiki>}}</nowiki></code>和类似)会返回用多余的HTML编码的字符串,即使其自身的输入参数不是HTML编码的: |
||
第1,267行: | 第1,273行: | ||
如果没有找到''搜索词'',函数返回-1。 |
如果没有找到''搜索词'',函数返回-1。 |
||
{{ |
{{memo-inline|1=使用该函数搜索最后一个分隔符时,给结果添加+1以检索最后一个分隔符之后的位置。 这在找不到分隔符时也有效,因为“-1 + 1”为零,也就是指定值的开头。}} |
||
{{note|1=<nowiki/> |
{{note|1=<nowiki/> |