require('strict')
local TaxonItalics = require('Module:TaxonItalics')
local Autotaxobox = require('Module:Autotaxobox')
local ItalicTitle = require('Module:Italic title')
local p = {} -- functions made public
local l = {} -- nonpublic internal functions and variables global to the module
l.system = * -- * for normal scientific classification (default)
-- 'ichnos' for trace fossil classification
-- 'veterovata' for egg fossil classification  
-- =============================================================================
-- ichnobox implements Template:Ichnobox; see the documentation of that
-- template for details.
-- The only difference from Template:Automatic taxobox is in the taxobox colour
-- and classification link and the parameters for type species and genera.
-- =============================================================================  
function p.ichnobox
l.system = 'ichnos'
return p.automaticTaxobox
end  
-- =============================================================================
-- oobox implements Template:Oobox; see the documentation of that
-- template for details.
-- The only difference from Template:Automatic taxobox is in the taxobox colour
-- and classification link and the parameters for type species and genera.
-- =============================================================================  
function p.oobox
l.system = 'veterovata'
return p.automaticTaxobox
end  
-- =============================================================================
-- automaticTaxobox implements Template:Automatic taxobox; see the documentation
-- of that template for details.
-- It also implements Template:Ichnobox and Template:Oobox. The small
-- differences are signalled by the module-wide variable l.system.
-- The following parameters present in the old template code version of
-- Template:Automatic taxobox were not used and have not been implemented:
-- image_caption_align
-- image2_caption_align
-- binomial2
-- binomial2_authority
-- binomial3
-- binomial3_authority
-- binomial4
-- binomial4_authority
-- =============================================================================  
function p.automaticTaxobox
local args
if .args['direct'] == 'yes' then args = .args
else args = :getParent.args end
local res = ''
-- ---------------------------------------------------------------------
-- pick up taxobox parameters from the caller that need to be processed;
-- most will be passed on unchanged
-- ---------------------------------------------------------------------
local pagename = args['pagename'] or '' -- for testing and debugging only
local italicTitle = args['italic_title'] or args['italic title'] or ''
local ichnos = ''
if l.system == 'ichnos' then ichnos = 'true' end
local veterovata = ''
if l.system == 'veterovata' then veterovata = 'true' end
local fossilRange = args['fossil_range'] or args['fossil range'] or args['temporal_range'] or args['temporal range'] or ''
local oldestFossil = args['oldest_fossil'] or args['oldest fossil'] or ''
local youngestFossil = args['youngest_fossil'] or args['youngest fossil'] or ''
local name = args['name'] or ''
local colourAs = args['color_as'] or args['color as'] or args['colour_as'] or args['colour as'] or ''
local taxon = args['taxon'] or ''
local authority = args['authority'] or ''
local parentAuthority = args['parent_authority'] or args['parent authority'] or ''
local subdivision = args['subdivision'] or ''
local subdivisionRef = args['subdivision_ref'] or args['subdivision ref'] or ''
local subdivisionRanks = args['subdivision_ranks'] or args['subdivision ranks'] or ''
local manualFlag = 'text' -- marks manually specified ranks
local binomial = args['binomial'] or args['binomial_'..manualFlag] or args['binomial '..manualFlag] or ''
local binomialAuthority = args['binomial_authority'] or args['binomial authority'] or ''
local genusManual = args['genus_'..manualFlag] or args['genus '..manualFlag] or''
local speciesManual = args['species_'..manualFlag] or args['species '..manualFlag] or''
-- ------------------------------------------------------
-- set the taxobox parameters determined by this function
-- ------------------------------------------------------
fossilRange = l.setfossilRange(, fossilRange, oldestFossil, youngestFossil)
-- use the base page name as the taxon if the taxon parameter is missing
local currentPagename = mw.title.getCurrentTitle
if pagename == '' then pagename = currentPagename.text end -- pagename para only used in testing and
local basePagename = pagename
if italicTitle ~= 'taxon' then basePagename = mw.ustring.gsub(basePagename, '%s+%b$', '', 1) end
local taxonParaMissingError = false
if taxon == '' then
taxonParaMissingError = true
taxon = basePagename
end
-- decide if the page name and taxobox name need to be italicized;
-- if italic_title is not set, then if the names are the taxon, use its rank to decide
local ok, taxonRank = Autotaxobox.getTaxonInfoItem(, taxon, 'rank') -- taxonRank needed later if not here
if italicTitle == '' then
if not (ok and taxonRank ~= '' and
:expandTemplate{ title = 'Is italic taxon', args = {taxonRank} } == 'yes') then
italicTitle = 'no'
end
end
-- remove any " (DISAMBIG)" or "/MODIFIER" from the taxon's name;
-- if the base page name is the same as the base taxon name, then italicization can be applied
local baseTaxon = taxon
if italicTitle ~= 'taxon' then baseTaxon = mw.ustring.gsub(baseTaxon, '%s+%b$', '', 1) end
baseTaxon = mw.ustring.gsub(baseTaxon, '/.*$', '', 1)
if italicTitle == '' and basePagename == baseTaxon then
italicTitle = 'yes'
end
-- italicize the page name (page title) if required
if currentPagename.namespace == 0 and (italicTitle == 'yes' or italicTitle == 'taxon') then
if italicTitle == 'taxon' or TaxonItalics.hasConnectingTerm(baseTaxon) then
res = res .. :expandTemplate{ title = 'Italic taxon title', args = {} }
italicTitle = 'yes'
else ItalicTitle._main({})
end
end
-- set the taxobox name if not supplied, italicizing it if appropriate.
if name == '' then
name = basePagename
if italicTitle == 'yes' then
name = TaxonItalics.italicizeTaxonName(name, false, false)
end
-- name = name .. '/' .. baseTaxon .. '/' .. nameRank
end
-- determine taxobox colour
local colour = ''
if colourAs ~= '' then
colour = :expandTemplate{ title = 'Taxobox colour', args = {colourAs} }
elseif l.system == 'ichnos' then
colour = :expandTemplate{ title = 'Taxobox colour', args = {'Ichnos'} }
elseif l.system == 'veterovata' then
colour = :expandTemplate{ title = 'Taxobox colour', args = {'Veterovata'} }
else
colour = Autotaxobox.getTaxoboxColour(, taxon)
end
-- fill in a missing subdivision_ranks parameter
if subdivision ~= * and subdivisionRanks == * and ok and taxonRank ~= '' then
subdivisionRanks = :expandTemplate{ title = 'Children rank', args = {taxonRank} }
end
-- set binomial parameters if the target taxon is (unusually) a species
local genusAuthority = ''
if binomial == '' then
if ok and taxonRank == 'species' then
binomial = TaxonItalics.italicizeTaxonName(taxon, false, false)
binomialAuthority = authority
end
end
-- handle any manually set ranks
local boldFirst = ''
local offset = 0
if speciesManual ~= '' then
offset = offset + 1
binomialAuthority = authority
if binomial == '' then binomial = '<span>Error: binomial parameter value is missing</span>' end
end
if genusManual ~= '' then
boldFirst = 'link'
offset = offset + 1
if offset == 1 then
genusAuthority = authority
else
genusAuthority = parentAuthority
end
end
-- process type genus and type species if present; italicize if they seem not to have an authority attached
local typeGenus = ''
local typeGenusAuthority = ''
local typeSpecies = ''
local typeSpeciesAuthority = ''
local typeIchnogenus = ''
local typeIchnogenusAuthority = ''
local typeIchnospecies = ''
local typeIchnospeciesAuthority = ''
local typeOogenus = ''
local typeOogenusAuthority = ''
local typeOospecies = ''
local typeOospeciesAuthority = ''
if l.system == '' then