跳转到内容

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

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

这是本页的一个历史版本,由チルノ留言 | 贡献2018年11月1日 (四) 08:10编辑。这可能和当前版本存在着巨大的差异。

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

一般設計指引

严重级别

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

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

文明

不考虑模板的严重级别的话,对其他用户进行警告时应该严守文明(即使是对于最具危害性的破坏)。记住,当你使用一个警告模板的时候,你是以维基百科的名义这样做的。参见Wikipedia:不要伤害新手Wikipedia:文明Wikipedia:礼仪

衍生模板

模板的派生版本(以新的名义出现的一个模板的一个不遵循标准的变种)不应该被包含在规范化模板的列表里或者在文档内被提及。尽管用户可以自由地创建、使用不遵循标准的模板,这类模板仍不应当为该专题所承认。

模板代码编写指引

模板分类

模板页面

用户警告模板应当被归类到Category:用户警告模板中,如果某一模板是到另一个模板的重定向页面,则应当通过分类关键词“重定向”被归类。用户封禁模板应当被分类到Category:封禁模板中,其分类关键词则视情况定为“暂时”或“无限期”。分类标签应当以noinclude语法标记到模板页面上。

<noinclude>
[[Category:用户警告模板]]
[[Category:封禁模板|无限期]]
</noinclude>

用户讨论页

任何将它被应用到的页面添加进一个分类的模板,都应当用分类参数前后包围住分类标签。如果模板使用<noinclude>标签,请注意将参数放置在此标签的里面。这使得在一个页面(例如讨论页面或列表页面)上使用模板时,不必通过加入未指定的分类参数值({{template|category=}})来添加该页面到一个分类里。

<includeonly>{{category|[[Category:封禁模板|无限期]]}}</noinclude>

模板参数

默认值

几乎每一个模板都有一个默认值,这样,错误使用模板时,不会使模板效果大打折扣。你可以通过使用管道语法({{{1|default value}}})来设置一个参数的默认值。例如,下面的模板采用了一个希望用户提供正确的代词的参数:

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

使用{{template|He}}来提供代词时,模板将会变成"He is cool";使用{{template}}忽略掉参数的话,模板将会显示默认值并变成 "He or she is cool"。

被命名的语法

当一个模板的参数可能会被加入能够破坏模板的符号(尤其是“|”管道符号和“=”等号)时,一个被命名的语法能够阻止这种情况的发生。这种情况下,被命名的和未被命名的语法是可以依需要共存的。例如,一个Wikilink模板可以通过给它们“安家”(将参数放在其他参数的默认值中)的方法同时指定一个名字和一个数字到参数当中:

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

使用{{template|article}}足够容易理解,并且会变成[[article]]。但是,一些符号如果这么用的话会破坏掉模板。这种情况下,需要被命名的语法:{{template|link=article|name}},这样子会变成 [[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>