Module:Autovirusbox/sandbox explained
require('strict')local ItalicTitle = require('Module:Italic title')local p = -- functions made publiclocal l = -- internal functions, kept separate
--
-- main implements Template:Virusbox; see the documentation of that template-- for details.--
function p.main(frame) local args if frame.args['direct']
'yes' then args = frame.args else args = frame:getParent.args end -- --------------------------------------------------------------------- -- pick up taxobox parameters from the caller that need to be processed; -- most are passed on unchanged -- --------------------------------------------------------------------- local name = args['name'] or local taxon = args['taxon'] or local parent = args['parent'] or local species = args['species'] or local strain = args['strain'] or local serotype = args['serotype'] or local virus = args['virus'] or local displayParents = args['display_parents'] or '1'--local authority = args['authority'] or local parentAuthority = args['parent_authority'] or local gParentAuthority = args['grandparent_authority'] or local ggParentAuthority = args['greatgrandparent_authority'] or local gggParentAuthority = args['greatgreatgrandparent_authority'] or local typeGenusAuthority = args['type_genus_authority'] or local subdivision = args['subdivision'] or local subdivisionRanks = args['subdivision_ranks'] or local subdivisionRef = args['subdivision_ref'] or args['subdivision ref'] or
-- ------------------------------------------------------ -- set the taxobox parameters determined by this function -- ------------------------------------------------------ local autoTaxon, autoTaxonType, infraTaxa, infraTaxaRanks, targetTaxon, targetTaxonRank = l.paramChk(frame, taxon, parent, species, strain, serotype, virus) -- set default taxobox name/title local italicsRequired = frame:expandTemplate
'yes' and args["italic_title"] ~= "no" if name
then if autoTaxonType
'ERROR' then name = '
ERROR: parameter(s) specifying taxon are incorrect; see documentation' else name = targetTaxon if italicsRequired then name = "
" .. targetTaxon .. "" end end end -- the page name (title) should be italicized if it's the same as the target taxon and that is italicized local currentPage = mw.title.getCurrentTitle local pagename = currentPage.text if pagename
targetTaxon then if italicsRequired then ItalicTitle._main end end -- is the auto-taxon name bold or linked (i.e. will it be the last row in the taxobox or not)? local boldFirst = 'bold' if autoTaxonType
'PARENT' then boldFirst = 'link' end -- italicize and link species name, or embolden if nothing below if species ~= then if infraTaxon ~= then species = ""..species.."" else species = ""..species.."" end end -- embolden lowest rank -- oops, here goes the problem if infraTaxon ~= then infraTaxon = ""..infraTaxon.."" end -- set offset and fix display_parents if there are ranks below autoTaxon local offset = 0 if infraTaxon ~= then offset = offset + 1 end if species ~= then offset = offset + 1 end if offset ~= 0 then displayParents = tostring(tonumber(displayParents) - offset) end -- fill in a missing subdivision_ranks parameter if subdivision ~= and subdivisionRanks
then subdivisionRanks = frame:expandTemplate end -- ------------------------------------------------ -- now call Taxobox/core with all of its parameters -- ------------------------------------------------ local res = frame:expandTemplate -- put page in error-tracking category if required if autoTaxonType
'ERROR' then res = res .. frame:expandTemplate end return resend
--
-- paramChk checks the taxon-specifying parameters for consistency, selecting-- the target taxon (the taxon that is the target of the taxobox), the-- infra-taxon (the taxon below species level), if any, and the 'auto-taxon',-- the taxon that is the entry point into the automated taxobox system.--
function l.paramChk(frame, taxon, parent, species, strain, serotype, virus) -- set target taxon and infra-taxon local infraTaxa = local infraTaxaRanks = local targetTaxon = local targetTaxonRank
-- populate infraTaxa if virus ~= then infraTaxa[#infraTaxa+1] = virus infraTaxaRanks[#infraTaxaRanks+1] = 'virus' end if serotype ~= then infraTaxa[#infraTaxa+1] = serotype infraTaxaRanks[#infraTaxaRanks+1] = 'serotype' end if strain ~= then infraTaxa[#infraTaxa+1] = strain infraTaxaRanks[#infraTaxaRanks+1] = 'strain' targetTaxon = infraTaxon targetTaxonRank = infraTaxonRank end -- populate targetTaxon using lowest if #infraTaxa > 1 then targetTaxon = infraTaxa[#infraTaxa] targetTaxonRank = infraTaxaRanks[#infraTaxaRanks] elseif species ~= then targetTaxon = species targetTaxonRank = 'species' else targetTaxon = taxon targetTaxonRank = frame:expandTemplate end -- set the autotaxon (entry into the automated taxobox system) if the -- parameters are valid; the default is invalid local autoTaxon = local autoTaxonType = 'ERROR' if taxon ~= then if parent..species..(table.concat(infraTaxa, ))
then autoTaxon = taxon autoTaxonType = 'TAXON' end elseif parent ~= and (species ~= or #infraTaxa > 1) then autoTaxon = parent autoTaxonType = 'PARENT' end return autoTaxon, autoTaxonType, infraTaxa, infraTaxaRanks, targetTaxon, targetTaxonRankend
return p