Модуль:Unsigned

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация

Реализация {{Unsigned}}.

local p = {} -- p stands for package

function p.main (frame)
	local arg1 = mw.ustring.gsub(frame:getParent().args[1] or '', '\226\128\142', '') -- invisible ‎ mark
	local arg2 = mw.ustring.gsub(frame:getParent().args[2] or '', '\226\128\142', '') -- invisible ‎ mark
	
	local agent, moment
	if arg2 == nil or arg2 == '' then
		agent = arg1
	else
		if mw.ustring.match(arg1, '[0-9]+ [а-я]+ 20[0-9]+') then
			agent = arg2
			moment = arg1
		else
			agent = arg1
			moment = arg2
		end
		moment = mw.text.trim(moment)		-- два пробела L-39 ломают «Инструменты обсуждения»
	end
	agent = mw.text.trim(agent) -- пробел в начале ломает ip: Special:Contributions/_ip
	
	if agent == nil or agent == '' then
		return '<span class="error">Unsigned: введены некорректные параметры</span>'
	end
	
	local res = '<small class="autosigned"> —&nbsp;\'\'Эта [[ВП:Подписывайтесь на страницах обсуждения|реплика]] добавлена '
	
	if mw.ustring.match(agent, '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$')
			or mw.ustring.match(agent, '^[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+$') 
			or mw.ustring.match(agent, '^[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+$') then
		res = res .. 'с IP [[Special:Contributions/' .. agent .. '|' .. agent .. ']] ({{фиттс|User talk:' .. agent .. '|о}})'
	else
		res = res .. frame:callParserFunction{ name = 'gender', args = { agent, 'участником', 'участницей' } }
			.. ' [[User:' .. agent .. '|' .. agent .. ']] ({{фиттс|User talk:'
			.. agent .. '|о}} • {{фиттс|Special:Contributions/' .. agent .. '|в}})'
	end
	
	if moment ~= nil and moment ~= '' then
		if not mw.ustring.match(moment, '(UTC)') then
			moment = moment .. '&#32;(UTC)'  -- L-39
		end
		res = res .. ' ' .. moment
	end
	
	res = res .. '\'\'</small>'
	return frame:preprocess(res)
end

return p