Module:Annotated link
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 12,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
![]() | This module is invoked by {{annotated link}} . |
![]() | This module may, by design, output alarming informational messages under certain circumstances; if these messages are displayed on any page invoking this module directly, or via any other module or template using it, the page will be added to Category:Pages displaying alarming messages about Module:Annotated link. |
Usage
{{#invoke:Annotated link|main |name= |display= |quote= |abbr= |abbr_title= |template_link= |aka= |wedge= |dash= |desc_first_letter_case= |space_cat= |prefix_parentheses= |link_lang= |link_lang_italic= |link_lang_nocat= |link_lang_size= |link_lang_cat= |link_lang_rtl= |aka_lang= |aka_lang_italic= |aka_lang_nocat= |aka_lang_size= |aka_lang_cat= |aka_lang_rtl= |wedge_lang= |wedge_lang_italic= |wedge_lang_nocat= |wedge_lang_size= |wedge_lang_cat= |wedge_lang_rtl= |only= |prefer= |fallback= |desc_lang_italic= |desc_lang_nocat= |desc_lang_size= |desc_lang_cat= |desc_lang_rtl= |desc_lang_no= }}
name
By providing only the required page name (including namespace), the module will use Module:GetShortDescription to look for an explicit {{short description}}
in that page, but if not found, will try to fetch the wikidata description. This is equivalent to stating |prefer=explicit
; see #prefer (below). If a description is found, it will be appended to a link created for the named page in the style expected for the likes of MOS:SEEALSO. If no description is found, the link will be created but no extra information will be appended – unless the extensive following parameters are employed.
Any foreign language (i.e. not en) text supplied to this module or retrieved by Module:GetShortDescription may be appropriately formatted, in accordance with MOS:OTHERLANG, via the parameters for Module:Lang; see #Foreign language text (below).
As this module is responsible for the use of all features of Module:GetShortDescription; all the parameters for that module are available through this module; see #Module:GetShortDescription parameters (below).
- Markup:
{{#invoke:Annotated link|main |name=The Partisan }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
This and the following example song titles should be double quoted per MOS:POPMUSIC; that will be handled by #quote (below), and you will see the parameters in use where appropriate from here on.
display
Providing a value for |display=
will format the piped link with a display string:
- Markup:
{{#invoke:Annotated link|main |name=Jump (Every Little Thing song) |display=Jump |quote=yes }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
quote
Stating |quote=yes
will double quote the link:
- Markup:
{{#invoke:Annotated link|main |name=The Partisan |quote=yes }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
- Markup:
{{#invoke:Annotated link|main |name=Jump (Every Little Thing song) |display=Jump |quote=yes }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
abbr
Providing a value for |abbr=
will append the link with the provided parenthesized abbreviation with <abbr>...</abbr>
semantic markup:
- Markup:
{{#invoke:Annotated link|main |name=Confédération Mondiale des Activités Subaquatiques |display=World Underwater Federation |abbr=CMAS }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
An optional |abbr_title=
may be provided:
- Markup:
{{#invoke:Annotated link|main |name=Confédération Mondiale des Activités Subaquatiques |display=World Underwater Federation |abbr=CMAS |abbr_title=Confédération Mondiale des Activités Subaquatiques }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
template_link
If the linked page is in the Template namespace; the link will be formatted in the manner expected by {{template link}}
:
- Markup:
{{#invoke:Annotated link|main |name=Template:Annotated link }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
Stating |template_link=code
will display the link formatted with <code>...</code>
:
- Markup:
{{#invoke:Annotated link|main |name=Template:Annotated link |template_link=code }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
The previously described parameters – |display=
, |quote=
, |abbr=
and |abbr_title=
– and all foreign language link options under |link_lang=
(see #Foreign language text (below)) will be ignored if the link is in the Template namespace.
Stating |template_link=no
will disable this special link formatting and the ignorance of the above-mentioned parameters:
- Markup:
{{#invoke:Annotated link|main |name=Template:Annotated link |template_link=no |display=Annotated link }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
aka
Providing a value for |aka=
will append the link (and |abbr=
if provided) with a useful alternative name:
- Markup:
{{#invoke:Annotated link|main |name=The Partisan |quote=yes |aka=La Complainte du partisan }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
- Markup:
{{#invoke:Annotated link|main |name=Confédération Mondiale des Activités Subaquatiques |display=World Underwater Federation |abbr=CMAS |aka=Confédération Mondiale des Activités Subaquatiques }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
These and some following examples contain foreign language text that, per MOS:OTHERLANG, should be appropriately displayed and declared via HTML markup as being of that language; this will be handled by various parameters; see #Foreign language text (below) for full details, and you will see the parameters in use where appropriate from here on.
wedge
Providing a value for |wedge=
will append the link (and |abbr=
and |aka=
in that order if either or both is provided) with any extra details felt suitable:
- Markup:
{{#invoke:Annotated link|main |name=The Partisan |quote=yes |wedge=from the album ''[[Songs from a Room]]'' |aka=La Complainte du partisan |aka_lang=fr }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
For complementary foreign language params; see #Foreign language text (below).
dash
For list consistency, per MOS:LISTFORMAT; by providing a value for |dash=
; the dash between the short description and the preceding text may be exchanged for a suitable alternative:
- Markup:
{{#invoke:Annotated link|main |name=The Partisan |quote=yes |dash=, }}
- Result: Lua error: bad argument #1 to 'gsub' (string expected, got table).
desc_first_letter_case
Short descriptions on en Wikipedia should be formatted with an uppercase first letter, but the typical application of this module will require the first character to be lowercase. By default; this module will ensure all the short descriptions retrieved by Module:GetShortDescription are transformed to start with a lowercase first letter, but this may be overridden if required using |desc_first_letter_case=upper
or |desc_first_letter_case=lower
.
prefix_parentheses
Sometimes date ranges in short descriptions are included in a suffixed parenthetical, per WP:SDDATES e.g. for Jimmy Wales: "Co-founder of Wikipedia (born 1966)".
However when listing people in disambiguation pages per MOS:DABPEOPLE, birth and death dates in parentheticals should precede the comma, as in "Jimmy Wales (born 1966), co-founder of Wikipedia".
If the optional parameter |prefix_parentheses=y
is provided, this behavior will be performed, so any suffixed parenthetical text will be moved to before the dash (or comma) separator.
Note that current consensus is to not use {{annotated link}} for disambiguation pages; see Template:Annotated link/doc#Usage.
space_cat
In the event that a short description with no spaces is retrieved and displayed; pages transcluding the annotation will be added to Category:Pages displaying short descriptions with no spaces via Module:Annotated link for interested editors to monitor for potential issues. Potential issues might include: garbage keyboard mashings, a typo of "none" while attempting to disable an explicit {{short description}}
or some misunderstanding on the part of an editor placing one.
If the transclusion on a page in this category is checked and it is determined to be okay; stating a value for |space_cat=
in the invocation will disable the categorisation. This should only be done on a case by cases basis, as opposed to as a default, or no potentially inappropriate annotations will be categorised; i.e. allow this parameter to be set in individual transclusions of templates which invoke this module, like {{annotated link}}
, rather than in the template code.
Module:GetShortDescription parameters
The value provided with |name=
is passed through this module to Module:GetShortDescription where it is also required; the expectations of this module are described in #name (above). Module:GetShortDescription uses the
value to find a {{short description}}
in the named page, or various alternatives depending on parameter values.
only
Providing a value for |only=
will limit the search to being only for the stated description. If no description is found, the result will be an empty string, unless a fallback is provided; see #fallback (below).
- Stating
|only=explicit
will limit the search to only short descriptions set by use of{{short description}}
on the searched page. - Stating
|only=wikidata
will limit the search to only wikidata descriptions.
prefer
Providing a value for |prefer=
will initiate the search for the stated description, but try for the alternative if none is found. If no description is found, the result will be an empty string, unless a fallback is provided; see #fallback (below).
- State
|prefer=explicit
to use the explicit short description if available, or try for the wikidata description if not. - State
|prefer=wikidata
to use the wikidata description if available, or try for an explicit short description if not.
fallback
If a |fallback=
value is provided, and no description is found by the expressed route, the appended description will be the stated fallback value.
Foreign language text
Module:GetShortDescription may return a foreign language (i.e. not en) wikidata description; editor discretion determines if that should be displayed. If it is displayed; it will be in accordance with MOS:OTHERLANG, by Module:Lang (the module powering {{lang}}
). The appropriate language code will be set automatically, but all other parameters of {{lang}}
are available to affect the formatting of the returned description:
Use |lang_italic=
, |lang_nocat=
, |lang_size=
, |lang_cat=
and |lang_rtl=
; see lang's documentation for details.
If the editor determines that {{lang}}
formatting is not appropriate; it may be disabled with |lang_no=yes
. The following {{lang}}
formatting parameters are optional, so there is no off-switch required.
link_lang
If the link text is of a foreign language (again; editor discretion); control the formatting with: |link_lang=<language code>
, |link_lang_italic=
, |link_lang_nocat=
, |link_lang_size=
, |link_lang_cat=
and |link_lang_rtl=
aka_lang
If the |aka=
text is of a foreign language (again; editor discretion); control the formatting with: |aka_lang=<language code>
, |aka_lang_italic=
, |aka_lang_nocat=
, |aka_lang_size=
, |aka_lang_cat=
, |aka_lang_rtl=
wedge_lang
If the |wedge=
text is of a foreign language (again; editor discretion); control the formatting with: |wedge_lang=<language code>
, |wedge_lang_italic=
, |wedge_lang_nocat=
, |wedge_lang_size=
, |wedge_lang_cat=
, |wedge_lang_rtl=
local p = {}
local getShortDescription = require( 'Module:GetShortDescription' ).main
local getArgs = require( 'Module:Arguments' ).getArgs
local mLang = require( 'Module:Lang' )
local function errorMessage( message )
return '<strong class="error">ERROR with invocation of [[Module:AnnotatedLink]]: ' .. message .. '</strong>'
end
local function langify( args )
local lang = args.lang
local text = args.text
-- Do as little as possible; return text immediately if langification is not required.
if not lang or lang == 'en' then
return text
end
return mLang._lang {
lang,
text,
italic = args.italic or '',
nocat = args.nocat or '',
size = args.size or '',
cat = args.cat or '',
rtl = args.rtl or ''
}
end
-- Short descriptions on en Wikipedia should be formatted with an uppercase first letter, but
-- the typical application of this module will require the first character to be lowercase.
-- By default; this module will ensure all the short descriptions retrieved by Module:GetShortDescription are
-- transformed to start with a lowercase first letter, but this may be overridden if required.
local function handleFirstLetterCase( short_description, case )
-- Do as little as possible; return short_description immediately if it's empty.
if short_description == '' then
return short_description
end
-- Only process short_description if it starts with a transformable character.
local case_parsed_short_description = mw.ustring.gsub( short_description, '^([^%d])', function( first_char )
if case == 'upper' then
return mw.ustring.upper( first_char )
end
return mw.ustring.lower( first_char )
end )
-- If the case of the first character is altered, apply a tracking category.
if case_parsed_short_description ~= short_description then
-- We're not doing this without discussion.
mw.log( '[[Category:Pages displaying an annotated link with a case-altered short description]]' )
end
return case_parsed_short_description
end
local function annotatedLink( args )
local name = args.name
if not name then
return errorMessage( 'a page name (including namespace) MUST be provided' )
end
local case = args.desc_first_letter_case or 'lower'
local abbr_title = args.abbr_title
local dash = args.dash or ' –'
local display = args.display
local wedge = args.wedge
local quote = args.quote
local abbr = args.abbr
local aka = args.aka
-- All the parameters for Module:GetShortDescription in one bundle.
local GSD_args = {
args = {
lang_italic = args.desc_lang_italic,
lang_nocat = args.desc_lang_nocat,
lang_size = args.desc_lang_size,
lang_cat = args.desc_lang_cat,
lang_rtl = args.desc_lang_rtl,
lang_no = args.desc_lang_no,
fallback = args.fallback,
prefer = args.prefer,
only = args.only,
name = name
}
}
-- Begin concatenation of result.
local result = langify( {
lang = args.link_lang,
text = '[[:' .. name .. '|' .. ( display or name ) .. ']]',
italic = args.link_lang_italic,
nocat = args.link_lang_nocat,
size = args.link_lang_size,
cat = args.link_lang_cat,
rtl = args.link_lang_rtl
} )
if quote then
result = '"' .. result .. '"'
end
if abbr then
result = result .. ' (<abbr'
if abbr_title then
result = result .. ' title="' .. abbr_title .. '"'
end
result = result .. '>' .. abbr .. '</abbr>)'
end
if aka then
result = result .. ', also known as ' .. langify( {
lang = args.aka_lang,
text = aka,
italic = args.aka_lang_italic,
nocat = args.aka_lang_nocat,
size = args.aka_lang_size,
cat = args.aka_lang_cat,
rtl = args.aka_lang_rtl
} )
end
if wedge then
result = result .. ', ' .. langify( {
lang = args.wedge_lang,
text = wedge,
italic = args.wedge_lang_italic,
nocat = args.wedge_lang_nocat,
size = args.wedge_lang_size,
cat = args.wedge_lang_cat,
rtl = args.wedge_lang_rtl
} )
end
-- Get the short description from Module:GetShortDescription
-- and hand it to handleFirstLetterCase() for processing.
local short_description = handleFirstLetterCase( getShortDescription( GSD_args ), case )
-- If a short description was fetched; append to result.
if short_description and short_description ~= '' then
result = result .. dash .. ' ' .. short_description
end
return result
end
function p.main( frame )
local args = getArgs( frame )
if not args then
return errorMessage( 'could not getArgs' )
end
return annotatedLink( args )
end
return p