Jump to content

Module:Userbox: Difference between revisions

Remove check for alt text in colour contrast checker. Categorizes too many userboxes which have no actual issue.
m (3 revisions imported: testing)
(Remove check for alt text in colour contrast checker. Categorizes too many userboxes which have no actual issue.)
Line 82:
local borderWidthNum = checkNum(args['border-width'] or args['border-s'], 1) -- Used to calculate width.
data.borderWidth = addSuffix(borderWidthNum, 'px')
data.borderColor = args['border-color'] or args[1'border-c'] or args['border-c'1] or args['id-c'] or '#999'
data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag.
data.bodyClass = args.bodyclass
Line 108:
data.idBackgroundColor = args['logo-background'] or args[1] or args['id-c'] or '#ddd'
data.idTextAlign = args['id-a'] or 'center'
data.idFontSize = checkNumAndAddSuffixcheckNum(args['logo-size'] or args[5] or args['id-s'], 14, 'pt')
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'
Line 124:
-- Get div tag values.
data.float = args.float or 'left'
local borderWidthNum = checkNum(args[9'border-s'] or args['border-s'9], 1) -- Used to calculate width.
data.borderWidth = addSuffix(borderWidthNum, 'px')
data.borderColor = args[1'border-c'] or args['border-c'6] or args['id1-c'] or args[1] or '#999999'
data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag.
data.bodyClass = args.bodyclass
 
-- Get table tag values.
data.backgroundColor = args[2'info-c'] or args['info-c'2] or '#eeeeee'
 
-- Get info values.
data.info = args[4].info or args.info[4] or "<code>{{{info}}}</code>"
data.infoTextAlign = args['info-a'] or 'left'
data.infoFontSize = checkNumAndAddSuffix(args['info-s'], 8, 'pt')
data.infoColor = args[8'info-fc'] or args['info-fc'8] or 'black'
data.infoPadding = args['info-p'] or '0 4px 0 4px'
data.infoLineHeight = args['info-lh'] or '1.25em'
Line 147:
data.idWidth = checkNumAndAddSuffix(args['id1-w'], 45, 'px')
data.idHeight = checkNumAndAddSuffix(args['id-h'], 45, 'px')
data.idBackgroundColor = args[1'id1-c'] or args['id1-c'1] or '#dddddd'
data.idTextAlign = 'center'
data.idFontSize = checkNumAndAddSuffixcheckNum(args['id1-s'], 14, 'pt')
data.idLineHeight = args['id1-lh'] or '1.25em'
data.idColor = args['id1-fc'] or data.infoColor
Line 160:
data.id2Width = checkNumAndAddSuffix(args['id2-w'], 45, 'px')
data.id2Height = data.idHeight
data.id2BackgroundColor = args[7'id2-c'] or args['id2-c'7] or args[1] or '#dddddd'
data.id2TextAlign = 'center'
data.id2FontSize = checkNumAndAddSuffixcheckNum(args['id2-s'], 14, 'pt')
data.id2LineHeight = args['id2-lh'] or '1.25em'
data.id2Color = args['id2-fc'] or data.infoColor
Line 179:
local borderWidthNum = checkNum(args['border-width'] or args['border-s'], 1) -- Used to calculate width.
data.borderWidth = addSuffix(borderWidthNum, 'px')
data.borderColor = args['border-color'] or args[1'border-c'] or args['border-c'1] or args['id-c'] or '#999'
data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag.
data.bodyClass = args.bodyclass
Line 205:
data.id2BackgroundColor = args['logo-background'] or args[1] or args['id-c'] or '#ddd'
data.id2TextAlign = args['id-a'] or 'center'
data.id2FontSize = checkNumAndAddSuffixcheckNum(args['logo-size'] or args[5] or args['id-s'], 14, 'pt')
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'
Line 229:
local tableroot = root:tag('table')
tableroot
:attr('role', 'presentation')
:css('border-collapse', 'collapse')
:css('width', data.width)
Line 238 ⟶ 239:
local tablerow = tableroot:tag('tr')
if data.showId then
tablerow:tag('thtd')
:css('border', '0')
:css('width', data.idWidth)
Line 244 ⟶ 245:
:css('background', data.idBackgroundColor)
:css('text-align', data.idTextAlign)
:css('font-size', data.idFontSize .. 'pt')
:css('font-weight', 'bold')
:css('color', data.idColor)
:css('padding', data.idPadding)
Line 270 ⟶ 272:
-- Render the second id html.
if data.showId2 then
tablerow:tag('thtd')
:css('border', '0')
:css('width', data.id2Width)
Line 276 ⟶ 278:
:css('background', data.id2BackgroundColor)
:css('text-align', data.id2TextAlign)
:css('font-size', data.id2FontSize .. 'pt')
:css('font-weight', 'bold')
:css('color', data.id2Color)
:css('padding', data.id2Padding)
Line 292 ⟶ 295:
elseif title.isTalkPage then
return tostring(root) -- talk page
end
 
