Модуль:Упоминание: различия между версиями
Перейти к навигации
Перейти к поиску
StasR (обсуждение | вклад) (удаление закомментированных обломков шаблона «персона») |
StasR (обсуждение | вклад) Нет описания правки |
||
Строка 3: | Строка 3: | ||
local Args, Doc, Frame | 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 abbr = mw.loadData( 'Модуль:Аббревиатуры' ) | ||
Строка 12: | Строка 13: | ||
local z = rankTable[para.rank] | local z = rankTable[para.rank] | ||
local i = 0 | local i = 0 | ||
if z then | if z then | ||
if z.diap then | if z.diap then | ||
for j, d in ipairs( z.diap ) do | for j, d in ipairs( z.diap ) do | ||
Строка 38: | Строка 39: | ||
return query | return query | ||
end | end | ||
Строка 47: | Строка 48: | ||
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, } ) | ||
if not Args then | if not Args then | ||
Строка 111: | Строка 111: | ||
return tools.errorMsg( 'персона', | return tools.errorMsg( 'персона', | ||
'Неизвестное звание «' .. rank .. '» в параметре «звание»') | 'Неизвестное звание «' .. rank .. '» в параметре «звание»') | ||
end | end | ||
end | end | ||
Строка 132: | Строка 132: | ||
-- сборка примечания | -- сборка примечания | ||
local | local refers = {} | ||
refers[#refers+1] = Args['сноска'] | |||
refers[#refers+1] = global.get( 'gUniref-Документ' ) | |||
refers = table.concat( refers, '¶' ) | |||
-- собрали примечание | -- собрали примечание | ||
if rank then | if rank then | ||
Строка 173: | Строка 168: | ||
end | end | ||
end | end | ||
if not noCargo then | if not noCargo then | ||
cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица упоминаний', args = { | cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица упоминаний', args = { | ||
person = fio, | person = fio, | ||
date = actionDate, | date = actionDate, | ||
reference = | reference = refers, | ||
comment = Args['пояснение'], | comment = Args['пояснение'], | ||
alias = DocAlias, | alias = DocAlias, | ||
Строка 184: | Строка 179: | ||
} } | } } | ||
end | end | ||
local out, suffix = Args[2], '' | local out, suffix = Args[2], '' | ||
Строка 205: | Строка 200: | ||
end | end | ||
suffix = suffix .. ' (' .. table.concat( tmp, '; ' ) .. ')' | suffix = suffix .. ' (' .. table.concat( tmp, '; ' ) .. ')' | ||
end | end | ||
if ownDate then | if ownDate then | ||
suffix = suffix .. ' [по сост. на ' .. tools.reparseDate( ownDate ) .. ']' | suffix = suffix .. ' [по сост. на ' .. tools.reparseDate( ownDate ) .. ']' | ||
end | end | ||
Строка 213: | Строка 208: | ||
out = fio | out = fio | ||
end | end | ||
if out ~= '' then | if out ~= '' then | ||
if dry then | if dry then | ||
Строка 221: | Строка 216: | ||
end | end | ||
out = out .. suffix | out = out .. suffix | ||
end | 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 .. cargoQ | return debugTxt .. out .. refTools.makeRef( Args['сноска'] ) .. cargoQ | ||
Версия от 10:15, 5 февраля 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.date < d[1] then
i = j-1
break
end
end
else
i = 1
end
end
local query = Frame:expandTemplate{ title = 'Таблица званий', args = {
person = para.person,
date = para.date,
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, } )
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' )
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
--@TODO Проверять формат ФИО (хотя кривое будет красным)
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
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 = Args['звание']
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, '¶' )
-- собрали примечание
if rank then
if not noCargo then
cargoQ = cargoQ .. toRank {
person = fio,
date = actionDate, --+ Doc.date, -- упоминание — на дату составления документа
rank = rank,
origin = 3, --+ tmp,
-- reference = reference,
alias = DocAlias,
isVolatile = porno,
}
end
end
if segment == '-' then
segment = nil
end
if pos or unit or segment then
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,
alias = DocAlias,
isVolatile = porno,
} }
end
end
if not noCargo then
cargoQ = cargoQ .. frame:expandTemplate{ title = 'Таблица упоминаний', args = {
person = fio,
date = actionDate,
reference = refers,
comment = Args['пояснение'],
alias = DocAlias,
isVolatile = porno,
} }
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 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( Args['сноска'] ) .. cargoQ
end
return pp