Module:Auteur koptekst

Uit Wikisource
Naar navigatie springen Naar zoeken springen

Documentatie voor deze module kan aangemaakt worden op de volgende pagina: Module:Auteur koptekst/doc

local p = {}

--Function retrieves year from a Wikidata timestamp in format +YYYY-MM-DD...
function year(timestamp)
	return mw.text.split(mw.text.split(timestamp, "+")[2], "-")[1];

--Main function
function p.main(frame)
	parent = frame:getParent();
	item_number = mw.wikibase.getEntityIdForCurrentPage();
	if(not item_number) then return ""; end --if there is no Wikidata item, return empty string
	item = mw.wikibase.getEntity(item_number);

	--First letter of authors surname is needed for a link to authors directory
	name_first_letter = "";
	if(parent.args["letter"]) then --value of this letter may be set in argument "letter"
		name_first_letter = parent.args["letter"];
	else --otherwise take the first letter of the last word of the page title
		name_first_letter = mw.text.split(item.sitelinks.nlwikisource.title, ":")[2]; --remove "Auteur:"
		name_first_letter = mw.text.split(item.sitelinks.nlwikisource.title, " "); --split strings into words 
		name_first_letter = name_first_letter[#name_first_letter]; --take the last word
		name_first_letter = mw.text.truncate( name_first_letter, 1,"" ); --take first letter of last word
	--Link to authors directory
	directory = "[[Hoofdportaal:Lijst van auteurs#"..name_first_letter..
			"|← Lijst van auteurs: ''"..name_first_letter.."'']]";
	--Authors name
	title = "";
	if( then title =; --title get a value of Wikidata label
	else title = mw.text.split(mw.title.getCurrentTitle().text, " %(")[1]; end --otherwise page name with text in brackets removed
	--Years of life of an author
	life = "";
	if(["P569"] and["P570"]) then --if there is a date of death, show years of life
		life = "<center>("..year(["P569"][1].mainsnak.datavalue.value.time)..
	elseif(["P569"]) then --if only date of birth, author is alive, show only his year of birth
		life = "<center>(geboren "..year(["P569"][1].mainsnak.datavalue.value.time)..")</center>";
	--Nationality of an author
	nationality = "";
	if(["P27"]) then 
		--Getting flag of authors country
		country_id = item:getBestStatements('P27')[1];
		country_item = mw.wikibase.getEntity(country_id); --Getting item about country of an author
		if(["P41"]) then
			nationality = "<center>[[File:"["P41"][1].mainsnak.datavalue.value..'|50x25px]]</center>';
		--Getting demonym, for this get P1549 from an item about country
		nationality_text = ""; nl_index = -1;
		if(["P1549"]) then
			--iterate over P1549 values, untill there is one in dutch
			for i=1,["P1549"],1 do
				if(["P1549"][i].mainsnak.datavalue.value.language=="nl") then
				  nl_index = i; break; end
		if(["P1549"] and nl_index~=-1) then --if demonym found among P1549 values, add it
			nationality_text = "<center>"["P1549"][nl_index].mainsnak.datavalue.value.text.."</center>";
		elseif( then --otherwise, just a name of a country
			nationality_text = "<center>""</center>";
		nationality = nationality..nationality_text;
	--Getting together the header
	header = '{| style="width:100%;background:#fb6"\n|-\n'..
		'| width="25%" | ''\n'..
		'| width="50%" | '.."<center><big>'''"..title.."'''</big></center>"'\n'..
		'| width="25%" | '..nationality..'\n'..'|}';
	op = {};
	if(item.sitelinks.nlwiki) then --adding link to Wikipedia article, if present
		table.insert(op, '[[:w:nl:'..item.sitelinks.nlwiki.title..'|Wikipedia artikel]]'); end
	if(item.sitelinks.nlwikiquote) then --adding link to Wikiquote article, if present
		table.insert(op, '[[:wikiquote:nl:'..item.sitelinks.nlwikiquote.title..'|Wikiquote]]'); end
	if(item.sitelinks.commonswiki and (not string.match(item.sitelinks.commonswiki.title, "Category:")) ) then --adding link to Commons category, if present
		table.insert(op, '[[:commons:'..item.sitelinks.commonswiki.title..'|Commons gallery]]'); end
	if(["P935"]) then --adding link to Commons page, if present
		table.insert(op, '[[:commons:Category:'["P935"][1].mainsnak.datavalue.value..'|Commons category]]'); end
	table.insert(op, '[[:wikidata:'..item_number..'|Wikidata item]]'); --adding link to Wikidata item
	op_list = table.concat(op, ", "); --concatenate all the links
	if(op_list~="") then op_list = '\n{| class="wikitable"\n|-\n| '.."'''Zusterprojecten:''' "..op_list..'\n|}'; end --getting together the linkbox

	return frame:preprocess(header..op_list); --final result

return p;