Template:Mbox/doc: Difference between revisions

From OIAr
Jump to navigation Jump to search
(→‎Demospace: remove wikipedia refs)
(redo template)
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
{{mbox templates}}
This is the {{tlx|mbox}} or '''message box''' meta-template.
This is the {{tlx|mbox}} or '''multi namespace message box''' meta-template.


This meta-template is used to build message box templates that are used on several types of pages and thus need to change style depending on what page they are used on. Based on page type detected it uses one of
It is used to build ''message box'' templates such as {{tlx|security risk}}. It offers several different colours, uses default images if no image parameter is given and it has some other features.
{{tlx|ambox}}, {{tlx|tmbox}}, {{tlx|imbox}}, {{tlx|cmbox}} and {{tlx|ombox}}.


Note that this template should only be used for message boxes that really need to adapt their style. Most message boxes do not need this and should use one of {{tlx|ambox}}, {{tlx|tmbox}}, {{tlx|imbox}}, {{tlx|cmbox}} or {{tlx|ombox}} directly. Using those templates directly means that your template will look the same on its template page and at any other place you show it, which makes it clear on what kind of pages it is supposed to be used. It also gives you access to any extra features those templates offer, and it saves some server load.
This meta-template uses the mbox CSS classes in [[MediaWiki:Common.css]]. The classes can also be used directly in a [http://www.mediawiki.org/wiki/Help:Table wikitable] if special functionality is needed. See the [http://en.wikipedia.org/wiki/Wikipedia:Ambox_CSS_classes how-to guide] for that.


=== Usage ===
=== Usage ===
This template takes the same parameters as {{tlx|ambox}} and {{tlx|imbox}} etc. See full documentation there.


Some of the boxes this template calls only handles images of max 52px width, thus that limitation also applies to this template or you will get ugly padding problems.
Simple usage example:


=== Demospace ===
<pre>
This template optionally takes the "demospace" parameter as described at {{tlx|namespace detect}}. That parameter is only for testing and demonstration purposes. If you want to lock your message box to one style then instead use one of the other mboxes directly.
{{mbox | text = Some text.}}
</pre>
 
{{mbox | text = Some text. bla.}}
Complex example:
 
<pre>
{{mbox
| type      = style
| small      = left
| image      = [[File:Emblem-question-yellow.svg|40px|alt=Question mark]]
| smallimage = [[File:Emblem-question-yellow.svg|20px|alt=Question mark]]
| textstyle  = color: red; font-weight: bold; font-style: italic;
| text      = Text for a big box, for the top of articles.
| smalltext  = Text for the top of article sections.
}}
</pre>
 
{{mbox
| type      = style
| small      = left
| image      = [[File:Emblem-question-yellow.svg|40px|alt=Question mark]]
| smallimage = [[File:Emblem-question-yellow.svg|20px|alt=Question mark]]
| textstyle  = color: red; font-weight: bold; font-style: italic;
| text      = Text for a big box, for the top of articles.
| smalltext  = Text for the top of article sections.
}}
 
But you are not really supposed to use red bold italic text.
 
=== Message box types ===
 
The following examples use different '''type''' parameters but use no image parameters thus they use the default images for each type.
 
{{mbox
| type  = critical
| text  = type=<u>critical</u> – Urgent warnings, such as {{tlx|XSS alert}}.
}}
{{mbox
| type  = important
| text  = type=<u>important</u> – Serious problems, such as {{tl|delete}}.
}}
{{mbox
| type  = warning
| text  = type=<u>warning</u> – Other problems, such as {{tl|deprecated}}.
}}
{{mbox
| type  = caution
| text  = type=<u>caution</u> – Points of concern, but not so serious, such as {{tl|description missing}} and {{tl|inuse}}.
}}
{{mbox
| type  = notice
| text  = type=<u>notice</u> – Points of information, such as {{tl|oldupgradenotes}}.
}}
{{mbox
| type  =
| text  = type=<u>(blank)</u> – Default; general 'box'.
}}
{{mbox
| type  = move
| text  = type=<u>move</u> – Merge, split and transwiki proposals, such as {{tl|move}} and {{tl|MoveToCommons}}.
}}
{{mbox
| type  = protection
| text  = type=<u>protection</u> – Protection notices..
}}
{{mbox
| type  = license
| text  = type=<u>license</u> – License notices, such as {{tl|Free screenshot}}
}}
 
=== Other images ===
 
The default images shown above are mostly for convenience. In many cases it is more appropriate to use more specific images. These examples use the '''image''' parameter to specify an image other than the default images.
 
{{mbox
| type  = warning
| image = [[File:Unbalanced scales.svg|40px|link=|alt=]]
| text  = type = content <br> image = <nowiki>[[File:Unbalanced scales.svg|40px|link=|alt=]]</nowiki> <br> This image is often used for {{tl|POV}} and similar issues.
}}
{{mbox
| type  = notice
| image = [[File:Wikitext.svg|50px|link=|alt=]]
| text  = type = style <br> image = <nowiki>[[File:Wikitext.svg|50px|link=|alt=]]</nowiki> <br> This image is often used for {{tl|wikify}} etc.
}}
{{mbox
| type  = move
| image = [[File:Merge-arrows.svg|50px|link=|alt=]]
| text  = type = move <br> image = <nowiki>[[File:Merge-arrows.svg|50px|link=|alt=]]</nowiki> <br> This image is used for {{tl|merge}} etc.
}}
 
=== More examples ===
 
Some other parameter combinations.
 
{{mbox
| text  = No type and no image given ('''default''')
}}
{{mbox
| image = none
| text  = No type and '''image=none''' – No image is used and the '''text''' uses the whole message box area.
}}
 
{{mbox
| image = [[File:Gnome globe current event.svg|42px|alt=Clock over a larger globe]]
| imageright = [[File:Nuvola apps bookcase.svg|40px|alt=Three stacked books]]
| text  = image = <nowiki>[[File:Gnome globe current event.svg|42px|alt=Clock over a larger globe]]</nowiki> <br> imageright = <nowiki>[[File:Nuvola apps bookcase.svg|40px|alt=Three stacked books]]</nowiki>
}}
 
{{mbox
| image = [[File:Gnome globe current event.svg|42px|alt=Clock over a larger globe]]
| imageright = [[File:Shuttle.svg|20px|link=|alt=]]
| text  = '''This article or section documents a current [[spaceflight]].'''
<br>Content may change as the mission progresses.
}}


=== Parameters ===
=== Parameters ===
List of all parameters:
List of all parameters:


<pre>
<pre>
{{mbox
{{mbox
| demospace = {{{demospace|}}} / main / talk / file / category / other
| type  = critical / serious / warning / notice / / move / protection
| type  = speedy / delete / content / style / notice / move / protection
| image = none / [[File:...|40px|...]]
| image = none / [[Image:Some image.svg|40px]]
| imagewidth = width of image section / default is 52px
| imageright = [[Image:Some image.svg|40px]]
| imageright = [[File:...|40px|...]]
| imagerightwidth = width of right image section / default is 52px
| style = CSS values
| style = CSS values
| textstyle = CSS values
| textstyle = CSS values
| text  = The message body text.  
| text  = The message body text.
| small = {{{small|}}} / left / yes
| small = {{{small|}}} / left
| smallimage = none / [[Image:Some image.svg|30px]]
| smallimage = none / [[File:...|20px|...]]
| smallimageright = none / [[Image:Some image.svg|30px]]
| smallimageright = none / [[File:...|20px|...]]
| smalltext  = A shorter message body text.
| smalltext  = A shorter message body text.
}}
}}
</pre>
</pre>


Note: The small parameters only have effect when the template is on an article, talk page or an "other" page. For documentation on the small parameters see {{tlx|ambox}}, {{tlx|tmbox}} and {{tlx|ombox}}. Using the small parameters when they are not valid has no effect, but also does no harm.
'''type'''
:If no '''type''' parameter is given the template has a 'blank' style.
 
'''image'''
:'''No parameter''' = If no '''image''' parameter is given the template uses a default image. Which default image it uses depends on the '''type''' parameter.
:'''An image''' = Should be an image with usual wiki notation. Widths of 40px - 50px are usually about right. (Images over 52 pixels wide will cause padding problems, unless you also set imagewidth.)
:: Often an icon is [[Wikipedia:Alternative text for images #Purely decorative images|purely decorative]] in the W3C sense that it repeats the text. To improve [[Wikipedia:Accessibility|accessibility]], it is desirable to not have it be announced by [[screen reader]]s, as well as to avoid it linking to an irrelevant page. If (and only if) the image license allows this, it can be marked with "{{para|link}}{{para|alt}}". For example:
:::<code><nowiki>image = [[File:Unbalanced scales.svg|40px|link=|alt=]]</nowiki></code>
:: Conversely, an icon that does not use "{{para|link}}{{para|alt}}", and which therefore is announced to visually impaired readers, should use an "{{para|alt|<var>[[Wikipedia:Alternative text for images|alt text]]</var>}}" parameter that describes the icon. With no {{para|link}} parameter (using the default link), the alt text should describe the icon's visual appearance. For example:
:::<code><nowiki>image = [[File:Gnome globe current event.svg|40px|alt=Clock over a larger globe]]</nowiki></code>
:: With a nonempty "{{para|link|<var>Page</var>}}" the alt text should describe the icon's function. For example:
:::<code><nowiki>image = [[File:Purple question mark.svg|40px|link=Special:Random|alt=Random article]]</nowiki></code>
:: An icon whose license requires attribution may have alt text, but ''must keep the default link''. Although public domain images do not require a link, many licenses do require one. Please see ''[[Wikipedia:Alternative text for images #Purely decorative images|Purely decorative images]]'' for more information about licensing.
:'''none''' = Means that no image is used.
:<s>'''blank'''</s> = This parameter is now deprecated. If you see it in use, change it to "image=none".
 
'''imagewidth'''
:Optional [[w:Cascading Style Sheets|CSS]] value used to set width of image's div section.  Allowing you to use images wider than the default 52px wide.
:'''Example'''
:: <code>imagewidth=100px</code>
 
'''imageright'''
:'''No parameter''' = If no '''imageright''' parameter is given then no image is shown on the right side.
:'''An image''' = Should be an image with usual wiki notation. 40px - 50px width are usually about right depending on the image height to width ratio. (Images over 52 pixels width will cause padding problems, unless you also set imagerightwidth.) For example:
::<code><nowiki>imageright = [[File:Nuvola apps bookcase.png|40px|alt=Three stacked books]]</nowiki></code>
:'''Anything''' = Any other object that you want to show on the right side.
 
'''imagerightwidth'''
:Optional [[w:Cascading Style Sheets|CSS]] value used to set width of image's div section.  Allowing you to use images wider than the default 52px wide.
:'''Example'''
:: <code>imagerightwidth=100px</code>
 
'''style'''
:Optional [[Cascading Style Sheets|CSS]] values used by the entire message box table. Without quotation marks <code>" "</code> but with the ending semicolons <code>;</code>. For example:
::<code>style = margin-bottom: 0.5em;</code>
 
'''textstyle'''
:Optional [[Cascading Style Sheets|CSS]] values used by the text cell. For example:
::<code>textstyle = text-align: center;</code>
 
'''text'''
:The message body text.
 
==== The small parameters ====
 
The small article message boxes are meant for the top of sections. Normally they should only contain one or two lines of text.
 
'''small'''
:'''left''' = Makes it a smaller left aligned message box. This also makes the default images smaller. Note that any data fed to the '''smallimage''', '''smallimageright''' and '''smalltext''' parameters is only used if "small=left". To make it so your template also understands the small parameter you can use this code:
::<code><nowiki>small = {{{small|}}}</nowiki></code>
{{mbox
| small = left
| text = small = left
}}
{{mbox
| type = style
| small = left
| text = type = style <br> small = left
}}
 
'''smallimage'''
:'''No parameter''' = If no '''smallimage''' parameter is given then this template falls back to use the '''image''' parameter. If the '''image''' parameter also is empty then a small default image is used.
:'''An image''' = Should be an image with usual wiki notation. 20px width is usually about right for boxes with one line of text, while 25px width is usually about right for boxes with two lines of text. For example:
::<code><nowiki>smallimage = [[File:Gnome globe current event.svg|20px|alt=Clock over a larger globe]]</nowiki></code>
:'''none''' = Means that no image is used. This overrides any image fed to '''image''', when "small=left".
{{mbox
| small = left
| image      = [[File:Replacement filing cabinet.svg|50px|link=|alt=]]
| smallimage = [[File:Replacement filing cabinet.svg|25px|link=|alt=]]
| text =
small = left <br> image = <nowiki>[[File:Replacement filing cabinet.svg|50px|link=|alt=]]</nowiki> <br> smallimage = <nowiki>[[File:Replacement filing cabinet.svg|25px|link=|alt=]]</nowiki>
}}
 
'''smallimageright'''
:'''No parameter''' = If no '''smallimageright''' parameter is given then this template falls back to use the '''imageright''' parameter. If the '''imageright''' parameter also is empty then no image is shown on the right side.
:'''An image''' = Should be an image with usual wiki notation. 20px - 25px width is usually about right. For example:
::<code><nowiki>smallimageright = [[File:Nuvola apps bookcase.png|20px|alt=Three stacked books]]</nowiki></code>
:'''Anything''' = Any other object that you want to show on the right side.
:'''none''' = Means that no right side image is used. This overrides any image fed to '''imageright''', when "small=left".
{{mbox
| small = left
| imageright = [[File:Gnome globe current event.svg|50px|alt=Clock over a larger globe]]
| smallimageright = none
| text =
small = left <br> imageright = <nowiki>[[File:Gnome globe current event.svg|50px|alt=Clock over a larger globe]]</nowiki> <br> smallimageright = none
}}
 
'''smalltext'''
:A shorter version of the message body text. If no '''smalltext''' parameter is given then this template falls back to use the '''text''' parameter.
 
=== Technical details ===
 
If you need to use special characters in the text parameter then you need to escape them like this:
 
<pre>
{{mbox
| text  = <div>
Equal sign = and a start and end brace { } work fine as they are.
But here is a pipe &amp;#124; and two end braces &lt;nowiki>}}&lt;/nowiki>.
And now a pipe and end braces &lt;nowiki>|}}&lt;/nowiki>.
</div>
}}
</pre>
 
{{mbox
| text  = <div>
Equal sign = and a start and end brace { } work fine as they are.
But here is a pipe &#124; and two end braces <nowiki>}}</nowiki>.
And now a pipe and end braces <nowiki>|}}</nowiki>.
</div>
}}
 
The <code>&lt;div></code> tags that surround the text in the example above are usually not needed. But if the text contains line breaks then sometimes we get weird line spacing. This especially happens when using vertical dotted lists. Then use the div tags to fix that.
 
This template uses CSS classes in [[MediaWiki:Common.css]] for most of its looks, thus it is fully skinnable.
 
This template calls {{tlx|mbox/core}} which holds most of the code for {{tlx|mbox}}, while {{tlx|mbox}} itself does parameter preprocessing.


=== See also ===
Internally this meta-template uses HTML wikimarkup instead of wikimarkup for the table code. That is the usual way we make meta-templates since wikimarkup has several drawbacks. For instance it makes it harder to use [[m:Help:ParserFunctions|parser functions]] and some special characters in parameters.
{{Mbox templates see also}}


{{mbox template family}}
The default images for this meta-template are in png format instead of svg format. The main reason is that some older web browsers have trouble with the transparent background that MediaWiki renders for svg images. The png images here have hand optimised transparent background colour so they look good in all browsers. Note that svg icons only look somewhat bad in the old browsers, thus such hand optimisation is only worth the trouble for very widely used icons.


<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||
<includeonly>
[[Category:Mbox templates]]
<!-- CATEGORIES AND INTERWIKIS HERE, THANKS -->
<!-- CATEGORIES AND INTERWIKIS HERE, THANKS -->
[[Category:Mbox templates|{{PAGENAME}}]]
</includeonly>
}}</includeonly>

