Jump to content

Modulus:Titulus

E Vicilibris


This module provides easy processing of arguments passed from #invoke. It is a meta-module, meant for use by other modules, and should not be called from #invoke directly. Its features include:

  • Easy trimming of arguments and removal of blank arguments.
  • Arguments can be passed by both the current frame and by the parent frame at the same time. (More details below.)
  • Arguments can be passed in directly from another Lua module or from the debug console.
  • Arguments are fetched as needed, which can help avoid (some) problems with ref tags.
  • Most features can be customized.

Basic use

[recensere]

First, you need to load the module. It contains one function, named getArgs.

local getArgs = require('Module:Arguments').getArgs

In the most basic scenario, you can use getArgs inside your main function. The variable args is a table containing the arguments from #invoke. (See below for details.)

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	-- Main module code goes here.
end

return p

However, the recommended practice is to use a function just for processing arguments from #invoke. This means that if someone calls your module from another Lua module you don't have to have a frame object available, which improves performance.

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	-- Main module code goes here.
end

return p

If you want multiple functions to use the arguments, and you also want them to be accessible from #invoke, you can use a wrapper function.

local getArgs = require('Module:Arguments').getArgs

local function makeInvokeFunc(funcName)
	return function (frame)
		local args = getArgs(frame)
		return p[funcName](args)
	end
end

local p = {}

p.func1 = makeInvokeFunc('_func1')

function p._func1(args)
	-- Code for the first function goes here.
end

p.func2 = makeInvokeFunc('_func2')

function p._func2(args)
	-- Code for the second function goes here.
end

return p

Options

[recensere]

The following options are available. They are explained in the sections below.

local args = getArgs(frame, {
	trim = false,
	removeBlanks = false,
	valueFunc = function (key, value)
		-- Code for processing one argument
	end,
	frameOnly = true,
	parentOnly = true,
	parentFirst = true,
	wrappers = {
		'Template:A wrapper template',
		'Template:Another wrapper template'
	},
	readOnly = true,
	noOverwrite = true
})

Trimming and removing blanks

[recensere]

Blank arguments often trip up coders new to converting MediaWiki templates to Lua. In template syntax, blank strings and strings consisting only of whitespace are considered false. However, in Lua, blank strings and strings consisting of whitespace are considered true. This means that if you don't pay attention to such arguments when you write your Lua modules, you might treat something as true that should actually be treated as false. To avoid this, by default this module removes all blank arguments.

Similarly, whitespace can cause problems when dealing with positional arguments. Although whitespace is trimmed for named arguments coming from #invoke, it is preserved for positional arguments. Most of the time this additional whitespace is not desired, so this module trims it off by default.

However, sometimes you want to use blank arguments as input, and sometimes you want to keep additional whitespace. This can be necessary to convert some templates exactly as they were written. If you want to do this, you can set the trim and removeBlanks arguments to false.

local args = getArgs(frame, {
	trim = false,
	removeBlanks = false
})

Custom formatting of arguments

[recensere]

Sometimes you want to remove some blank arguments but not others, or perhaps you might want to put all of the positional arguments in lower case. To do things like this you can use the valueFunc option. The input to this option must be a function that takes two parameters, key and value, and returns a single value. This value is what you will get when you access the field key in the args table.

Example 1: this function preserves whitespace for the first positional argument, but trims all other arguments and removes all other blank arguments.

local args = getArgs(frame, {
	valueFunc = function (key, value)
		if key == 1 then
			return value
		elseif value then
			value = mw.text.trim(value)
			if value ~= '' then
				return value
			end
		end
		return nil
	end
})

Example 2: this function removes blank arguments and converts all arguments to lower case, but doesn't trim whitespace from positional parameters.

local args = getArgs(frame, {
	valueFunc = function (key, value)
		if not value then
			return nil
		end
		value = mw.ustring.lower(value)
		if mw.ustring.find(value, '%S') then
			return value
		end
		return nil
	end
})

Note: the above functions will fail if passed input that is not of type string or nil. This might be the case if you use the getArgs function in the main function of your module, and that function is called by another Lua module. In this case, you will need to check the type of your input. This is not a problem if you are using a function specially for arguments from #invoke (i.e. you have p.main and p._main functions, or something similar).

