跳转到内容

模組:Delete2

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2020年1月31日 (五) 11:39编辑。这可能和当前版本存在着巨大的差异。

local data = require('Module:Template:Delete/data')

local z = {}

function extractShortDesc(item)
    if item['description'] then
        return item['description']:gsub('{', '{'):gsub('}', '}'):gsub('|', '|')
    else
        return ''
    end
end

function z.CSD_reason(frame)
	local args = frame:getParent().args
	map = {}
    for i, item in ipairs(data) do
        map[item['code']:lower()] = i
        for j, alias in ipairs(item['aliases']) do
            map[alias:lower()] = i
        end
    end
    i = 1
    rows = {}
    arg = args[1]
    if arg and map[mw.text.trim(arg:lower())] then
        item = data[map[mw.text.trim(arg:lower())]]
        if args.reason then 
        	return '[[WP:CSD#' .. item['code'] .. '|CSD ' .. item['code'] .. ']]:<span title="' .. extractShortDesc(item) .. '">' .. item['criteria'] .. '</span>'
        elseif args[2] ~= nil or args[2] ~= '' then
        	return '[[WP:CSD#' .. item['code'] .. '|' .. args[2] .. ']]'
        else
        	return '[[WP:CSD#' .. item['code'] .. '|CSD ' .. item['code'] .. ']]'
        end
        
    elseif arg and mw.text.trim(arg) ~= '' then
        return require('Module:Error').error{'錯誤:無法找到速刪代碼為' .. args[i] .. '的速刪項目。'}
    end
end

return z