Module:Infobox auteur

Uit Wikisource
Naar navigatie springen Naar zoeken springen

Documentatie voor deze module kan aangemaakt worden op de volgende pagina: Module:Infobox auteur/doc

local p = {}

--Function checking if a value id empty (nil or empty string)
function is_empty(ie_val)
	if(ie_val) then --if not nul, check for empty string
		if(string.len(ie_val)>0 and ie_val~="-") then return false; --length of value not zero and value not a dash, means not empty
		elseif(ie_val=="-") then return true; --dash, means empty
		else return true; end --empty string, means empty
	else return true; end --if nil, then value is empty

--Function gets a Wikidata item id and returns link to a corresponding Wikisource or Wikipedia page, or if absent, just text label
function title_for(item_id)
	tf_item = mw.wikibase.getEntity(item_id);
	if(tf_item.sitelinks and tf_item.sitelinks.nlwikisource) then --there is a sitelink to nlwikisource
		page = tf_item.sitelinks.nlwikisource.title;
		return "[[""|", " %(")[1].."]]";
	elseif(tf_item.sitelinks and tf_item.sitelinks.nlwiki) then --there is a sitelink to nlwiki
		page = tf_item.sitelinks.nlwiki.title;
		return "[[:w:""|", " %(")[1].."]]";
	elseif( then return; --there is a label in dutch
	else return ""; end --if none of above, return empty string

--Function transforms Wikidata timestamp in format +yyyy-mm-ddThh:mm:ss/pp into human readable date
function timestamp_to_text(timestamp)
	months = {"januari", "februari", "maart", "april", "mei", "juni", 
	  "juli", "augustus", "september", "oktober", "november", "december"};
	ttt_res = mw.text.split(timestamp, "+")[2]; --remove leading "+"
	ttt_res = mw.text.split(ttt_res, "T")[1]; --remove part after "T" (time of day)
	ttt_res = mw.text.split(ttt_res, "-"); --splitting what left into year, month and day
	if(tonumber(ttt_res[2])==0) then return ttt_res[1];
	else return ttt_res[3].." "..months[tonumber(ttt_res[2])].." "..ttt_res[1]; end

--Main function
function p.main(frame)
	parent = frame:getParent();
	args = parent.args;

	item = mw.wikibase.getEntity(mw.wikibase.getEntityIdForCurrentPage()); --getting wikidata item
	res = {'{| class="taxobox bordered"'}; --table for result

	if(is_empty(args["naam"])) then args["naam"] = "{{PAGENAME}}"; end --if argument "naam" not set, use page name
	table.insert(res, '\n|-\n| align="center" colspan="2"  bgcolor="#00aaFF" | '
	if(is_empty(args["portret"]) and item and["P18"]) then --if argument "portret" not set, get value from Wikidata
		args["portret"] = item:getBestStatements('P18')[1].mainsnak.datavalue.value;
	elseif(is_empty(args["portret"])) then --if there is none, take placeholder image
		args["portret"] = "Geenafbeeldingbeschikbaar.png";
	if(is_empty(args["portretbreedte"])) then args["portretbreedte"] = "242px"; end --if portret width not set, take the default
	table.insert(res, '\n|-\n| align="center" colspan="2" | [[Bestand:'..

	--Place and time of birth
	if(is_empty(args["gebplaats"]) and item and["P19"]) then 
		args["gebplaats"] = title_for(item:getBestStatements('P19')[1]; end
	if(is_empty(args["gebdatum"]) and item and["P569"]) then 
		args["gebdatum"] = timestamp_to_text(item:getBestStatements('P569')[1].mainsnak.datavalue.value.time); end
	if(args["gebplaats"] or args["gebdatum"]) then table.insert(res, "\n|-\n| Geboren || "); end
	if(args["gebplaats"]) then table.insert(res, args["gebplaats"]); end
	if(args["gebplaats"] and args["gebdatum"]) then table.insert(res, ", <br/>"); end
	if(args["gebdatum"]) then table.insert(res, args["gebdatum"]); end
	--Place and time of death
	if(is_empty(args["overlplaats"]) and item and["P20"]) then 
		args["overlplaats"] = title_for(item:getBestStatements('P20')[1]; end
	if(is_empty(args["overldatum"]) and item and["P570"]) then 
		args["overldatum"] = timestamp_to_text(item:getBestStatements('P570')[1].mainsnak.datavalue.value.time); end
	if(args["overlplaats"] or args["overldatum"]) then table.insert(res, "\n|-\n| Overleden || "); end
	if(args["overlplaats"]) then table.insert(res, args["overlplaats"]); end
	if(args["overlplaats"] and args["overldatum"]) then table.insert(res, ",<br/>"); end
	if(args["overldatum"]) then table.insert(res, args["overldatum"]); end
	if(is_empty(args["pseudoniem"]) and item and["P742"]) then 
		pseudo_list = {};
		--there can be multiple values of P742, adding each of them to the table
		for i = 1,["P742"],1 do 
			table.insert(pseudo_list,["P742"][i].mainsnak.datavalue.value); end
		args["pseudoniem"] = table.concat(pseudo_list, ", <br/>");
	if(not is_empty(args["pseudoniem"])) then 
		table.insert(res, "\n|-\n| [[w:Pseudoniem|Pseudoniem(en)]] || "..args["pseudoniem"]); end
	if(is_empty(args["nationaliteit"])) then args["nationaliteit"] = "Nederlands"; end --Dutch by default
	table.insert(res, "\n|-\n| Nationaliteit || "..args["nationaliteit"]);
	if(is_empty(args["genre"]) and item and["P136"]) then 
		genre_list = {};
		--there can be multiple values of P136, adding each of them to the table
		for i = 1,["P136"],1 do 
			table.insert(genre_list, title_for(["P136"][i]; end
		args["genre"] = table.concat(genre_list, ", <br/>"); --result is a table concatenated with separator being a comma and newline
	if(not is_empty(args["genre"])) then 
		table.insert(res, "\n|-\n| Genre(s) || "..args["genre"]); end
	if(is_empty(args["taal"])) then args["taal"] = "Nederlands"; end --Dutch by default
	table.insert(res, "\n|-\n| Taal of talen || "..args["taal"]);
	if(is_empty(args["werken"]) and item and["P800"]) then 
		werken_list = {};
		--there can be multiple values of P800, adding each of them to the table
		for i = 1,["P800"],1 do 
			table.insert(werken_list, title_for(["P800"][i]; end
		args["werken"] = table.concat(werken_list, ", <br/>");
	if(not is_empty(args["werken"])) then 
		table.insert(res, "\n|-\n| Belangrijkste werk(en) || "..args["werken"]); end
	--Link to Wikipedia page
	if(item and item.sitelinks.nlwiki) then
		table.insert(res, '\n|-\n| colspan="2" | [[Bestand:Wikipedia-logo.png|40px|left]]'..
			" '''[[:w:"..item.sitelinks.nlwiki.title.."|Meer over "..
			args["naam"].."]] op [[w:Hoofdpagina|Wikipedia]]'''");

	return frame:preprocess(table.concat(res)..'\n|}'); --the final result is the concatenated result table

return p;