Модуль:Упоминание: различия между версиями

Материал из Кадровый состав НКВД 1935-1939
Перейти к навигации Перейти к поиску
Нет описания правки
Нет описания правки
Строка 411: Строка 411:
out = fio
out = fio
end
end
out = '[[' .. fio .. '|<span class="nkvd-doc-mention">' .. out .. '</span>]]'
if dry then
out = '<span class="nkvd-doc-mention-dry">' .. out .. '</span>'
else
out = '[[' .. fio .. '|<span class="nkvd-doc-mention">' .. out .. '</span>]]'
end
else
else
out = ''
out = ''
end
end
out = out ..  '[[' .. fio .. '|<span class="fa fa-external-link nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
if not dry then
 
out = out ..  '[[' .. fio .. '|<span class="fa fa-external-link nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
end
--[====[
--[====[
if dry then
if dry then

Версия от 21:07, 16 декабря 2016

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

local pp = {}
local global = mw.ext.luaglobal;
local Args, Doc
tools = require( 'Модуль:Tools' )
local doctools = require( 'Модуль:DocTools' )
local rankTable = mw.loadData( 'Модуль:Звания' )
global.strict( true )
--[[
local function checkDouble ( ... )
    local res, k = {}
    for i, field in ipairs( { ... } ) do
        if Args[field] and Doc.h2v[field] then
            return 'В секции {{' .. field
                .. '}} у шаблона не может быть собственного параметра «'
                .. field .. '»'
        else
            res[i] = Args[field] or Doc.h2v[field]
        end
        k = i
    end
    return nil, unpack( res, 1, k )
end
--]]


pp.Main = function ( frame )
    local tmp
    local debugTxt = ''
	Args, tmp = tools.checkargs( frame:getParent().args,
        { true, '', ['дата'] = true, ['звание'] = true, ['подразделение'] = true,
			['место службы'] = true, -- добавлено по сравнению с персоной
            ['должность'] = true,
            ['награда'] = true, ['номер'] = true,
--            ['подразделение+'] = true,  ['должность+'] = true, ['звание+'] = true,
--            ['документ'] = true, ['действие'] = true, ['отмена'] = true,
            ['сноска'] = true, ['пояснение'] = true, } )
    if not Args then
        return tools.errorMsg( 'персона', 'Неизвестный параметр «' .. tmp .. '»' )
    end
    local dry = mw.text.trim( frame.args[1] or '' ) == 'dry'

	local porno = global.get( 'porno' )
	porno = (porno or 0) + 1
	global.set( 'porno', porno )

	Doc = global.get( 'gDoc' )
	if not Doc then
		return tools.errorMsg( 'персона',
			'Первым на странице должен размещаться шаблон {{ Документ }}' )
	end
    local noCargo = Doc.off or dry

	local fio = Args[1]
	if not fio then
		return tools.errorMsg ( 'персона', 'Не указано ФИО персоны' )
	end
	--@TODO Проверять формат ФИО (хотя кривое будет красным)

	if Doc.debug then
		debugTxt = {}
		for _, h in ipairs( Doc.n2h ) do
			table.insert( debugTxt, '[' .. h .. '] = ' .. mw.dumpObject( Doc.h2v[h] ) )
		end
		debugTxt = '\n******* ' .. table.concat( debugTxt, '; ' ) .. '\n'
	end


    local pos, unit, segment
        = Args['должность'], Args['подразделение'], Args['место службы']
    -- звание почти всегда (кроме присвоения званий) фиксировано, можно приготовить
    local rank = Args['звание']

    local ownDate = Args['дата']
	local actionDate
    if ownDate then
        ownDate = tools.parseDate( ownDate )
        if not ownDate then
            return tools.errorMsg( 'персона',
                'Некорректный формат даты в параметре «дата»')
        end
        if Doc.h2v['дата'] then
            return tools.errorMsg( 'персона',
                'В секции {{дата}} у шаблона не может быть собственного параметра «дата»' )
        end
        actionDate = ownDate
    else
        actionDate = Doc.date
    end

    -- сборка примечания
	local reference = {}
	if Args['сноска'] then
		table.insert( reference, tools.phrase( Args['сноска'] ) )
	end
	tmp = global.get( 'gUniref-Документ' )
	if tmp then
		table.insert( reference, tools.phrase( tmp ) )
	end
	reference = table.concat( reference, ' ' )
	-- собрали примечание
	local cargoQ = ''
--[====[
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  |присвоить звание|
    if Doc.h2v['действие'] == 'присвоить звание' then
        tmp, rank, newRank = checkDouble( 'звание', 'звание+' )
        if tmp then
            return tools.errorMsg( 'персона', tmp )
        end
        if not newRank then
            return tools.errorMsg( 'персона', 'Не задано присваиваемое звание' )
        end

        if Args['звание+'] then
			tmp = tools.db( rankTable, newRank, 'кого' )
			if not tmp then
				return tools.errorMsg( 'персона', 'Указано неизвестное звание' )
			end
            newText = ' <span class="nkvd-doc-new">— звание <b>'
                .. tmp .. '</b></span>'
        end
        originRank = 12
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |лишить звания|
    elseif Doc.h2v['действие'] == 'лишить звания' then
        newRank = 'лишен'
        originRank = 14
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |наградить|
    elseif  Doc.h2v['действие'] == 'наградить' then
        local prize, prizeNum
        tmp, prize = checkDouble( 'награда' )
        if tmp then
            return tools.errorMsg( 'персона', tmp )
        end
        if not prize then
            return tools.errorMsg( 'персона', 'Не указана награда' )
        end
        prizeNum = Args['номер']
        newText = ' <span class="nkvd-doc-new">'
        if Args['награда'] then
            newText = newText .. '— <b>' .. prize .. '</b>'
        end
        if prizeNum then
            newText = newText .. ' <i>[№ ' .. prizeNum .. ']</i>'
        end
        newText = newText .. '</span>'
        if not noCargo then
	        cargoQ = frame:expandTemplate{ title = 'Таблица наград', args = {
	            person = fio,
	            date = Doc.date,  -- не бывает собственной даты
	            prize = prize,
	            number = prizeNum,
	            origin = 12 + canceledDelta,
				canceled = canceledBy,
	            reference = reference,
				isVolatile = porno,
	            } }
		end
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  |лишить награды|
    elseif  Doc.h2v['действие'] == 'лишить награды' then
        local prize, prizeNum
        tmp, prize = checkDouble( 'награда' )
        if tmp then
            return tools.errorMsg( 'персона', tmp )
        end
        if not prize then
            return tools.errorMsg( 'персона', 'Не указана награда' )
        end
        prizeNum = Args['номер']
        newText = ' <span class="nkvd-doc-new">'
        if Args['награда'] then
            newText = newText .. '— <b>' .. prize .. '</b>'
        end
        if prizeNum then
            newText = newText .. ' <i>[№ ' .. prizeNum .. ']</i>'
        end
        newText = newText .. '</span>'
        if not noCargo then
	        cargoQ = frame:expandTemplate{ title = 'Таблица наград', args = {
	            person = fio,
	            date = Doc.date,  -- не бывает собственной даты
	            prize = prize,
	            number = prizeNum,
	            origin = 14 + canceledDelta,
				canceled = canceledBy,
	            reference = reference,
				isVolatile = porno,
	            } }
	    end
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |назначить|
    elseif  Doc.h2v['действие'] == 'назначить' then
        tmp, actionDate = checkDouble( 'дата' )
        if tmp then
            return tools.errorMsg( 'персона', tmp )
        end
        newPos, newUnit, newSegment, segment
            = Args['должность+'], Args['подразделение+'], segment, nil
        if not newPos or not (newUnit or Doc.revers) then
            return tools.errorMsg( 'персона',
                'Для назначения должны быть указаны должность и подразделение' )
        end
        if not actionDate then
            actionDate = Doc.date
        end
        if newUnit == '=' then
            newUnit = unit
        elseif unit == '=' then
            unit = newUnit
        end
		newText = ' <span class="nkvd-doc-new">— на должность <b>' .. newPos .. '</b>'
		if newUnit then
            if unit == newUnit then
                newText = newText .. ' того же подразделения'
            else
                newText = newText .. ' в подразделении <b>' .. newUnit .. '</b>'
            end
        end
        newText = newText .. '</span>'
        originPos = 12
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |уволить|
	elseif  Doc.h2v['действие'] == 'уволить'
			or Doc.h2v['действие'] == 'уволить и лишить звания' then
		local dismissTab = mw.loadData( 'Модуль:Виды увольнения' )
        tmp, actionDate = checkDouble( 'дата' )
        if tmp then
            return tools.errorMsg( 'персона', tmp )
        end
        if not actionDate then
            actionDate = Doc.date
        end
        if not Doc.h2v['увольнение'] then
			return tools.errorMsg( 'персона',
				'Действие «Уволить» обязательно должно включать секцию «увольнение»' )
		end
		local dismissMode = Doc.h2v['увольнение'][1]
        if not noCargo then
			cargoQ = frame:expandTemplate{ title = 'Таблица увольнений', args = {
				person = fio,
				dismissal_type = dismissTab.direction[dismissMode],
				article = Doc.h2v['увольнение'][2],
				formula = Doc.h2v['увольнение'][3],
				isVolatile = porno,
				} }
		end
        newPos = '-'
        newUnit = dismissTab.dirParam[dismissTab.direction[dismissMode]].unit
        originPos = 14
		if Doc.h2v['действие'] == 'уволить и лишить звания' then
            newRank = 'лишен'
        	originRank = 14
		end

	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |освободить от должности|
	elseif  Doc.h2v['действие'] == 'освободить от должности' then
		local dismissTab = mw.loadData( 'Модуль:Виды увольнения' )
        tmp, actionDate = checkDouble( 'дата' )
        if tmp then
            return tools.errorMsg( 'персона', tmp )
        end
        if not actionDate then
            actionDate = Doc.date
        end
        if not noCargo then
			cargoQ = frame:expandTemplate{ title = 'Таблица увольнений', args = {
				person = fio,
				dismissal_type = dismissTab.direction['резерв'],
				article = '',
				formula = '',
				isVolatile = porno,
				} }
		end
        newPos = '(резерв)'
        newUnit = Args['подразделение+']
        if newUnit  then
        	newText = ' <span class="nkvd-doc-new">с направлением в <b>'
        		.. newUnit .. '</b></span>'
        end
        originPos = 14

	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  |отменить|
	elseif  Doc.h2v['действие'] == 'отменить' then
		-- документ, действие, должность, звание, подразделение
		local cDoc = Args['документ']
		if not cDoc then
			return tools.errorMsg( 'персона',
				'Необходимо указать имя страницы отменяемого приказа' )
		end
		if mw.ustring.sub( cDoc, 1, 9 ) == 'Документ:' then
			cDoc = mw.ustring.sub( cDoc, 10, -1 )
		end
		cDoc = '[[Документ:' .. cDoc .. '|' .. cDoc .. ']]'
		local cAction = mw.ustring.lower( Args['действие'] )
		if not cAction then
			return tools.errorMsg( 'персона',
				'Необходимо указать отменяемое действие («действие=уволить/'
					.. 'лишить звания/откомандировать...»' )
		end
		-- в запись-new ставится newRank c origin=originRank + canceledDelta
		-- в запись-old ставится rank с origin=originRank-8
		-- решаем систему уравнений: originRank + canceledDelta = 11
		-- originRank - 8 = 3
		-- originRank = 11, canceledDelta = 0
		if cAction == 'присвоить звание' or cAction == 'лишить звания'
				or cAction == 'уволить и лишить звания' then
			newRank = 'Отмена документа ' .. cDoc
			originRank = 11
		end
		if cAction == 'назначить' or cAction == 'уволить'
				or cAction == 'уволить и лишить звания' then
			newPos = 'Отмена документа ' .. cDoc
			originPos = 11
		end

		beforeText = '<span class="nkvd-doc-new">' .. cDoc .. '</span> в части решения '
			.. '<span class="nkvd-doc-new">' .. cAction .. '</span>:<br>'


	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |ой!|
	else
		return tools.errorMsg( 'персона', 'Ошибка алгоритма:'
			.. ' неизвестное действие «' .. Doc.h2v['действие'] .. '»' )
    end

 	if newRank then
        if not noCargo then
			cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица званий', args = {
				person = fio,
				date = actionDate,
				rank = newRank,
				canceled = canceledBy,
	            origin = originRank + canceledDelta,
				reference = reference,
				isVolatile = porno,
				} }
		end
    end
--]====]
	if rank then
--[[
        if newRank then
            tmp = originRank - 8
        else
            tmp = 3
        end
--]]		
        if not noCargo then
			cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица званий', args = {
				person = fio,
				date = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
				rank = rank,
	            origin = 3, --+ tmp,
	--			reference = reference,
				isVolatile = porno,
				} }
		end
	end
