Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Error

From Net 7 Portal Wiki

Module:Error/doc

From Wikipedia, see:

This module implements the template {{error}}, see the documentation there.


The above doc is transcluded from Module:Error/doc. (edit | history)
Add categories to the /doc subpage, not here. Subpages of this template.


local p = {}

local function _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.
    text = tostring(args.message or args[1] or error('no message specified', 2))
    if not args.nocat then
        text = text .. "[[Category:Meta/Page with error '" .. text .. "']]"
    end
    return tostring(mw.html.create(tag)
        :addClass('error')
        :wikitext(text)
    )
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 _error(args)
end

return p