Revision as of 22:37, 23 March 2013

This is the {{mbox}} or message box meta-template.

It is used to build message box templates such as {{security risk}}. It offers several different colours, uses default images if no image parameter is given and it has some other features.

This meta-template uses the mbox CSS classes in MediaWiki:Common.css. The classes can also be used directly in a wikitable if special functionality is needed. See the how-to guide for that.

Usage

Simple usage example:

{{mbox | text = Some text.}}

Complex example:

{{mbox
| type       = style
| small      = left
| image      = [[File:Emblem-question-yellow.svg|40px|alt=Question mark]]
| smallimage = [[File:Emblem-question-yellow.svg|20px|alt=Question mark]]
| textstyle  = color: red; font-weight: bold; font-style: italic;
| text       = Text for a big box, for the top of articles.
| smalltext  = Text for the top of article sections.
}}

But you are not really supposed to use red bold italic text.

Message box types

The following examples use different type parameters but use no image parameters thus they use the default images for each type.

This message box is using an invalid "type=critical" parameter and needs fixing.
This message box is using an invalid "type=important" parameter and needs fixing.
This message box is using an invalid "type=warning" parameter and needs fixing.
This message box is using an invalid "type=caution" parameter and needs fixing.
This message box is using an invalid "type=license" parameter and needs fixing.

