Module:Archive Ukraine
Lua
Documentation for this module may be created at Module:Archive Ukraine/doc
Code
local p = {}
local archives = {
['ГДА СБУ'] = {
short = 'ГДА СБУ',
full = 'Галузевий державний архів Служби безпеки України',
category = 'Funds of Branch State Archives of the Security Service of Ukraine',
institution = 'ГДА СБУ'
},
['ДА АРК'] = {
short = 'ДА АРК',
full = 'Державний архів в Автономній Республіці Крим',
category = 'Funds of State Archives in the Autonomous Republic of Crimea',
institution = 'State Archive in the Autonomous Republic of Crimea'
},
['ДАВіО'] = {
short = 'ДАВіО',
full = 'Державний архів Вінницької області',
category = 'Funds of State Archive of Vinnytsia Oblast',
institution = 'State Archive of Vinnytsia Oblast'
},
['ДАВоО'] = {
short = 'ДАВоО',
full = 'Державний архів Волинської області',
category = 'Funds of State Archive of Volyn Oblast',
institution = 'State Archive of Volyn Oblast'
},
['ДАДО'] = {
short = 'ДАДО',
full = 'Державний архів Дніпропетровської області',
category = 'Funds of State Archive of Dnipropetrovsk Oblast',
institution = 'State Archive of Dnipropetrovsk Oblast'
},
['ДАДоО'] = {
short = 'ДАДоО',
full = 'Державний архів Донецької області',
category = 'Funds of State Archive of Donetsk Oblast',
institution = 'State Archive of Donetsk Oblast'
},
['ДАЖО'] = {
short = 'ДАЖО',
full = 'Державний архів Житомирської області',
category = 'Funds of State Archive of Zhytomyr Oblast',
institution = 'State Archive of Zhytomyr Oblast'
},
['ДАЗкО'] = {
short = 'ДАЗкО',
full = 'Державний архів Закарпатської області',
category = 'Funds of State Archive of Zakarpattia Oblast',
institution = 'State Archive of Zakarpattia Oblast'
},
['ДАЗпО'] = {
short = 'ДАЗпО',
full = 'Державний архів Запорізької області',
category = 'Funds of State Archive of Zaporizhzhia Oblast',
institution = 'State Archive of Zaporizhzhia Oblast'
},
['ДАІФО'] = {
short = 'ДАІФО',
full = 'Державний архів Івано-Франківської області',
category = 'Funds of State Archive of Ivano-Frankivsk Oblast',
institution = 'State Archive of Ivano-Frankivsk Oblast'
},
['ДАК'] = {
short = 'ДАК',
full = 'Державний архів міста Києва',
category = 'Funds of State Archives of Kyiv',
institution = 'State Archive of Kyiv'
},
['ДАКО'] = {
short = 'ДАКО',
full = 'Державний архів Київської області',
category = 'Funds of State Archive of Kyiv Oblast',
institution = 'State Archive of Kyiv Oblast'
},
['ДАКрО'] = {
short = 'ДАКрО',
full = 'Державний архів Кіровоградської області',
category = 'Funds of State Archive of Kirovohrad Oblast',
institution = 'State Archive of Kirovohrad Oblast'
},
['ДАЛО'] = {
short = 'ДАЛО',
full = 'Державний архів Львівської області',
category = 'Funds of State Archive of Lviv Oblast',
institution = 'State Archive of Lviv Oblast'
},
['ДАЛгО'] = {
short = 'ДАЛгО',
full = 'Державний архів Луганської області',
category = 'Funds of State Archive of Luhansk Oblast',
institution = 'State Archive of Luhansk Oblast'
},
['ДАМО'] = {
short = 'ДАМО',
full = 'Державний архів Миколаївської області',
category = 'Funds of State Archive of Mykolaiv Oblast',
institution = 'State Archive of Mykolaiv Oblast'
},
['ДАОО'] = {
short = 'ДАОО',
full = 'Державний архів Одеської області',
category = 'Funds of State Archive of Odesa Oblast',
institution = 'State Archive of Odesa Oblast'
},
['ДАПО'] = {
short = 'ДАПО',
full = 'Державний архів Полтавської області',
category = 'Funds of State Archive of Poltava Oblast',
institution = 'State Archive of Poltava Oblast'
},
['ДАРО'] = {
short = 'ДАРО',
full = 'Державний архів Рівненської області',
category = 'Funds of State Archive of Rivne Oblast',
institution = 'State Archive of Rivne Oblast'
},
['ДАС'] = {
short = 'ДАС',
full = 'Державний архів міста Севастополя',
category = 'Funds of State Archives of Sevastopol',
institution = 'State Archive of Sevastopol'
},
['ДАСО'] = {
short = 'ДАСО',
full = 'Державний архів Сумської області',
category = 'Funds of State Archive of Sumy Oblast',
institution = 'State Archive of Sumy Oblast'
},
['ДАТО'] = {
short = 'ДАТО',
full = 'Державний архів Тернопільської області',
category = 'Funds of State Archive of Ternopil Oblast',
institution = 'State Archive of Ternopil Oblast'
},
['ДАХО'] = {
short = 'ДАХО',
full = 'Державний архів Харківської області',
category = 'Funds of State Archive of Kharkiv Oblast',
institution = 'State Archive of Kharkiv Oblast'
},
['ДАХеО'] = {
short = 'ДАХеО',
full = 'Державний архів Херсонської області',
category = 'Funds of State Archive of Kherson Oblast',
institution = 'State Archive of Kherson Oblast'
},
['ДАХмО'] = {
short = 'ДАХмО',
full = 'Державний архів Хмельницької області',
category = 'Funds of State Archive of Khmelnytskyi Oblast',
institution = 'State Archive of Khmelnytskyi Oblast'
},
['ДАЧвО'] = {
short = 'ДАЧвО',
full = 'Державний архів Чернівецької області',
category = 'Funds of State Archive of Chernivtsi Oblast',
institution = 'State Archive of Chernivtsi Oblast'
},
['ДАЧгО'] = {
short = 'ДАЧгО',
full = 'Державний архів Чернігівської області',
category = 'Funds of State Archive of Chernihiv Oblast',
institution = 'State Archive of Chernihiv Oblast'
},
['ДАЧкО'] = {
short = 'ДАЧкО',
full = 'Державний архів Черкаської області',
category = 'Funds of State Archive of Cherkasy Oblast',
institution = 'State Archive of Cherkasy Oblast'
},
['ІР НБУВ'] = {
short = 'ІР НБУВ',
full = 'Інститут рукопису Національної бібліотеки України ім. В. І. Вернадського',
category = 'Funds of Manuscript Institute of Vernadsky National Library of Ukraine',
institution = 'Vernadsky National Library of Ukraine'
},
['КУІзА'] = {
short = 'КУ «Ізмаїльський архів»',
full = 'Комунальна установа «Ізмаїльський архів»',
category = 'Funds of Izmail Archive',
institution = 'КУІзА'
},
['ЦДАВО'] = {
short = 'ЦДАВО України',
full = 'Центральний державний архів вищих органів влади та управління України',
category = 'Funds of Central State Archives of Supreme Bodies of Power and Government of Ukraine',
institution = 'Central State Archives of Supreme Bodies of Power and Government of Ukraine'
},
['ЦДАГОУ'] = {
short = 'ЦДАГОУ',
full = 'Центральний державний архів громадських об\'єднань та україніки',
category = 'Funds of Central State Archives of Public Organizations and Ukrainica',
institution = 'Central State Archives of Public Organizations and Ukrainica'
},
['ЦДІАК'] = {
short = 'ЦДІАК України',
full = 'Центральний державний історичний архів України, м. Київ',
category = 'Funds of Central State Historical Archives of Ukraine in Kyiv',
institution = 'Central State Historical Archives of Ukraine in Kyiv'
},
['ЦДІАЛ'] = {
short = 'ЦДІАЛ України',
full = 'Центральний державний історичний архів України, м.Львів',
category = 'Funds of Central State Historical Archives of Ukraine in Lviv',
institution = 'Central State Historical Archives of Ukraine in Lviv'
}
}
local aliases = {
['ДААРК'] = 'ДА АРК',
['ДАДнО'] = 'ДАДО',
['ГАКО'] = 'ДАКО',
['ДАКірО'] = 'ДАКрО',
['ДАЛуО'] = 'ДАЛгО',
['ДАХкО'] = 'ДАХО',
['ДАХерО'] = 'ДАХеО',
['ДАХрО'] = 'ДАХеО',
['ЦДАГО'] = 'ЦДАГОУ'
}
local function normalizeArchive(code)
if not code then return nil end
return aliases[code] or code
end
local defaultCategory = 'Funds of archives in Ukraine - Unsorted by archive';
local translitMap = {
['А']='A',['Б']='B',['В']='V',['Г']='H',['Ґ']='G',
['Д']='D',['Е']='E',['Є']='Ye',['Ж']='Zh',
['З']='Z',['И']='Y',['І']='I',['Ї']='Yi',
['Й']='Y',['К']='K',['Л']='L',['М']='M',
['Н']='N',['О']='O',['П']='P',['Р']='R',
['С']='S',['Т']='T',['У']='U',['Ф']='F',
['Х']='Kh',['Ц']='Ts',['Ч']='Ch',['Ш']='Sh',
['Щ']='Shch',['Ю']='Yu',['Я']='Ya',
['а']='a',['б']='b',['в']='v',['г']='h',['ґ']='g',
['д']='d',['е']='e',['є']='ye',['ж']='zh',
['з']='z',['и']='y',['і']='i',['ї']='yi',
['й']='y',['к']='k',['л']='l',['м']='m',
['н']='n',['о']='o',['п']='p',['р']='r',
['с']='s',['т']='t',['у']='u',['ф']='f',
['х']='kh',['ц']='ts',['ч']='ch',['ш']='sh',
['щ']='shch',['ю']='yu',['я']='ya',
}
local function translit(s)
s = s or ''
return (mw.ustring.gsub(s, '.', translitMap))
end
local function onlyDigits(s)
s = s or ''
return (mw.ustring.gsub(s, '[^0-9]', ''))
end
local function pad(s, len)
len = len or 5
local n = tonumber(onlyDigits(s)) or 0
return string.format('%0' .. len .. 'd', n)
end
local function categoryExists(title)
local titleObj = mw.title.new('Category:' .. title)
return titleObj and titleObj.exists
end
local function explain(frame, short, full)
return frame:expandTemplate{
title = 'Explain',
args = { short, full }
}
end
local function addInstitution(frame, institution)
if not institution or institution == '' then
return ''
end
return frame:expandTemplate{
title = 'Institution:' .. institution,
args = {}
}
end
function p.addTemplate(frame)
local args = frame.args
local archiveCode = normalizeArchive(args.archive or args[1])
local fund = args.fund or args[2]
local inventory = args.inventory or args[3]
local file = args.file or args[4]
local pages = args.pages or args[5]
local link = args.link
local nocat = args.nocat
local noinst = args.noinst
local archive = archives[archiveCode] or {}
local archiveCategory = archive.category or defaultCategory
local out = {}
-- текст опису
local text =
string.format(
'%s. Ф. %s. Оп. %s.',
explain(frame, archive.short or archiveCode, archive.full or archiveCode),
fund,
inventory
)
if file and file ~= '' then
text = text .. ' Спр. ' .. file .. '.'
end
if pages and pages ~= '' then
text = text .. ' Арк. ' .. pages .. '.'
end
if link and link ~= '' then
text = '[' .. link .. ' ' .. text .. ']'
end
table.insert(out, text)
-- categories
if not nocat or nocat == '' then
local translitFund = translit(fund)
local sortKey =
pad(fund) ..
'-' ..
pad(inventory)
if file and file ~= '' then
sortKey = sortKey .. '-' .. pad(file)
end
local fundCategory =
archiveCategory ..
' - Fund ' ..
translitFund
if categoryExists(fundCategory) then
table.insert(
out,
string.format(
'[[Category:%s|%s]]',
fundCategory,
sortKey
)
)
else
table.insert(
out,
string.format(
'[[Category:%s|%s]]',
archiveCategory,
sortKey
)
)
-- tracking category
table.insert(
out,
string.format(
'[[Category:Archive files with missing fund categories|%s]]',
fundCategory
)
)
end
end
-- Institution
if not noinst or noinst == '' then
local inst = addInstitution(frame, archive.institution)
if inst ~= '' then
table.insert(out, inst)
end
end
return table.concat(out)
end
return p