Wikipedia:WikiProject User warnings/Help:Template coding
Wikipedia:WikiProject User warnings/t/documentation-header
General design guidelines
- Severity levels
- Every Wikipedia:WikiProject User warnings/t/glossary has a Wikipedia:WikiProject User warnings/t/glossary of four Wikipedia:WikiProject User warnings/t/glossary of increasing severity, designating a tone ranging from kindly to stern. Note that these don't necessarily designate a chronological order; a user may simply use a level of his choice based on the severity desired. For example, the test family is test0, test1, test2, test3.
- 0. Assumes Wikipedia:WikiProject User warnings/t/glossary; welcome with polite pointer to sandbox and/or to relevant help and policy pages.
- No faith assumption; pointer to sandbox with polite request to stop and mention of consequences.
- Assumes Wikipedia:WikiProject User warnings/t/glossary; stern cease and desist.
- Assumes bad faith; strong cease and desist, last warning.
- Every Wikipedia:WikiProject User warnings/t/glossary has a Wikipedia:WikiProject User warnings/t/glossary of four Wikipedia:WikiProject User warnings/t/glossary of increasing severity, designating a tone ranging from kindly to stern. Note that these don't necessarily designate a chronological order; a user may simply use a level of his choice based on the severity desired. For example, the test family is test0, test1, test2, test3.
- 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 template should ever have Wikipedia:WikiProject User warnings/t/glossary.
Template coding guidelines
Categorisation
- User warning templates
- User warning templates should be categorised to Category:User warning templates. If the template is a redirect page to another template, it should be categorised using the sort key "Redirect". The category tag should be on the template page within noinclude syntax. <noinclude>[[Category:User warning templates]]</noinclude>
<noinclude>[[Category:User warning templates|Redirect]]</noinclude>
- User warning templates should be categorised to Category:User warning templates. If the template is a redirect page to another template, it should be categorised using the sort key "Redirect". The category tag should be on the template page within noinclude syntax.
- User block templates
- User block templates should be categorised 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 block templates|Temporary]]</noinclude>
<noinclude>[[Category:User block templates|Indefinite]]</noinclude>
- User block templates should be categorised 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.
Parameters
- Default values
Nearly all parameters should have a default value, such that misuse does not break the template; exceptions can be made for extra parameters. 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 (she, he, it, they, et cetera).{{{1|They}}} are cool.Supplied the pronoun with{{template|He}}
, the template will expand to "He are cool" (grammar aside). Ignoring the parameter with{{template}}
, the template will default the value and expand to "They are cool".
- Expert syntax
Where use could conceivably include symbols that break templates (notably the pipe (|) and equals sign (=)), an Wikipedia:WikiProject User warnings/t/glossary should allow these. In such cases, an expert syntax and simple syntax can coexist as needed. For example, let us say we want to make a wikilink template.
[[{{{1}}}]]Using
{{template|article}}
is straightforward enough, and will expand to[[article]]
. A problem arises if the user tries to use certain symbols; for example, using{{template|article|name}}
will not output[[article|name]]
, because the pipe symbol is part of the parameter Wikipedia:WikiProject User warnings/t/glossary. In cases where a user might conceivably want to use the template like this, the template can be modified to use expert syntax instead.[[{{{link}}}]]The template now uses a named parameter to get the user's input. Using
{{template|link=article|name}}
will now output[[article|name]]
, as long as the named parameter is specified after any unnamed parameter. However, it's not at all a one-or-the-other proposition; it's possible to allow both named and unnamed parameters at once. Using the same example, the below template will accept the simple syntax on all parameters except those for which the expert syntax is used.[[{{{link|{{{1}}}}}}]]Although this may look complex, it's relatively simple. The named parameter uses the unnamed parameter as the default value, such that if the expert syntax isn't used the simple syntax is. The unnamed parameter can be given a default value of it's own, which will be used if neither syntaxes are used.
[[{{{link|{{{1|Main_page}}}}}}]]The above template used as
{{template}}
,{{template|article}}
, and{{template|link=article|name}}
will respectively output as[[Main_page]]
,[[article]]
, and[[article|name]]
.
Newlines and paragraphs
- Compatibility with lists
All user warning templates should be natively compatible with lists. For optimal intervention efficiency, talk pages with numerous warnings are sometimes organised into formatted lists sectioned by date. Due to the way Wikipedia parses wikisyntax into HTML, list items are closed at any newline. Due to this, many templates 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 at 1. By using HTML paragraph syntax directly, Wikipedia's paragraph parsing is circumvented and multiple-paragraph templates can then be added to organised 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 codeline; however, this is highly illegible to humans in edit view. To restore legibility, HTML comments can be inserted to emulate the appearance of wikisyntax paragraphs. Although this looks ungainly with two-term paragraphs, the comments are much less bulky when used with more realistic paragraphs.
<p>Paragraph 1.</p><!--
--><p>Paragraph 2.</p><!--
--><p>Paragraph 3.</p>
Specific to block templates
- CSS style
- 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 box with the user-block class.<div class="user-block">template message</div>
Should the user wish to, he can customise the appearance of all block templates by adding CSS to his user stylesheet. For example, the following code adds a dark red background with white text.
* .user-block { background:#C00; color:#FFF; }
- 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 box with the user-block class.