Module:Userbox: Difference between revisions

Remove check for alt text in colour contrast checker. Categorizes too many userboxes which have no actual issue.
m (1 revision imported)
imported>GKFX
(Remove check for alt text in colour contrast checker. Categorizes too many userboxes which have no actual issue.)
 
Line 108: Line 108:
data.idBackgroundColor = args['logo-background'] or args[1] or args['id-c'] or '#ddd'
data.idBackgroundColor = args['logo-background'] or args[1] or args['id-c'] or '#ddd'
data.idTextAlign = args['id-a'] or 'center'
data.idTextAlign = args['id-a'] or 'center'
data.idFontSize = checkNumAndAddSuffix(args['logo-size'] or args[5] or args['id-s'], 14, 'pt')
data.idFontSize = checkNum(args['logo-size'] or args[5] or args['id-s'], 14)
data.idColor = args['logo-color'] or args['id-fc'] or data.infoColor
data.idColor = args['logo-color'] or args['id-fc'] or data.infoColor
data.idPadding = args['logo-padding'] or args['id-p'] or '0 1px 0 0'
data.idPadding = args['logo-padding'] or args['id-p'] or '0 1px 0 0'
Line 149: Line 149:
data.idBackgroundColor = args['id1-c'] or args[1] or '#dddddd'
data.idBackgroundColor = args['id1-c'] or args[1] or '#dddddd'
data.idTextAlign = 'center'
data.idTextAlign = 'center'
data.idFontSize = checkNumAndAddSuffix(args['id1-s'], 14, 'pt')
data.idFontSize = checkNum(args['id1-s'], 14)
data.idLineHeight = args['id1-lh'] or '1.25em'
data.idLineHeight = args['id1-lh'] or '1.25em'
data.idColor = args['id1-fc'] or data.infoColor
data.idColor = args['id1-fc'] or data.infoColor
Line 162: Line 162:
data.id2BackgroundColor = args['id2-c'] or args[7] or args[1] or '#dddddd'
data.id2BackgroundColor = args['id2-c'] or args[7] or args[1] or '#dddddd'
data.id2TextAlign = 'center'
data.id2TextAlign = 'center'
data.id2FontSize = checkNumAndAddSuffix(args['id2-s'], 14, 'pt')
data.id2FontSize = checkNum(args['id2-s'], 14)
data.id2LineHeight = args['id2-lh'] or '1.25em'
data.id2LineHeight = args['id2-lh'] or '1.25em'
data.id2Color = args['id2-fc'] or data.infoColor
data.id2Color = args['id2-fc'] or data.infoColor
Line 205: Line 205:
data.id2BackgroundColor = args['logo-background'] or args[1] or args['id-c'] or '#ddd'
data.id2BackgroundColor = args['logo-background'] or args[1] or args['id-c'] or '#ddd'
data.id2TextAlign = args['id-a'] or 'center'
data.id2TextAlign = args['id-a'] or 'center'
data.id2FontSize = checkNumAndAddSuffix(args['logo-size'] or args[5] or args['id-s'], 14, 'pt')
data.id2FontSize = checkNum(args['logo-size'] or args[5] or args['id-s'], 14)
data.id2Color = args['logo-color'] or args['id-fc'] or data.infoColor
data.id2Color = args['logo-color'] or args['id-fc'] or data.infoColor
data.id2Padding = args['logo-padding'] or args['id-p'] or '0 0 0 1px'
data.id2Padding = args['logo-padding'] or args['id-p'] or '0 0 0 1px'
Line 245: Line 245:
:css('background', data.idBackgroundColor)
:css('background', data.idBackgroundColor)
:css('text-align', data.idTextAlign)
:css('text-align', data.idTextAlign)
:css('font-size', data.idFontSize)
:css('font-size', data.idFontSize .. 'pt')
:css('font-weight', 'bold')
:css('font-weight', 'bold')
:css('color', data.idColor)
:css('color', data.idColor)
Line 278: Line 278:
:css('background', data.id2BackgroundColor)
:css('background', data.id2BackgroundColor)
:css('text-align', data.id2TextAlign)
:css('text-align', data.id2TextAlign)
:css('font-size', data.id2FontSize)
:css('font-size', data.id2FontSize .. 'pt')
:css('font-weight', 'bold')
:css('font-weight', 'bold')
:css('color', data.id2Color)
:css('color', data.id2Color)
Line 301: Line 301:


local function has_text(wikitext)
local function has_text(wikitext)
local function get_alt(text)
return text:match("|alt=([^|]*)") or ""
end
wikitext = wikitext:gsub("]]", "|]]")
wikitext = wikitext:gsub("]]", "|]]")
wikitext = wikitext:gsub("%[%[%s*[Mm][Ee][Dd][Ii][Aa]%s*:[^|]-(|.-)]]", get_alt)
wikitext = wikitext:gsub("%[%[%s*[Mm][Ee][Dd][Ii][Aa]%s*:[^|]-(|.-)]]", "")
wikitext = wikitext:gsub("%[%[%s*[Ii][Mm][Aa][Gg][Ee]%s*:[^|]-(|.-)]]", get_alt)
wikitext = wikitext:gsub("%[%[%s*[Ii][Mm][Aa][Gg][Ee]%s*:[^|]-(|.-)]]", "")
wikitext = wikitext:gsub("%[%[%s*[Ff][Ii][Ll][Ee]%s*:[^|]-(|.-)]]", get_alt)
wikitext = wikitext:gsub("%[%[%s*[Ff][Ii][Ll][Ee]%s*:[^|]-(|.-)]]", "")
return mw.text.trim(wikitext) ~= ""
return mw.text.trim(wikitext) ~= ""
end
end
Line 316: Line 312:
end
end


if data.showId and contrast { data.idColor, data.idBackgroundColor, error = 0 } < 4.5 then
-- For bold text >= 14pt, requirement is only 3.
local idContrastThreshold = 4.5
local id2ContrastThreshold = 4.5
if (data.idFontSize or 0) >= 14 then
idContrastThreshold = 3
end
if (data.id2FontSize or 0) >= 14 then
id2ContrastThreshold = 3
end
if data.showId and contrast { data.idColor, data.idBackgroundColor, error = 0 } < idContrastThreshold then
if has_text(data.id or "") then
if has_text(data.id or "") then
legible = false
legible = false
Line 322: Line 328:
end
end


if data.showId2 and contrast { data.id2Color, data.id2BackgroundColor, error = 0 } < 4.5 then
if data.showId2 and contrast { data.id2Color, data.id2BackgroundColor, error = 0 } < id2ContrastThreshold then
if has_text(data.id2 or "") then
if has_text(data.id2 or "") then
legible = false
legible = false
Anonymous user