Module:Oteur

From Wikisource
Jump to navigation Jump to search
(en) This page is part of the Walloon Wikisource project. It’s temporarily placed in the incubator (wikisource.org) and will be moved to it’s own plateforme (wa.wikisource.org) when the projet will be enough diveloped.
(fr) Cette page fait partie du projet Wikisource en wallon. Elle est hébergée temporairement dans l’incubateur (wikisource.org) et sera transférée vers sa propre plateforme (wa.wikisource.org) une fois le projet suffisamment abouti.
(wa) Cisse pådje ci est on boket do pordjet Wikisourd e walon. Elle est pol moumint dvins l’ discloyoe (wikisource.org) eyet serè displaeceye eviè s’ prôpe platfôme (wa.wikisource.org) cwand l’ pordjet serè divnou diswalpé assez.

local p = {}
local lang = "wa"
local img = "Gray - replace this image male.svg"
local NS = mw.title.getCurrentTitle().namespace
local CatNS = mw.site.namespaces.Category.name

function p.main(frame)
	
	if frame.args.wd == nil or frame.args.wd == "" then return end
	
	-- data from Wikidata
	local item = mw.wikibase.getEntity(frame.args.wd)
	local html = mw.html.create()
	
	if NS == 108 then
		html:wikitext('[['..CatNS..':Walon]]')
		html:wikitext('[['..CatNS..':Oteurs]]')
		if frame.args.index ~= nil and frame.args.index ~= "" then 
			local I = string.upper(frame.args.index)
			div_index = mw.html.create( 'div' )
			div_index:wikitext('[[:Category:Oteurs-'..I..'|Oteurs-'..I..']]')
			html:wikitext('[['..CatNS..':Oteurs-'..I..']]')
		end
	end
	
	div_author = mw.html.create( 'div' )
	div_author:css({
		["margin-bottom"] = "1em",
		["border"] = "1px solid #BEA2A2",
		["background"] = "#E4D8D8",
		["overflow"] = "auto",
		["padding"] = "10px",
		["border-radius"] = "10px",
		["box-shadow"] = "0 0 10px #BEA2A2"
	})

	div_author_text = mw.html.create( 'div' )
	div_author_text:css({
		["margin-left"] = "200px"
	})
	
	div_iw = mw.html.create( 'div' )
	div_iw:css({
		["float"] = "right"
	})

	-- index
	if div_index ~= nil then div_iw:node( div_index ) end
	
	-- Wikidata
	if item.id~= nil then
		div_iw:wikitext( '<div>[[:d:'..item.id..'|Wikidata]]</div>' )
	end
	-- Wikipedia
	local iwd = item:getSitelink( lang..'wiki' )
	if iwd ~= nil then
		div_iw:wikitext( '<div>[[:w:'..lang..':'..iwd..'|Wikipedia]]</div>' )
	end
	-- Wiccionaire
	local iwkt = item:getSitelink( 'wawiktionary' )
	if iwkt ~= nil then
		div_iw:wikitext( '<div>[[:wikt:wa:'..iwkt..'|Wiccionaire]]</div>' )
	end
	-- Commons
	local iwc = item:formatPropertyValues('P373').value
	if iwc ~= nil and iwc ~= '' then
		div_iw:wikitext( '<div>[[:c:Category:'..iwc..'|Commons]]</div>' )
	end
	div_author:node( div_iw )
	
	local imgWD = item:getBestStatements('P18')
	if imgWD[1] ~= nil and imgWD[1].mainsnak.datavalue ~= nil then
		img = imgWD[1].mainsnak.datavalue.value
	end
	div_author:wikitext( '[[File:'..img..'|left|128px]]' )
 
	local fullnameWD = item:getLabel(lang)
	local fullnameWD_fr = item:getLabel('fr')
	if fullnameWD == nil then fullnameWD = "?" end
	div_author_name = mw.html.create( 'div' )
	div_author_fname = mw.html.create( 'span' )
	div_author_fname:css({
		["font-weight"] = "bold",
		["font-family"] = "sherif",
		["font-size"] = "200%"
	})
	div_author_fname:wikitext(fullnameWD)
	div_author_name:node( div_author_fname )
	
	local natWD = item:getBestStatements('P31')
	local i = 1 ; local noteur = 1
	while( natWD[i] ~= nil and natWD[i].mainsnak.datavalue ~= nil ) do
		if natWD[i].mainsnak.datavalue.value.id == 'Q10648343' then
			noteur = 2
		end
		i = i + 1 
	end
	
	if noteur == 1 then
		local akaWD = item:getBestStatements('P742')
		local i = 1
		local akas = {}
		local altname = ""
		while( akaWD[i] ~= nil and akaWD[i].mainsnak.datavalue ~= nil ) do
			table.insert(akas, akaWD[i].mainsnak.datavalue.value)
			if i == 3 then break end
			i = i + 1 
		end
		if fullnameWD_fr ~= nil or #akas > 0 then
			if fullnameWD_fr ~= nil and fullnameWD_fr ~= "" and fullnameWD_fr ~= fullnameWD  then
				altname = '<abbr title="no e francès">n.f.</abbr> ' .. fullnameWD_fr
			end
			if #akas > 0 then
				if altname ~= "" then altname = altname..' ; ' end
				altname = altname .. '<abbr title="no d’ pene">n.p.</abbr> ' .. table.concat(akas, ', ')
			end
			if altname ~= "" then
				div_author_name:wikitext(' ('..altname..')')
			end
		end
		div_author_text:node( div_author_name )
		
		local birthWD = item:getBestStatements('P569')
		local deathWD = item:getBestStatements('P570')
		if birthWD == nil or birthWD[1] == nil then birthWD = "?" else 
			if birthWD[1].mainsnak.datavalue.value.precision == 7 then
				birthWD = (tonumber(string.sub(birthWD[1].mainsnak.datavalue.value.time, 2, 3))+1).."<sup>inme</sup> sièke"
			elseif birthWD[1].mainsnak.datavalue.value.precision == 8 then
				birthWD = string.sub(birthWD[1].mainsnak.datavalue.value.time, 2, 4).."x"
			else
				birthWD = string.sub(birthWD[1].mainsnak.datavalue.value.time, 2, 5)
			end
		end
		if deathWD == nil or deathWD[1] == nil then deathWD = "?" else 
			if deathWD[1].mainsnak.datavalue.value.precision == 7 then
				deathWD = (tonumber(string.sub(deathWD[1].mainsnak.datavalue.value.time, 2, 3))+1).."<sup>inme</sup> sièke"
			elseif deathWD[1].mainsnak.datavalue.value.precision == 8 then
				deathWD = string.sub(deathWD[1].mainsnak.datavalue.value.time, 2, 4).."x"
			else
				deathWD = string.sub(deathWD[1].mainsnak.datavalue.value.time, 2, 5)
			end
		end
		div_author_dates = mw.html.create( 'div' )
		div_author_dates:wikitext(birthWD.." — "..deathWD)
		div_author_text:node( div_author_dates )
	else
		div_author_text:node( div_author_name )
	end
	
	if noteur > 1 then
		local oteursWD = item:getBestStatements('P527')
		local i =1
		local oteurs = {}
		while( oteursWD[i] ~= nil and oteursWD[i].mainsnak.datavalue ~= nil ) do
			local oteur = mw.wikibase.getLabel(oteursWD[i].mainsnak.datavalue.value.id)
			table.insert(oteurs, "[[:Author:"..oteur.."|"..oteur.."]]")
			i = i + 1 
		end
		div_author_oteurs = mw.html.create( 'div' )
		div_author_oteurs:wikitext(table.concat(oteurs, ", "))
		div_author_text:node( div_author_oteurs )
	end
	
	local descWD = item:getDescription( lang )
	if descWD == nil then descWD = "''i gn a co nou discrijhaedje so Wikidata''" end
	div_author_des = mw.html.create( 'div' )
	div_author_des:wikitext(descWD)
	div_author_text:node( div_author_des )
	
	div_author:node( div_author_text )
	html:node( div_author )
	return  html
end

return p