跳转到内容

模块:Error:修订间差异

来自维基百科
zhwiki>Xiplus-abot
已更改“Module:Error”的保护设置:​高風險模板:143636引用<!-- 機器人3 -->([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期))
 
zhwiki>Ahecht
allow accessing from other modules
第3行: 第3行:
local p = {}
local p = {}


local function _error(args)
function p._error(args)
    local message = args.message or args[1] or error('没有指定的-{zh-cn:信息; zh-tw:資訊}-', 2)
    message = tostring(message)
     local tag = mw.ustring.lower(tostring(args.tag))
     local tag = mw.ustring.lower(tostring(args.tag))


第14行: 第12行:


     -- Generate the html.
     -- Generate the html.
     local root = mw.html.create(tag)
     return tostring(mw.html.create(tag)
    root
         :addClass('error')
         :addClass('error')
         :wikitext(message)
        :cssText(args.style)
 
         :wikitext(tostring(args.message or args[1] or error('no message specified', 2)))
     return tostring(root)
     )
end
end


function p.error(frame)
function p.error(frame)
     local args
     local args
     if frame == mw.getCurrentFrame() then
     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的版本

本模块用于生成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