Modulo:Aŭtoro

El Vikifontaro

Dokumentado por ĉi tiu modulo povas esti kreata ĉe Modulo:Aŭtoro/dokumentado

local p = {}

function get_best_statement(item, property)
	local statements = item:getBestStatements(property)
	if statements[1] ~= nil and statements[1].mainsnak.datavalue ~= nil then
		return statements[1].mainsnak.datavalue.value	
	end
	return nil
end

function get_image(item)
	return get_best_statement(item, 'P18') or 'Silver - replace this image female and male.svg'
end

function get_birth_date(item)
	local date = get_best_statement(item, 'P569')
	if date ~= nil then
		local _,_, year = string.find(date.time, '[%+%-](%d%d%d+)%-')
		return year
	end
	return ''
end

function get_death_date(item)
	local date = get_best_statement(item, 'P570')
	if date ~= nil then
		local _,_, year = string.find(date.time, '[%+%-](%d%d%d+)%-')
		return year
	end
	return ''
end

function get_wikipedia_link(item)
	local name = item:getLabelWithLang('eo')
	local wp_link = item:getSitelink('eowiki')
	if wp_link == nil then
		return '[[w:' .. name .. '|<span style="color:#BA0000;">Biografio</span>]]'
	else
		return '[[w:' .. wp_link .. '|Biografio]]'
	end
end

function get_wikiquote_link(item)
	local name = item:getLabelWithLang('eo')
	local wq_link = item:getSitelink('eowikiquote')
	if wq_link == nil then
		return '[[q:' .. name .. '|<span style="color:#BA0000;">Citaĵoj</span>]]'
	else
		return '[[q:' .. wq_link .. '|Citaĵoj]]'
	end
end

function p.main(frame)
	local item = mw.wikibase.getEntity()
	if item == nil then
		return '<span style="color:red;font-weight:bold;">Tiu artikolo ne estas ligita al Vikidatumoj.</span>'
	end
	local description = item:getDescriptionWithLang('eo') or ''
	local name = item:getLabelWithLang('eo')
	local image = get_image(item)
	local birthdate = get_birth_date(item)
	local deathdate = get_death_date(item)
	local wp_link = get_wikipedia_link(item)
	local wq_link = get_wikiquote_link(item)
	local wd_link = item:getId()
	local s = [=[
	<div class="columns" style="background-color:#F1F1DE;border-radius: 0.7em;box-shadow: 0.2em 0.3em 0.2em #B7B7B7;" >
		<div class="column" style="width:20%%;margin-left:2em;margin-top:2em;margin-bottom:2em"><ul><li>%s</li><li>%s</li><li>[[d:%s|Vikidatumero]]</li></ul></div>
		<div class="column" style="width:50%%;text-align:center;"><div style="font-size:250%%">%s</div><div>%s (%s - %s)</div></div>
		<div class="column" style="width:auto;margin:1em;float:right;">[[Dosiero:%s|right|140px]]</div>
	</div>
	]=]
	local cat = ""
	if birthdate ~= '' then
		cat = cat .. mw.ustring.format("[[Kategorio:Naskiĝintoj en %s]]", birthdate)	
	end
	if deathdate ~= '' then
		cat = cat .. mw.ustring.format("[[Kategorio:Mortintoj en %s]]", deathdate)	
	end
	cat = cat .. "[[Kategorio:Aŭtoroj laŭ alfabeto]]"
	return mw.ustring.format(s, wp_link, wq_link, wd_link, name, description, birthdate, deathdate, image) .. cat
end

return p