Module:Annotated link
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
{{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, and if not found, will display nothing. 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.
Any foreign-language (i.e. not English) 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: The Partisan – 1943 song by Anna Marly and Emmanuel d'Astier, popularised by Leonard Cohen in 1969
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: "Jump" – 2001 single by Every Little Thing
quote
Stating |quote=yes
will double quote the link:
- Markup:
{{#invoke:Annotated link|main |name=The Partisan |quote=yes }}
- Result: "The Partisan" – 1943 song by Anna Marly and Emmanuel d'Astier, popularised by Leonard Cohen in 1969
- Markup:
{{#invoke:Annotated link|main |name=Jump (Every Little Thing song) |display=Jump |quote=yes }}
- Result: "Jump" – 2001 single by Every Little Thing
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: World Underwater Federation (CMAS) – International organisation for underwater activities
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: World Underwater Federation (CMAS) – International organisation for underwater activities
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: {{Annotated link}}
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:
{{Annotated link}}
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: Annotated link
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: "The Partisan", also known as La Complainte du partisan – 1943 song by Anna Marly and Emmanuel d'Astier, popularised by Leonard Cohen in 1969
- 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: World Underwater Federation (CMAS), also known as Confédération Mondiale des Activités Subaquatiques – International organisation for underwater activities
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: "The Partisan", also known as La Complainte du partisan, from the album Songs from a Room – 1943 song by Anna Marly and Emmanuel d'Astier, popularised by Leonard Cohen in 1969
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: "The Partisan", 1943 song by Anna Marly and Emmanuel d'Astier, popularised by Leonard Cohen in 1969
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.
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.
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.
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=
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Subpages of this module.
localfunctionpipedLink(name,display)return'[[:'..name..'|'..display..']]'end localfunctionisEmpty(value)returnvalue==nilorvalue==''end localfunctionnotEmpty(value)returnnotisEmpty(value)end -- Unescape functionality grabbed from https://stackoverflow.com/a/14899740/1832568 localfunctionunescape(str) str=string.gsub(str,'&#(%d+);',string.char) str=string.gsub(str,'&#x(%d+);',function(d)returnstring.char(tonumber(d,16))end) returnstr end localfunctionhashDelimitedList(list_string)returnmw.text.gsplit(unescape(list_string),'%s*#%s*')end localfunctionalarmingMessage(message) return'<span style="color:#d33">[[Module:Annotated link]] '..message..'.</span>'.. '[[Category:Pages displaying alarming messages about Module:Annotated link]]' end localfunctionoptionallyVisibleCategory(class,category) return'<span style="display:none" class="'..class..'">'..category.. '</span>[[Category:'..category..' via Module:Annotated link]]' end localfunctionhandleFirstLetterCase(short_description,case) returnmw.ustring.gsub(short_description,'^([^%d])',function(first_char) ifcase=='upper'then returnmw.ustring.upper(first_char) end returnmw.ustring.lower(first_char)end ) end localmLang=require('Module:Lang') localfunctionlangify(args) locallang=args.lang localtext=args.text ifisEmpty(lang)orlang=='en'then returntext end returnmLang._lang{ lang, text, italic=args.italic, nocat=args.nocat, size=args.size, cat=args.cat, rtl=args.rtl } end localfunctionformatResult(result,dash,description,prefix_parentheses) ifnotEmpty(description)then ifprefix_parenthesesthen localstartIdx=description:find("%(") ifstartIdxthen localbeforeParens=description:sub(1,startIdx-2) localinsideParens=description:sub(startIdx,-1) returnresult..' '..insideParens..dash..' '..beforeParens end end returnresult..dash..' '..description end returnresult end localfunctionannotatedLink(args) localname=args.name ifisEmpty(name)then returnalarmingMessage('requires a page name (including namespace)') end -- In order to handle an attempt to annotate a template link -- already formatted with the likes of {{tl|<template name>}}; -- unescape name to make sense of braces in lua patern matching. name=unescape(name) ifname:match('^{%b{}}$')then -- The possibility to extract useful data exists here: e.g. {{tl*|Template}}. returnalarmingMessage( 'requires only a page name (including namespace) without markup. '.. 'If an attempt is being made to annotate a link to a template, '.. 'provide only the template name with namespace e.g. "Template:Example"') end -- If a literal link was provided as name; -- extract the content and apply it to name and display as appropriate. localwikilink=mw.ustring.match(name,'^%[%[%s*:*%s*(.-)%s*%]%]$') ifwikilinkthen locallink_name,link_display=unpack(mw.text.split(wikilink,'%s*|%s*')) iflink_namethen name=link_name end iflink_displayandisEmpty(args.display)then args.display=link_display end end -- Prepare to concatenate. localresult localis_template=name:match('^Template:(.+)$') localtemplate_link=args.template_link ifis_templateandtemplate_link~='no'then result='{{'..pipedLink(name,is_template)..'}}' iftemplate_link=='code'then result='<code>'..result..'</code>' end else localdisplay=args.display ifisEmpty(display)then display=name end result=langify({ lang=args.link_lang, text=pipedLink(name,display), 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 }) ifnotEmpty(args.quote)then result='"'..result..'"' end localabbr=args.abbr ifnotEmpty(abbr)then result=result..' (<abbr' localabbr_title=args.abbr_title ifnotEmpty(abbr_title)then result=result..' title="'..abbr_title..'"' end result=result..'>'..abbr..'</abbr>)' end end ifisEmpty(result)then returnalarmingMessage('could not create a link for "'..name..'"') end localaka=args.aka ifnotEmpty(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 localwedge=args.wedge ifnotEmpty(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 -- Exclude wikidata fallback for any specified list of link titles, -- unless explicity instructed that it's okay. localnot_wikidata_for_links_starting_with=args.not_wikidata_for_links_starting_with ifisEmpty(args.wikidata)andnotEmpty(not_wikidata_for_links_starting_with)then foronly_explicitinhashDelimitedList(not_wikidata_for_links_starting_with)do ifname:match('^'..only_explicit)then args.only='explicit' break end end end -- Get the short description from Module:GetShortDescription. localshort_description=require('Module:GetShortDescription').main({ none_is_valid=args.none_is_valid, none_is_nil=args.none_is_nil, 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, prefer=args.prefer, only=args.only, name=name }) localdash=args.dash ifisEmpty(dash)then dash=' –' end localfallback=args.fallback ifisEmpty(short_description)orshort_description.redlinkthen returnformatResult(result,dash,fallback,args.prefix_parentheses) end ifshort_description.alarmthen returnshort_description.alarm end localmaintenance='' ifshort_description.redirectedthen maintenance=optionallyVisibleCategory( 'category-annotation-with-redirected-description', 'Pages displaying short descriptions of redirect targets') end localfellback ifshort_description.wikidatathen -- if short_description.fellback then -- fellback = true -- maintenance = maintenance..optionallyVisibleCategory( -- 'category-wikidata-fallback-annotation', -- 'Pages displaying wikidata descriptions as a fallback') -- end -- short_description = short_description.wikidata -- Filter against likely rubbish wikidata descriptions. -- local not_wikidata_descriptions_including = args.not_wikidata_descriptions_including -- if notEmpty(not_wikidata_descriptions_including) then -- Case insentive matching. -- local lower_case_short_description = short_description:lower() -- for exclusion in hashDelimitedList(not_wikidata_descriptions_including:lower()) do -- if lower_case_short_description:match(exclusion) then short_description='' -- break -- end -- end -- end ifisEmpty(short_description)then returnformatResult(result,dash,fallback,args.prefix_parentheses) end else short_description=short_description.explicit end locallower_case_name=name:lower() ifnotEmpty(short_description)andnotshort_description:match(' ')then -- Filter against likely rubbish single word descriptions. locallower_case_short_description=short_description:lower() localnot_single_word=args.not_single_word ifnotEmpty(not_single_word)then -- Case insentive matching. forsingle_wordinhashDelimitedList(not_single_word:lower())do ifsingle_word==lower_case_short_descriptionthen short_description='' break end end end ifisEmpty(short_description)orlower_case_name:match(lower_case_short_description)then returnformatResult(result,dash,fallback,args.prefix_parentheses) end ifisEmpty(args.space_cat)then maintenance=maintenance..optionallyVisibleCategory( 'category-spaceless-annotation', 'Pages displaying short descriptions with no spaces') end end iflower_case_name==short_description:lower()then iffellbackthen returnformatResult(result,dash,fallback,args.prefix_parentheses) end maintenance=maintenance..optionallyVisibleCategory( 'category-annotation-matches-name', 'Pages displaying short descriptions matching their page name') 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, but -- some descriptions may start with proper names and should start with an uppercase letter even if used in an annotaion. -- By default; this module will not affect the first letter case of descriptions retrieved by Module:GetShortDescription, but -- the first letter case may be transformed explicitly if required. localdesc_first_letter_case=args.desc_first_letter_case ifdesc_first_letter_case=='upper'ordesc_first_letter_case=='lower'then short_description=handleFirstLetterCase(short_description,desc_first_letter_case) end returnformatResult(result,dash,(short_descriptionorfallback)..maintenance,args.prefix_parentheses) end localp={} functionp.main(frame) localargs=require('Module:Arguments').getArgs(frame) ifisEmpty(args)then returnalarmingMessage('could not getArgs')-- This really would be alarming. end returnannotatedLink(args) end returnp