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

Материал из Кадровый состав НКВД 1935-1939
Перейти к навигации Перейти к поиску
Нет описания правки
Нет описания правки
(не показано 35 промежуточных версий этого же участника)
Строка 1: Строка 1:
local pp = {}
local pp = {}
local global = mw.ext.luaglobal;
local global = mw.ext.luaglobal;
local Args, Doc
local Args, Doc, Frame
tools = require( 'Модуль:Tools' )
tools = require( 'Модуль:Tools' )
refTools = require( 'Module:RefTools' )
local doctools = require( 'Модуль:DocTools' )
local doctools = require( 'Модуль:DocTools' )
local abbr = mw.loadData( 'Модуль:Аббревиатуры' )
local rankTable = mw.loadData( 'Модуль:Звания' )
local rankTable = mw.loadData( 'Модуль:Звания' )
--local pope = require( 'Модуль:Поиск персоны' )
global.strict( true )
global.strict( true )
--[[
 
local function checkDouble ( ... )
local function toRank( para )
    local res, k = {}
local z = rankTable[para.rank]
    for i, field in ipairs( { ... } ) do
local i = 0
        if Args[field] and Doc.h2v[field] then
if z then
            return 'В секции {{' .. field
if z.diap then
                .. '}} у шаблона не может быть собственного параметра «'
for j, d in ipairs( z.diap ) do
                .. field .. '»'
if para.cDate < d[1] then
        else
i = j-1
            res[i] = Args[field] or Doc.h2v[field]
break
        end
end
        k = i
end
    end
else
    return nil, unpack( res, 1, k )
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
end
--]]
 




pp.Main = function ( frame )
pp.Main = function ( frame )
Frame = frame
     local tmp
     local tmp
     local debugTxt = ''
     local debugTxt = ''
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,
--            ['подразделение+'] = 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' )
Строка 45: Строка 74:


Doc = global.get( 'gDoc' )
Doc = global.get( 'gDoc' )
local DocAlias = global.get( 'gDocAlias' )
if not Doc then
if not Doc then
return tools.errorMsg( 'персона',
return tools.errorMsg( 'упоминание',
'Первым на странице должен размещаться шаблон {{ Документ }}' )
'Первым на странице должен размещаться шаблон {{ Документ }}' )
end
end
Строка 53: Строка 83:
local fio = Args[1]
local fio = Args[1]
if not fio then
if not fio then
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 = ''


if Doc.debug then
if Doc.debug then
Строка 67: Строка 110:


     local pos, unit, segment
     local pos, unit, segment
         = Args['должность'], Args['подразделение'], Args['место службы']
         = doctools.abbr( Args['должность'], abbr.pos ), Args['подразделение'], doctools.abbr( Args['место службы'], abbr.segm )
    -- звание почти всегда (кроме присвоения званий) фиксировано, можно приготовить
    local rank = Args['звание']
local segmentDB
if Doc.universalSegment and not segment then
segmentDB = Doc.h2v['место службы']
else
segmentDB = segment
end


     local ownDate = Args['дата']
    local rank = doctools.abbr( Args['звание'], abbr.rank )
local actionDate
    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, ownDateFrom, ownDateTo = Args['дата'], Args['с'], Args['до']
if ownDate and ( ownDateFrom or ownDateTo ) then
return tools.errorMsg( 'упоминание',
'Вместе с параметром «дата» нельзя использовать параметры «с» и «до»' )
end
     if ownDate then
     if ownDate then
         ownDate = tools.parseDate( ownDate )
         ownDate = tools.parseDate( ownDate )
         if not ownDate then
         if not ownDate then
             return tools.errorMsg( 'персона',
             return tools.errorMsg( 'упоминание',
                 'Некорректный формат даты в параметре «дата»')
                 'Некорректный формат даты в параметре «дата»' )
         end
         end
end
    if ownDateFrom then
        ownDateFrom = tools.parseDate( ownDateFrom )
        if not ownDateFrom then
            return tools.errorMsg( 'упоминание',
                'Некорректный формат даты в параметре «c»' )
        end
end
    if ownDateTo then
        ownDateTo = tools.parseDate( ownDateTo )
        if not ownDateTo then
            return tools.errorMsg( 'упоминание',
                'Некорректный формат даты в параметре «до»' )
        end
