this module (still under testing) contains the code for Template:Scriptor.

Retrieves the Wikidata item for the author (providing the page *is* connected to Wikidata), and from its values adds the image, links to other projects, occupation(s) and years of birth/death.

It has the following subpages:


p = {}
function p.scriptor(frame)
    pframe = frame:getParent()
    config = frame.args
    args = pframe.args
   
--template parameters
	nomentmp = config["Nomen"]
	indicisnomentmp = config["IndicisNomen"]
	aliastmp = config["Alias"] 
	natiotmp = config["Natio"] 
	muneratmp = config["Munera"] 
	postnationemtmp = config["PostNationem"]
	imagotmp = config["NomenImago"] 

	--Retieves Wikidata item
	item = mw.wikibase.getEntity()	
	id = mw.wikibase.getEntityIdForCurrentPage()

--NOMEN: name of the autor (from template)
	if nomentmp ~= "0" then
		nomen =  nomentmp
	else
		nomen =  mw.title.getCurrentTitle().rootText
	end
	if indicisnomentmp ~= "0" then
		indicisnomen = indicisnomentmp
	else
		indicisnomen = nomen
	end
	categoriaomnia = "[[Categoria:Scriptores|".. indicisnomen.. "]]"
	indicislittera = mw.ustring.sub(tostring(indicisnomen), 1, 1)
	categorialitterae = "[[Categoria:Scriptor-".. indicislittera.. "|".. indicisnomen.. "]]"

--if the page is NOT connected to Wikidata, the template stops here, and returns only the name, occupation and generic categories (+ a warning)
	if id == nil then 
		alert= "QUAESO NEXUM WIKIDATA ADDE! - PLEASE CONNECT THIS PAGE WITH WIKIDATA [[Categoria:Scriptores sine re wikidata|".. indicisnomen.. "]]"
		if muneratmp ~= "0" then
			munera = muneratmp
		else
			munera = ""
		end
	return "'''".. nomen.."''' ".. munera.. categoriaomnia.. categorialitterae.. "<div align=center>".. alert.. "</div>"
	end
	
--DATES of birth and death (from wikidata)
	local saeculumquaero = require "Module:Scriptor/SaeculumQuaero"
	
	nativitaswd= item:formatPropertyValues( 'P569' ).value
	nativitas = string.gsub(nativitaswd, "BCE", "a.Ch.n.") --translates "BCE" in latin
	nativitas = string.gsub(nativitas, "unknown value", "?") --translates "unknown value" 
	nativitas = string.gsub(nativitas, "no value", "?") --translates "no value" 
	if nativitas < "0" then nativitas = "?" end
	if string.find(nativitaswd, "century") or string.find(nativitaswd, "saeculum") then
		nativitas = saeculumquaero.saeculum(nativitas) --fixes "century" in "Saeculo" and numbers in Roman numerals
	end
	nativitas = string.gsub(nativitas, ", ", " ''aut'' ")
	nativitas_cat = saeculumquaero.scriptor(nativitaswd, indicisnomen) --adds the "Saeculi" category ([[Categoria:Saeculi x scriptores]])
	if string.find(nativitaswd, "millennium") then --if the year is expressed as "millennium", it is returned as unknown
		nativitas = "?" 
		nativitas_cat = "[[Categoria:Saeculi incogniti scriptores]]"
	end
	
	morswd = item:formatPropertyValues( 'P570' ).value
	mors = string.gsub(morswd, "BCE", "a.Ch.n.")
	mors = string.gsub(mors, "unknown value", "?") --translates "unknown value" 
	mors = string.gsub(mors, "no value", "?") --translates "no value" 
	if mors < "0" then mors = "?" end
	if string.find(morswd, "century") or string.find(morswd, "saeculum") then
		mors= saeculumquaero.saeculum(mors) --fixes "century" in "Saeculo" and numbers in Roman numerals
	end
	mors = string.gsub(mors, ", ", " ''aut'' ") 
	mors_cat = saeculumquaero.scriptor(morswd, indicisnomen) --adds the "Saeculi" category ([[Categoria:Saeculi x scriptores]])
	if string.find(morswd, "millennium") then --if the year is expressed as "millennium", it is returned as unknown
		mors = "?" 
		mors_cat = "[[Categoria:Saeculi incogniti scriptores|".. indicisnomen.. "]]"
	end
	nativitas_cat = string.gsub(nativitas_cat, "Saeculi incogniti ante Christum scriptores", "Saeculi incogniti scriptores") --avoids the creation of "Saeculi incogniti ante Christum scriptores", which of course makes no sense
	if string.find(nativitas_cat, "Saeculi incogniti scriptores") then --removes the "incogniti" category, if at lest the century of death is known
		if string.find(mors_cat, "Saeculi incogniti scriptores") then
			nativitas_cat = "[[Categoria:Saeculi incogniti scriptores|".. indicisnomen.. "]]"
		else
			nativitas_cat = ""
		end
	end
	mors_cat = string.gsub(mors_cat, "Saeculi incogniti ante Christum scriptores", "Saeculi incogniti scriptores") --avoids the creation of "Saeculi incogniti ante Christum scriptores", which of course makes no sense
	if string.find(mors_cat, "Saeculi incogniti scriptores") then --removes the "incogniti" category, if at lest the century of birth is known
		if string.find(nativitas_cat, "Saeculi incogniti scriptores") then
			mors_cat = "[[Categoria:Saeculi incogniti scriptores|".. indicisnomen.. "]]"
		else
			mors_cat = ""
		end
	end
	
	if item:formatPropertyValues( 'P1317' ).value > "0" then --IF is specified a "floruit" period
		floruitwd = item:formatPropertyValues( 'P1317' ).value
		if string.find(floruitwd, "century") or string.find(floruitwd, "saeculum") then
			floruit= saeculumquaero.saeculum(floruitwd) --fixes "century" in "Saeculo" and numbers in Roman numerals
		else floruit= floruitwd
		end
		floruit = string.gsub(floruit, ", ", " ''aut'' ")
		floruit = ", ''floruit'' ".. floruit
		floruit_cat = saeculumquaero.scriptor(floruitwd, indicisnomen) --adds the "Saeculi" category ([[Categoria:Saeculi x scriptores]])
		if floruitwd ~= "unknown value" then
			nativitas_cat = ""; mors_cat = ""
		else
			floruit = ""; floruit_cat = ""
		end
	else
		floruit = ""; floruit_cat = ""
	end
	
		anni = nativitas.. " - ".. mors.. nativitas_cat.. mors_cat.. floruit.. floruit_cat --Puts together the years of birth and death in a single string

	
