local p = {}
local getArgs = require('Module:Arguments').getArgs
local Colorhime = require('Module:Colorhime')
-- Replicates {{Coloredlink|color|page|display}} → [[page|<span style="color:…">display</span>]]
local function coloredLink(color, page, display)
display = display or page
return string.format('[[%s|<span style="color:%s;">%s</span>]]', page, color, display)
end
-- Replicates {{ColoredEdit|color|display}} → external edit link of current page
local function coloredEdit(color, display)
local url = tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().fullText, { action = 'edit' }))
return string.format('[%s <span style="color:%s;">%s</span>]', url, color, display)
end
function p._main(args, frame)
-- Parameters (defaults mirror the original wikitext template)
local class = args.class or ''
local bordercolor = args.bordercolor or '#096'
local image = args.image or ''
local customimage = args.customimage or ''
local link = args.link or '虚拟UP主'
local color = args.color or '#096'
local bgcolor = args.bgcolor or ''
local article = args.article or ''
local exclamation = args.exclamation or ''
local linkcolor = args.linkcolor or ''
local customExcl = args['custom-excl'] or ''
-- autocolor: derive color and bgcolor automatically from a base colour
if (args.autocolor or '') ~= '' then
local chArgs = {
args.autocolor, -- [1]: the input hex colour
['color-txt'] = '132',
['color-r'] = '+88',
['alpha-r'] = 0.8,
['output'] = 'txt', -- → used as |color=
}
color = '#' .. Colorhime.getColor(chArgs)
chArgs['output'] = 'r' -- → used as |bgcolor=
bgcolor = Colorhime.getColor(chArgs)
bordercolor = color
end
-- image / width defaults
local imageParam
if customimage ~= '' then
imageParam = ''
else
imageParam = (image ~= '') and image or '萌薇头像.png'
end
local widthParam
if args.width and args.width ~= '' then
widthParam = args.width
elseif image ~= '' then
widthParam = '99'
else
widthParam = '64'
end
-- effective link colours (matches the {{#if:{{{linkcolor|}}}|…|#0645ad}} bits)
local effLink = (linkcolor ~= '') and linkcolor or '#0645ad'
local effQQ = (linkcolor ~= '') and linkcolor or '#36b'
-- |article= default: {{coloredlink|color|虚拟UP主}}相关条目
local articleParam
if article ~= '' then
articleParam = article
else
articleParam = coloredLink(color, '虚拟UP主') .. '相关条目'
end
-- text2: 协助[编辑本条目]前,请先阅读… (+ optional group invite)
local groupInvite = ''
if customExcl == '' then
groupInvite = string.format(
'同时欢迎加入%s'
.. '(QQ群:[https://qm.qq.com/q/kcFEEuZIeQ <span style="color:%s;">273049699</span>])'
.. '与更多同好编辑者交流。',
coloredLink(effLink, 'Template:萌娘百科虚拟UP主编辑组', '萌娘百科虚拟UP主编辑组'),
effQQ
)
end
local text2 = string.format(
'协助%s前,请先阅读%s及%s,%s'
.. '祝您在萌娘百科度过愉快的时光。',
coloredEdit(effLink, '编辑本条目'),
coloredLink(effLink, 'Help:萌百编辑简明指南/欢迎', '萌百编辑简明指南'),
coloredLink(effLink, '萌娘百科:虚拟UP主专题编辑指引', '本专题编辑指引'),
groupInvite
)
-- Build args for {{Customtop}}
local ctArgs = {
class = class,
bordercolor = bordercolor,
image = imageParam,
link = link,
width = widthParam,
customimage = customimage,
bgcolor = bgcolor,
color = color,
article = articleParam,
exclamation = exclamation,
text2 = text2,
}
-- Pass through positional improvement items (1..16)
for i = 1, 16 do
if args[i] and mw.text.trim(args[i]) ~= '' then
ctArgs[i] = args[i]
end
end
return frame:expandTemplate{ title = 'Customtop', args = ctArgs }
end
function p.main(frame)
local args = getArgs(frame, { parentFirst = true })
return p._main(args, frame)
end
return p