Minecraft Wiki
Advertisement

Переведено с соответствующего английского модуля.

p.unsigned реализует {{unsigned}} и {{undated}}.

p.auto реализует {{autoUnsigned}}.

Зависит от:[]

local p = {}
function base( args )
	local type = args['тип'] or 'Unsigned'
    local typetable = {unsigned = 'неподписанная', undated = 'не содержащая дату'} --добавлено в переводе
	local user = args['участник']
	local date = args['дата']
	if date and not date:find( '%(UTC%)$' ) and not date:find( '%(MSK%)$' ) then
		date = date .. ' (UTC)'
	end
	local nowiki = ''
	if mw.isSubsting() then
		nowiki = '<nowiki/>'
	end
	local text = {
		'<small>— Эта [[ruwiki:ВП:ПОД|' .. (typetable[mw.ustring.lower( type )] or 'неподписанная') .. ']] реплика была добавлена',
		'. Подписывайте свои сообщения с помощью ~~' .. nowiki .. '~~.</small><!-- Шаблон:' .. type .. ' -->'
	}
	if date then
		table.insert( text, 2, ' в ' .. date )
	end
	if user then
		local userLinks
		if not user:find( '[^:%x%.%d]' ) and require( 'Модуль:IPAddress' ).isIP( user ) then
			userLinks = 'с IP [[Служебная:Вклад/' .. user .. '|' .. user .. ']] ([[Обсуждение участника:' .. user .. '|обс.]])'
		else
			userLinks = 'участником [[Участник:' .. user .. '|' .. user .. ']] ([[Обсуждение участника:' .. user .. '|обс.]] · [[Служебная:Вклад/' .. user .. '|вклад]])'
		end
		table.insert( text, 2, ' ' .. userLinks )
	end

	return table.concat( text )
end

p.unsigned = function( f )
	local args = require( 'Модуль:ProcessArgs' ).norm( f.args or f )
	local type = args['тип'] or 'Unsigned'
	local user = args['участник']
	local date = args['дата']
	local nocat = args['некат'] or nil
	
	local category = { '' }
	if mw.isSubsting() then
		-- Не допускать подстановку, если требуемый аргумент отсутствует
		if type == 'Unsigned' and not user then
			local dateArg = ''
			if date then
				dateArg = '||' .. date
			end
			return '{{Unsigned' .. dateArg .. '}}'
		elseif type == 'Undated' and not date then
			return '{{Undated}}'
		end
	elseif mw.title:getCurrentTitle().namespace ~= 10 and not nocat then
		if type == 'Unsigned' and not user then
			table.insert( category, '[[Категория:Неправильное использование шаблона Unsigned]]' )
		elseif type == 'Undated' and not date then
			table.insert( category, '[[Категория:Неправильное использование шаблона Undated]]' )
		end
		table.insert( category, '[[Категория:Страницы с требующими подстановки шаблонами]]' )
	end
	
	return base( args ) .. table.concat( category )
end

p.auto = function( f )
	if mw.isSubsting() or mw.title:getCurrentTitle().namespace == 10 then
		local date = string.lower( f.args["дата"] or f["дата"] )
		local args = {
			['участник'] = f:preprocess( '{{safesubst:REVISIONUSER: {{safesubst:FULLPAGENAME}}}}' ),
			["дата"] = f:preprocess( '{{safesubst:#timel:G:i, d xg Y|{{safesubst:REVISIONTIMESTAMP: {{safesubst:FULLPAGENAME}} }}}}' )
		}
		
		if date == '1' or date == 'только' then
			args['тип'] = 'Undated'
			args['участник'] = nil
		elseif date == '0' or date == 'нет' then
			args["дата"] = nil
		end
		
		return base( args ) .. '<!-- Шаблон:AutoUnsigned -->'
	else
		return '<span class="error">Шаблон:AutoUnsigned необходимо использовать с подстановкой</span>[[Категория:Неправильное использование шаблона AutoUnsigned]]'
	end
end

return p
Advertisement