Modul:InfoboxEthnicGroup

Documentația acestui modul poate fi creată la Modul:InfoboxEthnicGroup/doc

local p = {}
require('strict')
local getArgs = require('Modul:Arguments').getArgs
local Wikidata = require('Modul:Wikidata')
local EditAtWikidata = require('Modul:EditAtWikidata')
local TableTools = require('Modul:TableTools')
local getNativeNamesList = require('Modul:InLocalLangs').getNativeNamesList
local Lang = require('Modul:Lang')
local Infobox = require('Modul:Infobox')
local infoboxImage = require('Modul:InfoboxImage').InfoboxImage

p.display = function(e)
	local ibargs = {}
	ibargs.antet = 'blank'
	ibargs['culoare cadru'] = '#b08261'
	ibargs['culoare text'] = '#fee8ab'
	ibargs.datastyle = 'background:#fff6d9'
	ibargs.imagestyle = 'background:#fff6d9'
	ibargs.wikidata = 'y'
	
	ibargs.title = e.name
	ibargs.subheader1 = e.ownName
	ibargs.subheaderstyle = 'background-color: #b08261; color: #fee8ab; font-size: 150%; padding-bottom: 5px'
	
	ibargs.image1 = infoboxImage{image=e.flag.image}
	ibargs.caption1 = e.flag.caption
	ibargs.image2 = infoboxImage{image=e.illustration.image}
	ibargs.caption2 = e.illustration.caption
	ibargs.image3 = infoboxImage{image=e.map}
	ibargs.caption3 = 'Harta distribuției'
	
	if e.population.total then
		ibargs.header5 = 'Populație totală'
		ibargs.data6 = e.population.total
		if e.population.timestamp then
			ibargs.data6 = ibargs.data6 .. ' ' .. tostring(mw.html.create('small'):wikitext('(', e.population.timestamp, ')'))
		end
		if e.population.extension then
			ibargs.data7 = e.population.extension .. ' ' .. tostring(mw.html.create('small'):wikitext('(inclusiv persoanele cu origini)'))
		end
	end
	if e.regionsraw or #e.regions > 0 then
		ibargs.header10 = 'Regiuni cu populație semnificativă'
		ibargs.data11 = e.regionsraw
		if #e.regions > 0 then
			local regtbl = mw.html.create('table')
				:attr('align', 'center')
				:css('width', '100%')
				:css('background', 'transparent')
				:css('line-height', '12pt')
				:css('text-align', 'left')
				:css('font-size', '95%')
			if e.regionsheader then
				regtbl:tag('tr'):tag('th')
					:css('font-size', '105%')
					:css('text-align', 'center')
					:attr('colspan', '3')
					:wikitext(e.regionsheader)
			end
			for _,reg in ipairs(e.regions) do
				if reg.regiune then
					local regTr = regtbl:tag('tr')
					
					local regTd = regTr:tag('td')
					regTd:attr('width', '30%')
					if reg.pop then
						regTd:wikitext(reg.regiune)
						regTr:tag('td')
									:attr('align', 'right')
									:wikitext(reg.pop, reg.ref)
					else
						regTd:attr('colspan', '2')
						regTd:wikitext(reg.regiune, reg.ref)
					end
				end
			end
			ibargs.data11 = tostring(regtbl)
		end
	end
	
	if e.langs then
		ibargs.header20 = 'Limbi vorbite'
		ibargs.data21 = e.langs
	end
	if e.religions then
		ibargs.header30 = 'Religii'
		ibargs.data31 = e.religions
	end
	if e.related then
		ibargs.header40 = 'Grupuri înrudite sau legate cultural'
		ibargs.data41 = e.related
	end
	ibargs.data49 = e.notes
	ibargs.doc = 'Infocaseta Grup etnic'
	return Infobox._infobox(ibargs)
end

p.fromArgs = function(args)
	local e = {}
	local qId = args.q or mw.wikibase.getEntityIdForCurrentPage()
	e.name = args['grup'] or Wikidata.findLabel(qId)
	e.ownName = args['nume_propriu']
	if not e.ownName then
		local nativeNames = getNativeNamesList(qId)
		local formattedNames = {}
		for lang,nativeNameSet in pairs(nativeNames) do
			for _,eachName in ipairs(nativeNameSet.texts) do
				table.insert(formattedNames, Lang.fromArgs(lang, nil, eachName, true))
			end
		end
		e.ownName = table.concat(formattedNames, tostring(mw.html.create('br')))
	end
	e.flag = {}
	e.flag.image = args.imagine_drapel or Wikidata.loadOneValueInChain({qId, 'P41', 'raw'})
	e.flag.description = args.flag_caption or Wikidata.loadOneValueInChain({qId, 'P163'})
	
	e.illustration = {}
	e.illustration.image = args['imagine']
	if e.illustration.image then
		e.illustration.caption = args['imagine_descriere'] or args['descriere']
	else
		e.illustration.image, e.illustration.caption = Wikidata.findImageAndCaption(qId)
	end
	e.map = Wikidata.loadOneValueInChain({qId, 'P242', 'raw'})
	e.population = {}
	e.population.total = args['populație'] or args['pop'] or Wikidata.loadOneValueInChain({qId, 'P1082'})
	e.population.timestamp = args['poptime']
	e.population.extension = args['genealogie']
	
	e.regionsraw = args['popplace'] or args['regiuni']
	e.regionsheader = args['tabelhdr']
	
	e.regions = TableTools.numData(args)
	
	e.langs = args['langs'] or args['limbi'] 
	if not e.langs then
		local lgslist = Wikidata.findValueListWithDecoratedQualifiers(qId, 'P2936', true)
		if lgslist and #lgslist > 0 then
			e.langs = table.concat(lgslist, tostring(mw.html.create('br')))
			e.langs = e.langs .. ' ' .. EditAtWikidata.displayMessage('P2936', qId)
		end
	end
	
	e.religions = args.rels or args.religii
	if not e.religions then
		local rellist = Wikidata.findValueListWithDecoratedQualifiers(qId, 'P140', true, {'$P1416'})
		if rellist and #rellist > 0 then
			e.religions = table.concat(rellist, tostring(mw.html.create('br')))
			e.religions = e.religions .. ' ' .. EditAtWikidata.displayMessage('P140', qId)
		end
	end
	
	e.related = args.related or args['grupuri_înrudite']
	if not e.related then
		local rellist = Wikidata.findValueListWithDecoratedQualifiers(qId, 'P527', true)
		if rellist and #rellist > 0 then
			e.related = table.concat(rellist, tostring(mw.html.create('br')))
			e.related = e.related .. ' ' .. EditAtWikidata.displayMessage('P527', qId)
		end
	end
	
	e.notes = args.note
	
	return p.display(e)
end

p.fromFrame = function(frame)
	local args = getArgs(frame)
	return p.fromArgs(args)
end

return p