跳转到内容

模組: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

local function userlist (args, format, template, count)
	local wt = {}
	local i = 1
	while true do
        username = args[i]
        if (username ~= nil) then
        	if username == '' then else
        		wt[#wt + 1] = string.format(format, username, (args['label' .. i] or username))
        	end
			if #wt >= (count or 50) then
				break
			end
			i = i +1
		else
			break
        end
	end
	if wt ~= '' then
		return mw.text.listToText(wt,'、','、')
	else
		return nil
	end
end

function p._ping(args)
	local error = ''
	local template = args['template'] or 'Template:Reply to'
	if args[6] and args[6] == '' then
		error = maxuser(template,'5')
	end
	if userlist (args, '-{[[User:%s|%s]]}-' , template, 5) == nil then
		return nouser(template)
	end
	return (args['@'] or '@') .. userlist (args, '-{[[User:%s|%s]]}-' , template, 5) .. (args['p'] or ':') .. error
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 error = ''
	if args[51] then
		error = maxuser('Template:Unping')
	end
	if userlist (args, '-{[[User:%s|%s]]}-' , template, 5) == nil then
		return nouser('Template:Unping')
	end
	return '<span class="plainlinks">' .. (args['@'] or '@') .. userlist (args, '-{[[User:%s|%s]]}-' , template, 5) .. '</span>' .. (args['p'] or ':') .. error
end

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

function p._hidden_ping(args)
	local error = ''
	if args[51] then
		error = maxuser('Template:Noping')
	end
	if userlist (args, '-{[[User:%s|%s]]}-' , 'Template:Noping') == nil then
		return nouser('Template:Noping')
	end
	return '<span class="plainlinks">' .. (args['@'] or '@') .. userlist (args, '-{[[User:%s|%s]]}-' , 'Template:Noping') .. '</span>' .. (args['p'] or ':') .. error
end

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

return p