Модул:Игралиште/Милан Јелисавчић/Laureats

Документацију овог модула можете да направите на страници Модул:Игралиште/Милан Јелисавчић/Laureats/док

-- by User:Милан Јелисавчић
local sources = require('Module:Sources')

local p = {}

local function awardyear(wdata, awardId)
	local claim
	if wdata.claims then
		claim = wdata.claims["P166"]
	end
	if (claim and claim[1] and claim[1].mainsnak.snaktype == "value" and 
		claim[1].mainsnak.datavalue.type == "wikibase-entityid" and 
		claim[1].mainsnak.datavalue.value["numeric-id"]) then
		local index = 1
		while claim[index] do
			if (claim[index].mainsnak.datavalue.value["numeric-id"] == awardId) then
				local qualifiers = claim[index].qualifiers
				if (qualifiers and qualifiers["P585"] and 
					qualifiers["P585"][1].snaktype == 'value' and 
					qualifiers["P585"][1].datavalue.type == 'time') then
					local snak = qualifiers['P585'][1]
					return mw.wikibase.formatValue(snak)
				end
			end
			index = index + 1
		end
	end
	return '-'
end

local function thumbnail(wdata)
	local claim
	if wdata.claims then
		claim = wdata.claims["P18"]
	end
	if (claim and 
		claim[1] and 
		claim[1].mainsnak.snaktype == "value" and 
		claim[1].mainsnak.datatype == "commonsMedia" and 
		claim[1].mainsnak.datavalue.value) then
		local image = claim[1].mainsnak.datavalue.value
		return '| ' .. '[[File:' .. image .. '|64px]] \n'
	else
		return '| \n'
	end
end

local function lifespan(wdata)
	local claim
	if wdata.claims then
		claim = wdata.claims["P31"]
	end
	if (claim and 
		claim[1] and 
		claim[1].mainsnak.snaktype == "value" and 
		claim[1].mainsnak.datavalue.type == "wikibase-entityid" and 
		claim[1].mainsnak.datavalue.value["numeric-id"] and 
		claim[1].mainsnak.datavalue.value["numeric-id"] == 5) then
		local yr = "%d%d%d%d$"
		local p569 = wdata:formatPropertyValues( 'P569' ).value
		if p569 ~= "" then
			if p569:match(yr) ~= nil then
				p569 = p569:match(yr)
			end
			local p570 = wdata:formatPropertyValues( 'P570' ).value
			if p570 ~= "" then
				if p570:match(yr) ~= nil then
					p570 = p570:match(yr)
				end
				return ' <span style="font-size:smaller;font-weight:100">(' .. p569 .. '-' .. p570 .. ')</span> '
			else
				return ' <span style="font-size:smaller;font-weight:100">(р. ' .. p569 .. ')</span>'
			end
		else
			return ' <span style="font-size:smaller;font-weight:100">(?)</span>'
		end
	else
		return ''
	end
end

function p.table(frame)
	-- init
	if frame.args['award'] then
		awardId = frame.args['award']
	end
	if frame.args['work'] then
		work_header = '!дело \n'
	else
		work_header = ''
	end
	
	-- header
	header = {
		'{| class="wikitable sortable" style="width:100%" \n',
		'!style="width:8px"|бр. \n',
		'!style="width:64px"|слика \n',
		'!особа \n',
		work_header,
		'!година \n',
		'!<span title="број основних изјава на ставци">реф.</span> \n',
		'|- \n'
	}
	resultTable = table.concat(header);
	
	index = 1
	rows = ''
	while frame.args[index] do
		Id = frame.args[index]
		local entity = mw.wikibase.getEntityObject(Id)
		
		local row_start = '|- \n'
		local row_index = '|' .. index .. ' \n'
		local image = thumbnail(entity)
		local person = '|' .. entity:getLabel('sr') .. ' ' .. lifespan(entity) .. entity:getDescription( 'sr' ) .. ' \n'
		local row_year = '| ' .. awardyear(entity, 944048) .. '\n'
		-- local ref = '| ' .. sources.renderReference(g_frame, entity) .. '\n'
		local row = 
			row_start .. 
			row_index .. 
			image .. 
			person ..
			row_year ..
			"| ref \n" ..
			"|- \n"
		mw.logObject(row)

		rows = rows .. row
		index = index + 1
	end
	
	return resultTable .. rows .. '|}\n'
end

return p