Editing Module:Userbox
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 82: | Line 82: | ||
local borderWidthNum = checkNum(args['border-width'] or args['border-s'], 1) -- Used to calculate width. | local borderWidthNum = checkNum(args['border-width'] or args['border-s'], 1) -- Used to calculate width. | ||
data.borderWidth = addSuffix(borderWidthNum, 'px') | data.borderWidth = addSuffix(borderWidthNum, 'px') | ||
data.borderColor = args['border-color'] or args['border-c' | data.borderColor = args['border-color'] or args[1] or args['border-c'] or args['id-c'] or '#999' | ||
data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag. | data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag. | ||
data.bodyClass = args.bodyclass | data.bodyClass = args.bodyclass | ||
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 = | data.idFontSize = checkNumAndAddSuffix(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.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 124: | Line 124: | ||
-- Get div tag values. | -- Get div tag values. | ||
data.float = args.float or 'left' | data.float = args.float or 'left' | ||
local borderWidthNum = checkNum(args['border-s' | local borderWidthNum = checkNum(args[9] or args['border-s'], 1) -- Used to calculate width. | ||
data.borderWidth = addSuffix(borderWidthNum, 'px') | data.borderWidth = addSuffix(borderWidthNum, 'px') | ||
data.borderColor = args['border-c' | data.borderColor = args[1] or args['border-c'] or args['id1-c'] or '#999999' | ||
data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag. | data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag. | ||
data.bodyClass = args.bodyclass | data.bodyClass = args.bodyclass | ||
-- Get table tag values. | -- Get table tag values. | ||
data.backgroundColor = args['info-c' | data.backgroundColor = args[2] or args['info-c'] or '#eeeeee' | ||
-- Get info values. | -- Get info values. | ||
data.info = | data.info = args[4] or args.info or "<code>{{{info}}}</code>" | ||
data.infoTextAlign = args['info-a'] or 'left' | data.infoTextAlign = args['info-a'] or 'left' | ||
data.infoFontSize = checkNumAndAddSuffix(args['info-s'], 8, 'pt') | data.infoFontSize = checkNumAndAddSuffix(args['info-s'], 8, 'pt') | ||
data.infoColor = args['info-fc' | data.infoColor = args[8] or args['info-fc'] or 'black' | ||
data.infoPadding = args['info-p'] or '0 4px 0 4px' | data.infoPadding = args['info-p'] or '0 4px 0 4px' | ||
data.infoLineHeight = args['info-lh'] or '1.25em' | data.infoLineHeight = args['info-lh'] or '1.25em' | ||
Line 147: | Line 147: | ||
data.idWidth = checkNumAndAddSuffix(args['id1-w'], 45, 'px') | data.idWidth = checkNumAndAddSuffix(args['id1-w'], 45, 'px') | ||
data.idHeight = checkNumAndAddSuffix(args['id-h'], 45, 'px') | data.idHeight = checkNumAndAddSuffix(args['id-h'], 45, 'px') | ||
data.idBackgroundColor = args['id1-c' | data.idBackgroundColor = args[1] or args['id1-c'] or '#dddddd' | ||
data.idTextAlign = 'center' | data.idTextAlign = 'center' | ||
data.idFontSize = | data.idFontSize = checkNumAndAddSuffix(args['id1-s'], 14, 'pt') | ||
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 160: | Line 160: | ||
data.id2Width = checkNumAndAddSuffix(args['id2-w'], 45, 'px') | data.id2Width = checkNumAndAddSuffix(args['id2-w'], 45, 'px') | ||
data.id2Height = data.idHeight | data.id2Height = data.idHeight | ||
data.id2BackgroundColor = args['id2-c' | data.id2BackgroundColor = args[7] or args['id2-c'] or args[1] or '#dddddd' | ||
data.id2TextAlign = 'center' | data.id2TextAlign = 'center' | ||
data.id2FontSize = | data.id2FontSize = checkNumAndAddSuffix(args['id2-s'], 14, 'pt') | ||
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 179: | Line 179: | ||
local borderWidthNum = checkNum(args['border-width'] or args['border-s'], 1) -- Used to calculate width. | local borderWidthNum = checkNum(args['border-width'] or args['border-s'], 1) -- Used to calculate width. | ||
data.borderWidth = addSuffix(borderWidthNum, 'px') | data.borderWidth = addSuffix(borderWidthNum, 'px') | ||
data.borderColor = args['border-color'] or args['border-c' | data.borderColor = args['border-color'] or args[1] or args['border-c'] or args['id-c'] or '#999' | ||
data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag. | data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag. | ||
data.bodyClass = args.bodyclass | data.bodyClass = args.bodyclass | ||
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 = | data.id2FontSize = checkNumAndAddSuffix(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.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) | ||
: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) | ||
: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*:[^|]-(|.-)]]", | wikitext = wikitext:gsub("%[%[%s*[Mm][Ee][Dd][Ii][Aa]%s*:[^|]-(|.-)]]", get_alt) | ||
wikitext = wikitext:gsub("%[%[%s*[Ii][Mm][Aa][Gg][Ee]%s*:[^|]-(|.-)]]", | wikitext = wikitext:gsub("%[%[%s*[Ii][Mm][Aa][Gg][Ee]%s*:[^|]-(|.-)]]", get_alt) | ||
wikitext = wikitext:gsub("%[%[%s*[Ff][Ii][Ll][Ee]%s*:[^|]-(|.-)]]", | wikitext = wikitext:gsub("%[%[%s*[Ff][Ii][Ll][Ee]%s*:[^|]-(|.-)]]", get_alt) | ||
return mw.text.trim(wikitext) ~= "" | return mw.text.trim(wikitext) ~= "" | ||
end | end | ||
Line 312: | Line 316: | ||
end | end | ||
if data.showId and contrast { data.idColor, data.idBackgroundColor, error = 0 } < 4.5 then | |||
if data.showId and contrast { data.idColor, data.idBackgroundColor, error = 0 } < | |||
if has_text(data.id or "") then | if has_text(data.id or "") then | ||
legible = false | legible = false | ||
Line 328: | Line 322: | ||
end | end | ||
if data.showId2 and contrast { data.id2Color, data.id2BackgroundColor, error = 0 } < | if data.showId2 and contrast { data.id2Color, data.id2BackgroundColor, error = 0 } < 4.5 then | ||
if has_text(data.id2 or "") then | if has_text(data.id2 or "") then | ||
legible = false | legible = false | ||
Line 335: | Line 329: | ||
if not legible then | if not legible then | ||
root:wikitext(' | root:wikitext('') | ||
end | end | ||
Line 349: | Line 343: | ||
cats[#cats + 1] = args.usercategory2 | cats[#cats + 1] = args.usercategory2 | ||
cats[#cats + 1] = args.usercategory3 | cats[#cats + 1] = args.usercategory3 | ||
if #cats > 0 then | |||
-- Get the title object | |||
local title | |||
if page then | |||
title = mw.title.new(page) | |||
title = mw.title. | 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 | else | ||
return nil | |||
end | end | ||
end | end | ||
return p | return p |