模組:沙盒/Lopullinen/icon

local p = {}

local getArgs = require('Module:Arguments').getArgs
local function makeInvokeFunc(funcName)
    return function(frame)
        local args = getArgs(frame)
        return p[funcName](args)
    end
end

local data = {
    -- quality ranks
    fa = { image = "Featured article star.svg", tooltip = "典範級條目", link = "Wikipedia:典范条目" },
    fl = { image = "Featured article star.svg", tooltip = "特色列表級條目", link = "Wikipedia:特色列表" },
    ga = { image = "Symbol support vote.svg", tooltip = "優良級條目", link = "Wikipedia:优良条目" },
    b = { image = "Symbol b class.svg", tooltip = "乙級條目", link = "Wikipedia:条目质量评级标准/乙级" },
    bl = { image = "Symbol b class.svg", tooltip = "乙級列表級條目", link = "Wikipedia:条目质量评级标准/乙级" },
    c = { image = "Symbol c class.svg", tooltip = "丙級條目", link = "Wikipedia:条目质量评级标准/丙级" },
    cl = { image = "Symbol c class.svg", tooltip = "丙級列表級條目", link = "Wikipedia:条目质量评级标准/丙级" },
    start = { image = "Symbol start class.svg", tooltip = "初級條目", link = "Wikipedia:条目质量评级标准/初级" },
    list = { image = "Symbol list class.svg", tooltip = "列表級條目", link = "Wikipedia:独立列表" },
    stub = { image = "Symbol stub class.svg", tooltip = "小作品級條目", link = "Wikipedia:小作品" },
    sl = { image = "Symbol sl class.svg", tooltip = "小列表級條目", link = "Wikipedia:小作品" },
    unassessed = { image = "Symbol question.svg", tooltip = "未評級條目", link = nil },

    -- reviews
    fac = { image = "Cscr-candidate.svg", tooltip = "典範條目評審", link = "Wikipedia:典范条目评选" },
    flc = { image = "Cscr-candidate.svg", tooltip = "特色列表評審", link = "Wikipedia:特色列表评选" },
    gan = { image = "GA candidate.svg", tooltip = "優良條目評審", link = "Wikipedia:優良條目評選" },
    pr = { image = "Nuvola apps kedit.svg", tooltip = "同行評審", link = "Wikipedia:同行评审" },
    bcr = { image = "B candidate.svg", tooltip = "專題乙級內容評審", link = "Template:WPBannerMeta/hooks/bchecklist" },

    -- tasks
    daily = { image = "Symbol current class.svg", tooltip = "日常任務", link = nil },
    short = { image = "Symbol future class.svg", tooltip = "短期任務", link = nil },
    long = { image = "Symbol deferred class.svg", tooltip = "長期任務", link = nil },

    -- trivia
    category = { image = "Symbol category class.svg", tooltip = "分類頁", link = nil },
    project = { image = "Symbol project class.svg", tooltip = "專案頁", link = nil },
    template = { image = "Symbol template class.svg", tooltip = "模板頁", link = nil },
    user = { image = "Symbol user class.svg", tooltip = "用戶頁", link = nil },
}

p.icon = makeInvokeFunc('_icon')
function p._icon(args)
    for k, v in pairs(data) do
        if mw.ustring.lower(args[1]) == k then
            return '[[File:' .. v['image'] ..
                    '|alt=' .. v['tooltip'] ..
                    '|link=' .. (v['link'] or '') ..
                    '|16px' ..
                    '|' .. v['tooltip'] ..
                    ']]'
        end
    end
end

p.footer = makeInvokeFunc('_footer')
function p._footer(args)
    local codes = mw.text.split(args[1], ',%s*')
    local images = {}
    for _, v in ipairs(codes) do
        if data[v] then
            local image = data[v]['image']
            table.insert(images, ': [[File:' .. image .. '|14px]]')
        end
    end
    if #images > 0 then
        return '<div class="hlist">\n' ..
                '; 點擊圖示檢視作者\n' .. table.concat(images, '\n') ..
                '</div>'
    end
    return ''
end

return p