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

Материал из Кадровый состав НКВД 1935-1939
Перейти к навигации Перейти к поиску
Нет описания правки
Нет описания правки
(не показаны 3 промежуточные версии этого же участника)
Строка 7: Строка 7:
local abbr = mw.loadData( 'Модуль:Аббревиатуры' )
local abbr = mw.loadData( 'Модуль:Аббревиатуры' )
local rankTable = mw.loadData( 'Модуль:Звания' )
local rankTable = mw.loadData( 'Модуль:Звания' )
local pope = require( 'Модуль:Поиск персоны' )
--local pope = require( 'Модуль:Поиск персоны' )
global.strict( true )
global.strict( true )


Строка 16: Строка 16:
if z.diap then
if z.diap then
for j, d in ipairs( z.diap ) do
for j, d in ipairs( z.diap ) do
if para.date < d[1] then
if para.cDate < d[1] then
i = j-1
i = j-1
break
break
Строка 26: Строка 26:
end
end


local query = Frame:expandTemplate{ title = 'Таблица званий', args = {
local query = Frame:expandTemplate{ title = 'Cargo:Ranks', args = {
person = para.person,
nLast = para.nLast,
date = para.date,
nFirst = para.nFirst,
nMiddle = para.nMiddle,
nDisambig = para.nDisambig,
nFull = para.nFull,
nPrecision = para.nPrecision,
cDate = para.cDate,
rank = para.rank,
rank = para.rank,
subrank = i,
subrank = i,
Строка 48: Строка 53:
Args, tmp = tools.checkargs( frame:getParent().args,
Args, tmp = tools.checkargs( frame:getParent().args,
         { true, '', ['дата'] = true, ['звание'] = true, ['подразделение'] = true,
         { true, '', ['дата'] = true, ['звание'] = true, ['подразделение'] = true,
['место службы'] = true,  
['место службы'] = true,
             ['должность'] = true,
             ['должность'] = true,
            ['сноска/должность'] = true, ['сноска/звание'] = true,
             ['сноска'] = true, ['пояснение'] = true, } )
             ['сноска'] = true, ['пояснение'] = true, } )
     if not Args then
     if not Args then
         return tools.errorMsg( 'упоминание', 'Неизвестный параметр «' .. tmp .. '»' )
         return tools.errorMsg( 'упоминание', 'Неизвестный параметр «' .. tmp .. '»' )
     end
     end
    local dry = mw.text.trim( frame.args[1] or '' ) == 'dry'
--    local dry = mw.text.trim( frame.args[1] or '' ) == 'dry'
local mode = frame.args.mode or ''
local dry = mode == '-'
local fio_precision
if mode == '?' then
fio_precision = '?'
end


local porno = global.get( 'porno' )
local porno = global.get( 'porno' )
Строка 72: Строка 84:
return tools.errorMsg ( 'упоминание', 'Не указано ФИО персоны' )
return tools.errorMsg ( 'упоминание', 'Не указано ФИО персоны' )
end
end
--@TODO Проверять формат ФИО (хотя кривое будет красным)
local fio_l, fio_f, fio_m, fio_d, fio_warn = tools.splitName( fio )
-- local fio_precision = nil
if not fio_l then
return tools.errorMsg( 'упоминание', fio_f )
end
if fio_d and ( mode == '-' or mode == '*' ) then
return tools.errorMsg( 'упоминание' .. mode, 'Этот вариант шаблона не может использоваться c индексом тезки' )
end
if mode == '*' then
fio = fio .. ' (*)'
fio_d = '(*)'
end
local cargoQ = ''
local cargoQ = ''
if not noCargo then
cargoQ = pope.makeP( fio ) or fio
if mw.ustring.find( cargoQ, '%', 1, true ) then
cargoQ = frame:expandTemplate{ title = 'Таблица неизвестных', args = {
pattern = cargoQ,
} }
elseif not mw.ustring.find( fio, '(', 1, true ) and mw.title.new( fio .. ' (I)' ).exists then
cargoQ = frame:expandTemplate{ title = 'Таблица неизвестных', args = {
pattern = fio .. ' %',
} }
else
cargoQ = ''
end
end


if Doc.debug then
if Doc.debug then
Строка 100: Строка 110:
     local pos, unit, segment
     local pos, unit, segment
         = doctools.abbr( Args['должность'], abbr.pos ), Args['подразделение'], doctools.abbr( Args['место службы'], abbr.segm )
         = doctools.abbr( Args['должность'], abbr.pos ), Args['подразделение'], doctools.abbr( Args['место службы'], abbr.segm )
    -- звание почти всегда (кроме присвоения званий) фиксировано, можно приготовить
 
     local rank = Args['звание']
     local rank = doctools.abbr( Args['звание'], abbr.rank )
     if rank then
     if rank then
     if rankTable[rank] then
     if rankTable[rank] then
Строка 109: Строка 119:
    end
    end
else
else
             return tools.errorMsg( 'персона',
             return tools.errorMsg( 'упоминание',
                 'Неизвестное звание «' .. rank .. '» в параметре «звание»')
                 'Неизвестное звание «' .. rank .. '» в параметре «звание»')
end
end
Строка 131: Строка 141:
     end
     end


    -- сборка примечания
--    -- сборка примечания
local refers = {}
-- local refers = {}
refers[#refers+1] = Args['сноска']
-- refers[#refers+1] = Args['сноска']
refers[#refers+1] = global.get( 'gUniref-Документ' )
-- refers[#refers+1] = global.get( 'gUniref-Документ' )
refers = table.concat( refers, '¶' )
-- refers = table.concat( refers, '¶' )
-- собрали примечание
-- -- собрали примечание
 
local referTable = {}
local ownRef, usedRef = refTools.collect( Args, 'сноска' ), {}
refTools.absorb( referTable, global.get( 'gUniref-Документ' ) )
refTools.absorb( referTable, ownRef )
 
if rank then
if rank then
         if not noCargo then
         if not noCargo then
cargoQ = cargoQ .. toRank {
cargoQ = cargoQ .. toRank {
person = fio,
nLast = fio_l,
date = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
nFirst = fio_f,
nMiddle = fio_m,
nDisambig = fio_d,
nFull = fio,
nPrecision = fio_precision,
cDate = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
rank = rank,
rank = rank,
            origin = 3, --+ tmp,
            origin = 3, --+ tmp,
-- reference = reference,
reference = table.concat(referTable['звание'] or {}, '¶' ),
alias = DocAlias,
alias = DocAlias,
isVolatile = porno,
isVolatile = porno,
}
}
end
end
usedRef['звание'] = true
end
end
if segment == '-' then
if segment == '-' then
Строка 155: Строка 177:
if pos or unit or segment then
if pos or unit or segment then
         if not noCargo then
         if not noCargo then
cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица назначений', args = {
cargoQ = cargoQ .. frame:expandTemplate{ title = 'Cargo:Designations', args = {
person = fio,
nLast = fio_l,
date = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
nFirst = fio_f,
nMiddle = fio_m,
nDisambig = fio_d,
nFull = fio,
nPrecision = fio_precision,
cDate = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
unit = unit,
unit = unit,
position = pos,
position = pos,
segment = segment,
segment = segment,
            origin = 3, --+ tmp,
            origin = 3, --+ tmp,
-- reference = reference,
reference = table.concat(referTable['должность'] or {}, '¶' ),
alias = DocAlias,
alias = DocAlias,
isVolatile = porno,
isVolatile = porno,
} }
} }
end
end
usedRef['должность'] = true
end
end


if not noCargo then
if not noCargo and Args['пояснение'] then
cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица упоминаний', args = {
cargoQ = cargoQ .. frame:expandTemplate{ title = 'Cargo:Mentions', args = {
person = fio,
nLast = fio_l,
date = actionDate,
nFirst = fio_f,
reference = refers,
nMiddle = fio_m,
nDisambig = fio_d,
nFull = fio,
nPrecision = fio_precision,
cDate = actionDate,
reference = table.concat(referTable['common'] or {}, '¶' ),
comment = Args['пояснение'],
comment = Args['пояснение'],
alias = DocAlias,
alias = DocAlias,
isVolatile = porno,
isVolatile = porno,
} }
} }
end
if Args['пояснение'] then
usedRef['common'] = true
end
for i, _ in pairs( ownRef ) do
if not usedRef[i] then
return tools.errorMsg( 'упоминание', 'указана сноска к незаданному параметру «' .. i .. '»')
end
end
end


Строка 216: Строка 258:
end
end
out = out .. suffix
out = out .. suffix
end
if referTable.common then
debugTxt = '[[Категория:Универсальные сноски]]' .. debugTxt
end
end


if fio_precision then
out = out .. ' <span class="nkvd-idx"><i class="fa fa-question fa-lg">'
.. '</i></span>'
end
if #fio_warn ~= 0 then
for _, warn in ipairs( fio_warn ) do
out = out .. ' <i class="fa fa-warning fa-lg" style="color: #f05f1a;"'
.. ' title="' .. warn .. '"></i>'
end
out = out .. '[[Категория:Неаккуратные ссылки на персоналии]]'
end
if not dry then
if not dry then
out = out ..  '[[' .. fio .. '|<span class="fa fa-external-link nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
out = out ..  '[[' .. fio .. '|<span class="fa fa-external-link nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
end
end
return debugTxt .. out .. refTools.makeRef( Args['сноска'] ) .. cargoQ
 
return debugTxt .. out .. refTools.makeRef( refTools.toline( ownRef ) ) .. cargoQ





Версия от 00:50, 27 февраля 2017

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

local pp = {}
local global = mw.ext.luaglobal;
local Args, Doc, Frame
tools = require( 'Модуль:Tools' )
refTools = require( 'Module:RefTools' )
local doctools = require( 'Модуль:DocTools' )
local abbr = mw.loadData( 'Модуль:Аббревиатуры' )
local rankTable = mw.loadData( 'Модуль:Звания' )
--local pope = require( 'Модуль:Поиск персоны' )
global.strict( true )

local function toRank( para )
	local z = rankTable[para.rank]
	local i = 0
	if z then
		if z.diap then
			for j, d in ipairs( z.diap ) do
				if para.cDate < d[1] then
					i = j-1
					break
				end
			end
		else
			i = 1
		end
	end

	local query = Frame:expandTemplate{ title = 'Cargo:Ranks', args = {
			nLast = para.nLast,
			nFirst = para.nFirst,
			nMiddle = para.nMiddle,
			nDisambig = para.nDisambig,
			nFull = para.nFull,
			nPrecision = para.nPrecision,
			cDate = para.cDate,
			rank = para.rank,
			subrank = i,
			canceled = para.canceled,
			origin = para.origin,
			reference = para.reference,
			alias = para.alias,
			isVolatile = para.isVolatile,
		} }
	return query
end



pp.Main = function ( frame )
	Frame = frame
    local tmp
    local debugTxt = ''
	Args, tmp = tools.checkargs( frame:getParent().args,
        { 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 mode = frame.args.mode or ''
	local dry = mode == '-'
	local fio_precision 
	if mode == '?' then
		fio_precision = '?'
	end

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

	Doc = global.get( 'gDoc' )
	local DocAlias = global.get( 'gDocAlias' )
	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
	local fio_l, fio_f, fio_m, fio_d, fio_warn = tools.splitName( fio )
--	local fio_precision = nil
	if not fio_l then
		return tools.errorMsg( 'упоминание', fio_f )
	end
	if fio_d and ( mode == '-' or mode == '*' ) then
		return tools.errorMsg( 'упоминание' .. mode, 'Этот вариант шаблона не может использоваться c индексом тезки' )
	end
	if mode == '*' then
		fio = fio .. ' (*)'
		fio_d = '(*)'
	end
	
	local cargoQ = ''

	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
        = doctools.abbr( Args['должность'], abbr.pos ), Args['подразделение'], doctools.abbr( Args['место службы'], abbr.segm )

    local rank = doctools.abbr( Args['звание'], abbr.rank )
    if rank then
    	if rankTable[rank] then
    		if rankTable[rank].redirect then
		    	rank = rankTable[rank].redirect
		    	Args['звание'] = rank
		    end
		else
            return tools.errorMsg( 'упоминание',
                'Неизвестное звание «' .. rank .. '» в параметре «звание»')
		end
    end

    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 refers = {}
--	refers[#refers+1] = Args['сноска']
--	refers[#refers+1] = global.get( 'gUniref-Документ' )
--	refers = table.concat( refers, '¶' )
--	-- собрали примечание

	local referTable = {}
	local ownRef, usedRef = refTools.collect( Args, 'сноска' ), {}
	refTools.absorb( referTable, global.get( 'gUniref-Документ' ) )
	refTools.absorb( referTable, ownRef )

	if rank then
        if not noCargo then
			cargoQ = cargoQ .. toRank {
				nLast = fio_l,
				nFirst = fio_f,
				nMiddle = fio_m,
				nDisambig = fio_d,
				nFull = fio,
				nPrecision = fio_precision,
				cDate = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
				rank = rank,
	            origin = 3, --+ tmp,
				reference = table.concat(referTable['звание'] or {}, '¶' ),
				alias = DocAlias,
				isVolatile = porno,
				}
		end
		usedRef['звание'] = true
	end
	if segment == '-' then
		segment = nil
	end
	if pos or unit or segment then
        if not noCargo then
			cargoQ = cargoQ .. frame:expandTemplate{ title = 'Cargo:Designations', args = {
				nLast = fio_l,
				nFirst = fio_f,
				nMiddle = fio_m,
				nDisambig = fio_d,
				nFull = fio,
				nPrecision = fio_precision,
				cDate = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
				unit = unit,
				position = pos,
				segment = segment,
	            origin = 3, --+ tmp,
				reference = table.concat(referTable['должность'] or {}, '¶' ),
				alias = DocAlias,
				isVolatile = porno,
				} }
		end
		usedRef['должность'] = true
	end

	if not noCargo and Args['пояснение'] then
		cargoQ = cargoQ .. frame:expandTemplate{ title = 'Cargo:Mentions', args = {
			nLast = fio_l,
			nFirst = fio_f,
			nMiddle = fio_m,
			nDisambig = fio_d,
			nFull = fio,
			nPrecision = fio_precision,
			cDate = actionDate,
			reference = table.concat(referTable['common'] or {}, '¶' ),
			comment = Args['пояснение'],
			alias = DocAlias,
			isVolatile = porno,
		} }
	end
	if Args['пояснение'] then
		usedRef['common'] = true
	end

	for i, _ in pairs( ownRef ) do
		if not usedRef[i] then
			return tools.errorMsg( 'упоминание', 'указана сноска к незаданному параметру «' .. i .. '»')
		end
	end


	local out, suffix = Args[2], ''
	if out == '-' then
		out = ''
	elseif out == '+' then
		if rank then
			suffix = ', ' .. tools.db( rankTable, rank, 'кто' ) -- rank
		end
		if pos or unit or segment then
			tmp = {}
			if pos then
				tmp[#tmp+1] = pos
			end
			if unit then
				tmp[#tmp+1] = unit
			end
			if segment then
				tmp[#tmp+1] = tools.segment( segment )
			end
			suffix = suffix .. ' (' .. table.concat( tmp, '; ' ) .. ')'
		end
		if ownDate then
			suffix = suffix .. ' [по сост. на ' .. tools.reparseDate( ownDate ) .. ']'
		end
		out = fio
	elseif out == '' then
		out = fio
	end

	if out ~= '' then
		if dry then
			out = '<span class="nkvd-doc-mention-dry">' .. out .. '</span>'
		else
			out = '[[' .. fio .. '|<span class="nkvd-doc-mention">' .. out .. '</span>]]'
		end
		out = out .. suffix
	end
	if referTable.common then
		debugTxt = '[[Категория:Универсальные сноски]]' .. debugTxt
	end

	if fio_precision then
		out = out .. ' <span class="nkvd-idx"><i class="fa fa-question fa-lg">'
			.. '</i></span>'
	end
	if #fio_warn ~= 0 then
		for _, warn in ipairs( fio_warn ) do
			out = out .. ' <i class="fa fa-warning fa-lg" style="color: #f05f1a;"'
				.. ' title="' .. warn .. '"></i>'
		end
		out = out .. '[[Категория:Неаккуратные ссылки на персоналии]]'
	end
	if not dry then
		out = out ..  '[[' .. fio .. '|<span class="fa fa-external-link nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
	end

	return debugTxt .. out .. refTools.makeRef(  refTools.toline( ownRef ) ) .. cargoQ



end
return pp