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 that need to be processed;
-- most are passed on unchanged
-- ---------------------------------------------------------------------
local args = frame.args
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 ''
--[[
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 ''
-- ------------------------------------------------------
-- 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
-- italicize species name, and embolden if nothing below
if species ~= '' then
if infraTaxon ~= '' then
species = "''"..species.."''"
else
species = "'''''"..species.."'''''"
end
end
-- embolden lowest rank
if infraTaxon ~= '' then
infraTaxon = "'''"..infraTaxon.."'''"
end
-- fill in a missing subdivision_ranks parameter
if subdivision ~= '' and subdivisionRanks == '' then
subdivisionRanks = 'RANKS?'
end
-- ------------------------------------------------
-- now call Taxobox/core with all of its parameters
-- ------------------------------------------------
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 = args['image'] or '',
image_upright = args['image_upright'] or '',
image_alt = args['image_alt'] or '',
image_caption = args['image_caption'] or '',
image2 = args['image2'] or '',
image2_upright = args['image2_upright'] or '',
image2_alt = args['image2_alt'] or '',
image2_caption = args['image2_caption'] or '',
species = species,
virus_infrasp = infraTaxon,
virus_infrasp_rank = infraTaxonRank,
display_taxa = displayParents,
type_genus = args['type_genus'] or '',
--type_genus_authority = args['type_genus_authority'] or '',
type_species = args['type_species'] or '',
--type_species_authority = args['type_species_authority'] or ''
subdivision_ranks = subdivisionRanks,
subdivision = subdivision,
type_strain = args['type_strain'] or '',
synonyms = args['synonyms'] or '',
synonyms_ref = args['synonyms_ref'] or '',
range_map = args['range_map'] or '',
range_map_upright = args['range_map_upright'] or '',
range_map_alt = args['range_map_alt'] or '',
range_map_caption = 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