Module:Userbox: Difference between revisions
m Protected "Module:Userbox": Moudle ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) |
No edit summary |
||
| Line 79: | Line 79: | ||
-- Get div tag values. | -- Get div tag values. | ||
data.float = args.float | data.float = args.float or 'left' | ||
local borderWidthNum = checkNum(args['border-width'] or args['border-s'], | 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'] or args[1] or args['id-c'] | data.borderColor = args['border-color'] or args['border-c'] or args[1] or args['id-c'] or '#999' | ||
data.width = | 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-background'] or args[2] or args['info-c'] | data.backgroundColor = args['info-background'] or args[2] or args['info-c'] or '#eee' | ||
-- Get info values. | -- Get info values. | ||
data.info = args.info or args[4] or "<code>{{{info}}}</code>" | data.info = args.info or args[4] or "<code>{{{info}}}</code>" | ||
data.infoTextAlign = args['info-a'] | data.infoTextAlign = args['info-a'] or 'left' | ||
data.infoFontSize = checkNumAndAddSuffix(args['info-size'] or args['info-s'], | data.infoFontSize = checkNumAndAddSuffix(args['info-size'] or args['info-s'], 8, 'pt') | ||
data.infoHeight = checkNumAndAddSuffix(args['logo-height'] or args['id-h'], | data.infoHeight = checkNumAndAddSuffix(args['logo-height'] or args['id-h'], 45, 'px') | ||
data.infoPadding = args['info-padding'] or args['info-p'] | data.infoPadding = args['info-padding'] or args['info-p'] or '0 4px 0 4px' | ||
data.infoLineHeight = args['info-line-height'] or args['info-lh'] | data.infoLineHeight = args['info-line-height'] or args['info-lh'] or '1.25em' | ||
data.infoColor = args['info-color'] or args['info-fc'] | data.infoColor = args['info-color'] or args['info-fc'] or 'black' | ||
data.infoOtherParams = args['info-other-param'] or args['info-op'] | data.infoOtherParams = args['info-other-param'] or args['info-op'] | ||
data.infoClass = args['info-class'] | data.infoClass = args['info-class'] | ||
| Line 104: | Line 104: | ||
data.id = id | data.id = id | ||
data.showId = id and true or false | data.showId = id and true or false | ||
data.idWidth = checkNumAndAddSuffix(args['logo-width'] or args['id-w'], | data.idWidth = checkNumAndAddSuffix(args['logo-width'] or args['id-w'], 45, 'px') | ||
data.idHeight = checkNumAndAddSuffix(args['logo-height'] or args['id-h'], | data.idHeight = checkNumAndAddSuffix(args['logo-height'] or args['id-h'], 45, 'px') | ||
data.idBackgroundColor = args['logo-background'] or args[1] or args['id-c'] | data.idBackgroundColor = args['logo-background'] or args[1] or args['id-c'] or '#ddd' | ||
data.idTextAlign = args['id-a'] | 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'] | data.idPadding = args['logo-padding'] or args['id-p'] or '0 1px 0 0' | ||
data.idLineHeight = args['logo-line-height'] or args['id-lh'] | data.idLineHeight = args['logo-line-height'] or args['id-lh'] or '1.25em' | ||
data.idOtherParams = args['logo-other-param'] or args['id-op'] | data.idOtherParams = args['logo-other-param'] or args['id-op'] | ||
data.idClass = args['id-class'] | data.idClass = args['id-class'] | ||
| Line 123: | Line 123: | ||
-- Get div tag values. | -- Get div tag values. | ||
data.float = args.float | data.float = args.float or 'left' | ||
local borderWidthNum = checkNum(args['border-s'] or args[9], | local borderWidthNum = checkNum(args['border-s'] or args[9], 1) -- Used to calculate width. | ||
data.borderWidth = addSuffix(borderWidthNum, 'px') | data.borderWidth = addSuffix(borderWidthNum, 'px') | ||
data.borderColor = args['border-c'] or args[6] or args['id1-c'] or args[1] | data.borderColor = args['border-c'] or args[6] or args['id1-c'] or args[1] or '#999999' | ||
data.width = | 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'] or args[2] | data.backgroundColor = args['info-c'] or args[2] or '#eeeeee' | ||
-- Get info values. | -- Get info values. | ||
data.info = args.info or args[4] or "<code>{{{info}}}</code>" | data.info = args.info or args[4] or "<code>{{{info}}}</code>" | ||
data.infoTextAlign = args['info-a'] | data.infoTextAlign = args['info-a'] or 'left' | ||
data.infoFontSize = checkNumAndAddSuffix(args['info-s'], | data.infoFontSize = checkNumAndAddSuffix(args['info-s'], 8, 'pt') | ||
data.infoColor = args['info-fc'] or args[8] | data.infoColor = args['info-fc'] or args[8] or 'black' | ||
data.infoPadding = args['info-p'] | data.infoPadding = args['info-p'] or '0 4px 0 4px' | ||
data.infoLineHeight = args['info-lh'] | data.infoLineHeight = args['info-lh'] or '1.25em' | ||
data.infoOtherParams = args['info-op'] | data.infoOtherParams = args['info-op'] | ||
| Line 145: | Line 145: | ||
data.showId = true | data.showId = true | ||
data.id = args.logo or args[3] or args.id1 or 'id1' | data.id = args.logo or args[3] or args.id1 or 'id1' | ||
data.idWidth = checkNumAndAddSuffix(args['id1-w'], | data.idWidth = checkNumAndAddSuffix(args['id1-w'], 45, 'px') | ||
data.idHeight = checkNumAndAddSuffix(args['id-h'], | data.idHeight = checkNumAndAddSuffix(args['id-h'], 45, 'px') | ||
data.idBackgroundColor = args['id1-c'] or args[1] | data.idBackgroundColor = args['id1-c'] or args[1] or '#dddddd' | ||
data.idTextAlign = | data.idTextAlign = 'center' | ||
data.idFontSize = | data.idFontSize = checkNumAndAddSuffix(args['id1-s'], 14, 'pt') | ||
data.idLineHeight = args['id1-lh'] | data.idLineHeight = args['id1-lh'] or '1.25em' | ||
data.idColor = args['id1-fc'] or data.infoColor | data.idColor = args['id1-fc'] or data.infoColor | ||
data.idPadding = args['id1-p'] | data.idPadding = args['id1-p'] or '0 1px 0 0' | ||
data.idOtherParams = args['id1-op'] | data.idOtherParams = args['id1-op'] | ||
| Line 158: | Line 158: | ||
data.showId2 = true | data.showId2 = true | ||
data.id2 = args.logo or args[5] or args.id2 or 'id2' | data.id2 = args.logo or args[5] or args.id2 or 'id2' | ||
data.id2Width = checkNumAndAddSuffix(args['id2-w'], | data.id2Width = checkNumAndAddSuffix(args['id2-w'], 45, 'px') | ||
data.id2Height = data.idHeight | data.id2Height = data.idHeight | ||
data.id2BackgroundColor = args['id2-c'] or args[7] or args[1] | data.id2BackgroundColor = args['id2-c'] or args[7] or args[1] or '#dddddd' | ||
data.id2TextAlign = | data.id2TextAlign = 'center' | ||
data.id2FontSize = | data.id2FontSize = checkNumAndAddSuffix(args['id2-s'], 14, 'pt') | ||
data.id2LineHeight = args['id2-lh'] | data.id2LineHeight = args['id2-lh'] or '1.25em' | ||
data.id2Color = args['id2-fc'] or data.infoColor | data.id2Color = args['id2-fc'] or data.infoColor | ||
data.id2Padding = args['id2-p'] | data.id2Padding = args['id2-p'] or '0 0 0 1px' | ||
data.id2OtherParams = args['id2-op'] | data.id2OtherParams = args['id2-op'] | ||
| Line 176: | Line 176: | ||
-- Get div tag values. | -- Get div tag values. | ||
data.float = args.float | data.float = args.float or 'left' | ||
local borderWidthNum = checkNum(args['border-width'] or args['border-s'], | 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'] or args[1] or args['id-c'] | data.borderColor = args['border-color'] or args['border-c'] or args[1] or args['id-c'] or '#999' | ||
data.width = | 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-background'] or args[2] or args['info-c'] | data.backgroundColor = args['info-background'] or args[2] or args['info-c'] or '#eee' | ||
-- Get id values. | -- Get id values. | ||
| Line 191: | Line 191: | ||
-- Get info values. | -- Get info values. | ||
data.info = args.info or args[4] or "<code>{{{info}}}</code>" | data.info = args.info or args[4] or "<code>{{{info}}}</code>" | ||
data.infoTextAlign = args['info-align'] or args['info-a'] | data.infoTextAlign = args['info-align'] or args['info-a'] or 'left' | ||
data.infoFontSize = checkNumAndAddSuffix(args['info-size'] or args['info-s'], | data.infoFontSize = checkNumAndAddSuffix(args['info-size'] or args['info-s'], 8, 'pt') | ||
data.infoPadding = args['info-padding'] or args['info-p'] | data.infoPadding = args['info-padding'] or args['info-p'] or '0 4px 0 4px' | ||
data.infoLineHeight = args['info-line-height'] or args['info-lh'] | data.infoLineHeight = args['info-line-height'] or args['info-lh'] or '1.25em' | ||
data.infoColor = args['info-color'] or args['info-fc'] | data.infoColor = args['info-color'] or args['info-fc'] or 'black' | ||
data.infoOtherParams = args['info-other-param'] or args['info-op'] | data.infoOtherParams = args['info-other-param'] or args['info-op'] | ||
-- Get id2 values. | -- Get id2 values. | ||
data.showId2 = true | data.showId2 = true | ||
data.id2 = args.logo or args[3] or args.id or 'id' | data.id2 = args.logo or args[3] or args.id or 'id' | ||
data.id2Width = checkNumAndAddSuffix(args['logo-width'] or args['id-w'], | data.id2Width = checkNumAndAddSuffix(args['logo-width'] or args['id-w'], 45, 'px') | ||
data.id2Height = checkNumAndAddSuffix(args['logo-height'] or args['id-h'], | data.id2Height = checkNumAndAddSuffix(args['logo-height'] or args['id-h'], 45, 'px') | ||
data.id2BackgroundColor = args['logo-background'] or args[1] or args['id-c'] | data.id2BackgroundColor = args['logo-background'] or args[1] or args['id-c'] or '#ddd' | ||
data.id2TextAlign = args['id-a'] | 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'] | data.id2Padding = args['logo-padding'] or args['id-p'] or '0 0 0 1px' | ||
data.id2LineHeight = args['logo-line-height'] or args['id-lh'] | data.id2LineHeight = args['logo-line-height'] or args['id-lh'] or '1.25em' | ||
data.id2OtherParams = args['logo-other-param'] or args['id-op'] | data.id2OtherParams = args['logo-other-param'] or args['id-op'] | ||
| Line 215: | Line 215: | ||
function p.render(data) | function p.render(data) | ||
-- Renders the userbox html using the content of the data table. | -- Renders the userbox html using the content of the data table. | ||
-- Render the div tag html. | -- Render the div tag html. | ||
local root = mw.html.create('div') | local root = mw.html.create('div') | ||
root | root | ||
:css('float', data.float) | |||
:css('border', (data.borderWidth or '') .. ' solid ' .. (data.borderColor or '')) | |||
:css('margin', '1px') | |||
:css('width', data.width) | |||
:addClass('wikipediauserbox') | |||
:addClass(data.bodyClass) | |||
-- Render the table tag html. | -- Render the table tag html. | ||
local tableroot = root:tag('table') | local tableroot = root:tag('table') | ||
tableroot:attr('role', 'presentation') | tableroot | ||
:attr('role', 'presentation') | |||
:css('border-collapse', 'collapse') | |||
:css('width', data.width) | |||
:css('margin-bottom', '0') | |||
:css('margin-top', '0') | |||
:css('background', data.backgroundColor) | |||
-- Render the id html. | |||
local tablerow = tableroot:tag('tr') | local tablerow = tableroot:tag('tr') | ||
if data.showId then | |||
tablerow:tag('td') | |||
:css('border', '0') | |||
:css('width', data.idWidth) | |||
:css('height', data.idHeight) | |||
:css('background', data.idBackgroundColor) | |||
:css('text-align', data.idTextAlign) | |||
:css('font-size', data.idFontSize) | |||
:css('font-weight', 'bold') | |||
:css('color', data.idColor) | |||
:css('padding', data.idPadding) | |||
:css('line-height', data.idLineHeight) | |||
:css('vertical-align', 'middle') | |||
:cssText(data.idOtherParams) | |||
:addClass(data.idClass) | |||
:wikitext(data.id) | |||
end | |||
-- | -- Render the info html. | ||
tablerow:tag('td') | |||
:css('border', '0') | |||
:css('text-align', data.infoTextAlign) | |||
:css('font-size', data.infoFontSize) | |||
:css('padding', data.infoPadding) | |||
:css('height', data.infoHeight) | |||
:css('line-height', data.infoLineHeight) | |||
:css('color', data.infoColor) | |||
:css('vertical-align', 'middle') | |||
:cssText(data.infoOtherParams) | |||
:addClass(data.infoClass) | |||
:wikitext(data.info) | |||
-- Render the second id html. | |||
if data.showId2 then | |||
tablerow:tag('td') | |||
:css('border', '0') | |||
:css('width', data.id2Width) | |||
:css('height', data.id2Height) | |||
:css('background', data.id2BackgroundColor) | |||
:css('text-align', data.id2TextAlign) | |||
:css('font-size', data.id2FontSize) | |||
:css('font-weight', 'bold') | |||
:css('color', data.id2Color) | |||
:css('padding', data.id2Padding) | |||
:css('line-height', data.id2LineHeight) | |||
:css('vertical-align', 'middle') | |||
:cssText(data.id2OtherParams) | |||
:wikitext(data.id2) | |||
end | end | ||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
if (title.namespace == 2) and not title.text:match("/") then | if (title.namespace == 2) and not title.text:match("/") then | ||
return | return tostring(root) -- regular user page | ||
elseif title.namespace == 14 then | elseif title.namespace == 14 then | ||
return | return tostring(root) -- category | ||
elseif title.isTalkPage then | elseif title.isTalkPage then | ||
return | return tostring(root) -- talk page | ||
end | end | ||
local legible = true | local legible = true | ||
local contrast = require('Module:Color contrast')._ratio | local contrast = require('Module:Color contrast')._ratio | ||
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 | ||
if | if contrast { data.infoColor, data.backgroundColor, error = 0 } < 4.5 then | ||
legible = false | legible = false | ||
end | end | ||
if data.showId and contrast { data.idColor, data.idBackgroundColor, error = 0 } < 4.5 then | |||
if has_text(data.id or "") then | |||
legible = false | |||
end | |||
if data.showId | |||
if has_text(data.id or "") then legible = false end | |||
end | end | ||
if data.showId2 | if data.showId2 and contrast { data.id2Color, data.id2BackgroundColor, error = 0 } < 4.5 then | ||
if has_text(data.id2 or "") then legible = false end | if has_text(data.id2 or "") then | ||
legible = false | |||
end | |||
end | end | ||
| Line 372: | Line 332: | ||
end | end | ||
return | return tostring(root) | ||
end | end | ||
| Line 385: | Line 345: | ||
cats[#cats + 1] = args.usercategory4 | cats[#cats + 1] = args.usercategory4 | ||
cats[#cats + 1] = args.usercategory5 | cats[#cats + 1] = args.usercategory5 | ||
if #cats > 0 then | |||
-- 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 | else | ||
return nil | |||
end | end | ||
end | end | ||
return p | return p | ||