Jump to content

Help:Cite/VisualEditor reference names

From mediawiki.org

When re-using a reference in VisualEditor that doesn't already have a name, VisualEditor automatically assigns one, using :n as the default pattern (e.g. <ref name=":1">, <ref name=":2">).

These names can be configured to be human-readable and content based. Admins can enable the mechanism to use improved auto-generated names via Special:CommunityConfiguration/Cite-VisualEditor-Autonames. Wikis that don't use content-based reference names and/or the simple default names described below will continue to use <ref name=":n">. Note that it might take a couple of minutes for the community configuration change to take effect.

Simple configuration

[edit]

Without further configuration reference names will be auto-generated using existing message keys like MediaWiki:Visualeditor-cite-tool-name-xx if the reference uses a template that's configured for VisualEditor's citation tool (see MediaWiki:Cite-tool-definition.json) and MediaWiki:Cite-ve-dialogbutton-reference-title if the reference uses a different template or none at all.

Many projects use message keys like the following, while others use custom keys (e.g. pl:MediaWiki:Visualeditor-cite-tool-name-any) for citation templates defined in MediaWiki:Cite-tool-definition.json:

Using these message keys ensures that reference names are localized to the project's language, e.g. <ref name="Book-1"> on English Wikipedia or <ref name="Libro-1"> on Spanish Wikipedia.

If you want to use a different autoname or change the default separator, create an -autoname message key, e.g. MediaWiki:Cite-ve-dialogbutton-reference-title-autoname or MediaWiki:Visualeditor-cite-tool-name-book-autoname. Creating an autoname message key that's identical to the default key will remove the separator (e.g. Reference in MediaWiki:Cite-ve-dialogbutton-reference-title-autoname will lead to <ref name="Reference1"> instead of <ref name="Reference-1"> when using MediaWiki:Cite-ve-dialogbutton-reference-title). You can also add any other separator or change the content entirely.

Numbering starts at 1 and increments each time a citation type is re-used (e.g. reusing a second basic reference would create <ref name="Reference-2"> on English Wikipedia). Autogenerated reference names always get a number to make it easier to identify autonames and ensure we always provide a unique name.

Content-based reference names

[edit]

If you want to configure reference names based on the reference content, you can create templates defining which citation template parameters to use for generating a meaningful name, e.g. a combination of |author= and |year= and some fallback options.

Simple {{Autoname }} example:

{{#if:{{{author|}}}
 |{{{author}}}{{#if:{{{year|}}}|{{{year}}}-}}
 |{{#if:{{{publisher|}}}
   |{{{publisher}}}{{#if:{{{year|}}}|{{{year}}}-}}
  }}
}}

This example template defines |author= and |year= as the preferred citation template parameters for generating the reference name and lists |publisher= as a fallback option. The template adds a separator if there's a year to distinguish the year from the number that's added automatically. It doesn't add a separator if the citation template doesn't use |year=.

Similar to non-content-based fallback options a number will be added automatically to avoid ref name collisions, e.g. "Miller-1998-1" using the example template above. Note that the separator (e.g. –) has to be added via the autoname template as well, it's not added automatically. If the autoname template returns empty content one of the non-content-based fallback options like "Reference-1" will be used instead. Make sure to use the {{#if}} parser function if you want to add a separator to avoid the autoname template returning non-empty content – e.g. {{{first|}}}{{{year|}}}- would still lead to a result even if both parameters are not used in the citation template.

It's also possible to use the autoname template to define a fallback ref name if none of the desired citation template parameters can be used.

Wikis can use modules to use more advanced mechanisms for the reference name creation, e.g. to partially use a citation template parameter (only using the year within |date= or only using the first author's last name extracted from |author(s)=). Example on testwiki: [1][2] – test edit [3]).

Use MediaWiki:Cite-autoname-template-map.json to define which autoname template(s) to use for which citation template(s). You can define a default autoname template using * and specific autoname templates to be used for a defined set of citation templates instead of the default. If a citation template is part of multiple lists of autoname templates, the first (non-default) autoname template defined in the JSON will be used.

Example:

{
    "autoname": [ "*" ],
    "autonamePrint": [ "Cite book", "Cite journal", "Cite magazin" ],
    "autonameWeb": [ "Cite web", "Cite insta", "Cite archive" ]
}

Autoname templates can only be considered if they have been added to MediaWiki:Cite-autoname-template-map.json prior to the reference name creation. Note that non-default autoname templates will only affect citation templates listed in the JSON which currently requires adding template redirect names as well (example edit on French Wikipedia [4]). Autoname templates and their assigned citation templates have to exist in the template namespace.

Technical instructions

[edit]

Please note the following when configuring autonames: "Forbidden" characters will be removed, not escaped when creating autonames. Local configuration might lead to autogenerated names that consist of numbers only which would result in reference errors. Make sure to avoid such autonames (e.g. don't use template parameters like |year= exclusively to create reference names).

Repository

[edit]

See also

[edit]