模块:Error:修订间差异
外观
zhwiki>Xiplus-abot 小 已更改“Module:Error”的保护设置:高風險模板:143636引用<!-- 機器人3 -->([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期)) |
zhwiki>Ahecht allow accessing from other modules |
||
| 第3行: | 第3行: | ||
local p = {} | local p = {} | ||
function p._error(args) | |||
local tag = mw.ustring.lower(tostring(args.tag)) | local tag = mw.ustring.lower(tostring(args.tag)) | ||
| 第14行: | 第12行: | ||
-- Generate the html. | -- Generate the html. | ||
return tostring(mw.html.create(tag) | |||
:addClass('error') | :addClass('error') | ||
:wikitext(message) | :cssText(args.style) | ||
:wikitext(tostring(args.message or args[1] or error('no message specified', 2))) | |||
) | |||
end | end | ||
function p.error(frame) | function p.error(frame) | ||
local args | local args | ||
if frame == | if type(frame.args) == 'table' then | ||
-- We're being called via #invoke. The args are passed through to the module | -- We're being called via #invoke. The args are passed through to the module | ||
-- from the template page, so use the args that were passed into the template. | -- from the template page, so use the args that were passed into the template. | ||
| 第38行: | 第35行: | ||
args.message = nil | args.message = nil | ||
end | end | ||
return _error(args) | return p._error(args) | ||
end | end | ||
return p | return p | ||
2025年9月11日 (四) 23:10的版本
| 此Module被引用於約87,000個頁面。 為了避免造成大規模的影響,所有對此Module的編輯應先於沙盒或測試樣例上測試。 測試後無誤的版本可以一次性地加入此Module中,但是修改前請務必於討論頁發起討論。 模板引用數量會自動更新。 |
本模块用于生成class属性为error的错误提示,可用于{{error}},用法详见模板说明。
-- This module implements {{error}}.
local p = {}
function p._error(args)
local tag = mw.ustring.lower(tostring(args.tag))
-- Work out what html tag we should use.
if not (tag == 'p' or tag == 'span' or tag == 'div') then
tag = 'strong'
end
-- Generate the html.
return tostring(mw.html.create(tag)
:addClass('error')
:cssText(args.style)
:wikitext(tostring(args.message or args[1] or error('no message specified', 2)))
)
end
function p.error(frame)
local args
if type(frame.args) == 'table' then
-- We're being called via #invoke. The args are passed through to the module
-- from the template page, so use the args that were passed into the template.
args = frame.args
else
-- We're being called from another module or from the debug console, so assume
-- the args are passed in directly.
args = frame
end
-- if the message parameter is present but blank, change it to nil so that Lua will
-- consider it false.
if args.message == "" then
args.message = nil
end
return p._error(args)
end
return p