Module:Infoboesse

Èn årtike di Wikipedia.
Sauter à la navigation Sauter à la recherche

La documentation pour ce module peut être créée à Module:Infoboesse/doc

local p = {}
local wd = require("Module:Wikidata")
local CatNS = mw.site.namespaces.Category.name
local lang = mw.getContentLanguage():getCode()

function p.main(frame)
	local id = nil
	if frame.args.wd ~= nil and frame.args.wd ~= "" then 
		id = frame.args.wd
	end
	
	-- data from Wikidata
	local entity = wd.getEntity(id)
	if not entity then return end
	local articleId = entity:getId()
	
	-- variåve ki contént tot l' côde html di l'infoboesse
	local html = mw.html.create()

	-- templatestyle
	html:node(frame:extensionTag{ 
		name = 'templatestyles', 
		args = { src = 'Infoboesse/styles.css' } }
	)
	
	div_main = mw.html.create( 'div' )
	div_main:addClass("infoboesse")
	
	-- tite, k' est l' label
	div_title = mw.html.create( 'div' )
	div_title:addClass("infoboesse-tite")
	div_title:node(entity:getLabel())
	div_main:node(div_title)
	
	-- imådje
	local img = entity:getClaims('P18')
	local imgname = nil
	local imgdes = nil
	if frame.args.imadje ~= nil and frame.args.imadje ~= "" then
		imgname = frame.args.imadje
	elseif img[1] ~= nil and img[1].mainsnak.datavalue ~= nil then
		imgname = img[1].mainsnak.datavalue.value
		if img[1].qualifiers ~=nil and 
		   img[1].qualifiers["P2096"] ~= nil then
			for i, imgtxt in ipairs( img[1].qualifiers["P2096"] ) do
		    	if imgtxt.datavalue.value.language ~= nil and 
		    	   imgtxt.datavalue.value.language == "wa" then
		    		imgdes = imgtxt.datavalue.value.text
		    	end
			end
		end
	end
	if imgname ~= nil then
		div_main:wikitext( '[[File:'..imgname..'|center|200px]]' )
		if imgdes ~= nil then
			local div_imgdes = mw.html.create( 'div' )
		    		         :addClass("infoboesse-imadje-discrijhaedje")
		    		         :wikitext(imgdes)
		    div_main:node(div_imgdes)
		end
	else
		div_im = mw.html.create( 'div' )
		div_im:addClass("infoboesse-pontdimadje")
		div_im:wikitext("I gn a co pont d' imådje dizo licince libe so les [[:c:|Cmons]]. Si vos nd avoz ene po nozôtes, [[:c:Special:UploadWizard|eberwetez-l' vaici]], et merci co traze côps.")
		div_main:node(div_im)
	end
	
	-- prinde on dzo-module sorlon l' nateure di l' elemint
	local nat = entity:getClaims('P31')
	local nat_data = nil
	if nat:hasValue("Q5") then
		nat_data = "biyografeye"
	elseif nat:hasValue("Q11032") or
		   nat:hasValue("Q41298") then
		nat_data = "gazete"
	end
	
	if nat_data then
		local nat_data = require('Module:Infoboesse/'..nat_data)
		nat_data = nat_data.get_infos(entity)
		div_main:node(nat_data)
	end
	
	-- wikidata loyén
	div_wd = mw.html.create( 'div' )
	div_wd:addClass("infoboesse-wikidata")
	div_wd:wikitext("[[:d:"..articleId.."|WIKIDATA]]")
	div_main:node(div_wd)
	
	html:node(div_main)
	return  html
end

function p.get_simple_html_table(data)
	local html = mw.html.create()
	local tb = mw.html.create( 'table' )
	for i, v in ipairs( data ) do
	    if v[1] and v[2] and 
	       v[1] ~="" and v[2] ~= "" then
		    local tr = mw.html.create( 'tr' )
		    local th = mw.html.create( 'th' )
		    local td = mw.html.create( 'td' )
		    th:wikitext(v[1])
		    td:wikitext(v[2])
		    tr:node(th)
		    tr:node(td)
		    tb:node(tr)
		end
	end
	html:node(tb)
	return html
end

return p