--[[	
	if newPos or newUnit or newSegment then
        if not noCargo then
			cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица назначений', args = {
				person = fio,
				date = actionDate,
				unit = newUnit,
				segment = newSegment,
				position = newPos,
				canceled = canceledBy,
	            origin = originPos + canceledDelta,
				reference = reference,
				isVolatile = porno,
				} }
		end
	end
--]]	
	if segment == '-' then
		segment = nil
	end
	if pos or unit or segment then
--[[		
        if newPos or newUnit then
            tmp = originPos - 8
        else
            tmp = 3
        end
--]]
        if not noCargo then
			cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица назначений', args = {
				person = fio,
				date = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
				unit = unit,
				position = pos,
				segment = segment,
	            origin = 3, --+ tmp,
	--			reference = reference,
				isVolatile = porno,
				} }
		end
	end
	
	if not noCargo then
		cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица упоминаний', args = {
			person = fio,
			date = actionDate,
			reference = reference,
			comment = Args['пояснение'],
			isVolatile = porno,
		} }
	end
		

	local out = Args[2]
	if out ~= '-' then
		if out == '' then
			out = fio
		end
		if dry then
			out = '<span class="nkvd-doc-mention-dry">' .. out .. '</span>'
		else
			out = '[[' .. fio .. '|<span class="nkvd-doc-mention">' .. out .. '</span>]]'
		end
	else
		out = ''
	end
	if not dry then
		out = out ..  '[[' .. fio .. '|<span class="fa fa-external-link nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
	end
--[====[	
	if dry then
		out = fio
	else
		out = '[[' .. fio .. ']]'
	end
	out = beforeText .. '<span class="nkvd-doc-fio">' .. out .. '</span>'
	if Args['звание'] then
		tmp = tools.db( rankTable, Args['звание'], 'кто' )
		if not tmp then
			return tools.errorMsg( 'персона', 'Указано неизвестное звание' )
		end
		out = out .. ', ' .. tmp
	end
	if Args['подразделение'] or Args['должность'] then
		if Args['подразделение'] then
			tmp = { unit }
		else
			tmp = {}
		end
		table.insert( tmp, pos )
		out = out .. ' (' .. table.concat( tmp, '; ' ) .. ')'
	end
	if newText ~= '' then
		out = out .. newText
	end
	if Args['дата'] then
		out = out .. ' <span class="nkvd-doc-new">c <b>'
            .. tools.reparseDate( ownDate ) .. '</b></span>'
	end
	if porno == 800 then
		debugTxt = '[[Категория:Чересчур длинный документ]]' .. debugTxt
	end

	if dry then
		dry = 'no'
	else
		dry = ''
	end
--]====]
--	global.set( 'gDoc', Doc )
	return debugTxt .. out .. cargoQ



end
return pp