Other images

The default images shown above are mostly for convenience. In many cases it is more appropriate to use more specific images. These examples use the image parameter to specify an image other than the default images.

This message box is using an invalid "type=warning" parameter and needs fixing.

More examples

Some other parameter combinations.

Parameters

List of all parameters:

{{mbox
| type  = critical / serious / warning / notice / / move / protection
| image = none / [[File:...|40px|...]]
| imagewidth = width of image section / default is 52px
| imageright = [[File:...|40px|...]]
| imagerightwidth = width of right image section / default is 52px
| style = CSS values
| textstyle = CSS values
| text  = The message body text.
| small = {{{small|}}} / left
| smallimage = none / [[File:...|20px|...]]
| smallimageright = none / [[File:...|20px|...]]
| smalltext  = A shorter message body text.
}}

type

If no type parameter is given the template has a 'blank' style.

image

No parameter = If no image parameter is given the template uses a default image. Which default image it uses depends on the type parameter.
An image = Should be an image with usual wiki notation. Widths of 40px - 50px are usually about right. (Images over 52 pixels wide will cause padding problems, unless you also set imagewidth.)
Often an icon is purely decorative in the W3C sense that it repeats the text. To improve accessibility, it is desirable to not have it be announced by screen readers, as well as to avoid it linking to an irrelevant page. If (and only if) the image license allows this, it can be marked with "|link=|alt=". For example:
image = [[File:Unbalanced scales.svg|40px|link=|alt=]]
Conversely, an icon that does not use "|link=|alt=", and which therefore is announced to visually impaired readers, should use an "|alt=alt text" parameter that describes the icon. With no |link= parameter (using the default link), the alt text should describe the icon's visual appearance. For example:
image = [[File:Gnome globe current event.svg|40px|alt=Clock over a larger globe]]
With a nonempty "|link=Page" the alt text should describe the icon's function. For example:
image = [[File:Purple question mark.svg|40px|link=Special:Random|alt=Random article]]
An icon whose license requires attribution may have alt text, but must keep the default link. Although public domain images do not require a link, many licenses do require one. Please see Purely decorative images for more information about licensing.
none = Means that no image is used.
blank = This parameter is now deprecated. If you see it in use, change it to "image=none".

