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

Материал из Кадровый состав НКВД 1935-1939
Перейти к навигации Перейти к поиску

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

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


local function printattr( onefio, n ) -- должна печатать "хвосты" (индекс тезки, предупреждение об отсутствии перенаправления и стандартное завершение параметра персоны)
	local out = {}
	if onefio.d  then
		out = { ' <span class="nkvd-idx">' .. onefio.d .. '</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.a, onefio.r, onefio.s ) )
	return table.concat( out )
end


local function printFio( fio, n )
	local onefio = fio[n]
	local out = { '<b>' .. onefio.l .. '</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].l .. '</b>' .. printattr( fio[n+i], 2 ) )
		end
		table.insert( out, ' (' .. table.concat( list, ', ' ) .. ')' )
	end
	if onefio.i ~= '' then
		table.insert( out, ', ' .. onefio.i )
		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].i .. printattr( fio[n+i], 2 ) )
			end
			table.insert( out, ' (' .. table.concat( list, ', ' ) .. ')' )
		end
		if onefio.o ~= '' then
			table.insert( out, ' ' .. onefio.o )
			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].o .. printattr( fio[n+i], 2 ) )
					else
						table.insert( list,
							fio[n+i].i .. ' ' .. fio[n+i].o .. 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
return function () -- return gender, text, where	 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 where = {}
	local lastFio = 1
	local dotted
	for i, fio in ipairs( gFio ) do
--		fa, im, ot, idx = unpack( fio, 1, 4 )
		fa, im, ot, idx = fio.l, (fio.i or ''), (fio.o or ''), (fio.d or '')
--		where[i] = 'nLast="' .. fa .. '" AND nFirst' .. tools.cargoString( fio.f )
--			.. ' AND nMiddle' .. tools.cargoString( fio.m )
--			.. ' AND nDisambig' .. tools.cargoString( idx ) .. ' AND nPrecision IS NULL'
		dotted = dotted or string.sub( im, -1, -1 ) == '.' or string.sub( ot, -1, -1 ) == '.'
		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].l then
				tmp = 'F'
			else
				tmp = ''
			end
			if im == gFio[lastFio].i then
				tmp = tmp .. 'I'
			end
			if ot == gFio[lastFio].o 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].l 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 dotted then
		out = out .. '[[Категория:Персоналии с неполным именем]]'
	end
	if gender == 3 then -- М и Ж не пишем.
		out = out .. 'Пол ' .. genders[gender] .. '. '
	end
--	table.insert( gOut, out )
--	return gender, fioForJournals
--	where = table.concat( where, ' OR ' )
--	return gender, out, where
	return gender, out
end