模板:When pagename is/doc

来自About High Performance
Sxzhang讨论 | 贡献2023年11月7日 (二) 16:50的版本 (导入1个版本)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索

Lua错误:无法创建进程:proc_open(/dev/null): failed to open stream: Operation not permitted

This is the {{When pagename is}} meta-template. It helps other templates detect what page they are on, using pattern matching on the pagename.

Usage

This template takes one or more parameters. Most of the parameters don't have fixed names, instead they are part of the pattern matching. Like this: <syntaxhighlight lang="wikitext"> Doc page text </syntaxhighlight>

If the template is on "Template:Example/doc" the code above will return this:

Doc page text

If the template is on any other page than a /doc page it will return this:

Other pages text

Here is a description of the full pattern matching: <syntaxhighlight lang="wikitext"> Any pagename that ends in "/doc". </syntaxhighlight>

The matching goes from top to bottom, and returns the first parameter that matches. "Top to bottom" means the order shown above, not the order you happen to feed the parameters.

There's no limit to the number of parameters that you can use, other than what the servers and MediaWiki system can handle.

Most of the matching is case-sensitive. For instance "/test" matches "User:Example/test" but not "User:Example/Test".

Matching on partial subpage names such as "/some*" has some limitations, see its own section below.

If an empty (but defined) parameter matches, the matching stops and the template returns an empty string. That's on purpose and can be used like this: <syntaxhighlight lang="wikitext">

</syntaxhighlight>

The code above will render nothing when on a /doc page. But when on a /sandbox page it will return this:

Sandbox text

And when on any other page it will return this:

Other pages text

Partial subpage names

This template can also match on partial subpage names. Like this: <syntaxhighlight lang="wikitext"> Other pages text </syntaxhighlight>

If on "User:Example/Archive 1" the code above will return this:

Archive page text

The parameter name "/some*" must be lower case. But it matches subpage names in both upper and lower case such as "User:Example/SomeThing" and "User:Example/something".

The partial matching only supports matching on 4, 6 and 8 characters. Thus using "/some*", "/someth*" and "/somethin*" works, but using "/som*" or "/somet*" doesn't work.

Longer patterns match first, thus if both "/somethin*" and "/some*" are defined, and the current page is "User:Example/Something", then the data from "/somethin*" will be used.

"page" parameter

For testing and demonstration purposes this template can take a parameter named page. Like this: <syntaxhighlight lang="wikitext"> Test pages text </syntaxhighlight>

No matter on what kind of page the code above is used it will return this:

Test pages text

The page parameter makes this template behave exactly as if on that page. The pagename doesn't have to be an existing page.

If the page parameter is empty or undefined, the name of the current page determines the result.

You can make it so your template also understands the page parameter. That means you can demonstrate the different appearances of your template in the documentation for your template. Then do like this: <syntaxhighlight lang="wikitext"> Other pages text </syntaxhighlight>

Namespace matching

This template doesn't have namespace matching. If you need that then combine this template with one of the namespace-detection templates such as {{When on template page}}. Like this: <syntaxhighlight lang="wikitext"> Template doc page text. </syntaxhighlight>

If on "User:Example/doc" the code above will return nothing. But if on "Template:Example/doc" it will return this:

Template doc page text.

Technical details

This template detects subpages even when used in namespaces that don't have the MediaWiki subpage feature enabled. Thus this template works the same in all namespaces.

For more technical details, see the talk page.

Lua错误:无法创建进程:proc_open(/dev/null): failed to open stream: Operation not permitted