Модуль:Конец анкеты/ФИО

Материал из Кадровый состав НКВД 1935-1939
< Модуль:Конец анкеты
Версия от 14:48, 29 января 2016; StasR (обсуждение | вклад)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)
Перейти к навигации Перейти к поиску

Для документации этого модуля может быть создана страница Модуль:Конец анкеты/ФИО/doc

local global = mw.ext.luaglobal
local tools = require( 'Модуль:Tools' )
local genders = { 'мужской', 'женский', 'странный' }


local function printattr( onefio, n ) -- должна печатать "хвосты" (индекс тезки, предупрежедние об отсутствии перенаправления и стандартное завершение параметра персоны)
	local out = {}
	if onefio[4] ~= '' then
		out = { ' <span class="nkvd-idx">' .. onefio[4] .. '</span>' }
	end
	if n ~= 1 then
		if mw.title.new( onefio.fiot ).id == 0 then
			table.insert( out, ' [' .. tostring( mw.uri.fullUrl( onefio.fiot, {
					action = 'edit',
					preload = 'Template:Redirect_pattern',
					editintro = 'Template:Redirect_editnotice',
					['preloadparams[]'] = mw.title.getCurrentTitle().prefixedText
					} ) )
				.. ' <i class="fa fa-warning fa-lg" style="color: #f05f1a;"'
				.. ' title="Создайте страницу-перенаправление для ссылок на псевдоним"></i>]'
				.. '[[Категория:Персоналии с псевдонимами без перенаправления]]' )
		end
	end
	table.insert( out, tools.commonParams( onefio[5], onefio[6], onefio[7] ) )
	return table.concat( out )
end


local function printFio( fio, n )
	local onefio = fio[n]
	local out = { '<b>' .. onefio[1] .. '</b>' }
	if onefio.group == 'F' then
		table.insert( out, printattr( onefio, n )  )
		local list = {}
		for i = 1, onefio.size-1 do
			table.insert( list, '<b>' .. fio[n+i][1] .. '</b>' .. printattr( fio[n+i], 2 ) )
		end
		table.insert( out, ' (' .. table.concat( list, ', ' ) .. ')' )
	end
	if onefio[2] ~= '' then
		table.insert( out, ', ' .. onefio[2] )
		if onefio.group == 'I' then
			table.insert( out, printattr( onefio, n )  )
			local list = {}
			for i = 1, onefio.size-1 do
				table.insert( list, fio[n+i][2] .. printattr( fio[n+i], 2 ) )
			end
			table.insert( out, ' (' .. table.concat( list, ', ' ) .. ')' )
		end
		if onefio[3] ~= '' then
			table.insert( out, ' ' .. onefio[3] )
			if onefio.group == 'O' or onefio.group == 'IO' then
				table.insert( out, printattr( onefio, n )  )
				local list = {}
				for i = 1, onefio.size-1 do
					if onefio.group == 'O' then
						table.insert( list, fio[n+i][3] .. printattr( fio[n+i], 2 ) )
					else
						table.insert( list,
							fio[n+i][2] .. ' ' .. fio[n+i][3] .. printattr( fio[n+i], 2 ) )
					end
				end
				table.insert( out, ' (' .. table.concat( list, ', ' ) .. ')' )
			end
		end
	end
	if not onefio.group then
		table.insert( out, printattr( onefio, n )  )
	end
	return table.concat( out )
end


return function (gOut) -- return gender, fioForJournals	 OR nil, error
	local gFio =  global.get( 'gFIO' )
	local out = {}
	if not gFio then
		return false, tools.errorMsg( 'Конец анкеты', 'В анкете не было шаблона {{ ФИО }}' )
	end
	local gender = global.get( 'gGender' ) or 0
	local fa, im, ot, idx, tmp
	local fioForJournals = {}
	local lastFio = 1
	for i, fio in ipairs( gFio ) do
		fa, im, ot, idx = unpack( fio, 1, 4 )

		tmp = 0
		if mw.ustring.sub( ot, -2, -1 ) == 'ич' or mw.ustring.sub( ot, -3, -1 ) == 'глы'
				 or mw.ustring.sub( ot, -3, -1 ) == 'аде' then
			tmp = 1
		elseif  mw.ustring.sub( ot, -2, -1 ) == 'на' or mw.ustring.sub( ot, -3, -1 ) == 'ызы' then
			tmp = 2
		end
		if gender == 0 then
			gender = tmp
		elseif gender ~= 0 and tmp ~= 0 and gender ~= tmp then
			gender = 3
		end
		fio.fiot = fa
		if im ~= '' then
			fio.fiot = fa .. ', ' .. im
			if ot ~= '' then
				fio.fiot = fio.fiot .. ' ' .. ot
			end
		end
		if idx ~= '' then
			fio.fiot = fio.fiot .. ' ' .. idx
		end
		table.insert( fioForJournals, fio.fiot )
		if i ~= 1 then
			if fa == gFio[lastFio][1] then
				tmp = 'F'
			else
				tmp = ''
			end
			if im == gFio[lastFio][2] then
				tmp = tmp .. 'I'
			end
			if ot == gFio[lastFio][3] then
				tmp = tmp .. 'O'
			end
			if gFio[lastFio].group then
				if 		   gFio[lastFio].group == 'F' and tmp == 'IO'
						or gFio[lastFio].group == 'I' and tmp == 'FO'
						or gFio[lastFio].group == 'O' and tmp == 'FI'
						or gFio[lastFio].group == 'IO' and fa == gFio[lastFio][1] then -- F FI FO
					gFio[lastFio].size = gFio[lastFio].size + 1
				else
					table.insert( out, printFio( gFio, lastFio ) )
					lastFio = i
				end
			else
				if tmp == 'F' then
					gFio[lastFio].group = 'IO'
					gFio[lastFio].size = 2
				elseif tmp == 'FI' then
					gFio[lastFio].group = 'O'
					gFio[lastFio].size = 2
				elseif tmp == 'FO' then
					gFio[lastFio].group = 'I'
					gFio[lastFio].size = 2
				elseif tmp == 'IO' then
					gFio[lastFio].group = 'F'
					gFio[lastFio].size = 2
				else
					table.insert( out, printFio( gFio, lastFio ) )
					lastFio = i
				end
			end
		end
	end
	table.insert( out, printFio( gFio, lastFio ) )
	if gender == 2 then
		tmp = 'она'
	else
		tmp = 'он'
	end
	out = table.concat( out, ', <i>' .. tmp .. ' же</i> ' ) .. '. '
	if gender == 0 or gender == 3 then
		out = out .. '[[Категория:Персоналии с проблемами пола]]'
	end
	if gender == 3 then -- М и Ж не пишем.
		out = out .. 'Пол ' .. genders[gender] .. '. '
	end
	table.insert( gOut, out )
	return gender, fioForJournals
end