Module:Article stub box

From Remilia Wiki
Jump to navigation Jump to search

Compatibility stub-box implementation used by Template:Asbox. Native articles can use Template:Stub.


-- Compatibility interface for Template:Asbox. Native articles use Template:Stub.
-- The original interface was adapted from English Wikipedia's Module:Asbox
-- by CodeHydro, Jackmcbarn and Mr. Stradivarius (CC BY-SA).
local p = {}

function p.main(frame)
    local args = require('Module:Arguments').getArgs(frame)
    local words = { 'This' }
    for _, word in ipairs({ args.subject or '', args.article or 'article', args.qualifier or '' }) do
        if word ~= '' then table.insert(words, word) end
    end
    local categories = { '[[Category:All stub articles]]' }
    local names = {}
    for key, value in pairs(args) do
        if type(key) == 'string' and (key == 'category' or key:match('^category%d+$')) then
            names[value] = true
        end
    end
    local sorted = {}
    for name in pairs(names) do table.insert(sorted, name) end
    table.sort(sorted)
    for _, name in ipairs(sorted) do
        table.insert(categories, '[[Category:' .. name .. ']]')
    end
    local image = args.icon
    if not image and args.image then
        image = '[[File:' .. args.image .. '|' .. (args.pix or '40x30') .. 'px|link=|alt=' .. (args.imagealt or '') .. ']]'
    end
    local output = require('Module:Message')._stub({
        text = table.concat(words, ' ') .. ' is a stub.',
        image_content = image or false,
        note = args.note,
        categories = table.concat(categories),
        nocat = require('Module:Yesno')(args.nocat, false),
    })
    if args.name then
        output = output .. require('Module:Navbar')._navbar({ args.name, mini = 'yes' })
    end
    return frame:extensionTag('templatestyles', '', { src = 'Module:Message/styles.css' }) .. output
end

function p.templatepage()
    return 'See [[Template:Asbox]] for the compatibility interface and [[Template:Stub]] for the native article notice.'
end

return p