“模板:Ambox/sandbox”的版本间的差异

wikilife>Menaechmi
(Undid revision 800512965 by Menaechmi (talk) nope)
(没有差异)

2017年9月14日 (四) 08:58的版本

50px Template documentation[view] [edit] [history] [purge]

{{#ifeq:sandbox |doc

    | 

{{#ifeq:show |show

|
        }}{{#if: |
         |   {{#ifexist:模板:Ambox
                  | [[Category:{{#switch:模板 |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]]
                  |
                 }}
        }}
    | 
   }}
Message box
meta-templates
templatecontext
{{Ambox}}article
{{Cmbox}}category
{{Imbox}}image
{{Tmbox}}talk
{{Fmbox}}footer / header
{{Ombox}}other pages
{{Mbox}}auto-detect
{{Asbox}}article stub
{{Dmbox}}disambiguation
{{#switch:
 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:模板|模板
   | template
   | other
   }}
 }}

| template = {{#ifeq:Ambox/sandbox|Infobox||{{#ifeq:sandbox|Infobox|[[Category:Infobox templates|模板:Remove first word]]}}}} | other | #default = }}

{{Ambox}} stands for Article message box, which is a metatemplate. It is used to build message boxes for templates used in articles, such as {{underlinked}}. It offers several different colours, images and some other features.

Basic usage

The box below shows the most common parameters that are accepted by {{Ambox}}. The purpose of each is described below.

{{Ambox
| name  = 
| subst = <includeonly>{{subst:substcheck}}</includeonly>
| small = {{{small|}}}
| type  = 
| image = 
| sect  = {{{1|}}}
| issue = 
| talk  = {{{talk|}}}
| fix   = 
| date  = {{{date|}}}
| cat   = 
| all   = 
}}

Full usage

Full parameters

The "All parameters" box shows all possible parameters for this template. However, it is not recommended to copy this, because it will never be required to use all parameters simultaneously.

All parameters
{{Ambox
| name        = 
| subst       = <includeonly>{{subst:substcheck}}</includeonly>
| small       = {{{small|}}}
| type        = 
| image       = 
| imageright  = 
| smallimage  = 
| smallimageright = 
| class       = 
| style       = 
| textstyle   = 
| sect        = {{{1|}}}
| issue       = 
| talk        = {{{talk|}}}
| fix         = 
| date        = {{{date|}}}
| text        = 
| smalltext   = 
| plainlinks  = no
| removalnotice =
| cat         = 
| all         = 
| cat2        = 
| all2        = 
| cat3        = 
| all3        = 
}}

Common parameters

name

The name parameter specifies the name of the template, without the Template namespace prefix. For example {{Underlinked}} specifies |{{SAFESUBST:#if:name|name=}}Underlinked.

This parameter should be updated if the template is ever moved. The purpose of this parameter is twofold:

  • If incorrectly substituted, it allows the meta-template to notify the name of the template which has been substituted, which may help editors to fix the problem.
  • It allows the template to have a more useful display on its template page, for example to show the date even when not specified, and to apply categorisation of the template itself.

subst

The subst parameter allows the meta-template to detect whether the template has been incorrectly substituted, and give an appropriate warning. It will also add such pages to Category:Pages with incorrectly substituted templates. Just copy the code exactly as it appears in the box.

small

The small parameter should be passed through the template, as this will allow editors to use the small format by specifying |{{SAFESUBST:#if:small|small=}}left on an article:

{{#ifeq:left|left|}}

Otherwise the standard format will be produced:

{{#ifeq:{{{small}}}|left|}}

Other variations:

  • For templates which should never be small, specify |{{SAFESUBST:#if:small|small=}}no or do not pass the small parameter at all.
  • For templates which should always be small, just specify |{{SAFESUBST:#if:small|small=}}left.
  • For templates which should default to small, try |{{SAFESUBST:#if:small|small=}}{{{small|left}}}. This will allow an editor to override by using |{{SAFESUBST:#if:small|small=}}no on an article.

To use a small box that adjusts its width to match the text, use |{{SAFESUBST:#if:style|style=}}width: auto; margin-right: 0px; and |{{SAFESUBST:#if:textstyle|textstyle=}}width: auto; together:

{{#ifeq:left|left|}}

See § sect below for more information on how to limit |{{SAFESUBST:#if:small|small=}} display to cases when the template is being used for a section instead of the whole article (recommended, to prevent inconsistent top-of-article display).

type

The type parameter defines the colour of the left bar, and the image that is used by default. The type is chosen not on aesthetics but is based on the type of issue that the template describes. The seven available types and their default images are shown below.

{{#ifeq:{{{small}}}|left|}} {{#ifeq:{{{small}}}|left|}} {{#ifeq:{{{small}}}|left|}} {{#ifeq:{{{small}}}|left|}} {{#ifeq:{{{small}}}|left|}} {{#ifeq:{{{small}}}|left|}} {{#ifeq:{{{small}}}|left|}}

If no type parameter is given the template defaults to |{{SAFESUBST:#if:type|type=}}notice.

image

You can choose a specific image to use for the template by using the image parameter. Images are specified using the standard syntax for inserting files in Wikipedia (see Wikipedia:Manual of Style/Images#How to place an image.) Widths of 40-50px are typical. For example:

  • {{POV}} specifies |{{SAFESUBST:#if:image|image=}}[[File:Unbalanced scales.svg|40px|link=|alt=]] and looks like this:
{{#ifeq:|left|}}
  • {{underlinked}} specifies |{{SAFESUBST:#if:image|image=}}[[File:Ambox wikify.svg|50x40px|link=|alt=]] and looks like this:
{{#ifeq:模板|{{subst:NAMESPACE}}||}}{{#ifeq:{{{small}}}|left|}}

Please note:

  • If no image is specified then the default image corresponding to the type is used. (See #type above.)
  • If |{{SAFESUBST:#if:image|image=}}none is specified, then no image is used and the text uses the whole message box area.
  • If an icon is purely decorative and also in the public domain, accessibility can be improved by suppressing the link to the file page by adding "|{{SAFESUBST:#if:link|link=}}|{{SAFESUBST:#if:alt|alt=}}" as seen above.

sect

Many article message templates begin with the text This article ... and it is often desirable that this wording change to This section ... if the template is used on a section instead. The value of this parameter will replace the word "article". Various possibilities for use include: |{{SAFESUBST:#if:sect|sect=}}list, |{{SAFESUBST:#if:sect|sect=}}table, |{{SAFESUBST:#if:sect|sect=}}"In popular culture" material, etc.

If using this feature, be sure to remove the first two words ("This article") from the template's text, otherwise it will be duplicated.

A common way to facilitate this functionality is to pass |{{SAFESUBST:#if:sect|sect=}}{{{1|}}}. This will allow editors to type section, for example, as the first unnamed parameter of the template to change the wording. For example, {{Advert|section}} produces:

{{#ifeq:{{{small}}}|left|}}

Another approach is to pass |{{SAFESUBST:#if:sect|sect=}}{{{section|{{{sect|}}}}}} to provide a named value. Another is to use {{Yesno}} to parse the value for a positive, and pass |{{SAFESUBST:#if:sect|sect=}}section if true.

These approaches can be combined, and this is recommended. The following ready-to-use code:

| sect = {{#ifeq:{{yesno|def=|1={{{sect|{{{section}}}}}} }}|yes|section|{{{sect|{{{section|{{{1|}}}}}}}}} }}

enables the following:

  • Any positive value that {{Yesno}} can detect will be used with the named parameter in the ambox-based template to get "section" instead of "article": |{{SAFESUBST:#if:section|section=}}y, |{{SAFESUBST:#if:sect|sect=}}True, etc. It is recommended to allow both |{{SAFESUBST:#if:sect|sect=}} and |{{SAFESUBST:#if:section|section=}} so that editors do not have to guess which one will work. The sample code above does this for you.
  • Any other value passed, in any manner, will replace "article": |{{SAFESUBST:#if:|=}}section and its subsections, |{{SAFESUBST:#if:1|1=}}list, |{{SAFESUBST:#if:sect|sect=}}section, |{{SAFESUBST:#if:section|section=}}table, etc.

It is also advisable to restrict use of the |{{SAFESUBST:#if:small|small=}} parameter so that it is made contingent upon the template being applied to a section (or whatever) rather than the whole article, to prevent the small version of the template being used at the top of the article where it would be inconsistent with other article-wide cleanup/dispute banners:

| small = {{#if:{{{sect|{{{section|{{{1|}}}}}}}}}|{{#if:{{{small|{{{left|}}}}}}|left}} }}

(In this case, any value of |{{SAFESUBST:#if:small|small=}} or |{{SAFESUBST:#if:left|left=}} will trigger the small, left display, as long as some value of |{{SAFESUBST:#if:sect|sect=}} or one of its aliases in that template has also been provided.) This code can be copy-pasted and used with the above code block. See, e.g., Template:Trivia and its Template:Trivia/testcases to observe the combined functionality.

issue and fix

The issue parameter is used to describe the issue with the article. Try to keep it short and to-the-point (approximately 10-20 words) and be sure to include a link to a relevant policy or guideline.

The fix parameter contains some text which describes what should be done to improve the article. It may be longer than the text in issue, but should not usually be more than two sentences.

When the template is in its compact form (when placed inside {{multiple issues}}) or small form (when using |{{SAFESUBST:#if:small|small=}}left), the issue is the only text that will be displayed. For example, {{Citation style}} defines

  • |issue=This article '''has an unclear citation style'''.
  • |fix=The references used may be made clearer with a different or consistent style of [[Wikipedia:Citing sources|citation]], [[Wikipedia:Footnotes|footnoting]], or [[Wikipedia:External links|external linking]].

When used stand-alone it produces the whole text:

{{#ifeq:|left|}}

But when used inside {{Multiple issues}} or with |{{SAFESUBST:#if:small|small=}}left it displays only the issue:

{{#ifeq:{{{small}}}|left|}} {{#ifeq:left|left|}}

talk

Some article message templates include a link to the talk page, and allow an editor to specify a section heading to link directly to the relevant section. To achieve this functionality, simply pass the talk parameter through, i.e. |{{SAFESUBST:#if:talk|talk=}}{{{talk|}}}

This parameter may then be used by an editor as follows:

  • |{{SAFESUBST:#if:talk|talk=}}SECTION HEADING – the link will point to the specified section on the article's talk page, e.g. |{{SAFESUBST:#if:talk|talk=}}Foo
  • |{{SAFESUBST:#if:talk|talk=}}FULL PAGE NAME – the template will link to the page specified (which may include a section anchor), e.g. |{{SAFESUBST:#if:talk|talk=}}Talk:Banana#Foo

Notes:

  • When this parameter is used by a template, the talk page link will appear on the template itself (in order to demonstrate the functionality) but this will only display on articles if the parameter is actually defined.
  • In order to make sure there is always a link to the talk page, you can use |{{SAFESUBST:#if:talk|talk=}}{{{talk|#}}}.
  • If the talk page does not exist, there will be no link, whatever the value of the parameter.

date

Passing the date parameter through to the meta-template means that the date that the article is tagged may be specified by an editor (or more commonly a bot). This will be displayed after the message in a smaller font.

Passing this parameter also enables monthly cleanup categorisation when the cat parameter is also defined.

info

This parameter is for specifying additional information. Whatever you add here will appear after the date, and will not be displayed if the template is being wrapped in {{multiple issues}}.

removalnotice

If you specify |{{SAFESUBST:#if:removalnotice|removalnotice=}}yes, then the following notice will be displayed after the date and after the info text:

This will not be displayed if the template is being wrapped in {{multiple issues}}.

cat

This parameter defines a monthly cleanup category. If |{{SAFESUBST:#if:cat|cat=}}CATEGORY then:

  • articles will be placed in Category:CATEGORY from DATE if |{{SAFESUBST:#if:date|date=}}DATE is specified.
  • articles will be placed in Category:CATEGORY if the date is not specified.

For example, {{No footnotes}} specifies |{{SAFESUBST:#if:cat|cat=}}Articles lacking in-text citations and so an article with the template {{No footnotes|date=June 2010}} will be placed in Category:Articles lacking in-text citations from June 2010.

The cat parameter should not be linked, nor should the prefix Category: be used.

all

The all parameter defines a category into which all articles should be placed.

The all parameter should not be linked, nor should the prefix Category: be used.

Additional parameters

imageright

An image on the right side of the message box may be specified using this parameter. The syntax is the same as for the image parameter, except that the default is no image.

smallimage and smallimageright

Images for the small format box may be specified using these parameters. They will have no effect unless |{{SAFESUBST:#if:small|small=}}left is specified.

class

Custom CSS classes to apply to the box. If adding multiple classes, they should be space-separated.

style and textstyle

Optional CSS values may be defined, without quotation marks " " but with the ending semicolons ;.

  • style specifies the style used by the entire message box table. This can be used to do things such as modifying the width of the box.
  • textstyle relates to the text cell.

text and smalltext

Instead of specifying the issue and the fix it is possible to use the text parameter instead.

Customised text for the small format can be defined using smalltext.

plainlinks

Normally on Wikipedia, external links have an arrow icon next to them, like this: Example.com. However, in message boxes, the arrow icon is suppressed by default, like this: Example.com. To get the normal style of external link with the arrow icon, use |{{SAFESUBST:#if:plainlinks|plainlinks=}}no.

cat2, cat3, all2, and all3

  • cat2 and cat3 provide for additional monthly categories; see #cat.
  • all2 and all3 provide for additional categories into which all articles are placed, just like #all.

Technical notes

  • This meta-template uses the ambox 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.
  • If you need to use special characters in the text parameter then you need to escape them like this:
{{Ambox
| 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>
}}
{{#ifeq:{{{small}}}|left|}}
  • 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 Module:Message box which holds most of the code for {{Ambox}}, while {{Ambox}} itself does parameter preprocessing.
  • Internally, this meta-template uses HTML markup instead of wikimarkup for the table code. That is the usual way meta-templates are made, 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.
  • For more technical details see the talk page and the "See also" links below. Since this template works almost exactly like {{Tmbox}}, {{Imbox}}, {{Cmbox}} and {{Ombox}} their talk pages and related pages might also contain more details.

TemplateData

style="background: #{{#switch:
 {{#if: 
{{{demospace}}} main other
   }} 
 }}
main = F0F2F5 other #default = CCFFCC }}; font-size:87%; padding:0.2em 0.3em; text-align:{{safesubst:#if:|left|{{safesubst:#if:|left|center}}}}; {{safesubst:#if:|color: {{{fc}}};|}}" |
TemplateData documentation used by VisualEditor and other tools

{{safesubst:#if:

- The following is a closed discussion. 模板:Strongbad }}
{{#if:1|{{#switch:
={{#ifeq:{{safesubst:#switch: {{{lc}}} no n f false off 0 = no = no ¬ = no yes y t true on 1 = yes #default = no

}}|no|S|s}}ee the monthly parameter usage report for {{#if:|[[Template:]]|this template}}.

none=Parameter usage report For=Parameter usage report for {{#if:|[[Template:]]|Template:Ambox}}. #default=[1]

}}|This is the {{#if:|TemplateData|TemplateData}} documentation for this template used by VisualEditor and other tools; {{#switch:

={{#ifeq:{{safesubst:#switch: yes no n f false off 0 = no = no ¬ = no yes y t true on 1 = yes #default = no

}}|no|S|s}}ee the monthly parameter usage report for {{#if:|[[Template:]]|this template}}.

none=Parameter usage report For=Parameter usage report for {{#if:|[[Template:]]|Template:Ambox}}. #default=[2]

}}}}

TemplateData for Ambox

{{#switch:
 {{#if:
{{{demospace}}} 模板 template other
   }}
 }}
sandbox|1}}{{#ifeq:sandbox|doc|1}}

}}

other #default =

}} <templatedata> { "params": { "1": {}, "small": {}, "talk": {}, "date": {} } } </templatedata>

Mbox family

There are seven metatemplates in the Module:Message box family:
  • {{Ambox}}, for messageboxes on article pages.
  • {{Cmbox}}, for messageboxes on category pages.
  • {{Imbox}}, for messageboxes on file (image) pages.
  • {{Tmbox}}, for messageboxes on talk pages.
  • {{Fmbox}}, for header and footer messageboxes.
  • {{Ombox}}, for messageboxes on other types of page.
  • {{Mbox}}, for messageboxes that are used in different namespaces and change their presentation accordingly.

Closely related metatemplates:

  • {{Asbox}}, for messageboxes in article stubs.
  • {{Dmbox}}, for messageboxes on disambiguation or set-index pages.
  • {{Ivory messagebox}}, a simple full-width box with default ivory background intended to frame important messages or notices.

Templates intended to be used in conjunction with Mboxes:

See also

{{#if:{{#ifeq:sandbox|sandbox|1}}{{#ifeq:sandbox|doc|1}}|| }}