--ALIAS: to add alternative name(s) or pseudonym(s); they will be inserted before the dates of birth/death (template)
	if aliastmp ~= "0" then
		alias = aliastmp.. "; "
	else
		alias = ""
	end

--NATIO: country of cityzenship (Wikidata)
	natiowd = item:formatPropertyValues( 'P27' ).value
	genuswd = item:formatPropertyValues( 'P21' ).value --sexual gender, for female authors' adjectives

	if natiotmp ~= "0" then
		natio = natiotmp
	else
		natio = natiowd
	end
	natio = string.lower(natio)
	local civitatemquaero = require "Module:Scriptor/CivitatemQuaero"
	natio_adj = civitatemquaero.civitas(natio, indicisnomen, "adj", genuswd)
	natio_cat = civitatemquaero.civitas(natio, indicisnomen, "cat", genuswd)
	
--MUNERA: occupations (from Wikidata)
	munerawd = item:formatPropertyValues( 'P106' ).value
	if muneratmp ~= "0" then
		munera = muneratmp
	else
		if
		string.find(munerawd, ",")
		then
			munera = string.lower(munerawd).. "que"
		else
			munera = string.lower(munerawd)
		end
	end
	
	--generates the munera (occupation) categories
	officiumwd = item:formatPropertyValues( 'P39' ).value --for king, emperors, popes...
	if officiumwd then officium = officiumwd else officium = "" end
		
	ordowd = item:formatPropertyValues( 'P611' ).value --for members of the clergy
	if ordowd then ordo = ordowd else ordo = "" end
		
	sanctitaswd = item:formatPropertyValues( 'P411' ).value --for christian saints
	if sanctitaswd then sanctitas = sanctitaswd else sanctitas = "" end
		
	nobilitaswd = item:formatPropertyValues( 'P511' ).value --for nobles, Doctors of the church etc.
	if nobilitaswd then nobilitas = nobilitaswd else nobilitas = "" end
		
	omniamunera = string.lower(muneratmp.. " ".. munerawd.. " ".. postnationemtmp .. " ".. officium.. " ".. ordo.. " ".. sanctitas.. " ".. nobilitas)
	local muneraquaero = require "Module:Scriptor/MuneraQuaero"
		munera_cat = muneraquaero.scriptor(omniamunera, indicisnomen)
		
	if postnationemtmp ~= "0" then
		postnationem = postnationemtmp
		if string.sub(postnationem, 1, 1) == "," or string.sub(postnationem, 1, 1) == ";" or string.sub(postnationem, 1, 1) == "." then
			postnationem = postnationem
		else
			postnationem = " ".. postnationem
		end
	else
		postnationem = ""
	end
	
--IMAGO: add the image (from Wikidata)
	imagowd= item:formatPropertyValues( 'P18' ).value
	if imagotmp ~= "0" then
		imago = "[[File:".. imagotmp .."|200px|right|".. nomen.. "]]" 
	else
		if imagowd < "0" then
			imago= ""
		else
			imago = "[[File:".. imagowd .."|200px|right|".. nomen.. "]]" 
		end
	end
	