Formula:Cot Example 1:

local args = getArgs(frame, {
	valueFunc = function (key, value)
		if key == 1 then
			return value
		elseif type(value) == 'string' then
			value = mw.text.trim(value)
			if value ~= '' then
				return value
			else
				return nil
			end
		else
			return value
		end
	end
})

Example 2:

local args = getArgs(frame, {
	valueFunc = function (key, value)
		if type(value) == 'string' then
			value = mw.ustring.lower(value)
			if mw.ustring.find(value, '%S') then
				return value
			else
				return nil
			end
		else
			return value
		end
	end
})

Formula:Cob

Also, please note that the valueFunc function is called more or less every time an argument is requested from the args table, so if you care about performance you should make sure you aren't doing anything inefficient with your code.

Frames and parent frames

[recensere]

Arguments in the args table can be passed from the current frame or from its parent frame at the same time. To understand what this means, it is easiest to give an example. Let's say that we have a module called Module:ExampleArgs. This module prints the first two positional arguments that it is passed.

Formula:Cot

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local first = args[1] or ''
	local second = args[2] or ''
	return first .. ' ' .. second
end

return p

Formula:Cob

Module:ExampleArgs is then called by Template:ExampleArgs, which contains the code {{#invoke:ExampleArgs|main|firstInvokeArg}}. This produces the result "firstInvokeArg".

Now if we were to call Template:ExampleArgs, the following would happen:

Code Result
{{ExampleArgs}} firstInvokeArg
{{ExampleArgs|firstTemplateArg}} firstInvokeArg
{{ExampleArgs|firstTemplateArg|secondTemplateArg}} firstInvokeArg secondTemplateArg

There are three options you can set to change this behaviour: frameOnly, parentOnly and parentFirst. If you set frameOnly then only arguments passed from the current frame will be accepted; if you set parentOnly then only arguments passed from the parent frame will be accepted; and if you set parentFirst then arguments will be passed from both the current and parent frames, but the parent frame will have priority over the current frame. Here are the results in terms of Template:ExampleArgs:

frameOnly
Code Result
{{ExampleArgs}} firstInvokeArg
{{ExampleArgs|firstTemplateArg}} firstInvokeArg
{{ExampleArgs|firstTemplateArg|secondTemplateArg}} firstInvokeArg
parentOnly
Code Result
{{ExampleArgs}}
{{ExampleArgs|firstTemplateArg}} firstTemplateArg
{{ExampleArgs|firstTemplateArg|secondTemplateArg}} firstTemplateArg secondTemplateArg
parentFirst
Code Result
{{ExampleArgs}} firstInvokeArg
{{ExampleArgs|firstTemplateArg}} firstTemplateArg
{{ExampleArgs|firstTemplateArg|secondTemplateArg}} firstTemplateArg secondTemplateArg

Notes:

  1. If you set both the frameOnly and parentOnly options, the module won't fetch any arguments at all from #invoke. This is probably not what you want.
  2. In some situations a parent frame may not be available, e.g. if getArgs is passed the parent frame rather than the current frame. In this case, only the frame arguments will be used (unless parentOnly is set, in which case no arguments will be used) and the parentFirst and frameOnly options will have no effect.

Wrappers

[recensere]

The wrappers option is used to specify a limited number of templates as wrapper templates, that is, templates whose only purpose is to call a module. If the module detects that it is being called from a wrapper template, it will only check for arguments in the parent frame; otherwise it will only check for arguments in the frame passed to getArgs. This allows modules to be called by either #invoke or through a wrapper template without the loss of performance associated with having to check both the frame and the parent frame for each argument lookup.

For example, the only content of Template:Side box (excluding content in noinclude tags) is {{#invoke:Side box|main}}. There is no point in checking the arguments passed directly to the #invoke statement for this template, as no arguments will ever be specified there. We can avoid checking arguments passed to #invoke by using the parentOnly option, but if we do this then #invoke will not work from other pages either. If this were the case, the Formula:Para in the code {{#invoke:Side box|main|text=Some text}} would be ignored completely, no matter what page it was used from. By using the wrappers option to specify 'Template:Side box' as a wrapper, we can make {{#invoke:Side box|main|text=Some text}} work from most pages, while still not requiring that the module check for arguments on the Template:Side box page itself.

Wrappers can be specified either as a string, or as an array of strings.

local args = getArgs(frame, {
	wrappers = 'Template:Wrapper template'
})


local args = getArgs(frame, {
	wrappers = {
		'Template:Wrapper 1',
		'Template:Wrapper 2',
		-- Any number of wrapper templates can be added here.
	}
})

Notes:

  1. The module will automatically detect if it is being called from a wrapper template's /sandbox subpage, so there is no need to specify sandbox pages explicitly.
  2. The wrappers option effectively changes the default of the frameOnly and parentOnly options. If, for example, parentOnly were explicitly set to false with wrappers set, calls via wrapper templates would result in both frame and parent arguments being loaded, though calls not via wrapper templates would result in only frame arguments being loaded.
  3. If the wrappers option is set and no parent frame is available, the module will always get the arguments from the frame passed to getArgs.

Writing to the args table

[recensere]

Sometimes it can be useful to write new values to the args table. This is possible with the default settings of this module. (However, bear in mind that it is usually better coding style to create a new table with your new values and copy arguments from the args table as needed.)

args.foo = 'some value'

It is possible to alter this behaviour with the readOnly and noOverwrite options. If readOnly is set then it is not possible to write any values to the args table at all. If noOverwrite is set, then it is possible to add new values to the table, but it is not possible to add a value if it would overwrite any arguments that are passed from #invoke.

Ref tags

[recensere]

This module uses metatables to fetch arguments from #invoke. This allows access to both the frame arguments and the parent frame arguments without using the pairs() function. This can help if your module might be passed ref tags as input.

As soon as ref tags are accessed from Lua, they are processed by the MediaWiki software and the reference will appear in the reference list at the bottom of the article. If your module proceeds to omit the reference tag from the output, you will end up with a phantom reference - a reference that appears in the reference list, but no number that links to it. This has been a problem with modules that use pairs() to detect whether to use the arguments from the frame or the parent frame, as those modules automatically process every available argument.

This module solves this problem by allowing access to both frame and parent frame arguments, while still only fetching those arguments when it is necessary. The problem will still occur if you use pairs(args) elsewhere in your module, however.

Known limitations

[recensere]

The use of metatables also has its downsides. Most of the normal Lua table tools won't work properly on the args table, including the # operator, the next() function, and the functions in the table library. If using these is important for your module, you should use your own argument processing function instead of this module.


p = {}

function p.titulus(frame)
    pframe = frame:getParent()
    config = frame.args
    args = pframe.args
   
--template parameters
	operaetitulus = config["OperaeTitulus"]
	subtitulus = config["SubTitulus"] or ""
	scriptor = config["Scriptor"] or ""
	liber = config["Liber"] or ""
	annus = config["Annus"] or ""
	annusmonstratus = config["AnnusMonstratus"] or ""
	operaewikipagina = config["OperaeWikiPagina"] or ""
	fons = config["Fons"] or ""
	editio = config["Editio"] or ""
	recensor = config["Recensor"] or ""
	genera = config["Genera"] or ""
	frons = config["Frons"] or ""
	scriptor2 = config["Scriptor2"]
	scriptor3 = config["Scriptor3"]
	scriptor4 = config["Scriptor4"]
	scriptor5 = config["Scriptor5"]
	scriptor6 = config["Scriptor6"]
	
--initializes internal variables, for ease of concatenation
	categoriaomnia=""; categoriacapiti = ""; categoriascriptoris = ""; categorialibri = ""; anninumerus = ""; categoriaanni = ""; categoriagenerum = ""
	nexusscriptoris2 = ""; nexusscriptoris3 = ""; nexusscriptoris4 = ""; nexusscriptoris5 = ""; nexusscriptoris6 = ""
	categoriascriptoris2 = ""; categoriascriptoris3 = ""; categoriascriptoris4 = ""; categoriascriptoris5 = ""; categoriascriptoris6 = ""
--fetches the title of the page
	titulus = mw.title.getCurrentTitle().text
	
--checks if the page is a subpage, i.e. if it has slashes /
	if mw.ustring.find(titulus, "/") then
		subpagina = true
	else
		subpagina = false
	end
	
--Generating the strings that translate the templates' parameters

--SCRIPTOR (author of the work)
	if scriptor == "Anonimus" or scriptor == "0" then --for anonimous works
		nexusscriptoris= "Sine Nomine"; 
		categoriascriptoris = "[[Categoria:Opera sine nomine scripta|".. titulus.. "]]" --adds the work in the Categoria:Opera sine nomine scripta
			
	else --when the author is known
		nexusscriptoris = "[[Scriptor:".. scriptor.. "|".. scriptor.. "]]"; 
		if mw.title.new("Scriptor:"..scriptor).isRedirect then
			scriptor = tostring(mw.title.new("Scriptor:".. scriptor).redirectTarget) --fixes the scriptor's name, if redirect, to insert it in the category
			scriptor = string.gsub(scriptor, "Scriptor:", "")
		end
		categoriascriptoris = "[[Categoria:Opera quae ".. scriptor.. " scripsit|".. titulus.. "]]" --adds the work in the author's category
	end
	
--SCRIPTOR2, 3 etc., for works with more authors (up to 5)
	if scriptor2 ~= "0" then --2
		nexusscriptoris2 = ", [[Scriptor:".. scriptor2.. "|".. scriptor2.. "]]"; 
		if mw.title.new("Scriptor:"..scriptor2).isRedirect then
			scriptor2 = tostring(mw.title.new("Scriptor:".. scriptor2).redirectTarget) --fixes the scriptor's name, if redirect, to insert it in the category
			scriptor2 = string.gsub(scriptor2, "Scriptor:", "")
		end
		categoriascriptoris2 = "[[Categoria:Opera quae ".. scriptor2.. " scripsit|".. titulus.. "]]"
	end
	if scriptor3 ~= "0" then --3
		nexusscriptoris3 = ", [[Scriptor:".. scriptor3.. "|".. scriptor3.. "]]"; 
		if mw.title.new("Scriptor:"..scriptor3).isRedirect then
			scriptor3 = tostring(mw.title.new("Scriptor:".. scriptor3).redirectTarget) --fixes the scriptor's name, if redirect, to insert it in the category
			scriptor3 = string.gsub(scriptor3, "Scriptor:", "")
		end
		categoriascriptoris3 = "[[Categoria:Opera quae ".. scriptor3.. " scripsit|".. titulus.. "]]"
	end
	if scriptor4 ~= "0" then --4
		nexusscriptoris4 = ", [[Scriptor:".. scriptor4.. "|".. scriptor4.. "]]"; 
		if mw.title.new("Scriptor:"..scriptor4).isRedirect then
			scriptor4 = tostring(mw.title.new("Scriptor:".. scriptor4).redirectTarget) --fixes the scriptor's name, if redirect, to insert it in the category
			scriptor4 = string.gsub(scriptor4, "Scriptor:", "")
		end
		categoriascriptoris2 = "[[Categoria:Opera quae ".. scriptor4.. " scripsit|".. titulus.. "]]"
	end
	if scriptor5 ~= "0" then --5
		nexusscriptoris5 = ", [[Scriptor:".. scriptor5.. "|".. scriptor5.. "]]"; 
		if mw.title.new("Scriptor:"..scriptor5).isRedirect then
			scriptor5 = tostring(mw.title.new("Scriptor:".. scriptor5).redirectTarget) --fixes the scriptor's name, if redirect, to insert it in the category
			scriptor5 = string.gsub(scriptor5, "Scriptor:", "")
		end
		categoriascriptoris5 = "[[Categoria:Opera quae ".. scriptor5.. " scripsit|".. titulus.. "]]"
	end
	if scriptor6 ~= "0" then --6
		nexusscriptoris6 = ", [[Scriptor:".. scriptor6.. "|".. scriptor6.. "]]"; 
		if mw.title.new("Scriptor:"..scriptor6).isRedirect then
			scriptor6 = tostring(mw.title.new("Scriptor:".. scriptor6).redirectTarget) --fixes the scriptor's name, if redirect, to insert it in the category
			scriptor6 = string.gsub(scriptor6, "Scriptor:", "")
		end
		categoriascriptoris6 = "[[Categoria:Opera quae ".. scriptor6.. " scripsit|".. titulus.. "]]"
	end

--OPERAETITULUS (title oh the work)
	if operaetitulus == "0" then error('quaeso titulum operis in campo |OperaeTitulus= insere') end --if the title is not specified, calls for error

	if subpagina == false then --if the page is not a subpage
		nexusoperaetituli = operaetitulus --does not gerate a link
	elseif subpagina == true then --if the page is a subpage
		if operaewikipagina > "0" then 
			nexusoperaetituli = "[[".. operaewikipagina.. "|".. operaetitulus.. "]]"
		else
			nexusoperaetituli = "[[".. operaetitulus.. "]]"
		end
	end
	
--SUBTITULUS (subtitle of the work)
	if subtitulus ~= "0" then
		nexussubtituli = subtitulus
	else
		nexussubtituli = ""
	end
	
--ANNUS (publication year)
	if annus ~= "0" then --if the "annus" parameter is defined...
		if annusmonstratus > "0" then
			nexusanni = annusmonstratus --visualizes a different value from that used for categorizations, for cases like "inter 1650 et 1655" or similar
		else
			nexusanni = annus --the year will be visualized just as inserted in the template
		end
		if mw.ustring.find(annus, "aCn") or mw.ustring.find(annus, "a.C.n.") or mw.ustring.find(annus, "a C n") or mw.ustring.find(annus, "a. C. n.") or mw.ustring.find(annus, "a. Ch. n.") or mw.ustring.find(annus, "a.Ch.n.") or mw.ustring.find(annus, "a.Ch") or mw.ustring.find(annus, "aCh") then --looks for posssible permutations of "a.C.n."
			acn = " ante Christum"
		else 
			acn = ""
		end
		--looks for the century (which should be written in Roman numerals), and translates it into category description
		if mw.ustring.find(annus, "XXI") then
			saeculum = "primi vicesimi"
		elseif mw.ustring.find(annus, "XX") then
			saeculum = "vicesimi"
		elseif mw.ustring.find(annus, "XIX") then
			saeculum = "undevicesimi"
		elseif mw.ustring.find(annus, "XVIII") then
			saeculum = "duodevicesimi"
		elseif mw.ustring.find(annus, "XVII") then
			saeculum = "septimi decimi"
		elseif mw.ustring.find(annus, "XVI") then
			saeculum = "sexti decimi"
		elseif mw.ustring.find(annus, "XIV") then
			saeculum = "quarti decimi"
		elseif mw.ustring.find(annus, "XV") then
			saeculum = "quinti decimi"
		elseif mw.ustring.find(annus, "XIII") then
			saeculum = "tertii decimi"
		elseif mw.ustring.find(annus, "XII") then
			saeculum = "duodecimi"
		elseif mw.ustring.find(annus, "XI") then
			saeculum = "undecimi"
		elseif mw.ustring.find(annus, "IX") then
			saeculum = "noni"
		elseif mw.ustring.find(annus, "X") then
			saeculum = "decimi"
		elseif mw.ustring.find(annus, "VIII") then
			saeculum = "octavi"
		elseif mw.ustring.find(annus, "VII") then
			saeculum = "septimi"
		elseif mw.ustring.find(annus, "VI") then
			saeculum = "sexti"
		elseif mw.ustring.find(annus, "IV") then
			saeculum = "quarti"
		elseif mw.ustring.find(annus, "V") then
			saeculum = "quinti"
		elseif mw.ustring.find(annus, "III") then
			saeculum = "tertii"
		elseif mw.ustring.find(annus, "II") then
			saeculum = "secundi"
		elseif mw.ustring.find(annus, "II") then
			saeculum = "primi"
			
		else --if there is not a roman numeral, will look for year number
			anninumerus = tonumber(string.gsub(annus, "%D", ""), 10) --removes from "annus" anything that is not a digit; than translates the year into the corresponding century
			if anninumerus == nil then anninumerus = 0 end --avoids script error if the year is nonstandard (the page will go in Categoria:Saeculi incogniti opera)
			if anninumerus <= 99 then
				saeculum = "primi"
			elseif anninumerus <= 199 then
				saeculum = "secundi"	
			elseif anninumerus <= 299 then
				saeculum = "tertii"
			elseif anninumerus <= 399 then
				saeculum = "quarti"
			elseif anninumerus <= 499 then
				saeculum = "quinti"
			elseif anninumerus <= 599 then
				saeculum = "sexti"
			elseif anninumerus <= 699 then
				saeculum = "septimi"
			elseif anninumerus <= 799 then
				saeculum = "octavi"
			elseif anninumerus <= 899 then
				saeculum = "noni"
			elseif anninumerus <= 999 then
				saeculum = "decimi"
			elseif anninumerus <= 1099 then
				saeculum = "undecimi"
			elseif anninumerus <= 1199 then
				saeculum = "duodecimi"
			elseif anninumerus <= 1299 then
				saeculum = "tertii decimi"
			elseif anninumerus <= 1399 then
				saeculum = "quarti decimi"
			elseif anninumerus <= 1499 then
				saeculum = "quinti decimi"
			elseif anninumerus <= 1599 then
				saeculum = "sexti decimi"
			elseif anninumerus <= 1699 then
				saeculum = "septimi decimi"
			elseif anninumerus <= 1799 then
				saeculum = "duodevicesimi"
			elseif anninumerus <= 1899 then
				saeculum = "undevicesimi"
			elseif anninumerus <= 1999 then
				saeculum = "vicesimi"
			elseif anninumerus <= 2099 then
				saeculum = "primi vicesimi"
			elseif anninumerus <= 2199 then
				saeculum = "secundi vicesimi" --well, who knows...
			else --if cant' find the year, inserts the century as "incognitus"
				saeculum = "incogniti"
			end
		end
		categoriaanni = "[[Categoria:Saeculi ".. saeculum.. acn.. " opera|".. titulus.. "]]" --generates the category by putting together the "saeculum" and the eventuale "aCn"

	else --if the annus parameter is not compiled, the year is unknown and the corresponding category is added
	nexusanni = "anno incognito"
	categoriaanni = "[[Categoria:Saeculi incogniti opera|".. titulus.. "]]"
	end
	
--RECENSOR and EDITIO, for edition year and curator
	if recensor ~= "0" then
		editioest=true
		nexusrecensoris= "[[Scriptor:".. recensor.. "|".. recensor.. "]] recensuit"
	else
		nexusrecensoris = ""
	end
	if editio ~= "0" then
		if recensor > "0" then comma = "; " else comma = "" end
		nexuseditionis= "</br>editio: ".. editio.. comma
		categoriaeditionis = "[[Categoria:Opera cum editione|".. titulus.. "]]"
	else
		nexuseditionis = "editio: incognita"
		categoriaeditionis = "[[Categoria:Opera sine editione|".. titulus.. "]]"
	end
	
--FONS, generates a link to the source of the text
	if fons ~= "0" then
		nexusfontis = "fons: ".. fons
		categoriafontis = "[[Categoria:Opera cum fonte|".. titulus.. "]]"
	else
		nexusfontis = "fons: incognitus" 
		if mw.title.new("Disputatio:"..mw.title.getCurrentTitle().rootText).exists then --TEMPORARY PATCH (25/06/20): looks for the discussion page to add the "sine fonte" category
			categoriafontis = "[[Categoria:Opera sine fonte|".. titulus.. "]] [[Categoria:Opera cum fonte in disputatione|".. titulus.. "]]" --this category is only a TEMPORARY working tool, the whole string will be deleted after all the works are properly categorized!
		else
			categoriafontis = "[[Categoria:Opera sine fonte|".. titulus.. "]]"
		end	
	end
	nexusfontis = nexusfontis.. categoriafontis
	--LIBER (generates a link to the scanned copy OR, lacking this, the discussion page)
	if liber ~= "0" then
	nexuslibri = "fons: [[Liber:".. liber.. "|librum vide]]"
		if mw.title.new("Liber:"..liber).exists then
			categoriafontis = "[[Categoria:Opera cum libro digitale".. "|".. titulus.. "]]"
		else
			error("Librum ".. liber.. " deest! - there is not such index!")
		end
	nexusfontis = nexuslibri.. categoriafontis
	end 

--GENERA (puts the page into the "genera" categories)
	if genera ~= "0" then --if the "genera" parameter is defined...
		genera = string.gsub(genera, ", ", ",") --adjusts the commas
		genera = string.gsub(genera, ",", "]][[Categoria:") --splits the arguments, separated by commas, generating a category for each one
		categoriagenerum = "[[Categoria:".. genera.. "]]"
	else --if the "genera" parameter is not defined...
		categoriagenerum = "[[Categoria:Opera sine generibus]]" --adds the corresponding category
	end
	
--FRONS (locates a front page for exports)
	if frons ~= "0" then
		nexusfrontis = frons
	else
		nexusfrontis = ""
	end
	
--puts the generic category "Opera omnia", collecting all published works
	categoriaomnia = "[[Categoria:Opera omnia".. "|".. titulus.. "]]"
	
--Retieves Wikidata item
	item = mw.wikibase.getEntity()	
	id = mw.wikibase.getEntityIdForCurrentPage()
	
	if id == nil then
		wikidata_cat = "[[Categoria:Opera sine re wikidata".. "|".. titulus.. "]]"
	else
		wikidata_cat = ""
	end
			
	if subpagina == true then
	categoriacapiti = "[[Categoria:Capita ex operibus".. "|".. titulus.. "]]" --adds the "capita" (''chapter'') category 
	categoriascriptoris = ""
	categoriafontis = ""
	if annus == "0" then nexusanni = "" end
	categoriaanni = ""
	categoriagenerum = ""
	nexusfrontis = ""
	categoriaomnia = ""
	if editio == "0" then nexuseditionis = "" end
	if fons == "0" then nexusfontis = "" end
	if liber ~= "0" then nexusfontis = nexuslibri end
	categoriaeditionis = ""
	wikidata_cat = ""
	end


--builds the table
	tab = '<div id="ws-data" class="ws-noexport" style="display:none; speak:none">'
	tab = tab.. '<span id="ws-author">'.. scriptor..  '</span>'
	tab = tab.. '<span id="ws-title">'.. operaetitulus.. '</span>'
	tab = tab.. '<span id="ws-scan">'.. liber.. '</span>'
	tab = tab.. '<span id="ws-year">'.. annus.. '</span>'
if nexusfrontis > "0" then
	tab = tab.. '<span id="ws-cover">'.. nexusfrontis.. '</span>'
	tab = tab.. '</div>'
else
    tab = tab.. '</div>'
end
	tab = tab.. '<div class="titulusHeaderBox">'
    tab = tab.. '<div class="ws-noexport" style="padding:1ex;font-size:120%; font-weight: bold;">'
    tab = tab.. categoriaomnia.. nexusscriptoris.. categoriascriptoris.. nexusscriptoris2.. categoriascriptoris2.. nexusscriptoris3.. categoriascriptoris3.. nexusscriptoris4.. categoriascriptoris4.. nexusscriptoris5.. categoriascriptoris5.. nexusscriptoris6.. categoriascriptoris6
    tab = tab.. '</div>'
    tab = tab.. '<div class="ws-noexport" style="padding:1ex;font-size:140%;font-variant:small-caps; font-weight: bold;">'
	tab = tab.. nexusoperaetituli.. categoriacapiti.. categoriagenerum
	tab = tab.. '</div>'
	tab = tab.. '<div class="ws-noexport" style="padding:1ex;font-size:110%; font-weight:bold;">'
    tab = tab.. nexussubtituli
    tab = tab.. '</div>'
	tab = tab.. '<div class="ws-noexport" class="ws-noexport" style="padding:1ex; font-weight: bold;">'
    tab = tab.. nexusanni.. categoriaanni
    tab = tab.. '</div>'
    tab = tab.. '<div align="left" class="ws-noexport" style="padding:1ex;font-size:65%; font-weight:bold;">'
    tab = tab.. nexuseditionis.. nexusrecensoris.. categoriaeditionis.. "</br>".. nexusfontis.. wikidata_cat
    tab = tab.. '</div>'
	tab = tab.. '</div>'
	tab = tab.. '<div title="beginning"></div>'
	tab = tab.. '<div class="text">'
	
return tab
    
    end
return p