Модуль:Пам'ятка культурної спадщини України

{{i}} Документація модуля[створити]
require('Module:No globals')
local IUH = {}
IUH.__index = IUH

local IUHconfig = require('Module:Памятка культурної спадщини України/config')

local Munconfig

local IUHucfirst

local theregword

function IUH:armsgen(regid, statusid)
local arms
arms = 'Lesser Coat of Arms of Ukraine.svg'
if statusid~='Н' then
if regid then
	if IUHconfig.regarms[regid] then
		arms = IUHconfig.regarms[regid]
		end
	end
end
return arms
end

function table.contains(table, element)
  for _, value in pairs(table) do
    if value == element then
      return true
    end
  end
  return false
end

function IUH:regidexists(regid, disp)
local cato
if disp==true then cato = 'Об’єкти культурної спадщини ' else cato = 'Памятники культурного наследия Украины ' end
if mw.title.new('Category:'..cato..IUHconfig.regins[regid]).exists then
	return true
end
return false
end

function IUH:dispterrcheck(regid)
	if table.contains(IUHconfig.reginsdisp,regid) then return true end
	return false
end

function IUH:gencat(regid, statusid, munid)
	local regdisp
	local regido
	local cat
	cat = 'Памятники культурної спадщини України'
	if regid and IUHconfig.regins[regid] then
	regdisp=self:dispterrcheck(regid)
	regido = self:regidexists(regid, regdisp) else
	regdisp = false
	regido = false
	end
	if statusid then
		if regid then
			if IUHconfig.regins[regid] then
				if IUHconfig.statuscats[statusid] and IUHconfig.statuscats[statusid][1] then
					if mw.title.new('Category:' .. IUHconfig.statuscats[statusid][1]..' памятники культурного наследия '..IUHconfig.regins[regid]).exists then
					cat = IUHconfig.statuscats[statusid][1]..' памятники культурного наследия '..IUHconfig.regins[regid]
					else
					local cattemp
					cattemp = cat
					if regdisp==true then
					cat='Объекты культурного наследия'
					end						
					local secondcat
					if IUHconfig.statuscats[statusid] and IUHconfig.statuscats[statusid][2] and mw.title.new('Category:'..cattemp..' '..IUHconfig.statuscats[statusid][2]).exists then
					secondcat = ']][[Категория:'..cattemp..' '..IUHconfig.statuscats[statusid][2]
					else secondcat = ''
					end
					if regido==true then
					cat = cat..' '..IUHconfig.regins[regid]
					else
					if cat=='Объекты культурного наследия' then cat='Памятники культурного наследия Украины'
					end
					if secondcat~='' then
					cat=mw.ustring.sub(secondcat,15,-1)
					secondcat = ''
					end
					end				
					cat = cat..' '..IUHconfig.regins[regid]..secondcat
				end
				else
					if regdisp==true then
					cat='Объекты культурного наследия'
					end
					if regido==true then
					cat = cat..' '..IUHconfig.regins[regid]
					else
					if cat=='Объекты культурного наследия' then cat = 'Памятники культурного наследия Украины' end					
					end
				end
			else
				if IUHconfig.statuscats[statusid] and IUHconfig.statuscats[statusid][2] then
					if mw.title.new('Category:'..cat..' '..IUHconfig.statuscats[statusid][2]).exists then
					cat = cat..' '..IUHconfig.statuscats[statusid][2]
					end
				end
			end
					if munid and ((munid~=nil) and (munid~='')) then
					if Munconfig and Munconfig.munins[munid] then
					if IUHconfig.statuscats[statusid] and IUHconfig.statuscats[statusid][1] then
					if mw.title.new('Category:' .. IUHconfig.statuscats[statusid][1]..' памятники культурного наследия '..Munconfig.munins[munid]).exists then
					cat = IUHconfig.statuscats[statusid][1]..' памятники культурного наследия '..Munconfig.munins[munid]
					else
					local thirdcat
					local checker
					if regdisp==true then checker = 'Объекты культурного наследия ' else checker = 'Памятники культурного наследия Украины ' end
					if mw.title.new('Category:'..checker..Munconfig.munins[munid]).exists then
					if IUHconfig.regins[regid]~=nil then
					if mw.title.new('Category:' .. IUHconfig.statuscats[statusid][1]..' памятники культурного наследия '..IUHconfig.regins[regid]).exists then
					thirdcat = ']][[Категория:'..checker..Munconfig.munins[munid]
					else
					thirdcat = ''
					if regdisp==true then
					cat = mw.ustring.gsub(cat,'Объекты культурного наследия '..IUHconfig.regins[regid],'Объекты культурного наследия '..Munconfig.munins[munid])
					else
					cat = mw.ustring.gsub(cat,'Памятники культурного наследия Украины '..IUHconfig.regins[regid],'Памятники культурного наследия Украины '..Munconfig.munins[munid])
					end
					end
					else
					thirdcat = ']][[Категория:Памятники культурного наследия Украины '..Munconfig.munins[munid]
					end
					else thirdcat = ''
					end
					cat = cat..thirdcat
					end
					end
				end
				end
	else
		if IUHconfig.statuscats[statusid] and IUHconfig.statuscats[statusid][2] then
			if mw.title.new('Category:'..cat..' '..IUHconfig.statuscats[statusid][2]).exists then
				cat = cat..' '..IUHconfig.statuscats[statusid][2]
		end
		end
			
	end
	else
			if regid then
			if IUHconfig.regins[regid] then
				if regdisp==true then
				cat='Объекты культурного наследия'
				end
				if regido==true then
				cat = cat..' '..IUHconfig.regins[regid]
				else
				if cat=='Объекты культурного наследия' then cat = 'Памятники культурного наследия Украины' end
				end
				end
				if munid and ((munid~=nil) and (munid~='')) then
				if (Munconfig and Munconfig.munins[munid]) then
					local checker
					if regdisp==true then
					checker = 'Объекты культурного наследия ' else checker = 'Памятники культурного наследия Украины '
					end
					if mw.title.new('Category:'..checker..''..Munconfig.munins[munid]).exists then
					cat = checker..Munconfig.munins[munid]
					end
				end			
			end
			end
	end
	return cat
				
