Module:Autotaxobox Explained

--

require('strict')local TaxonItalics = require('Module:TaxonItalics') -- use a function from Module:TaxonItalics to italicize a taxon namelocal TableRow = '|-\n'local TableEnd = '|}\n'local p = -- functions made publiclocal l = -- internal functions, kept separatelocal colour = -- colour for taxobox and taxonomy listings

--getMaxSearchLevels}}local MaxSearchLevels = 100

function p.getMaxSearchLevels return MaxSearchLevelsend

--taxoboxColour|TAXON}}function p.taxoboxColour(frame) return p.getTaxoboxColour(frame, frame.args[1] or )end

function p.getTaxoboxColour(frame, currTaxon) -- note that colour is global to this function; default is empty string local i = 1 -- count levels processed local searching = currTaxon ~= -- still searching for a colour? local foundICTaxon = false -- record whether 'incertae sedis' found while searching and i <= MaxSearchLevels do local plainCurrTaxon, dummy = l.stripExtra(currTaxon) -- remove trailing text after / if string.lower(plainCurrTaxon)

'incertae sedis' then foundICTaxon = true else local possibleColour = frame:expandTemplate if string.sub(possibleColour,1,3)

'rgb' then colour = possibleColour searching = false end end if searching then local ok, parent = p.getTaxonInfoItem(frame, currTaxon, 'parent') if ok and parent ~= then currTaxon = parent i = i + 1 else searching = false -- run off the top of the hierarchy or tried to use non-existent taxonomy template end end end if colour

then if foundICTaxon then colour = frame:expandTemplate elseif searching then -- hierarchy exceeds MaxSearchLevels levels colour = frame:expandTemplate else colour = 'transparent' end end return colourend

--= = = = = = = = = = = = = topLevelTaxon = = = = = = = = = = = = = = = = Defines the correct top level taxa, one of which should terminate everytaxonomic hierarchy encoded in taxonomy templates.= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =function l.topLevelTaxon(taxon) return taxon

'Life' or taxon

'Veterovata' or taxon

'Ichnos'end

--taxoboxList|TAXON|display_taxa = the number of taxa *above* TAXON to force to be displayed|authority = taxonomic authority for TAXON|parent_authority = taxonomic authority for TAXON's parent|gparent_authority = taxonomic authority for TAXON's grandparent|ggparent_authority = taxonomic authority for TAXON's greatgrandparent|ggparent_authority = taxonomic authority for TAXON's greatgreatgrandparent|bold_first = 'bold' to bold TAXON in its row|virus = 'yes' to apply virus taxa italicization standards}}function p.taxoboxList(frame) local currTaxon = frame.args[1] or if currTaxon

then return end local displayN = (tonumber(frame.args['display_taxa']) or 1) + 1 local authTable = authTable[1] = frame.args['authority'] or authTable[2] = frame.args['parent_authority'] or authTable[3] = frame.args['gparent_authority'] or authTable[4] = frame.args['ggparent_authority'] or authTable[5] = frame.args['gggparent_authority'] or local boldFirst = frame.args['bold_first'] or 'link' -- values 'link' or 'bold' local virus = frame.args['virus'] or 'no' -- values 'yes' or 'no' local offset = tonumber(frame.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(frame, 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(frame, 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(frame, taxonTable[i], taxonRankTable[i], topTaxonN

i, authTable[i], displayN >= i, , virus) end -- display target taxon, always displayed and emboldened res = res .. l.showTaxon(frame, taxonTable[1], taxonRankTable[1], topTaxonN

1, authTable[1], true, boldFirst, virus) return resend

--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =Show one taxon row in a taxobox.= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =function l.showTaxon(frame, 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 frame:expandTemplate .. '\n' .. TableRow else -- no taxonomy template for this taxon return frame:expandTemplate .. '\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 frame:expandTemplate

'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(frame, taxon, 'always_display') force = alwaysDisplay

'yes' or alwaysDisplay

'true' end if force then local res = l.tableCell(frame:expandTemplate .. ':') local bold = 'no' if boldFirst

'bold' then bold = 'yes' end if auth ~= then auth = '
' .. auth .. '' end local res = res .. l.tableCell(l.getTaxonLink(frame, taxon, rank, bold,
, , virus) .. auth) -- italic, abbreviated return res .. TableRow else return end endend

--taxonomyList|TAXON}}function p.taxonomyList(frame) local currTaxon = frame.args[1] or if currTaxon

then return '