end
local actionDate
    if ownDate or ownDateFrom or ownDateTo then
         if Doc.h2v['дата'] then
         if Doc.h2v['дата'] then
             return tools.errorMsg( 'персона',
             return tools.errorMsg( 'упоминание',
                 'В секции {{дата}} у шаблона не может быть собственного параметра «дата»' )
                 'В секции {{дата}} у шаблона не может быть собственного параметра «дата» («с», «по»)' )
         end
         end
         actionDate = ownDate
         actionDate = ownDate
     else
     else
         actionDate = Doc.date
         actionDate = Doc.h2v['дата'] or Doc.date
     end
     end
 
     if ( ownDateFrom or ownDateTo ) and not pos and ( not rank or not ownDateFrom or ownDateTo ) then -- ¬( pos|(rank&From&¬To)|(¬From&¬To) )
     -- сборка примечания
return tools.errorMsg( 'упоминание',
local reference = {}
'Параметры «с» и «до» используются лишь для указания периода пребывания в должности, либо для даты получения звания' )
if Args['сноска'] then
table.insert( reference, tools.phrase( Args['сноска'] ) )
end
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>'


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


-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |ой!|
local referTable = {}
else
local ownRef, usedRef = refTools.collect( Args, 'сноска' ), {}
return tools.errorMsg( 'персона', 'Ошибка алгоритма:'
refTools.absorb( referTable, global.get( 'gUniref-Документ' ) )
.. ' неизвестное действие «' .. Doc.h2v['действие'] .. '»' )
refTools.absorb( referTable, ownRef )
    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 rank then
--[[
        if newRank then
            tmp = originRank - 8
        else
            tmp = 3
        end
--]]
         if not noCargo then
         if not noCargo then
cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица званий', args = {
local origin = 3
person = fio,
if not pos and ownDateFrom then
date = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
origin = 12
end
cargoQ = cargoQ .. toRank {
nLast = fio_l,
nFirst = fio_f,
nMiddle = fio_m,
nDisambig = fio_d,
nFull = fio,
nPrecision = fio_precision,
cDate = actionDate or ownDateFrom or ownDateTo,
rank = rank,
rank = rank,
            origin = 3, --+ tmp,
            origin = origin,
-- reference = reference,
reference = table.concat(referTable['звание'] or {}, '' ),
isVolatile = porno,
alias = DocAlias,
} }
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,
isVolatile = porno,
} }
}
end
end
usedRef['звание'] = true
end
end
--]]
if segment == '-' then
if segment == '-' then
segment = nil
segment = nil
end
end
if pos or unit or segment then
if pos or unit or segmentDB then
--[[
        if newPos or newUnit then
            tmp = originPos - 8
        else
            tmp = 3
        end
--]]
         if not noCargo then
         if not noCargo then
cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица назначений', args = {
if actionDate then
person = fio,
cargoQ = cargoQ .. frame:expandTemplate{ title = 'Cargo:Designations', args = {
date = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
nLast = fio_l,
unit = unit,
nFirst = fio_f,
position = pos,
nMiddle = fio_m,
segment = segment,
nDisambig = fio_d,
            origin = 3, --+ tmp,
nFull = fio,
-- reference = reference,
nPrecision = fio_precision,
isVolatile = porno,
cDate = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
unit = unit,
position = pos,
segment = segmentDB,
origin = 3, --+ tmp,
reference = table.concat(referTable['должность'] or {}, '¶' ),
alias = DocAlias,
isVolatile = porno,
} }
} }
else
if ownDateFrom 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 = ownDateFrom,
unit = unit,
position = pos,
segment = segmentDB,
origin = 12, --+ tmp,
reference = table.concat(referTable['должность'] or {}, '¶' ),
alias = DocAlias,
isVolatile = porno,
} }
end
if ownDateTo 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 = ownDateTo,
unit = unit,
position = pos,
segment = segmentDB,
origin = 4, --+ tmp,
reference = table.concat(referTable['должность'] or {}, '¶' ),
alias = DocAlias,
isVolatile = porno,
} }
end
end
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 = reference,
nMiddle = fio_m,
nDisambig = fio_d,
nFull = fio,
nPrecision = fio_precision,
cDate = actionDate or ownDateFrom,
reference = table.concat(referTable['common'] or {}, '¶' ),
comment = Args['пояснение'],
comment = Args['пояснение'],
alias = DocAlias,
isVolatile = porno,
isVolatile = porno,
} }
} }
end
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 = Args[2]
--[===[
if out ~= '-' then
local out, suffix = Args[2], ''
if out == '' then
if out == '-' then
out = fio
out = ''
elseif out == '+' then
if rank then
suffix = ', ' .. tools.db( rankTable, rank, 'кто' ) -- rank
end
end
out = '[[' .. fio .. '|<span class="nkvd-doc-mention">' .. out .. '</span>]]'
if pos or unit or segment then
else
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 ) .. ']'
elseif ownDateFrom or ownDateTo then
local tmp = ''
if ownDateFrom then
tmp = ' c ' .. tools.reparseDate( ownDateFrom )
end
if ownDateTo then
tmp = tmp .. ' до ' .. tools.reparseDate( ownDateTo )
end
suffix = suffix .. ' [' .. string.sub( tmp, 2, -1 ) .. ']'
end
out = fio
elseif  out == 'д' then
out = ''
out = ''
suffix = pos
if ownDate then
suffix = suffix .. ' [по сост. на ' .. tools.reparseDate( ownDate ) .. ']'
elseif ownDateFrom or ownDateTo then
local tmp = ''
if ownDateFrom then
tmp = ' c ' .. tools.reparseDate( ownDateFrom )
end
if ownDateTo then
tmp = tmp .. ' до ' .. tools.reparseDate( ownDateTo )
end
suffix = suffix .. ' [' .. string.sub( tmp, 2, -1 ) .. ']'
end
elseif out == '' then
out = fio
end
end
out = out ..  '[[' .. fio .. '|<span class="fa fa-bookmark nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'


--[====[
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
end
out = out .. suffix
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-check-circle-o nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
end
 
return debugTxt .. out .. refTools.makeRef(  refTools.toline( ownRef ) ) .. cargoQ
--]===]
 
 
local formstr = Args[2]
if formstr == '+' then
formstr = '{n:*}{r:, *}{p: (*)}{d: [*]}'
elseif formstr == '!' then
formstr = '{n:*}{r:, *}{p: (*)}{d: [*]}{c: — *}'
elseif formstr == '' then
formstr = '{n:*}'
elseif formstr == '-' then
formstr = ''
elseif formstr == 'д' then
formstr = '{p:*}{d: [*]}'
end
local values = {}
if dry then
if dry then
out = fio
values.n = '<span class="nkvd-doc-mention-dry">' .. fio .. '</span>'
else
else
out = '[[' .. fio .. ']]'
values.n = '[[' .. fio .. '|<span class="nkvd-doc-mention">' .. fio .. '</span>]]'
end
end
out = beforeText .. '<span class="nkvd-doc-fio">' .. out .. '</span>'
if fio_precision then
if Args['звание'] then
values.n = values.n .. '&nbsp;<span class="nkvd-idx"><i class="fa fa-question fa-lg"></i></span>'
tmp = tools.db( rankTable, Args['звание'], 'кто' )
end
if not tmp then
if #fio_warn ~= 0 then
return tools.errorMsg( 'персона', 'Указано неизвестное звание' )
for _, warn in ipairs( fio_warn ) do
values.n = values.n .. ' <i class="fa fa-warning fa-lg" style="color: #f05f1a;"'
.. ' title="' .. warn .. '"></i>'
end
end
out = out .. ', ' .. tmp
values.n = values.n .. '[[Категория:Неаккуратные ссылки на персоналии]]'
end
if rank then
values.r = tools.db( rankTable, rank, 'кто' )
end
end
if Args['подразделение'] or Args['должность'] then
if pos or unit or segment then
if Args['подразделение'] then
local tmp = {}
tmp = { unit }
if pos then
else
tmp[#tmp+1] = pos
tmp = {}
end
if unit then
tmp[#tmp+1] = unit
end
if segment then
tmp[#tmp+1] = tools.segment( segment )
end
end
table.insert( tmp, pos )
values.p = table.concat( tmp, '; ' )
out = out .. ' (' .. table.concat( tmp, '; ' ) .. ')'
end
end
if newText ~= '' then
if ownDate then
out = out .. newText
values.t = tools.reparseDate( ownDate )
values.d = 'по сост. на ' .. values.t
elseif ownDateFrom or ownDateTo then
local tmp = {}
if ownDateFrom then
tmp[#tmp+1] = 'c ' .. tools.reparseDate( ownDateFrom )
end
if ownDateTo then
tmp[#tmp+1] = 'до ' .. tools.reparseDate( ownDateTo )
end
values.d = table.concat( tmp, ' ' )
values.t = values.d
end
end
if Args['дата'] then
if Args['пояснение'] then
out = out .. ' <span class="nkvd-doc-new">c <b>'
values.c = Args['пояснение']
            .. tools.reparseDate( ownDate ) .. '</b></span>'
end
end
if porno == 800 then
local out = string.gsub( formstr, '%{([a-z]):(.-)%}', function ( idx, pattern )
debugTxt = '[[Категория:Чересчур длинный документ]]' .. debugTxt
if values[idx] then
local n = string.find( pattern, '*', 1, true )
return string.sub( pattern, 1, n-1 ) .. values[idx] .. string.sub( pattern, n+1, -1 )
end
return ''
end )
 
if out == formstr and not dry then
out = '[[' .. fio .. '|<span class="nkvd-doc-mention">' .. out .. '</span>]]'
end
end


if dry then
if referTable.common then
dry = 'no'
debugTxt = '[[Категория:Универсальные сноски]]' .. debugTxt
else
end
dry = ''
if not dry then
out = out ..  '[[' .. fio .. '|<span class="fa fa-check-circle-o nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
end
end
--]====]
-- global.set( 'gDoc', Doc )
return debugTxt .. out .. cargoQ


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




end
function pp.UniversalSegment( frame )
local Doc = global.get( 'gDoc' )
Doc.universalSegment = true
global.set( 'gDoc', Doc )
end
end
return pp
return pp

Версия от 16:04, 20 марта 2022

Для документации этого модуля может быть создана страница Модуль:Упоминание/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,
            ['сноска'] = 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 segmentDB
	
	if Doc.universalSegment and not segment then
		segmentDB = Doc.h2v['место службы']
	else
		segmentDB = segment
	end

    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, ownDateFrom, ownDateTo = Args['дата'], Args['с'], Args['до']
	if ownDate and ( ownDateFrom or ownDateTo ) then
		return tools.errorMsg( 'упоминание',
			'Вместе с параметром «дата» нельзя использовать параметры «с» и «до»' )
	end
    if ownDate then
        ownDate = tools.parseDate( ownDate )
        if not ownDate then
            return tools.errorMsg( 'упоминание',
                'Некорректный формат даты в параметре «дата»' )
        end
	end
    if ownDateFrom then
        ownDateFrom = tools.parseDate( ownDateFrom )
        if not ownDateFrom then
            return tools.errorMsg( 'упоминание',
                'Некорректный формат даты в параметре «c»' )
        end
	end
    if ownDateTo then
        ownDateTo = tools.parseDate( ownDateTo )
        if not ownDateTo then
            return tools.errorMsg( 'упоминание',
                'Некорректный формат даты в параметре «до»' )
        end
	end
	local actionDate
    if ownDate or ownDateFrom or ownDateTo then
        if Doc.h2v['дата'] then
            return tools.errorMsg( 'упоминание',
                'В секции {{дата}} у шаблона не может быть собственного параметра «дата» («с», «по»)' )
        end
        actionDate = ownDate
    else
        actionDate = Doc.h2v['дата'] or Doc.date
    end
    if ( ownDateFrom or ownDateTo ) and not pos and ( not rank or not ownDateFrom or ownDateTo ) then -- ¬( pos|(rank&From&¬To)|(¬From&¬To) )
		return tools.errorMsg( 'упоминание',
			'Параметры «с» и «до» используются лишь для указания периода пребывания в должности, либо для даты получения звания' )
	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
			local origin = 3
			if not pos and ownDateFrom then
				origin = 12
			end
			cargoQ = cargoQ .. toRank {
				nLast = fio_l,
				nFirst = fio_f,
				nMiddle = fio_m,
				nDisambig = fio_d,
				nFull = fio,
				nPrecision = fio_precision,
				cDate = actionDate or ownDateFrom or ownDateTo,
				rank = rank,
	            origin = origin,
				reference = table.concat(referTable['звание'] or {}, '¶' ),
				alias = DocAlias,
				isVolatile = porno,
				}
		end
		usedRef['звание'] = true
	end
	if segment == '-' then
		segment = nil
	end
	if pos or unit or segmentDB then
        if not noCargo then
			if actionDate 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 = segmentDB,
					origin = 3, --+ tmp,
					reference = table.concat(referTable['должность'] or {}, '¶' ),
					alias = DocAlias,
					isVolatile = porno,
				} }
			else
				if ownDateFrom 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 = ownDateFrom,
						unit = unit,
						position = pos,
						segment = segmentDB,
						origin = 12, --+ tmp,
						reference = table.concat(referTable['должность'] or {}, '¶' ),
						alias = DocAlias,
						isVolatile = porno,
					} }
				end
				if ownDateTo 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 = ownDateTo,
						unit = unit,
						position = pos,
						segment = segmentDB,
						origin = 4, --+ tmp,
						reference = table.concat(referTable['должность'] or {}, '¶' ),
						alias = DocAlias,
						isVolatile = porno,
					} }
				end
			end
		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 or ownDateFrom,
			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 ) .. ']'
		elseif ownDateFrom or ownDateTo then
			local tmp = ''
			if ownDateFrom then
				tmp = ' c ' .. tools.reparseDate( ownDateFrom )
			end
			if ownDateTo then
				tmp = tmp .. ' до ' .. tools.reparseDate( ownDateTo )
			end
			suffix = suffix .. ' [' .. string.sub( tmp, 2, -1 ) .. ']'
		end
		out = fio
	elseif  out == 'д' then
		out = ''
		suffix = pos
		if ownDate then
			suffix = suffix .. ' [по сост. на ' .. tools.reparseDate( ownDate ) .. ']'
		elseif ownDateFrom or ownDateTo then
			local tmp = ''
			if ownDateFrom then
				tmp = ' c ' .. tools.reparseDate( ownDateFrom )
			end
			if ownDateTo then
				tmp = tmp .. ' до ' .. tools.reparseDate( ownDateTo )
			end
			suffix = suffix .. ' [' .. string.sub( tmp, 2, -1 ) .. ']'
		end

	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
	end
	out = out .. suffix
	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-check-circle-o nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
	end

	return debugTxt .. out .. refTools.makeRef(  refTools.toline( ownRef ) ) .. cargoQ