--PUTS together all the above strings in the single string "Descriptio"
	descriptio = imago.. "'''".. nomen.. "''' ".. categoriaomnia.. categorialitterae.. " (".. alias.. anni.. ")".. natio_cat.. " ".. munera.. munera_cat.. " ".. natio_adj.. postnationem.. "."
	
	
--CATEGORIAOPERUM: creates a link to Category:Opera quae "X" scripsit
	categoriaoperum= "<div style='margin:5px;'> <div style='display: table-cell; vertical-align: middle;'>[[File:Wikisource-logo.svg|20px]] '''''[[:Categoria:Opera quae ".. mw.title.getCurrentTitle().rootText.. " scripsit|Categoria operum]]'''''</div></div>"
	categoriaoperumnexus = "Categoria:Opera quae ".. mw.title.getCurrentTitle().rootText.. " scripsit"
	if mw.title.new(categoriaoperumnexus).exists == false then
		sineopera_cat = "[[Categoria:Scriptores sine categoria operum|"..indicisnomen.. "]]"
	else
		sineopera_cat = ""
	end
--INTERPRETATIONES: creates a link to Category:Opera quae "X" latine vertit
	interpretationumnexus = "Categoria:Opera quae ".. mw.title.getCurrentTitle().rootText.. " latine vertit"
	if mw.title.new(interpretationumnexus).exists == true then
		interpretationes= "<div style='margin:5px;'> <div style='display: table-cell; vertical-align: middle;'>[[File:Wikisource-logo.svg|20px]] '''''[[:Categoria:Opera quae ".. mw.title.getCurrentTitle().rootText.. " latine vertit|Interpretationes]]'''''</div></div>"
	else
		interpretationes = ""
	end
--OPERARECENSA: creates a link to Category:Opera quae "X" latine vertit
	recensanexus = "Categoria:Opera quae ".. mw.title.getCurrentTitle().rootText.. " recensuit"
	if mw.title.new(recensanexus).exists == true then
		recensa= "<div style='margin:5px;'> <div style='display: table-cell; vertical-align: middle;'>[[File:Wikisource-logo.svg|20px]] '''''[[:Categoria:Opera quae ".. mw.title.getCurrentTitle().rootText.. " recensuit|Opera recensa]]'''''</div></div>"
	else
		recensa = ""
	end
--VICIPAEDIA: creates a link to Wikipedia
	if item:getSitelink("lawiki") then
		vicipaedia = "<div style='margin:5px;'> <div style='display: table-cell; vertical-align: middle;'>[[File:Wikipedia-logo.svg|20px]] '''''[[:w:".. item:getSitelink("lawiki").. "|Vita]]'''''</div></div>"
	else
		vicipaedia = ""
	end

--VICICITATIONES: creates a link to Wikiquote
	if item:getSitelink("lawikiquote") then
		vicicitationes = "<div style='margin:5px;'> <div style='display: table-cell; vertical-align: middle;'>[[File:Wikiquote-logo.svg|20px]] '''''[[:w:".. item:getSitelink("lawikiquote").. "|Citationes]]'''''</div></div>"
	else
		vicicitationes = ""
	end
	
--COMMUNIA: creates a link to Commons
	if item:formatPropertyValues( 'P373' ).value > "0" then
		communia = "<div style='margin:5px;'> <div style='display: table-cell; vertical-align: middle;'>[[File:Commons-logo.svg|20px]] '''''[[:commons:Category:".. item:formatPropertyValues( 'P373' ).value.. "|Fascicula]]'''''</div></div>"
	else
		if item:getSitelink("commonswiki") then
			communia = "<div style='margin:5px;'> <div style='display: table-cell; vertical-align: middle;'>[[File:Commons-logo.svg|20px]] '''''[[:commons:".. item:getSitelink("commonswiki").. "|Fascicula]]'''''</div></div>"
		else
			communia = ""
		end
	end
	
--WIKIDATA: creates a link to wikidata
	wikidata= "<div style='margin:5px;'> <div style='display: table-cell; vertical-align: middle;'>[[File:Wikidata-logo.svg|20px]] '''''[[:d:".. id.. "|Data]]'''''</div></div>"

--PUTS together the "other prjects" string in the single string "inceptis"

	inceptis = categoriaoperum.. sineopera_cat.. interpretationes.. recensa.. vicipaedia.. vicicitationes.. communia.. wikidata
	
	
	--AUCTORITAS: imports Authority control values
	
	local auctoritatemQuaero = require "Module:Scriptor/Auctoritas"

	auctoritas = auctoritatemQuaero.box(item)
	auctoritas = "<div style='clear:both;' align='center'>".. auctoritas.. "</div>"
	

	return descriptio.. inceptis.. auctoritas
	
    end
return p