end

function IUH:genmunicipality(munid)
	if munid then
	if tonumber(munid) then
		munid = Munconfig.municipality[munid]
	end
	if not Munconfig.munins[munid] then
		munid = nil
		end
	end
	return munid
end

function IUH:returnnotnill(variable)
	if variable then
		if variable ~=nil then
			return variable
			end
		end
	return ''
end

function IUH:getmunconfig(regid)
	local Munconfigstring
		if mw.title.new('Модуль:Памятник культурного наследия Украины/config/'..regid).exists then
			if require('Модуль:Памятник культурного наследия Украины/config/'..regid)~=nil then
			Munconfigstring ='Памятник культурного наследия Украины/config/'..regid
			end
		end
	if Munconfigstring~= nil and Munconfigstring~='' and require(Munconfigstring)~=nil then
	return require(Munconfigstring)
	else
	return nil
	end
end

function IUH:genstatus(statusid, number)
	local statusword
	statusword = ''
	if not statusid then
	if number then
	if(mw.ustring.sub(number,-2))=='-Н' then
	statusid = 'Н'
	end
	if (IUHconfig.regarms[mw.ustring.sub(number,-2)] or IUHconfig.regaliases_native[mw.ustring.sub(number,-2)]) then
	statusid = 'М'
	end
	end
	end
	if statusid then
	if not IUHconfig.statuscats[statusid] then
	statusid = nil
	end	
	if statusid~=nil and IUHconfig.statuscats[statusid] and IUHconfig.statuscats[statusid][2] then
    statusword = IUHconfig.statuscats[statusid][2]
    else statusword = '' end
    end
	return {['statusid']=statusid, ['statusword']=statusword,}
end

function IUH:genreg(regid, number)
	
	if regid then
	if IUHconfig.regaliases_native[regid] then
	regid = IUHconfig.regaliases_native[regid]
	end
	if not IUHconfig.regarms[regid] then
	regid = nil
	end
	end
	if number then
	local regtest = mw.ustring.sub(number,-2)
	if IUHconfig.regaliases_native[regtest] then
	regid = IUHconfig.regaliases_native[regtest]
	end
	if IUHconfig.regarms[regtest] then
	if not regid then
	regid = regtest
	end
	end
	end
	return regid
end


function IUH:coregen(number, regid, statusid, munid)
	local statusword
	local URL
	local regidword
	local statusarms
	local regcatword
	if number then
	if mw.ustring.len(tostring(number)) > 10 then
	number = nil
	end
	end
	if not theregword then
	if IUHucfirst == true then
		theregword = 'Охр. №'
	else
		theregword = 'охр. №'
	end
