Module:Autovirusbox
Appearance
![]() | This Lua module is used on many pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
Uses the following templates:
- Template:Children rank
- Template:Is italic taxon
- Template:Main other
- Template:Taxobox colour
- Template:Taxobox/core
- Template:Taxon info
Usage
This module implements the function of {{Virusbox}} – see that template's documentation for details and parameters.
It can be called via {{Virusbox |...}}
, or directly, in which case |direct=yes
must be supplied, i.e. {{#invoke:Autovirusbox|main |direct=yes |...}}
.
require('Module:No globals')
local p = {} -- functions made public
local l = {} -- internal functions, kept separate
-- =============================================================================
function p.main(frame)
-- --------------------------------------------
-- pick up taxobox parameters from the caller;
-- most are passed on unchaged
-- --------------------------------------------
local taxon = frame.args['taxon'] or ''
local parent = frame.args['parent'] or ''
local species = frame.args['species'] or ''
local strain = frame.args['strain'] or ''
local serotype = frame.args['serotype'] or ''
local virus = frame.args['virus'] or ''
local displayParents = frame.args['display_parents'] or ''
--[[
local authority = frame.args['authority'] or ''
local parentAuthority = frame.args['parent_authority'] or ''
local gParentAuthority = frame.args['grandparent_authority'] or ''
local ggParentAuthority = frame.args['greatgrandparent_authority'] or ''
local gggParentAuthority = frame.args['greatgreatgrandparent_authority'] or ''
local typeGenusAuthority = frame.args['type_genus_authority'] or ''
]]
local subdivisionRanks = frame.args['subdivision_ranks'] or ''
-- ----------------------------------------------------------
-- now set the taxobox parameters determined by this function
-- ----------------------------------------------------------
local autoTaxon, autoTaxonType, infraTaxon, infraTaxonRank = l.paramChk(taxon, parent, species, strain, serotype, virus)
-- set taxobox name/title
local name = 'ERROR in determining taxobox name'
if autoTaxonType == 'TAXON' then
name = autoTaxon
local autoTaxonRank = frame:expandTemplate{ title = 'Taxon info', args = { autoTaxon, 'rank' } }
if frame:expandTemplate{ title = 'Is italic taxon', args = { autoTaxonRank, virus = 'yes' } } == 'yes' then
name = "''"..name.."''"
end
elseif infraTaxon ~= '' then
name = infraTaxon
elseif species ~= '' then
name = "''"..species.."''"
end
-- show species in italics; bold if nothing below
if species ~= '' then
if infraTaxon ~= '' then
species = "''"..species.."''"
else
species = "'''''"..species.."'''''"
end
end
-- show lowest rank in bold if it exists
if infraTaxon ~= '' then
infraTaxon = "'''"..infraTaxon.."'''"
end
-- ---------------------
-- now call Taxobox/core
-- ---------------------
local res = frame:expandTemplate{ title = 'Template:Taxobox/core/sandbox', args =
{ virus = 'yes',
colour = frame:expandTemplate{ title = 'Template:Taxobox colour', args = { 'virus' } },
name = name,
parent = autoTaxon,
--[[
authority = authority,
parent_authority = parentAuthority,
grandparent_authority = gparentAuthority,
grandparent_authority = gparentAuthority,
greatgrandparent_authority = ggparentAuthority,
greatgreatgrandparent_authority = gggparentAuthority,
]]
image = frame.args['image'] or '',
image_upright = frame.args['image_upright'] or '',
image_alt = frame.args['image_alt'] or '',
image_caption = frame.args['image_caption'] or '',
image2 = frame.args['image2'] or '',
image2_upright = frame.args['image2_upright'] or '',
image2_alt = frame.args['image2_alt'] or '',
image2_caption = frame.args['image2_caption'] or '',
species = species,
virus_infrasp = infraTaxon,
virus_infrasp_rank = infraTaxonRank,
display_taxa = displayParents,
type_genus = frame.args['type_genus'] or '',
--type_genus_authority = frame.args['type_genus_authority'] or '',
type_species = frame.args['type_species'] or '',
--type_species_authority = frame.args['type_species_authority'] or ''
subdivision_ranks = subdivisionRanks,
subdivision = frame.args['subdivision'] or '',
type_strain = frame.args['type_strain'] or '',
synonyms = frame.args['synonyms'] or '',
synonyms_ref = frame.args['synonyms_ref'] or '',
range_map = frame.args['range_map'] or '',
range_map_upright = frame.args['range_map_upright'] or '',
range_map_alt = frame.args['range_map_alt'] or '',
range_map_caption = frame.args['range_map_caption'] or '',
} }
return res
end
-- =============================================================================
function l.paramChk(taxon, parent, species, strain, serotype, virus)
local infraTaxon = ''
local infraTaxonRank = ''
if strain ~= '' then
infraTaxon = strain
infraTaxonRank = 'strain'
elseif serotype ~= '' then
infraTaxon = serotype
infraTaxonRank = 'serotype'
elseif virus ~= '' then
infraTaxon = virus
infraTaxonRank = 'virus'
end
local autoTaxon = ''
local autoTaxonType = ''
if taxon ~= '' then
if parent..species..infraTaxon ~= '' then
autoTaxonType = 'ERROR'
else
autoTaxon = taxon
autoTaxonType = 'TAXON'
end
else
if parent ~= '' then
if species ~= '' then
autoTaxon = parent
autoTaxonType = 'PARENT'
else
if infraTaxon ~= '' then
autoTaxon = parent
autoTaxonType = 'PARENT'
else
autoTaxonType = 'ERROR'
end
end
end
end
return autoTaxon, autoTaxonType, infraTaxon, infraTaxonRank
end
return p