Məzmuna keç

Modul:Reply to

Sənədləşdirmə

Bu modul {{reply to}} şablonuna tətbiq olunmuşdur.

local p = {}
local getArgs = require('Module:Arguments').getArgs
local error = require('Module:Error').error

function p.main(frame)
	local args = getArgs(frame, {removeBlanks = false})
	local users = {}
	local limit = tonumber(args.limit) or 50
	local i = 1
	while args[i] and i <= limit do
		users[i] = string.format('[[İstifadəçi:%s|%s]]', args[i], args['label' .. i] or args['l' .. i] or args[i])
		i = i + 1
	end
	if not next(users) then
		return error{'[[Şablon:Reply to|Reply to]] şablonunda xəta: istifadəçi adı göstərilməyib'}
	end

	local formattedUsers = ''
	if #users == 1 then
		formattedUsers = '@' .. users[1] .. ':'
	elseif #users == 2 then
		formattedUsers = '@' .. users[1] .. ' və ' .. users[2] .. ':'
	else
		formattedUsers = '@' .. table.concat(users, ', ', 1, #users - 1)
		formattedUsers = formattedUsers .. ' və ' .. users[#users] .. ':'
	end

	return tostring(
		mw.html.create('span')
			:addClass('template-ping')
			:wikitext(formattedUsers)
	)
end

return p