Module:Automated taxobox: Difference between revisions

m
1 revision imported
en>Centrist16
(Created page with "require('Module:No globals') local TaxonItalics = require('Module:TaxonItalics') local Autotaxobox = require('Module:Autotaxobox') local ItalicTitle = require('Module:Italic t...")
 
m (1 revision imported)
 
(2 intermediate revisions by 2 users not shown)
Line 1:
require('Module:No globalsstrict')
local TaxonItalics = require('Module:TaxonItalics')
local Autotaxobox = require('Module:Autotaxobox')
local ItalicTitle = require('Module:Italic title')
local p = {} -- functions made public
local l = {} -- nonpublic internal functions, keptand variables global to the separatemodule
l.system = '' -- '' for normal scientific classification (default)
-- 'ichnos' for trace fossil classification
-- 'veterovata' for egg fossil classification
 
-- =============================================================================
-- ichnobox implements Template:Ichnobox; see the documentation of that
-- template for details.
-- The only difference from Template:Automatic taxobox is in the taxobox colour
-- and classification link and the parameters for type species and genera.
-- =============================================================================
 
function p.ichnobox(frame)
l.system = 'ichnos'
return p.automaticTaxobox(frame)
end
 
-- =============================================================================
-- oobox implements Template:Oobox; see the documentation of that
-- template for details.
-- The only difference from Template:Automatic taxobox is in the taxobox colour
-- and classification link and the parameters for type species and genera.
-- =============================================================================
 
function p.oobox(frame)
l.system = 'veterovata'
return p.automaticTaxobox(frame)
end
 
