Module:Alert list
Appearance
This module provides functionality to Template:Alert list.
Usage
[edit]To use this module, add the following code to your wiki page:
{{#invoke:Alert_list|main}}
Inputs
[edit]See Template:Alert list#Usage.
Outputs
[edit]This module outputs a single string containing the HTML markup for the generated alert list. Each alert will include:
- The icon (either the custom icon or the one associated with the specified type)
- The label (either the custom label or the one associated with the specified type)
- The optional message, action, and timestamp (if provided)
local p = {}
local standardIcons = require('Module:Standard icons')
local iconTable = standardIcons.getIconTable()
local labelTable = {
["frequent-domain"] = "Frequent domain",
["prohibited-domain"] = "Prohibited domain appears in article",
["new-domain"] = "Unrecognized domain",
["flagged-domain"] = "Flagged domain",
alert = "Alert",
discuss = "New talk page thread",
info = "Information",
}
local function renderNotification(args, index)
local typeKey = args['type' .. index]
local icon = args['icon' .. index] or iconTable[typeKey]
local label = args['label' .. index] or labelTable[typeKey]
local msg = args['msg' .. index]
local action = args['action' .. index]
local time = args['time' .. index]
if not icon or not label then
return ''
end
local notification = {
'* [[File:' .. icon .. "|25px|link=]] <span class='notification-list-label'>" .. label .. "</span>",
}
if msg and msg ~= '' then
table.insert(notification, '*: ' .. msg)
end
if action and action ~= '' then
table.insert(notification, '*: ' .. action)
end
if time and time ~= '' then
table.insert(notification, '*: <small>' .. time .. '</small>')
end
return table.concat(notification, '\n')
end
function p.main(frame)
local args = frame:getParent().args
local output = {}
local maxIndex = 0
for key, _ in pairs(args) do
local index = tonumber(key:match("(%d+)$"))
if index and index > maxIndex then
maxIndex = index
end
end
for index = 1, maxIndex do
local notification = renderNotification(args, index)
if notification ~= '' then
table.insert(output, notification)
end
end
return '<div class="notification-list">\n' .. table.concat(output, '\n') .. '\n</div>'
end
return p