这个问题与MediaWiki语法及其模板和解析器函数的不一致行为有关。
当直接放置在Wiki页面中时,这两个片段都可以按预期工作:
{{#ifeq:{{{1|}}}|{{{2}}}|{{{1}}}}}
第
{{#ifeq:{{{1|{{FULLPAGENAME}}}}}|{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}:{{ROOTPAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{{1|{{FULLPAGENAME}}}}}}}
一个片段很简单。第二个输出页面的全名,但前提是它不是子页面。
但是,当每个片段都放在模板中时,假设模板中的第一个:iSequal ,第二个是模板中的第二个:iSrootPage 页面,例如每个输出是#if测试的主题,第一个继续按预期行为,而第二个始终产生#if语句的 string而不是空的部分。
so:
{{#if:{{iSequal | a | b}} |等于|不等式}}
将输出“不等式”
,而:
{#{#{{isRootPage}}}} | root | non-root}}}
将始终输出“ root”,即使放置在子页面中,或者将非上页的名称作为参数传递给模板:iSrootpage:iSrootpage,驱动模板以返回模板没有什么。
根据
此功能评估一个测试字符串并确定是否
是空的。仅包含空白的测试字符串被认为
为空。
此外,即使在#IFEQ测试失败时返回空字符串的iSrootPage的不一致行为仍然存在:通过将第四个空参数引入模板中的#ifeq,即通过添加第三|来返回空字符串。其次是一无所有/空间。
似乎在模板的输出和#if解析器函数之间发生了一些事情。
对这种行为差异有已知的解释吗?
是否有一些语法黑客可以按预期工作?
还是我错过了一些明显的东西?
编辑:在Mediawiki 1.35.5中见证了此行为
This question pertains to the inconsistent behaviour of Mediawiki syntax and its templates and parser functions.
When placed directly in a wiki page, both these snippets work as expected:
{{#ifeq:{{{1|}}}|{{{2}}}|{{{1}}}}}
and
{{#ifeq:{{{1|{{FULLPAGENAME}}}}}|{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}:{{ROOTPAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{{1|{{FULLPAGENAME}}}}}}}
The first snippet is simple. The second outputs the full name of the page, but only if it is not a sub-page.
However, when each snippet is placed in a template, let's say the first in Template:IsEqual, and the second in Template:IsRootPage, both of which are then included in some page, such as the output of each is the subject of an #if test, the first continues to behave as expected, while the second always yields the string not empty section of the #if statement.
So:
{{#if:{{IsEqual|A|B}}|equal|unequal}}
will output "unequal"
while:
{{#if:{{IsRootPage}}|root|non-root}}
will always output "root", even if placed in a subpage or if the name of a non-top-page is passed as a parameter to Template:IsRootPage, driving the template to return nothing.
According to the documentation of #if:
This function evaluates a test string and determines whether or not it
is empty. A test string containing only white space is considered to
be empty.
Moreover, the inconsistent behaviour persists for Template:IsRootPage even when it is amended to return an empty string when the #ifeq test fails, by introducing a fourth empty parameter to the #ifeq in the template, i.e by adding a third | followed by nothing/space.
It seems that something happens in between the output of the template and the #if parser function.
Is there a known explanation for this discrepancy in behaviour?
Is there some syntax hack to make it work as expected?
Or am I missing something that's otherwise obvious?
Edit: This behaviour is witnessed in Mediawiki 1.35.5
发布评论
评论(1)
您的示例模板页面具有子页面时不会返回空字符串。它返回
< nowiki/>
{{#if:< nowiki/> | yes | yes | nove}}}
正确返回是
yes 。如果您删除
< nowiki/>
,则将获得所需的行为。Your sample template does not return an empty string when the page has sub pages. It returns
<nowiki/>
for which{{#if:<nowiki/>|yes|no}}
properly returnsyes
.If you remove the
<nowiki/>
, you'll get the behavior you want.