Module:Infobox auteur
Uiterlijk
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
end
--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 "[["..page.."|"..mw.text.split(page, " %(")[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:"..page.."|"..mw.text.split(page, " %(")[1].."]]";
elseif(tf_item.labels.nl) then return tf_item.labels.nl.value; --there is a label in dutch
else return ""; end --if none of above, return empty string
end
--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 tonumber(ttt_res[3]).." "..months[tonumber(ttt_res[2])].." "..ttt_res[1]; end
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
--Name
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" | '
.."<big>'''"..args["naam"].."'''</big>");
--Portret
if(is_empty(args["portret"]) and item and item.claims["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";
end
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:'..
args["portret"].."|"..args["portretbreedte"].."|center|"..args["naam"].."]]");
--Place and time of birth
if(is_empty(args["gebplaats"]) and item and item.claims["P19"]) then
args["gebplaats"] = title_for(item:getBestStatements('P19')[1].mainsnak.datavalue.value.id); end
if(is_empty(args["gebdatum"]) and item and item.claims["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 item.claims["P20"]) then
args["overlplaats"] = title_for(item:getBestStatements('P20')[1].mainsnak.datavalue.value.id); end
if(is_empty(args["overldatum"]) and item and item.claims["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
--Pseudonim
if(is_empty(args["pseudoniem"]) and item and item.claims["P742"]) then
pseudo_list = {};
--there can be multiple values of P742, adding each of them to the table
for i = 1,#item.claims["P742"],1 do
table.insert(pseudo_list, item.claims["P742"][i].mainsnak.datavalue.value); end
args["pseudoniem"] = table.concat(pseudo_list, ", <br/>");
end
if(not is_empty(args["pseudoniem"])) then
table.insert(res, "\n|-\n| [[w:Pseudoniem|Pseudoniem(en)]] || "..args["pseudoniem"]); end
--Nationality
if(is_empty(args["nationaliteit"])) then args["nationaliteit"] = "Nederlands"; end --Dutch by default
table.insert(res, "\n|-\n| Nationaliteit || "..args["nationaliteit"]);
--Genres
if(is_empty(args["genre"]) and item and item.claims["P136"]) then
genre_list = {};
--there can be multiple values of P136, adding each of them to the table
for i = 1,#item.claims["P136"],1 do
table.insert(genre_list, title_for(item.claims["P136"][i].mainsnak.datavalue.value.id)); end
args["genre"] = table.concat(genre_list, ", <br/>"); --result is a table concatenated with separator being a comma and newline
end
if(not is_empty(args["genre"])) then
table.insert(res, "\n|-\n| Genre(s) || "..args["genre"]); end
--Language
if(is_empty(args["taal"])) then args["taal"] = "Nederlands"; end --Dutch by default
table.insert(res, "\n|-\n| Taal of talen || "..args["taal"]);
--Works
if(is_empty(args["werken"]) and item and item.claims["P800"]) then
werken_list = {};
--there can be multiple values of P800, adding each of them to the table
for i = 1,#item.claims["P800"],1 do
table.insert(werken_list, title_for(item.claims["P800"][i].mainsnak.datavalue.value.id)); end
args["werken"] = table.concat(werken_list, ", <br/>");
end
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.svg|40px|left|class=noviewer|Logo Wikipedia]]'..
" '''[[:w:"..item.sitelinks.nlwiki.title.."|Meer over "..
args["naam"].."]] op [[w:Hoofdpagina|Wikipedia]]'''");
end
return frame:preprocess(table.concat(res)..'\n|}'); --the final result is the concatenated result table
end
return p;