--]===]


	local formstr = Args[2]
	if formstr == '+' then
		formstr = '{n:*}{r:, *}{p: (*)}{d: [*]}'
	elseif formstr == '!' then
		formstr = '{n:*}{r:, *}{p: (*)}{d: [*]}{c: — *}'
	elseif formstr == '' then
		formstr = '{n:*}'
	elseif formstr == '-' then
		formstr = ''
	elseif formstr == 'д' then
		formstr = '{p:*}{d: [*]}'
	end
	local values = {}
	if dry then
		values.n = '<span class="nkvd-doc-mention-dry">' .. fio .. '</span>'
	else
		values.n = '[[' .. fio .. '|<span class="nkvd-doc-mention">' .. fio .. '</span>]]'
	end
	if fio_precision then
		values.n = values.n .. '&nbsp;<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
			values.n = values.n .. ' <i class="fa fa-warning fa-lg" style="color: #f05f1a;"'
				.. ' title="' .. warn .. '"></i>'
		end
		values.n = values.n .. '[[Категория:Неаккуратные ссылки на персоналии]]'
	end
	if rank then
		values.r = tools.db( rankTable, rank, 'кто' )
	end
	if pos or unit or segment then
		local 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
		values.p = table.concat( tmp, '; ' )
	end
	if ownDate then
		values.t = tools.reparseDate( ownDate )
		values.d = 'по сост. на ' .. values.t
	elseif ownDateFrom or ownDateTo then
		local tmp = {}
		if ownDateFrom then
			tmp[#tmp+1] = 'c ' .. tools.reparseDate( ownDateFrom )
		end
		if ownDateTo then
			tmp[#tmp+1] = 'до ' .. tools.reparseDate( ownDateTo )
		end
		values.d = table.concat( tmp, ' ' )
		values.t = values.d
	end
	if Args['пояснение'] then
		values.c = Args['пояснение']
	end
	local out = string.gsub( formstr, '%{([a-z]):(.-)%}', function ( idx, pattern )
			if values[idx] then
				local n = string.find( pattern, '*', 1, true )
				return string.sub( pattern, 1, n-1 ) .. values[idx] .. string.sub( pattern, n+1, -1 )
			end
			return ''
		end )

	if out == formstr and not dry then
		out = '[[' .. fio .. '|<span class="nkvd-doc-mention">' .. out .. '</span>]]'
	end

	if referTable.common then
		debugTxt = '[[Категория:Универсальные сноски]]' .. debugTxt
	end
	if not dry then
		out = out ..  '[[' .. fio .. '|<span class="fa fa-check-circle-o nkvd-doc-mention-flag" title="Упоминание — ' .. fio .. '"></span>]]'
	end

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


end
function pp.UniversalSegment( frame )
	local Doc = global.get( 'gDoc' )
	Doc.universalSegment = true
	global.set( 'gDoc', Doc )
end
return pp