imagewidth

Optional CSS value used to set width of image's div section. Allowing you to use images wider than the default 52px wide.
Example
imagewidth=100px

imageright

No parameter = If no imageright parameter is given then no image is shown on the right side.
An image = Should be an image with usual wiki notation. 40px - 50px width are usually about right depending on the image height to width ratio. (Images over 52 pixels width will cause padding problems, unless you also set imagerightwidth.) For example:
imageright = [[File:Nuvola apps bookcase.png|40px|alt=Three stacked books]]
Anything = Any other object that you want to show on the right side.

imagerightwidth

Optional CSS value used to set width of image's div section. Allowing you to use images wider than the default 52px wide.
Example
imagerightwidth=100px

style

Optional CSS values used by the entire message box table. Without quotation marks " " but with the ending semicolons ;. For example:
style = margin-bottom: 0.5em;

textstyle

Optional CSS values used by the text cell. For example:
textstyle = text-align: center;

text

The message body text.

The small parameters

The small article message boxes are meant for the top of sections. Normally they should only contain one or two lines of text.

small

left = Makes it a smaller left aligned message box. This also makes the default images smaller. Note that any data fed to the smallimage, smallimageright and smalltext parameters is only used if "small=left". To make it so your template also understands the small parameter you can use this code:
small = {{{small|}}}

