Sari la conținut

Modul:InfoboxMinistry

De la Wikipedia, enciclopedia liberă
local p = {}
local wikidata = require('Modul:Wikidata')
local infobox = require('Modul:Infobox').infobox
local getArgs = require('Modul:Arguments').getArgs
local ibImage = require('Modul:InfoboxImage').InfoboxImage

local fromArgs = function(name, interface, leadership, history)
	local ibArgs = {antet = 'default', imageclass="Stema", doc="Infocaseta Minister", wikidata="y"}
	ibArgs.title = name
	ibArgs.image = ibImage{image = interface.stema}
	local idx = 1
	ibArgs['label' .. tostring(idx)] = 'Primul ministru'
	ibArgs['data' .. tostring(idx)] = leadership.firstLeader
	ibArgs['class'.. tostring(idx)] = 'note'
	idx = idx + 1
	ibArgs['label' .. tostring(idx)] = 'Ministru actual'
	ibArgs['data' .. tostring(idx)] = leadership.currentLeader
	idx = idx + 1
	ibArgs['label' .. tostring(idx)] = 'Fondat'
	ibArgs['data' .. tostring(idx)] = history.inception
	idx = idx + 1
	ibArgs['label' .. tostring(idx)] = 'Site oficial'
	ibArgs['data' .. tostring(idx)] = interface.website
	idx = idx + 1

	return infobox(ibArgs)
end

local fromFrame = function(frame)
	local args = getArgs(frame)
	local interface = {}
	interface.stema = args['Stema'] or args['imagine'] or wikidata.findOneValue('P94')
	interface.website = args['Web'] or wikidata.findOneValue('P856')
	
	local name = args['Nume'] or args['nume_articol']
	if not name then
		local offNameWdClaims = wikidata.findBestClaimsForProperty('P1488')
		if offNameWdClaims then for _,eachOffNameClaim in ipairs(offNameWdClaims) do
			if eachOffNameClaim.type == 'statement' and eachOffNameClaim.mainsnak.snaktype == 'value' and eachOffNameClaim.mainsnak.datavalue.value.language == 'ro' then
				name = eachOffNameClaim.mainsnak.datavalue.value.text
			end
		end end
	end
	if not name then name = wikidata.findLabel() end
	local leadership = {}
	leadership.firstLeader = args['Primul']
	leadership.currentLeader = args['Actual']
	if not leadership.currentLeader then
		local positionWdIds = wikidata.findBestClaimsForProperty(nil, 'P2388')
		if positionWdIds and positionWdIds[1] and positionWdIds[1].type == 'statement' and positionWdIds[1].mainsnak.snaktype == 'value' then
			leadership.currentLeader = wikidata.findOneValue('P1308', positionWdIds[1].mainsnak.datavalue.value.id)
		end
	end
	local history = {}
	history.inception = args['Fondat'] or wikidata.findOneValue('P571')
	
	return p.fromArgs(name, interface, leadership, history)
end

p.fromArgs = fromArgs
p.fromFrame = fromFrame
return p