function l.topLevelTaxon(taxon)
return taxon == 'Life' or taxon == 'Veterovata' or taxon == 'Ichnos'
end  
--=========================== taxoboxList =================================
Returns the rows of taxa in an automated taxobox, based on the taxonomic
hierarchy for the supplied taxon.
Usage:  
=============================================================================
function p.taxoboxList
local currTaxon = .args[1] or ''
if currTaxon == * then return * end
local displayN = (tonumber(.args['display_taxa']) or 1) + 1
local authTable = {}
authTable[1] = .args['authority'] or ''
authTable[2] = .args['parent_authority'] or ''
authTable[3] = .args['gparent_authority'] or ''
authTable[4] = .args['ggparent_authority'] or ''
authTable[5] = .args['gggparent_authority'] or ''
local boldFirst = .args['bold_first'] or 'link' -- values 'link' or 'bold'
local virus = .args['virus'] or 'no' -- values 'yes' or 'no'
local offset = tonumber(.args['offset'] or 0)
-- adjust the authority table if 'authority' refers to a rank lower than the target taxon
if offset ~= 0 then
for i = 1, 5 do
local j = i + offset
if j <= 5 then
authTable[i] = authTable[j]
else
authTable[i] = ''
end
end
end
local taxonTable, taxonRankTable = l.makeTable(, currTaxon)
local res = ''
local topTaxonN = taxonTable.n
-- display all taxa above possible greatgreatgrandparent, without authority
for i = topTaxonN, 6, -1 do
res = res .. l.showTaxon(, taxonTable[i], taxonRankTable[i], topTaxonN==i, *, displayN >= i, *, virus)
end
-- display all taxa above possible parent, with authority if given
for i = math.min(topTaxonN, 5), 2, -1 do
res = res .. l.showTaxon(, taxonTable[i], taxonRankTable[i], topTaxonN==i, authTable[i], displayN >= i, '', virus)
end
-- display target taxon, always displayed and emboldened
res = res .. l.showTaxon(, taxonTable[1], taxonRankTable[1], topTaxonN==1, authTable[1], true, boldFirst, virus)
return res
end  
--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Show one taxon row in a taxobox.  
function l.showTaxon(, taxon, rank, isTopTaxon, auth, force, boldFirst, virus)
-- it's an error if this is the top taxon and it's not a top level taxon (e.g. "Life")
if isTopTaxon then
if l.topLevelTaxon(taxon) then
return '' -- don't display a top level taxon
elseif (mw.title.new('Taxonomy/'..taxon, 'Template') or {}).exists then
-- taxonomy template for this taxon has no parent specified
return :expandTemplate{ title = 'Template:Create taxonomy', args = {taxon, msg='Taxonomy template does not specify a parent'} } .. '\n' .. TableRow
else
-- no taxonomy template for this taxon
return :expandTemplate{ title = 'Template:Create taxonomy', args = {taxon, msg='Missing taxonomy template'} } .. '\n' .. TableRow
end
else
-- if showing is not already forced, force if it's a principal rank or an authority is specified
force = force or :expandTemplate{ title = 'Template:Principal rank', args = {rank} } == 'yes' or
auth ~= ''
if not force then
-- if showing is still not already forced, force if the taxonomy template has 'always_display' set
local ok, alwaysDisplay = p.getTaxonInfoItem(, taxon, 'always_display')
force = alwaysDisplay == 'yes' or alwaysDisplay == 'true'
end
if force then
local res = l.tableCell(:expandTemplate{ title = 'Template:Anglicise rank', args = {rank} } .. ':')
local bold = 'no'
if boldFirst == 'bold' then bold = 'yes' end
if auth ~= '' then
auth = '
<small>' .. auth .. '</small>'
end
local res = res .. l.tableCell(l.getTaxonLink(, taxon, rank, bold, *, *, virus) .. auth) -- italic, abbreviated
return res .. TableRow
else
return ''
end
end
end  
--========================== taxonomyList =================================
Returns the cells of the taxonomy table displayed on the hand side of
"Template:Taxonomy...." pages.
Usage:
=============================================================================
function p.taxonomyList
local currTaxon = .args[1] or ''
if currTaxon == '' then
return '{|\n' .. TableRow .. l.tableCell('') .. l.tableCell('ERROR: no taxon supplied') .. TableEnd
end
local taxonTable, taxonRankTable = l.makeTable(, currTaxon)
local rankValTable = l.getRankTable
local lastRankVal = 1000000
local orderOk = true
-- check whether the taxonomy is for viruses; use already determined taxon colour if possible
local virus = 'no'
local taxoColour = colour
if taxoColour == '' then
if taxonTable[taxonTable.n] == 'Ichnos' or taxonTable[taxonTable.n] == 'Veterovata' then
taxoColour = :expandTemplate{ title = 'Template:Taxobox colour', args = { taxonTable[taxonTable.n] } }
else
taxoColour = :expandTemplate{ title = 'Template:Taxobox colour', args = { taxonTable[taxonTable.n - 1] } }
end
end
if taxoColour == :expandTemplate{ title = 'Template:Taxobox colour', args = { 'virus' } } then
virus = 'yes'
end
-- add information message
local res = '<p>Bold ranks show taxa that will be shown in taxoboxes
because rank is principal or <code>always_display=yes</code>.</p>\n'  
-- start table
res = res .. '{|\n' .. TableRow .. '! colspan=4|Ancestral taxa\n'
-- deal first with the top level taxon; if there are no errors, it should be Life/Veterovata/Ichnos, which are
-- not displayed
local taxon = taxonTable[taxonTable.n]
if not l.topLevelTaxon(taxon) then
local msg = 'Taxonomy template missing'
if mw.title.new('Taxonomy/'..taxon, 'Template').exists then
msg = 'Parent taxon needed'
end
res = res .. TableRow .. l.tableCell('colspan=2', :expandTemplate{title = 'Template:Create taxonomy', args = {taxon, msg = msg}})
end
-- now output the rest of the table
local currRankVal
for i = taxonTable.n-1, 1, -1 do
-- check ranks are in order in the hierarchy
taxon = taxonTable[i]
local rank = taxonRankTable[i]
currRankVal = l.lookupRankVal(rankValTable, rank)
if currRankVal then
orderOk = currRankVal < lastRankVal
if orderOk then lastRankVal = currRankVal end
else
orderOk = true
end
-- see if the row will be displayed in a taxobox; bold the rank if so
local boldRank = false
local ok, alwaysDisplay = p.getTaxonInfoItem(, taxon, 'always_display')
if ok and (alwaysDisplay == 'yes' or alwaysDisplay == 'true') then
boldRank = true
else
boldRank = :expandTemplate{ title = 'Template:Principal rank', args = {rank} } == 'yes'
end
-- now return a row of the taxonomy table with anomalous ranks marked
local errorStr = ''
if not orderOk then errorStr = 'yes' end
local link = l.getTaxonLink(, taxon, rank, *, *, '', virus) -- bold, italic, abbreviated
res = res .. l.taxonomyListRow(, taxon, rank, link, boldRank, errorStr)
end
-- close table
res = res .. TableEnd
-- error-tracking for taxonomy templates
-- if the last row has an anomalous rank, put the page in an error-tracking category
local errCat1 = ''
if not orderOk then
errCat1 = '\n'
end
-- if the last row has a taxon name in the page name that does not match the link text,
-- put the taxonomy template in a tracking category
local dummy, linkText = p.getTaxonInfoItem(, taxon, 'link_text')
local match = l.matchTaxonLink(taxon, linkText, currRankVal and currRankVal < rankValTable['genus'])
local errCat2 = ''
if not match then
errCat2 = '\n'
end
if errCat1..errCat2 ~= '' then
res = res .. :expandTemplate{ title = 'Template other', args = { errCat1..errCat2} }
end
return res
end  
-- = = = = = = = = = = = = = = taxonomyListRow = = = = = = = = = = = = = =
Returns a single row of the taxonomy table displayed on the hand side
of "Template:Taxonomy...." pages.  
function l.taxonomyListRow(, taxon, rank, link, boldRank, error)
local res = ''
if taxon == * or rank == * then return res end
local baseTaxon, qualifier = l.stripExtra(taxon)
-- if appropriate, make it clear that some taxa have been skipped via a ... row
if qualifier == '/skip' then
res = res .. TableRow .. l.tableCell('.....') .. l.tableCell('.....')
end
-- now generate a row of the table
res = res .. TableRow
local cellContent = ''
local anglicizedRank = :expandTemplate{ title = 'Template:Anglicise rank', args = { rank } }
if boldRank then