smallimage

No parameter = If no smallimage parameter is given then this template falls back to use the image parameter. If the image parameter also is empty then a small default image is used.
An image = Should be an image with usual wiki notation. 20px width is usually about right for boxes with one line of text, while 25px width is usually about right for boxes with two lines of text. For example:
smallimage = [[File:Gnome globe current event.svg|20px|alt=Clock over a larger globe]]
none = Means that no image is used. This overrides any image fed to image, when "small=left".

smallimageright

No parameter = If no smallimageright parameter is given then this template falls back to use the imageright parameter. If the imageright parameter also is empty then no image is shown on the right side.
An image = Should be an image with usual wiki notation. 20px - 25px width is usually about right. For example:
smallimageright = [[File:Nuvola apps bookcase.png|20px|alt=Three stacked books]]
Anything = Any other object that you want to show on the right side.
none = Means that no right side image is used. This overrides any image fed to imageright, when "small=left".

smalltext

A shorter version of the message body text. If no smalltext parameter is given then this template falls back to use the text parameter.

Technical details

If you need to use special characters in the text parameter then you need to escape them like this:

{{mbox
| text  = <div>
Equal sign = and a start and end brace { } work fine as they are.
But here is a pipe &#124; and two end braces <nowiki>}}</nowiki>.
And now a pipe and end braces <nowiki>|}}</nowiki>.
</div>
}}

The <div> tags that surround the text in the example above are usually not needed. But if the text contains line breaks then sometimes we get weird line spacing. This especially happens when using vertical dotted lists. Then use the div tags to fix that.

This template uses CSS classes in MediaWiki:Common.css for most of its looks, thus it is fully skinnable.

This template calls {{mbox/core}} which holds most of the code for {{mbox}}, while {{mbox}} itself does parameter preprocessing.

Internally this meta-template uses HTML wikimarkup instead of wikimarkup for the table code. That is the usual way we make meta-templates since wikimarkup has several drawbacks. For instance it makes it harder to use parser functions and some special characters in parameters.

The default images for this meta-template are in png format instead of svg format. The main reason is that some older web browsers have trouble with the transparent background that MediaWiki renders for svg images. The png images here have hand optimised transparent background colour so they look good in all browsers. Note that svg icons only look somewhat bad in the old browsers, thus such hand optimisation is only worth the trouble for very widely used icons.