跳转到内容

模組:Reply to

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

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

local p = {}

local function errormsg (msg)
	return require('Module:Error').error{ msg }
end

local function nouser (template)
	return errormsg( '錯誤:使用[[' ..  template .. ']]時出現錯誤:並無提供-{zh:使用者名稱;zh-tw:使用者名稱;zh-cn:用户名;}-。模板用法見於[[' ..  template .. ']]。' )
end

local function maxuser (template, count)
	return errormsg( '錯誤:[[' ..  template .. ']]最多支持' .. (count or '50') .. '个-{zh-hant:用戶;zh-tw:使用者;zh-hans:用户;}-。如果需要超过' .. (count or '50') .. '个,必须使用多个模板。模板用法見於[[' ..  template .. ']]。' )
end

function p._ping(args)
	local ret = {}
	local error = ''
	local format = string.format
	local template = args['template'] or 'Template:Reply to'
	local i = 1
	while true do
        username = args[i]
        if (username ~= nil) then
        	if username == '' then else
        		ret[#ret + 1] = '[[User:' .. username .. '|' .. (args['label' .. i] or username)  .. ']]'
        	end
			if #ret >= 5 then
				break
			end
			i = i +1
		else
			break
        end
	end
	if args[6] and args[6] == '' then
		error = maxuser(template,'5')
	end
	ret = mw.text.listToText(ret,'、','、')
	if ret == '' then
		return nouser(template)
	end
	ret = (args['@'] or '@') .. '-{' .. ret .. '}-' .. (args['p'] or ':') .. error
	return ret
end

function p.ping(frame)
	local args = {}
	if frame.args.parent then
        args = frame:getParent().args
    else
        args = frame.args
    end
    args['template'] = frame.args['template']
	return p._ping(args)
end

function p._unping(args)
	local ret = {}
	local error = ''
	local format = string.format
	local i = 1
	while true do
        username = args[i]
        if (username ~= nil) then
        	if username == '' then else
        		ret[#ret + 1] = '[[User:' .. username .. '|' .. (args['label' .. i] or username)  .. ']]'
        	end
			if #ret >= 50 then
				break
			end
			i = i +1
		else
			break
        end
	end
	if args[51] then
		error = maxuser('Template:Unping')
	end
	ret = mw.text.listToText(ret,'、','、')
	if ret == '' then
		return nouser('Template:Unping')
	end
	ret = '<span class="plainlinks">@-{' .. ret .. '}-</span>' .. (args['p'] or ':') .. error
	return ret
end

function p.unping(frame)
	local args = frame:getParent().args
	return p._unping(args)
end

function p._hidden_ping(args)
	local ret = {}
	local error = ''
	local format = string.format
	local i = 1
	while true do
        username = args[i]
        if (username ~= nil) then
        	if username == '' then else
        		ret[#ret + 1] = '[[User:' .. username .. '|' .. (args['label' .. i] or username)  .. ']]'
        	end
			if #ret >= 50 then
				break
			end
			i = i +1
		else
			break
        end
	end
	if args[51] then
		error = maxuser('Template:Noping')
	end
	ret = mw.text.listToText(ret)
	if ret == '' then
		return  nouser('Template:Noping')
	end
	ret = '<span style="display:none">' .. ret .. '</span>' .. error
	return ret
end

function p.hidden_ping(frame)
	local args = frame:getParent().args
	return p._hidden_ping(args)
end

return p