end
	local statusarray = self:genstatus(statusid, number)
	statusid = statusarray.statusid
	statusword = statusarray.statusword or ''
	regid = self:genreg(regid, number)
	regcatword = ''
	if regid then
		if munid then
		Munconfig = self:getmunconfig(regid)
		end
	end
	local namespacecheck = mw.ustring.len(self.frame:preprocess('{{NAMESPACE}}'))
	if statusid then
	if statusid =='Н' then
		if self.args['сов'] then
			URL = 'http://search.ligazakon.ua/l_doc2.nsf/link1/KP630970.html'
		else
			URL = 'http://mincult.kmu.gov.ua/control/uk/publish/article?art_id=245279051&cat_id=244910406'
		end
	else
		if statusid == 'М' then
			URL = 'http://mincult.kmu.gov.ua/control/uk/publish/article?art_id=245279032&cat_id=244910406'
		else
			URL = 'http://mincult.kmu.gov.ua/control/uk/publish/officialcategory?cat_id=244910406'
		end
	end
	else
		URL = 'http://mincult.kmu.gov.ua/control/uk/publish/officialcategory?cat_id=244910406'
	end
	if number then
		regidword = '['..URL..' '..theregword..' '..number..']'
			
	else
		regidword = ''
	end
    statusarms = self:armsgen(regid, statusid)	
	if not self.args['nocat'] then
	if namespacecheck==0 then
	regcatword='[[Категория:'..self:gencat(regid, statusid)..']]'
	end
	end	
	return {['number']=number, ['regidword']=regidword, ['regcatword']=regcatword, ['statusword']=statusword, ['statusarms']=statusarms,}
end

function IUH:render()
	local ArmstoRender
	local numarg, regarg, statarg
	local municipality = self.args['Район'] or self.args['Город']
	if self.args['1'] then
	numarg = self.args['1']
	end
	if self.args['номер'] then
	numarg = self.args['номер']
	end
	if self.args['2'] then
	regarg = self.args['2']
	end
	if self.args['регион'] then
	regarg = self.args['регион']
	end
	if self.args['3'] then
	statarg = self.args['3']
	end
	if self.args['статус'] then
	statarg = self.args['статус']
	end
	local div, divend
	div, divend = '', ''	
	local Coredata
	local statuswordrender
	local regidrender
	self.micro = mw.ustring.find(self:returnnotnill(self.args['мини']),'микро',0,true)~=nil and true or false	
	local minidiv = mw.ustring.find(self:returnnotnill(self.args['мини']),'div',0,true)~=nil and true or false	
	if self.args['мини'] then
	if minidiv==true then
	div, divend = '<div>','</div>'
	end		
	IUHucfirst = true
	Coredata = self:coregen(numarg, regarg, statarg, municipality)
	if Coredata.statusword == '' then statuswordrender = '' else statuswordrender = ' '..Coredata.statusword end
	if Coredata.regidword~='' then regidrender =(self.micro~=true and '. ' or '')..'{{nobr|1='..Coredata.regidword..'}}' else regidrender = '' end
	if self.args['Без герба'] then
	ArmstoRender = '' else ArmstoRender = '[[Файл:'..Coredata.statusarms..'|20px|link=|Герб]]&nbsp;' end
	local stringtoreturn = self.frame:preprocess(div..ArmstoRender..'<span title="Пам`ятка культурної спадщини України" style="margin-left: 0.2em; font-size: 85%;">'..(self.micro~=true and ('Пам’ятка культурної спадщини України'..statuswordrender) or '')..regidrender..'</span>'..divend..Coredata.regcatword)
    return stringtoreturn
	else
	IUHucfirst = false
	Coredata = self:coregen(numarg, regarg, statarg, municipality)
	if Coredata.statusword == '' then statuswordrender = '' else statuswordrender = ' '..Coredata.statusword end
	if Coredata.regidword~='' then
	regidrender = self.frame:preprocess('<br><small>'..Coredata.regidword..'</small>') else regidrender = '' end
	local embwidth, embclass, embwidthcss, embbordercss, cellspa
	if not self.args['встраивать'] then
		embclass = 'infobox'
		embwidthcss = '280px'
		embwidth = nil
		embbordercss = nil
	else
		embclass = nil
		embwidthcss = nil		
		embwidth = '100%'
		embbordercss = '1px solid #a2a9b1'
		if self.args['встраивать']=='UNESCO' then
		cellspa = '5'
		end
	end	
	local builder = mw.html.create()
	builder = builder:tag('table')
    	:attr('width', embwidth)
    	:attr('cellspacing', cellspa)
    	:addClass(embclass)
    	:css('width', embwidthcss)
    	:css('border', embbordercss)
    	:tag('tr')
    		:tag('td')
    			:cssText('vertical-align: middle; padding: 5px;')
    			:wikitext('[[Файл:'..Coredata.statusarms..'|45px|link=|Герб]]')
    			:done()
    		:tag('td')
    			:cssText('text-align:center; vertical-align:middle; background:'..(self.args['цвет'] or '{{цвет|Украина}}')..'; width:100%;')
    			:wikitext('<span style="white-space: normal !important; font-weight: bold;">Памятник культурного наследия Украины'..statuswordrender..'</span>'..regidrender..Coredata.regcatword)
    			:done()
    		:done()
    builder = builder:done()
	return builder
	end
