local p = {}
function p.main(frame)
local userGroups = mw.text.jsonDecode(mw.title.new("Module:UserGroup/data"):getContent())
local userRole = {}
for _, name in ipairs(userGroups.bureaucrat or {}) do
userRole[name] = 'bureaucrat'
end
for _, name in ipairs(userGroups.sysop or {}) do
if not userRole[name] then
userRole[name] = 'sysop'
end
end
for _, name in ipairs(userGroups.patroller or {}) do
if not userRole[name] then
userRole[name] = 'patroller'
end
end
local colorMap = {
bureaucrat = '#6610f2',
sysop = '#ec407a',
patroller = '#f77f38',
unknown = '#666666'
}
local container = mw.html.create('ul')
container:addClass('flextable')
for i, username in ipairs(frame.args) do
username = mw.text.trim(username)
if username ~= '' then
local role = userRole[username]
local color = colorMap[role] or colorMap.unknown
local item = container:tag('li')
item:css{
['background-color'] = '#f8f9fa',
padding = '0.2em 0.4em',
['border'] = '1px solid #a2a9b1',
['min-width'] = '160px',
['text-align'] = 'center',
['font-weight'] = 'bold',
['justify-content'] = 'center',
['align-items'] = 'center',
['display'] = 'flex'
}
local colored_span_html = string.format(
'<span style="color:%s">-{%s}-</span>',
color,
mw.text.nowiki(username)
)
local anchor_link_wikitext = string.format(
"[[#%s|%s]]",
username,
colored_span_html
)
item:wikitext(anchor_link_wikitext)
end
end
return tostring(container)
end
return p