-- =============================================================================
-- automaticTaxobox implements Template:Automatic taxobox; see the documentation
-- of that template for details.
-- It also implements Template:Ichnobox and Template:Oobox. The small
-- differences are signalled by the module-wide variable l.system.
-- The following parameters present in the old template code version of
-- Template:Automatic taxobox were not used and have not been implemented:
Line 25 ⟶ 54:
if frame.args['direct'] == 'yes' then args = frame.args
else args = frame:getParent().args end
local res = ''
-- ---------------------------------------------------------------------
-- pick up taxobox parameters from the caller that need to be processed;
Line 31 ⟶ 61:
local pagename = args['pagename'] or '' -- for testing and debugging only
local italicTitle = args['italic_title'] or args['italic title'] or ''
local ichnos = ''
if l.system == 'ichnos' then ichnos = 'true' end
local veterovata = ''
if l.system == 'veterovata' then veterovata = 'true' end
local fossilRange = args['fossil_range'] or args['fossil range'] or args['temporal_range'] or args['temporal range'] or ''
local oldestFossil = args['oldest_fossil'] or args['oldest fossil'] or ''
Line 38 ⟶ 72:
local taxon = args['taxon'] or ''
local authority = args['authority'] or ''
local parentAuthority = args['parent_authority'] or args['parent authority'] or ''
local subdivision = args['subdivision'] or ''
local subdivisionRef = args['subdivision_ref'] or args['subdivision ref'] or ''
local subdivisionRanks = args['subdivision_ranks'] or args['subdivision ranks'] or ''
local manualFlag = 'text' -- marks manually specified ranks
local binomial = args['binomial'] or ''
local binomialAuthoritybinomial = args['binomial_authoritybinomial'] or args['binomial_authoritybinomial_'..manualFlag] or args['binomial '..manualFlag] or ''
local binomialAuthority = args['binomial_authority'] or args['binomial authority'] or ''
local genusManual = args['genus_'..manualFlag] or args['genus '..manualFlag] or''
local speciesManual = args['species_'..manualFlag] or args['species '..manualFlag] or''
-- ------------------------------------------------------
-- set the taxobox parameters determined by this function
Line 48 ⟶ 87:
-- use the base page name as the taxon if the taxon parameter is missing
local currentPagename = mw.title.getCurrentTitle()
if pagename == '' then pagename = currentPagename.text end -- pagename para only used in testing and debugging
local basePagename = mw.ustring.gsub(pagename, '%s+%b()$', '', 1)
if italicTitle ~= 'taxon' then basePagename = mw.ustring.gsub(basePagename, '%s+%b()$', '', 1) end
local taxonParaMissingError = false
if taxon == '' then
Line 66 ⟶ 106:
-- remove any " (DISAMBIG)" or "/MODIFIER" from the taxon's name;
-- if the base page name is the same as the base taxon name, then italicization can be applied
local baseTaxon = mw.ustring.gsub(mw.ustring.gsub(taxon, '%s+%b()$', '', 1), '/.*$', '', 1)
if italicTitle ~= 'taxon' then baseTaxon = mw.ustring.gsub(baseTaxon, '%s+%b()$', '', 1) end
baseTaxon = mw.ustring.gsub(baseTaxon, '/.*$', '', 1)
if italicTitle == '' and basePagename == baseTaxon then
italicTitle = 'yes'
end
-- italicize the page name (page title) if required
if currentPagename.namespace == 0 and (italicTitle == 'yes' andor currentPagename.namespaceitalicTitle == 0'taxon') then
if italicTitle == 'taxon' or TaxonItalics.hasConnectingTerm(baseTaxon) then
ItalicTitle._main({})
res = res .. frame:expandTemplate{ title = 'Italic taxon title', args = {} }
italicTitle = 'yes'
else ItalicTitle._main({})
end
end
-- set the taxobox name if not supplied, italicizing it if appropriate.
Line 86 ⟶ 132:
if colourAs ~= '' then
colour = frame:expandTemplate{ title = 'Taxobox colour', args = {colourAs} }
elseif l.system == 'ichnos' then
colour = frame:expandTemplate{ title = 'Taxobox colour', args = {'Ichnos'} }
elseif l.system == 'veterovata' then
colour = frame:expandTemplate{ title = 'Taxobox colour', args = {'Veterovata'} }
else
colour = Autotaxobox.getTaxoboxColour(frame, taxon)
Line 94 ⟶ 144:
end
-- set binomial parameters if the target taxon is (unusually) a species
local genusAuthority = ''
if binomial == '' then
if ok and taxonRank == 'species' then
Line 99 ⟶ 150:
binomialAuthority = authority
end
end
-- handle any manually set ranks
local boldFirst = ''
local offset = 0
if speciesManual ~= '' then
offset = offset + 1
binomialAuthority = authority
if binomial == '' then binomial = '<span class="error">Error: binomial parameter value is missing</span>' end
end
if genusManual ~= '' then
boldFirst = 'link'
offset = offset + 1
if offset == 1 then
genusAuthority = authority
else
genusAuthority = parentAuthority
end
end
-- process type genus and type species if present; italicize if they seem not to have an authority attached
local typeGenus = ''
local typeGenusAuthority = ''
local typeSpecies = ''
local typeSpeciesAuthority = ''
local typeIchnogenus = ''
local typeIchnogenusAuthority = ''
local typeIchnospecies = ''
local typeIchnospeciesAuthority = ''
local typeOogenus = ''
local typeOogenusAuthority = ''
local typeOospecies = ''
local typeOospeciesAuthority = ''
if l.system == '' then
typeGenus = l.italicizeTypeName(args['type_genus'] or args['type genus'] or '')
typeGenusAuthority = args['type_genus_authority'] or args['type genus authority'] or ''
typeSpecies = l.italicizeTypeName(args['type_species'] or args['type species'] or '')
typeSpeciesAuthority = args['type_species_authority'] or args['type species authority'] or ''
elseif l.system == 'ichnos' then
typeIchnogenus = l.italicizeTypeName(args['type_ichnogenus'] or args['type ichnogenus'] or '')
typeIchnogenusAuthority = args['type_ichnogenus_authority'] or args['type ichnogenus authority'] or ''
typeIchnospecies = l.italicizeTypeName(args['type_ichnospecies'] or args['type ichnospecies'] or '')
typeIchnospeciesAuthority = args['type_ichnospecies_authority'] or args['type ichnospecies authority'] or ''
elseif l.system == 'veterovata' then
typeOogenus = l.italicizeTypeName(args['type_oogenus'] or args['type oogenus'] or '')
typeOogenusAuthority = args['type_oogenus_authority'] or args['type oogenus authority'] or ''
typeOospecies = l.italicizeTypeName(args['type_oospecies'] or args['type oospecies'] or '')
typeOospeciesAuthority = args['type_oospecies_authority'] or args['type oospecies authority'] or ''
end
-- ------------------------------------------------
-- now call Taxobox/core with all of its parameters
-- ------------------------------------------------
local res = res .. frame:expandTemplate{ title = 'Taxobox/core', args =
{ ['edit link']ichnos = 'e'ichnos,
veterovata = veterovata,
['edit link'] = 'e',
temporal_range = fossilRange,
display_taxa = args['display_parents'] or args['display parents'] or '1',
parent = taxon,
authority = authority,
parent_authority = args['parent_authority'] or args['parent authority'] or ''parentAuthority,
grandparent_authority = args['grandparent_authority'] or args['grandparent authority'] or '',
greatgrandparent_authority = args['greatgrandparent_authority'] or args['greatgrandparent authority'] or '',
Line 135 ⟶ 234:
diversity_ref = args['diversity_ref'] or args['diversity ref'] or '',
diversity_link = args['diversity_link'] or args['diversity link'] or '',
bold_first = boldFirst,
offset = offset,
genus = genusManual,
genus_authority = genusAuthority,
species = speciesManual,
binomial = binomial,
binomial_authority = binomialAuthority,
trinomial = args['trinomial'] or '',
trinomial_authority = args['trinomial_authority'] or args['trinomial authority'] or '',
type_genus = args['type_genus'] or args['type genus'] or ''typeGenus,
type_genus_authority = args['type_genus_authority'] or args['type genus authority'] or ''typeGenusAuthority,
type_species = args['type_species'] or args['type species'] or ''typeSpecies,
type_species_authority = args['type_species_authority'] or args['type species authority'] or ''typeSpeciesAuthority,
type_ichnogenus = typeIchnogenus,
type_ichnogenus_authority = typeIchnogenusAuthority,
type_ichnospecies = typeIchnospecies,
type_ichnospecies_authority = typeIchnospeciesAuthority,
type_oogenus = typeOogenus,
type_oogenus_authority = typeOogenusAuthority,
type_oospecies = typeOospecies,
type_oospecies_authority = typeOospeciesAuthority,
subdivision = subdivision,
subdivision_ref = subdivisionRef,
subdivision_ranks = subdivisionRanks,
type_strain = args['type_strain'] or args['type strain'] or '',
type_strain_ref = args['type_strain_ref'] or args['type strain ref'] or '',
range_map = args['range_map'] or args['range map'] or '',
range_map_upright = args['range_map_upright'] or args['range map upright'] or '',
Line 167 ⟶ 281:
-- put page in error-tracking categories if required
local errCat1 = ''
if genusManual ~= '' or speciesManual ~= '' or binomial ~= '' then errCat1 = '[[Category:Automatic taxoboxes using binomialmanual parameterparameters]]' end
local errCat2 = ''
if taxonParaMissingError then errCat2 = '[[Category:Automatic taxoboxes relying on page title]]' end
Line 207 ⟶ 321:
end
return res
end
 
-- =============================================================================
-- l.italicizeTypeName(typeName) checks whether the name of a type genus or
-- species should be italicized, because it appears to be a bare name.
-- =============================================================================
 
function l.italicizeTypeName(typeName)
if typeName and not (string.find(typeName, "<", 1, true) or string.find(typeName, ">", 1, true)) then
typeName = TaxonItalics.italicizeTaxonName(typeName, false, false)
end
return typeName
end
 
-- **************************** Speciesbox support *****************************
 
-- =============================================================================
-- l.genusOf(str) extracts the genus from a string. Normally this will be the
-- first word of the string (e.g. given 'Bellis perennis' it returns 'Bellis').
-- It also handles a string containing a nothogenus with a spaced × (e.g. given
-- '× Heucherella tiarelloides' it returns '× Heucherella').
-- =============================================================================
 
function l.genusOf(str)
local res = mw.ustring.match(str, '^[^%s]*', 1)
if res == mw.ustring.char(215) then
res = res .. ' ' .. mw.ustring.match(str, '^[^%s]*', 3)
end
return res
end
 
-- =============================================================================
-- l.doSpeciesboxName(name, taxon, genus, species, basePageTitle, italicTitle)
-- returns a name for a taxobox created by Template:Speciesbox. The name will be
-- italicized if appropriate. It also generates code to italicize the page title
-- if appropropriate. In both cases the test for italicization is that the base
-- taxon name (stripped of any disambiguation or qualifier) is the same as the
-- base page title.
-- =============================================================================
 
function p.speciesboxName(frame)
local name = frame.args[1] or ''
local taxon = frame.args[2] or ''
local genus = frame.args[3] or ''
local species = frame.args[4] or ''
local basePageTitle = frame.args[5] or ''
local italicTitle = frame.args[6] or ''
return l.doSpeciesboxName(name, taxon, genus, species, basePageTitle, italicTitle)
end
function l.doSpeciesboxName(name, taxon, genus, species, basePageTitle, italicTitle)
if taxon ~= '' then
genus = mw.ustring.gsub(l.genusOf(taxon), '/.*$', '', 1) -- strip any qualifier
else
genus = mw.ustring.gsub(mw.ustring.gsub(genus, '%s+%b()$', '', 1), '/.*$', '', 1) -- strip any disambig and qualifier
if species == '' then taxon = genus
else taxon = genus .. ' ' .. species
end
end
local italicizeP = italicTitle ~= 'no' and (basePageTitle == taxon or basePageTitle == genus) -- use basePageTitle to match taxon/genus
-- deal with taxobox name (i.e. its caption)
if name == '' then
name = basePageTitle
if italicizeP then name = TaxonItalics.italicizeTaxonName(name, false, false) end
end
-- deal with page title
if italicizeP then
local pageTitle = mw.title.getCurrentTitle().text -- formatting the page title with DISPLAYTITLE needs the full page title
if italicTitle ~= 'test' then
pageTitle = TaxonItalics.italicizeTaxonName(pageTitle, false, false, true) -- format pageTitle, not italicizing any parenthesized term
local nsText = mw.title.getCurrentTitle().nsText -- for drafts and other pages not in mainspace
if nsText ~= '' then
pageTitle = nsText .. ':' .. pageTitle
end
mw.getCurrentFrame():callParserFunction('DISPLAYTITLE', pageTitle)
else
name = name .. ' \\Italic title\\ ' .. pageTitle -- for testing and debugging
end
end
return name
end
 
-- =============================================================================
-- =============================================================================
function p.infraspeciesboxName(frame)
local name = frame.args[1] or ''
local genus = frame.args[2] or ''
local species = frame.args[3] or ''
local ct = frame.args[4] or ''
local infraspecies = frame.args[5] or ''
local basePageTitle = frame.args[6] or ''
local italicTitle = frame.args[7] or ''
return l.doinfraspeciesboxName(name, genus, species, ct, infraspecies, basePageTitle, italicTitle)
end
function l.doinfraspeciesboxName(name, genus, species, ct, infraspecies, basePageTitle, italicTitle)
genus = mw.ustring.gsub(mw.ustring.gsub(genus, '%s+%b()$', '', 1), '/.*$', '', 1) -- strip any disambig and qualifier
local taxon = genus .. ' ' .. species
if ct == '' then taxon = taxon .. ' ' .. infraspecies
else taxon = taxon .. ' ' .. ct .. ' ' .. infraspecies
end
local italicizeP = italicTitle ~= 'no' and (basePageTitle == taxon) -- use basePageTitle to match taxon
-- deal with taxobox name (i.e. its caption)
if name == '' then
name = basePageTitle
if italicizeP then name = TaxonItalics.italicizeTaxonName(name, false, false) end
end
-- deal with page title
if italicizeP then
local pageTitle = mw.title.getCurrentTitle().text -- formatting the page title with DISPLAYTITLE needs the full page title
pageTitle = TaxonItalics.italicizeTaxonName(pageTitle, false, false, true) -- format pageTitle, not italicizing any parenthesized term
if italicTitle ~= 'test' then
mw.getCurrentFrame():callParserFunction('DISPLAYTITLE', pageTitle)
else
name = name .. ' \\Italic title\\ ' .. pageTitle -- for testing and debugging
end
end
return name
end