- 欢迎来到THBWiki!如果您是第一次来到这里,请点击右上角注册一个帐户
- 有任何意见、建议、求助、反馈都可以在 讨论板 提出
- THBWiki以专业性和准确性为目标,如果你发现了任何确定的错误或疏漏,可在登录后直接进行改正
模块:error
跳到导航
跳到搜索
模块文档[创建]
local p = {}
function p.error(args)
local tag = tostring(args.tag):lower()
if tag ~= 'p' and tag ~= 'span' and tag ~= 'div' then
tag = 'strong'
end
return tostring(mw.html.create(tag)
:addClass('error')
:cssText(args.style)
:wikitext(args.msg)
)
end
function p._main(args)
args = args or {}
local msg = args.msg or args[1] or '错误'
local name = args.name or args[2]
local key = args.key
local cat = args.cat or '有模板错误的页面'
if name then
key = key or ('%s | %s'):format(name, msg)
msg = ('[[[%s]]] %s'):format(name, msg)
else
key = key or msg
end
args.msg = msg
local err = p.error(args)
if cat ~= '' then
cat = (key == '') and ('[[分类:%s]]'):format(cat)
or ('[[分类:%s|^%s^]]'):format(cat, mw.text.nowiki(key))
end
return err .. cat
end
function p.main(frame)
local parent = frame:getParent()
local title = tostring(parent:getTitle())
local args = (title == '模板:error') and parent.args or frame.args
-- 找出错误来自什么模板
if not (args.name or args[2]) and title:match('^模板:') and title ~= '模板:error' then
args.name = title
end
return p._main(args)
end
return p