跳转到内容

维基专题:用戶警告/Help:模板代碼

维基百科,自由的百科全书

这是本页的一个历史版本,由チルノ留言 | 贡献2018年10月30日 (二) 09:58 (填坑、水编辑)编辑。这可能和当前版本存在着巨大的差异。

本頁面是用戶警告專題文件的一部分。

一般設計指引

严重级别

每个模板系列包含了四个代表着递增的严重性的模板,指明了从友善到严厉的语气。这并没有明确指出时间上的先后顺序,一个用户可以简单地根据其所认为的严重程度选择一个级别。例如,测试的模板系列为:测试1、测试2、测试3、测试4。

  1. 假设该用户不怀恶意:礼貌地指导他去使用沙盒编辑和/或阅读相关的帮助和方针页面,以表示欢迎;
  2. 无法假设用户完全可信任:礼貌地请求其停止破坏并提及后果,引导他去沙盒编辑;
  3. 假设用户有着自欺的念头:严厉制止并打消其念头;
  4. 假设用户存在主观恶意:强行制止并打消其念头,最后的警告。

Civility

Regardless of the severity level of the template, the user warning should be a model of civility (even for the most destructive vandal). Remember than when you use a warning template, you do so in Wikipedia's name. See Please do not bite the newcomers, Civility, and Etiquette.

Derivatives

No derivative template (a non-standard variant of a template under a new name) should be included in the list of standardized templates or mentioned in the documentation. Although users are free to create and use non-standard templates, these should not be recognized by the project.

Template coding guidelines

Categorization

Template page

User warning templates should be categorized to Category:User warning templates (if the template is a redirect page to another template, it should be categorized using the sort key "Redirect"). User block templates should be categorized to Category:User block templates, with the sort key "Temporary" or "Indefinite" as appropriate. The category tag should be on the template page within noinclude syntax.

<noinclude>
[[Category:User warning templates]]
[[Category:User block templates|Indefinite]]
</noinclude>

User talk page

Any template that places pages it's used on into a category should surround the category tags with the category parameter. If the template uses <noinclude> tags, be careful to place the parameter inside these tags. This allows the use of the template on a page (such as a talk or list page) without adding that page to a category by using the template with no value specified for the category parameter: {{template|category=}}.

<includeonly>{{category|[[Category:User block templates|Temporary]]}}</noinclude>

Parameters

Default values

Nearly every parameter should have a default value, such that misuse does not break the template. You can set the default value of a parameter by using piped syntax ({{{1|default value}}}). For example, the template below takes a parameter which expects the user to supply the proper pronoun.

{{{1|He or she}}} is cool.

Supplied the pronoun with {{template|He}}, the template will expand to "He is cool". Ignoring the parameter with {{template}}, the template will default the value and expand to "He or she is cool".

Named syntax

When a template's parameters might be given symbols that break templates (notably the '|' pipe symbol and '=' equals sign), a named syntax should allow these. In such cases, a named and unnamed can coexist as needed. For example, a wikilink template can assign both a name and a number to a parameter by 'nesting' them (placing parameters in other parameters' default values).

[[{{{link|{{{1|{{{default value}}}}}}]]

Using {{template|article}} is straightforward enough, and will expand to [[article]]. However, some symbols will break the template if used like that. These require the named syntax: {{template|link=article|name}}, which will expand to [[article|name]].

Nested substitution

Any template containing templates, magic variables, or ParserFunctions should include an optional "subst" parameter at the appropriate location for a subst: modifier. This allows users to easily substitute a template and all nested templates. For example, consider the following template code:

This is {{{{{subst|}}}CURRENTYEAR}}.

Attempting to substitute the template using {{subst:template}} will output "This is {{CURRENTYEAR}}", leaving the nested code unsubstituted. Using the substitution parameter ({{subst:template|subst=subst:}}), the template outputs "This is 2025".

Block template CSS

Wikipedia allows registered users to maintain a personal stylesheet located at user:username/skin.css, where 'username' is the username and 'skin' is the name of the skin in use (usually monobook). To help users take full advantage of this feature, block templates should be enclosed in a CSS container with the "user-block" class.

<div class="user-block">template message</div>

Should the user wish to, they can customize the appearance of all block templates by adding CSS to their user stylesheet. For example, the following code adds a dark red background with white text.

* .user-block { background:#C00; color:#FFF; }

Compatibility with lists

All user warning and block templates should be natively compatible with lists. For optimal intervention efficiency, talk pages with numerous warnings are sometimes organized into formatted lists sectioned by date (see the guidelines). Due to the way Wikipedia parses wiki syntax into HTML, list items are closed at any newline.

Templates with newlines will break any list they are placed in: the first paragraph will be in the list, the others out, and any subsequent templates in the list will begin a new list. By using HTML paragraph syntax directly, Wikipedia's paragraph parsing is circumvented and multiple-paragraph templates can then be added to organized warning lists without problem.

<p>Paragraph 1.</p><p>Paragraph 2.</p><p>Paragraph 3.</p>

To prevent the problem with newlines, templates must be on a single code line; however, this is highly illegible to humans in edit view. To restore legibility, HTML comments can be inserted to emulate the appearance of newlines. Although this looks ungainly with two-term lines, the comments are much less bulky when used with more realistic paragraphs.

<p>Paragraph 1.</p><!--
--><p>Paragraph 2.</p><!--
--><p>Paragraph 3.</p>