Module:Message box: Difference between revisions

From Chalo Chatu, Zambia online encyclopedia
Jump to navigationJump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Unified Message box module for Chalo Chatu
local p = {}
local p = {}


-- Disable TemplateStyles temporarily
-- Helper: get box style
local function loadTemplateStyles()
local function makeStyle(type, inline)
-- Normally loads Module:Message box/ombox.css
    local colors = {
-- But disabled because TemplateStyles is not installed
        notice = '#f9f9f9',
return '' -- Return nothing to avoid raw tags
        warning = '#fff2cc',
        error  = '#fdd',
        info    = '#eaf3ff'
    }
 
    local border = {
        notice = '#aaa',
        warning = '#fc3',
        error  = '#d33',
        info    = '#36c'
    }
 
    if inline then
        return string.format(
            "border:1px solid %s; background:%s; padding:0.5em; margin:0.5em 0;",
            border[type] or '#aaa',
            colors[type] or '#f9f9f9'
        )
    else
        return string.format(
            "border:2px solid %s; background:%s; padding:0.5em; margin:1em auto; width:80%%;",
            border[type] or '#aaa',
            colors[type] or '#f9f9f9'
        )
    end
end
end


-- This function is called directly by some modules
-- Article message box
function p.ombox(frame)
function p.ambox(frame)
local args = frame:getParent().args
    local args = frame:getParent().args
local boxType = args.type or 'notice'
    local text = args['text'] or ''
local boxClass = 'mbox mbox-' .. boxType
    local type = args['type'] or 'notice'
local boxStyle = args.style or ''
 
local text = args.text or ''
    local style = makeStyle(type, false)
    return string.format('<div style="%s">%s</div>', style, text)
local box = mw.html.create('table')
box:addClass(boxClass)
box:cssText(boxStyle)
local tr = box:tag('tr')
tr:tag('td'):addClass('mbox-text'):wikitext(text)
return loadTemplateStyles() .. tostring(box)
end
end


-- This is the "main" function that Module:High-use expects
-- Alias: mbox = ambox
function p.main(_type, data)
p.mbox = p.ambox
local boxType = data.type or 'notice'
 
local boxClass = 'mbox mbox-' .. boxType
-- Inline message box
local boxStyle = data.style or ''
function p.imbox(frame)
local text = data.text or ''
    local args = frame:getParent().args
    local text = args['text'] or ''
local box = mw.html.create('table')
    local type = args['type'] or 'notice'
box:addClass(boxClass)
 
box:cssText(boxStyle)
    local style = makeStyle(type, true)
    return string.format('<div style="%s">%s</div>', style, text)
local tr = box:tag('tr')
tr:tag('td'):addClass('mbox-text'):wikitext(text)
return loadTemplateStyles() .. tostring(box)
end
end
-- Alias: infobox = imbox
p.infobox = p.imbox


return p
return p

Latest revision as of 17:44, 3 September 2025

-- Module:Message box/doc -- This is the documentation page for Module:Message box. -- Editors: Please do not edit the module itself here. Documentation only.

Module:Message box

This module creates standardized message boxes such as {{ambox}}, {{imbox}}, {{ombox}}, etc. It is a Lua implementation of the various "box" templates and should be used via those templates, not directly.

Usage

You normally do not call this module directly. Instead, use one of the wrapper templates:

  • {{ambox}} – for article message boxes
  • {{imbox}} – for file and image pages
  • {{tmbox}} – for talk page message boxes
  • {{ombox}} – for other namespaces
  • {{cmbox}} – for category pages

Each wrapper template passes parameters to this module to generate a consistent, styled message box.

Parameters

The wrapper templates accept the following parameters:

type
The type of message box. Examples: speedy, delete, content, style, notice, protection.
This controls the color and icon.
image
Optional custom image/icon (overrides default).
text
The main message text shown in the box.
small
If set to "yes", produces a smaller version of the box.
style
Additional CSS styling applied to the box.
class
Adds custom classes to the message box.

Example

{{ambox | type = content | text = This article needs additional references for verification. }}

Produces:

This article needs additional references for verification.

See also


-- Unified Message box module for Chalo Chatu
local p = {}

-- Helper: get box style
local function makeStyle(type, inline)
    local colors = {
        notice = '#f9f9f9',
        warning = '#fff2cc',
        error   = '#fdd',
        info    = '#eaf3ff'
    }

    local border = {
        notice = '#aaa',
        warning = '#fc3',
        error   = '#d33',
        info    = '#36c'
    }

    if inline then
        return string.format(
            "border:1px solid %s; background:%s; padding:0.5em; margin:0.5em 0;",
            border[type] or '#aaa',
            colors[type] or '#f9f9f9'
        )
    else
        return string.format(
            "border:2px solid %s; background:%s; padding:0.5em; margin:1em auto; width:80%%;",
            border[type] or '#aaa',
            colors[type] or '#f9f9f9'
        )
    end
end

-- Article message box
function p.ambox(frame)
    local args = frame:getParent().args
    local text = args['text'] or ''
    local type = args['type'] or 'notice'

    local style = makeStyle(type, false)
    return string.format('<div style="%s">%s</div>', style, text)
end

-- Alias: mbox = ambox
p.mbox = p.ambox

-- Inline message box
function p.imbox(frame)
    local args = frame:getParent().args
    local text = args['text'] or ''
    local type = args['type'] or 'notice'

    local style = makeStyle(type, true)
    return string.format('<div style="%s">%s</div>', style, text)
end

-- Alias: infobox = imbox
p.infobox = p.imbox

return p