Content deleted Content added
Fred Gandt (talk | contribs) exclude Wikidata fallback descriptions that are the same as the linked article title; maintenance required is out of reasonable scope |
disable wikidata short descriptions, per RFC and multiple talk page discussions. Please report any bugs on the template talk page |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1:
local function pipedLink(
local function isEmpty(
local function notEmpty(
-- Unescape functionality grabbed from https://stackoverflow.com/a/14899740/1832568
local function unescape(
str = string.gsub(
str = string.gsub(
return str
end
local function hashDelimitedList(
local function alarmingMessage(
return '<span style="color:#d33">[[Module:Annotated link]] '
end
local function optionallyVisibleCategory(
return '<span style="display:none" class="'
'</span>[[Category:' end
local function handleFirstLetterCase(
return mw.ustring.gsub(
if case == 'upper' then
return mw.ustring.upper( end return mw.ustring.lower(
)
end
local mLang = require(
local function langify(
local lang = args.lang
local text = args.text
if isEmpty(
return text end return mLang._lang {
lang,
Line 47 ⟶ 52:
end
local function formatResult(
if notEmpty(
if prefix_parentheses then
local startIdx = description:find("%(")
if startIdx then
local beforeParens = description:sub(1, startIdx - 2)
local insideParens = description:sub(startIdx, -1)
return result..' '..insideParens..dash..' '..beforeParens
end
end
return result..dash..' '..description
end
return result
end
local function annotatedLink(
local name = args.name
if isEmpty(
return alarmingMessage( 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(
if name:match(
-- The possibility to extract useful data exists here: e.g. {{tl*|Template}}.
return alarmingMessage(
'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. local wikilink = mw.ustring.match(
if wikilink then
local link_name, link_display = unpack(
if link_name then
name = link_name end if link_display and isEmpty(
args.display = link_display end end
Line 77 ⟶ 102:
local result
local is_template = name:match(
local template_link = args.template_link
if is_template and template_link ~= 'no' then
result = '{{'
if template_link == 'code' then
result = '<code>'
end
else
local display = args.display
if isEmpty(
display = name end ▲ result = langify( {
lang = args.link_lang,
text = pipedLink(
italic = args.link_lang_italic,
nocat = args.link_lang_nocat,
Line 96 ⟶ 122:
cat = args.link_lang_cat,
rtl = args.link_lang_rtl
}
if notEmpty(
result = '"' end local abbr = args.abbr
if notEmpty(
result = result
local abbr_title = args.abbr_title
if notEmpty(
result = result end
result = result
end
end
if isEmpty(
return alarmingMessage( end local aka = args.aka
if notEmpty(
result = result
lang = args.aka_lang,
text = aka,
Line 121 ⟶ 153:
cat = args.aka_lang_cat,
rtl = args.aka_lang_rtl
}
end
local wedge = args.wedge
if notEmpty(
result = result
lang = args.wedge_lang,
text = wedge,
Line 134 ⟶ 166:
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. local not_wikidata_for_links_starting_with = args.not_wikidata_for_links_starting_with
if isEmpty(
for only_explicit in hashDelimitedList(
if name:match(
args.only = 'explicit' break end
end
end
-- Get the short description from Module:GetShortDescription.
local short_description = require(
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,
Line 159 ⟶ 194:
only = args.only,
name = name
}
local dash = args.dash
if isEmpty(
dash = ' –' end local fallback = args.fallback
if isEmpty(
return formatResult( end if short_description.alarm then
return short_description.alarm end local maintenance = ''
if short_description.redirected then
maintenance = optionallyVisibleCategory(
'category-annotation-with-redirected-description', 'Pages displaying short descriptions of redirect targets' end
Line 179 ⟶ 222:
if short_description.wikidata then
-- 'category-wikidata-fallback-annotation', -- 'Pages displaying wikidata descriptions as a fallback' -- Filter against likely rubbish wikidata descriptions.
-- Case insentive matching.
short_description = '' --
-- end
-- end
-- end
end
else
▲ if isEmpty( short_description ) then return formatResult( result, dash, fallback ) end
end local lower_case_name = name:lower()
if notEmpty(
-- Filter against likely rubbish single word descriptions.
local not_single_word = args.not_single_word
if notEmpty(
-- Case insentive matching.
for single_word in hashDelimitedList(not_single_word:lower()) do
▲ local lower_case_short_description = short_description:lower()
break
end
end
end
if isEmpty(
return formatResult(result, dash, fallback, args.prefix_parentheses)
▲ if isEmpty( args.space_cat ) then
end
if isEmpty(args.space_cat) then
maintenance = maintenance..optionallyVisibleCategory(
'category-spaceless-annotation',
'Pages displaying short descriptions with no spaces')
end
end
if
if fellback then
return formatResult( end maintenance = maintenance
'category-annotation-matches-name', 'Pages displaying short descriptions matching their page name' end
Line 224 ⟶ 289:
local desc_first_letter_case = args.desc_first_letter_case
if desc_first_letter_case == 'upper' or desc_first_letter_case == 'lower' then
short_description = handleFirstLetterCase(
end
return formatResult(
end
local p = {}
function p.main(
local args = require(
if isEmpty(
return alarmingMessage( end
return annotatedLink(
end
|