local chargslegible = {}true
local contrast = require('Module:Color contrast')._ratio
 
local function has_text(wikitext)
wikitext = wikitext:gsub("]]", "|]]")
wikitext = wikitext:gsub("%[%[%s*[Mm][Ee][Dd][Ii][Aa]%s*:[^|]-(|.-)]]", "")
wikitext = wikitext:gsub("%[%[%s*[Ii][Mm][Aa][Gg][Ee]%s*:[^|]-(|.-)]]", "")
wikitext = wikitext:gsub("%[%[%s*[Ff][Ii][Ll][Ee]%s*:[^|]-(|.-)]]", "")
return mw.text.trim(wikitext) ~= ""
end
 
if contrast { data.infoColor, data.backgroundColor, error = 0 } < 4.5 then
legible = false
end
 
-- 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
legible = false
end
end
 
if data.showId2 and contrast { data.id2Color, data.id2BackgroundColor, error = 0 } < id2ContrastThreshold then
if has_text(data.id2 or "") then
legible = false
end
end
 
if not legible then
root:wikitext('[[Category:Userboxes with insufficient color contrast]]')
end
 
Line 305 ⟶ 349:
cats[#cats + 1] = args.usercategory2
cats[#cats + 1] = args.usercategory3
if cats[#cats >+ 1] 0= thenargs.usercategory4
cats[#cats + 1] = args.usercategory5
-- Get the title object
local -- Get the title object
local title
if page then
title = mw.title.new(page)
else
title = mw.title.getCurrentTitle()
end
-- Build category handler arguments.
local chargs = {}
chargs.page = page
chargs.nocat = args.nocat
chargs.main = '[[Category:Pages with misplaced templates]]'
if args.notcatsubpages then
chargs.subpage = 'no'
end
-- User namespace.
local user = ''
for i, cat in ipairs(cats) do
user = user .. makeCat(cat)
end
chargs.user = user
-- Template namespace.
local basepage = title.baseText
local template = ''
for i, cat in ipairs(cats) do
template = template .. makeCat(cat, ' ' .. basepage)
end
chargs.template = template
return categoryHandler(chargs)
else
title = mw.title.getCurrentTitle()
return nil
end
-- Build category handler arguments.
local chargs = {}
chargs.page = page
chargs.nocat = args.nocat
chargs.main = '[[Category:Pages with misplaced templates in the wrong namespace]]'
if args.notcatsubpages then
chargs.subpage = 'no'
end
-- User namespace.
local user = ''
for i, cat in ipairs(cats) do
user = user .. makeCat(cat)
end
chargs.user = user
-- Template namespace.
local basepage = title.baseText
local template = ''
for i, cat in ipairs(cats) do
template = template .. makeCat(cat, ' ' .. basepage)
end
chargs.template = template
return categoryHandler(chargs)
end
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.