end

function IUH:renderText()
	local ArmstoRender = ''
	local numarg, regarg, statarg
	local municipality = self.args['Район'] or self.args['Город']
	if self.args['1'] then
	numarg = self.args['1']
	end
	if self.args['номер'] then
	numarg = self.args['номер']
	end
	if self.args['2'] then
	regarg = self.args['2']
	end
	if self.args['регион'] then
	regarg = self.args['регион']
	end
	if self.args['3'] then
	statarg = self.args['3']
	end
	if self.args['статус'] then
	statarg = self.args['статус']
	end
	local Coredata
	local statuswordrender
	local regidrender
	if self.args['мини'] then
	IUHucfirst = true
	Coredata = self:coregen(numarg, regarg, statarg, municipality)
	if Coredata.statusword == '' then statuswordrender = '' else statuswordrender = ' '..Coredata.statusword end
	if Coredata.regidword~='' then regidrender ='. {{nobr|1='..Coredata.regidword..'}}' else regidrender = '' end
	local stringtoreturn = self.frame:preprocess('<span title="Памятник культурного наследия Украины" style="margin-left: 0.2em; font-size: 85%;">Памятник культурного наследия Украины'..statuswordrender..regidrender..'</span>'..Coredata.regcatword)
    return stringtoreturn
	else
	IUHucfirst = false
	Coredata = self:coregen(numarg, regarg, statarg, municipality)
	if Coredata.statusword == '' then statuswordrender = '' else statuswordrender = ' '..Coredata.statusword end
	if Coredata.regidword~='' then
	regidrender = self.frame:preprocess('<br><small>'..Coredata.regidword..'</small>') else regidrender = '' end
	return '<span style="white-space: normal !important; font-weight: bold;">Памятник культурного наследия Украины'..statuswordrender..'</span>'..regidrender..Coredata.regcatword
	end
end

function IUH:renderArms()
	local ArmstoRender = ''
	local numarg, regarg, statarg
	local municipality = self.args['Район'] or self.args['Город']
	if self.args['1'] then
	numarg = self.args['1']
	end
	if self.args['номер'] then
	numarg = self.args['номер']
	end
	if self.args['2'] then
	regarg = self.args['2']
	end
	if self.args['регион'] then
	regarg = self.args['регион']
	end
	if self.args['3'] then
	statarg = self.args['3']
	end
	if self.args['статус'] then
	statarg = self.args['статус']
	end
	local Coredata
	local statuswordrender
	local regidrender
	IUHucfirst = true
	Coredata = self:coregen(numarg, regarg, statarg, municipality)
	return Coredata.statusarms
end

function IUH.new(frame, args)
	if not args then
		args = require('Module:Arguments').getArgs(frame, {wrappers = {'Template:Памятник культурного наследия Украины', 'Template:Культурное наследие Крым'}})
		--return
	end
	local obj = {
		frame = frame,
		args = args
	}
	return setmetatable(obj, IUH)
end

local p = {}

function p.main(frame)
	return IUH.new(frame):render()
end

function p.mainText(frame)
	return IUH.new(frame):renderText()
end


function p.mainArms(frame)
	return IUH.new(frame):renderArms()
end

return p