跳转到内容

模組:ACGaward/nominee check

维基百科,自由的百科全书

这是本页的一个历史版本,由Lopullinen留言 | 贡献2023年11月5日 (日) 12:01 (it seems work)编辑。这可能和当前版本存在着巨大的差异。

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 = 1},
}

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

    -- 未完成
    if args[1] == '0' or args[1] == 'x' then
        return "[[File:Red x.svg|13px|alt=紅叉|link=]] '''未完成'''。"
    end

    -- 分割字符串
    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

    return '[[File:Green check.svg|13px|alt=緑勾|link=]] 符合' .. table.concat(items, '、') .. ",計'''" .. score .. "'''分。"
end

return p