跳转到内容

模組:ACGaward/nominee check

维基百科,自由的百科全书
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 criteria = {
    ['1a'] = {'短條目', score = 1},
    ['1b'] = {'中條目', score = 2},
    ['1c'] = {'長條目', score = 3},
    ['1d'] = {'活動條目', score = 1},  -- 與舊標準相容
    ['2a'] = {'小擴充', score = 1},
    ['2b'] = {'中擴充', score = 2},
    ['2c'] = {'大擴充', score = 3},
    ['2d'] = {'活動條目', score = 1},  -- 與舊標準相容
    ['3'] = {'活動條目', score = 1},
    ['4a'] = {'DYK', score = 1},
    ['4b'] = {'優良', score = 5},
    ['4c'] = {'典特', score = 10},
    ['4d'] = {'特色圖片', score = 5},
    ['5']  = {'格式', score = 1},
    ['6']  = {'媒体', score = 3},
    ['7']  = {'他荐', score = 1},
    ['8']  = {'完整评审', score = 1},
}

p.main = makeInvokeFunc('_main')
function p._main(args)
    if args[1] == nil then
        return
    end

    -- Not done
    if args[1] == '0' or args[1] == 'x' then
        return "[[File:Red x.svg|13px|alt=✗|link=]] '''不得分'''。"
    end


    -- Done
    local items = {}
    local _items = mw.text.split(args[1], '%s+')

    local score = 0
    for _, item in ipairs(_items) do
        for code, criterion in pairs(criteria) do
            if item:find('^' .. code) then
                local _, _, commentary = mw.ustring.find(item, '[((](.+)[))]$')
                commentary = commentary or criterion[1]
                table.insert(items, '<span style="margin-right: 0.2em; font-weight: bold;">' .. code .. "</span>" .. '<small>' .. commentary .. '</small>')
                score = score + criterion.score
                break
            end
        end
    end
    score = args.score or score

    local successful_message = '符合' .. table.concat(items, '、') .. ",'''得" .. score .. "分'''"
    if args.no == nil then
        return '[[File:Green check.svg|13px|alt=✓|link=]] ' .. successful_message .. '。'
    end

    -- Partly done
    local items_failed = {}
    local _items_failed = mw.text.split(args.no, '%s+')

    for _, item in ipairs(_items_failed) do
        for code, criterion in pairs(criteria) do
            if item:find('^' .. code) then
                local _, _, commentary = mw.ustring.find(item, '[((](.+)[))]$')
                commentary = commentary or criterion[1]
                table.insert(items_failed, '<span style="margin-right: 0.2em; font-weight: bold;">' .. code .. "</span>" .. '<small>' .. commentary .. '</small>')
                break
            end
        end
    end

    return '[[File:Yellow check.svg|13px|alt=✓|link=]] ' .. successful_message .. ';' .. '不符合' .. table.concat(items_failed, '、') .. '。'

end

return p