Jump to content

Module:Autovirusbox

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Peter coxhead (talk | contribs) at 15:23, 16 January 2019 (show error message in standard format). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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
	if frame.args['direct'] == 'yes' then args = frame.args
	else args = frame:getParent().args end
	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 '0'
--[[
	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, targetTaxon = l.paramChk(taxon, parent, species, strain, serotype, virus)
	-- set taxobox name/title
	local name = 'Error in determining taxobox name'
	if autoTaxonType == 'ERROR' then
		name = '<span class="error">ERROR: parameter(s) specifying taxon are incorrect; see [[Template:Virusbox/doc#Usage|documentation]]</span>'
	elseif 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
	-- 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
		local targetTaxonRank = frame:expandTemplate{ title = 'Taxon info', args = { autoTaxon, 'rank' } }
		subdivisionRanks =  frame:expandTemplate{ title = 'Children rank', args = {targetTaxonRank } }
	end
	-- ------------------------------------------------
	-- now call Taxobox/core with all of its parameters
	-- ------------------------------------------------
	local res = frame:expandTemplate{ title = 'Template:Taxobox/core/sandbox', args =
		{ ['edit link'] = 'e',
		  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 '',
		} }
	-- put in error-tracking category if required
	if autoTaxonType == 'ERROR' then
		res = res .. frame:expandTemplate{ title = 'Main other', args = {'[[Category:Virusboxes with incorrect parameters that specify taxon]]'} }
	end
	return res
end

-- =============================================================================

function l.paramChk(taxon, parent, species, strain, serotype, virus)
	-- set target taxon and infra-taxon
	local infraTaxon = ''
	local infraTaxonRank = ''
	local targetTaxon = taxon
	if strain ~= '' then
		infraTaxon = strain
		infraTaxonRank = 'strain'
		targetTaxon = infraTaxon
	elseif serotype ~= '' then
		infraTaxon = serotype
		infraTaxonRank = 'serotype'
		targetTaxon = infraTaxon
	elseif virus ~= '' then
		infraTaxon = virus
		infraTaxonRank = 'virus'
		targetTaxon = infraTaxon
	elseif species ~= '' then
		targetTaxon = species
	end
	-- set autotaxon (entry into the automated taxobox system)
	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, targetTaxon
end

return p