跳转到内容

模組:Delete2

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

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2021年2月6日 (六) 14:02 (test)编辑。这可能和当前版本存在着巨大的差异。

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

local z = {}

function extractAliases(item)
    allnames = {item['code']}
    for j, alias in ipairs(item['aliases']) do
        table.insert(allnames, alias)
    end
    return allnames
end

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

function z.reasons_box(frame)
	local wt = [=[
{|class="wikitable
|-
!速刪編號!!可使用的代碼!!簡介!!詳細說明
	]=]
    for i, item in ipairs(data) do
        allnames = extractAliases(item)
        wt = wt .. string.format([=[
|-
|%s
|
* %s
|%s
|%s
        ]=]
        , item['code'], mw.text.listToText(allnames, '\n* ', '\n* '), item['criteria'], extractShortDesc(item):gsub('{{', '{{tl|'):gsub('|', '|'):gsub('}}', '}}'))
    end
    wt = wt .. '|}'
    return frame:preprocess(wt)
end

function z.reasons_box_sb(frame)
	local wt = [=[

<span style="font-weight:bold; background-color:#FFDD77; color:#800000;">(*)</span><span style="font-weight:bold; color:red;">提醒:此渲染版本為沙盒版本,可能與目前通行版本有所不同!</span>

{|class="wikitable
|-
!速刪編號!!可使用的代碼!!簡介!!詳細說明
	]=]
    for i, item in ipairs(require('Module:Template:Delete/data/sandbox')) do
        allnames = extractAliases(item)
        wt = wt .. string.format([=[
|-
|%s
|
* %s
|%s
|%s
        ]=]
        , item['code'], mw.text.listToText(allnames, '\n* ', '\n* '), item['criteria'], extractShortDesc(item):gsub('&#123;&#123;', '{{tl|'):gsub('&#124;', '|'):gsub('&#125;&#125;', '}}'))
    end
    wt = wt .. '|}'
    return frame:preprocess(wt)
end

function z.CSD_reason(frame)
	if frame.args.parent then
        args = frame:getParent().args
    else
        args = frame.args
    end
	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 ~= nil then
        if arg and map[mw.text.trim(arg:lower())] then
            item = data[map[mw.text.trim(arg:lower())]]
            local text = ''
            if args[2] ~= nil and args[2] ~= '' then
        	    text = args[2]
            elseif args['notCSD'] ~= nil and args['notCSD'] ~= '' then
        	    text = item['code']
            else
        	    text = 'CSD ' .. item['code']
            end
            if args.reason then
            	return '[[WP:CSD#' .. item['code'] .. '|' .. text .. ']]:<span title="' .. extractShortDesc(item) .. '">' .. item['criteria'] .. '</span>'
            elseif args.onlyreason then
            	return '<span title="' .. extractShortDesc(item) .. '">' .. item['criteria'] .. '</span>'
            else
            	return '[[WP:CSD#' .. item['code'] .. '|' .. text .. ']]'
            end
        elseif arg and mw.text.trim(arg) ~= '' then
            return require('Module:Error').error{'錯誤:無法找到速刪代碼為' .. args[i] .. '的速刪項目。'}
        end
    else
       	return '[[WP:CSD|' .. (args[2] or '快速删除方针') .. ']]'
    end
end

function z.CSD_reason_sb(frame)
	if frame.args.parent then
        args = frame:getParent().args
    else
        args = frame.args
    end
	map = {}
    for i, item in ipairs(sbdata) 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 ~= nil then
        if arg and map[mw.text.trim(arg:lower())] then
            item = sbdata[map[mw.text.trim(arg:lower())]]
            local text = ''
            if args[2] ~= nil and args[2] ~= '' then
        	    text = args[2]
            elseif args['notCSD'] ~= nil and args['notCSD'] ~= '' then
        	    text = item['code']
            else
        	    text = 'CSD ' .. item['code']
            end
            if args.reason then
            	return '[[WP:CSD#' .. item['code'] .. '|' .. text .. ']]:<span title="' .. extractShortDesc(item) .. '">' .. item['criteria'] .. '</span>'
            elseif args.onlyreason then
            	return '<span title="' .. extractShortDesc(item) .. '">' .. item['criteria'] .. '</span>'
            else
            	return '[[WP:CSD#' .. item['code'] .. '|' .. text .. ']]'
            end
        elseif arg and mw.text.trim(arg) ~= '' then
            return require('Module:Error').error{'錯誤:無法找到速刪代碼為' .. args[i] .. '的速刪項目。'}
        end
    else
       	return '[[WP:CSD|' .. (args[2] or '快速删除方针') .. ']]'
    end
end

return z