Module:Autotaxobox: திருத்தங்களுக்கு இடையிலான வேறுபாடு
No edit summary |
No edit summary அடையாளம்: Reverted |
||
வரிசை 1: | வரிசை 1: | ||
--[[************************************************************************* |
|||
This module provides support to the automated taxobox system – the templates |
|||
Automatic taxobox, Speciesbox, Subspeciesbox, Infraspeciesbox, etc. |
|||
In particular it provides a way of traversing the taxonomic hierarchy encoded |
|||
in taxonomy templates (templates with names of the form |
|||
"Template:Taxonomy/TAXON_NAME") without causing template expansion depth |
|||
errors. |
|||
*****************************************************************************]] |
|||
require('strict') |
require('strict') |
||
local TaxonItalics = require('Module:TaxonItalics') |
local TaxonItalics = require('Module:TaxonItalics') |
||
local |
local Autotaxobox = require('Module:Autotaxobox') |
||
local |
local ItalicTitle = require('Module:Italic title') |
||
local p = {} -- functions made public |
local p = {} -- functions made public |
||
local l = {} -- internal functions |
local l = {} -- nonpublic internal functions and variables global to the module |
||
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 |
|||
Limit the maximum depth of a taxonomic hierarchy that can be traversed; |
|||
-- template for details. |
|||
avoids excessive processing time and protects against incorrectly set up |
|||
-- The only difference from Template:Automatic taxobox is in the taxobox colour |
|||
hierarchies, e.g. loops. |
|||
-- and classification link and the parameters for type species and genera. |
|||
The value can be obtained externally via |
|||
-- ============================================================================= |
|||
{{#invoke:Autotaxobox|getMaxSearchLevels}} |
|||
=============================================================================]] |
|||
local MaxSearchLevels = 100 |
|||
function p. |
function p.ichnobox(frame) |
||
l.system = 'ichnos' |
|||
return MaxSearchLevels |
|||
return p.automaticTaxobox(frame) |
|||
end |
end |
||
-- |
-- ============================================================================= |
||
-- oobox implements Template:Oobox; see the documentation of that |
|||
Determines the correct colour for a taxobox, by searching up the taxonomic |
|||
-- template for details. |
|||
hierarchy from the supplied taxon for the first taxon (other than |
|||
-- The only difference from Template:Automatic taxobox is in the taxobox colour |
|||
'incertae sedis') that sets a taxobox colour. It is assumed that a valid |
|||
-- and classification link and the parameters for type species and genera. |
|||
taxobox colour is defined using CSS rgb() syntax. |
|||
-- ============================================================================= |
|||
If no taxon that sets a taxobox colour is found, then 'transparent' is |
|||
returned unless the taxonomic hierarchy is too deep, when the error colour is |
|||
returned. |
|||
Usage: {{#invoke:Autotaxobox|taxoboxColour|TAXON}} |
|||
=============================================================================]] |
|||
function p.taxoboxColour(frame) |
|||
return p.getTaxoboxColour(frame, frame.args[1] or '') |
|||
end |
|||
function p. |
function p.oobox(frame) |
||
l.system = 'veterovata' |
|||
-- note that colour is global to this function; default is empty string |
|||
return p.automaticTaxobox(frame) |
|||
local i = 1 -- count levels processed |
|||
local searching = currTaxon ~= '' -- still searching for a colour? |
|||
local foundICTaxon = false -- record whether 'incertae sedis' found |
|||
while searching and i <= MaxSearchLevels do |
|||
local plainCurrTaxon, dummy = l.stripExtra(currTaxon) -- remove trailing text after / |
|||
if string.lower(plainCurrTaxon) == 'incertae sedis' then |
|||
foundICTaxon = true |
|||
else |
|||
local possibleColour = frame:expandTemplate{ title = 'வார்ப்புரு:Taxobox colour', args = { plainCurrTaxon } } |
|||
if string.sub(possibleColour,1,3) == 'rgb' then |
|||
colour = possibleColour |
|||
searching = false |
|||
end |
|||
end |
|||
if searching then |
|||
local ok, parent = p.getTaxonInfoItem(frame, currTaxon, 'parent') |
|||
if ok and parent ~= '' then |
|||
currTaxon = parent |
|||
i = i + 1 |
|||
else |
|||
searching = false -- run off the top of the hierarchy or tried to use non-existent taxonomy template |
|||
end |
|||
end |
|||
end |
|||
if colour == '' then |
|||
if foundICTaxon then |
|||
colour = frame:expandTemplate{ title = 'வார்ப்புரு:Taxobox colour', args = { 'incertae sedis' } } |
|||
elseif searching then |
|||
-- hierarchy exceeds MaxSearchLevels levels |
|||
colour = frame:expandTemplate{ title = 'வார்ப்புரு:Taxobox/Error colour', args = { } } |
|||
else |
|||
colour = 'transparent' |
|||
end |
|||
end |
|||
return colour |
|||
end |
end |
||
-- |
-- ============================================================================= |
||
-- automaticTaxobox implements Template:Automatic taxobox; see the documentation |
|||
Defines the correct top level taxa, one of which should terminate every |
|||
-- of that template for details. |
|||
taxonomic hierarchy encoded in taxonomy templates. |
|||
-- It also implements Template:Ichnobox and Template:Oobox. The small |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
-- differences are signalled by the module-wide variable l.system. |
|||
function l.topLevelTaxon(taxon) |
|||
-- The following parameters present in the old template code version of |
|||
return taxon == 'Life' or taxon == 'Veterovata' or taxon == 'Ichnos' |
|||
-- Template:Automatic taxobox were not used and have not been implemented: |
|||
end |
|||
-- image_caption_align |
|||
-- image2_caption_align |
|||
-- binomial2 |
|||
-- binomial2_authority |
|||
-- binomial3 |
|||
-- binomial3_authority |
|||
-- binomial4 |
|||
-- binomial4_authority |
|||
-- ============================================================================= |
|||
function p.automaticTaxobox(frame) |
|||
--[[=========================== taxoboxList ================================= |
|||
local args |
|||
Returns the rows of taxa in an automated taxobox, based on the taxonomic |
|||
if frame.args['direct'] == 'yes' then args = frame.args |
|||
hierarchy for the supplied taxon. |
|||
else args = frame:getParent().args end |
|||
Usage: |
|||
local res = '' |
|||
{{#invoke:Autotaxobox|taxoboxList|TAXON |
|||
-- --------------------------------------------------------------------- |
|||
|display_taxa = the number of taxa *above* TAXON to force to be displayed |
|||
-- pick up taxobox parameters from the caller that need to be processed; |
|||
|authority = taxonomic authority for TAXON |
|||
-- most will be passed on unchanged |
|||
|parent_authority = taxonomic authority for TAXON's parent |
|||
-- --------------------------------------------------------------------- |
|||
|gparent_authority = taxonomic authority for TAXON's grandparent |
|||
local pagename = args['pagename'] or '' -- for testing and debugging only |
|||
|ggparent_authority = taxonomic authority for TAXON's greatgrandparent |
|||
local italicTitle = args['italic_title'] or args['italic title'] or '' |
|||
|ggparent_authority = taxonomic authority for TAXON's greatgreatgrandparent |
|||
local ichnos = '' |
|||
|bold_first = 'bold' to bold TAXON in its row |
|||
if l.system == 'ichnos' then ichnos = 'true' end |
|||
|virus = 'yes' to apply virus taxa italicization standards |
|||
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 '' |
|||
function p.taxoboxList(frame) |
|||
local oldestFossil = args['oldest_fossil'] or args['oldest fossil'] or '' |
|||
local youngestFossil = args['youngest_fossil'] or args['youngest fossil'] or '' |
|||
if currTaxon == '' then return '' end |
|||
local |
local name = args['name'] or '' |
||
local colourAs = args['color_as'] or args['color as'] or args['colour_as'] or args['colour as'] or '' |
|||
local authTable = {} |
|||
local taxon = args['taxon'] or '' |
|||
local authority = args['authority'] or '' |
|||
local parentAuthority = args['parent_authority'] or args['parent authority'] or '' |
|||
authTable[3] = frame.args['gparent_authority'] or '' |
|||
local subdivision = args['subdivision'] or '' |
|||
local subdivisionRef = args['subdivision_ref'] or args['subdivision ref'] or '' |
|||
local |
local subdivisionRanks = args['subdivision_ranks'] or args['subdivision ranks'] or '' |
||
local |
local manualFlag = 'text' -- marks manually specified ranks |
||
local |
local binomial = args['binomial'] or args['binomial_'..manualFlag] or args['binomial '..manualFlag] or '' |
||
local binomialAuthority = args['binomial_authority'] or args['binomial authority'] or '' |
|||
-- adjust the authority table if 'authority' refers to a rank lower than the target taxon |
|||
local genusManual = args['genus_'..manualFlag] or args['genus '..manualFlag] or'' |
|||
if offset ~= 0 then |
|||
local speciesManual = args['species_'..manualFlag] or args['species '..manualFlag] or'' |
|||
for i = 1, 5 do |
|||
-- ------------------------------------------------------ |
|||
local j = i + offset |
|||
-- set the taxobox parameters determined by this function |
|||
if j <= 5 then |
|||
-- ------------------------------------------------------ |
|||
authTable[i] = authTable[j] |
|||
fossilRange = l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil) |
|||
else |
|||
-- use the base page name as the taxon if the taxon parameter is missing |
|||
authTable[i] = '' |
|||
local currentPagename = mw.title.getCurrentTitle() |
|||
end |
|||
if pagename == '' then pagename = currentPagename.text end -- pagename para only used in testing and |
|||
local basePagename = pagename |
|||
if italicTitle ~= 'taxon' then basePagename = mw.ustring.gsub(basePagename, '%s+%b()$', '', 1) end |
|||
local taxonParaMissingError = false |
|||
if taxon == '' then |
|||
taxonParaMissingError = true |
|||
taxon = basePagename |
|||
end |
|||
-- decide if the page name and taxobox name need to be italicized; |
|||
-- if italic_title is not set, then if the names are the taxon, use its rank to decide |
|||
local ok, taxonRank = Autotaxobox.getTaxonInfoItem(frame, taxon, 'rank') -- taxonRank needed later if not here |
|||
if italicTitle == '' then |
|||
if not (ok and taxonRank ~= '' and |
|||
frame:expandTemplate{ title = 'Is italic taxon', args = {taxonRank} } == 'yes') then |
|||
italicTitle = 'no' |
|||
end |
end |
||
end |
end |
||
-- remove any " (DISAMBIG)" or "/MODIFIER" from the taxon's name; |
|||
local taxonTable, taxonRankTable = l.makeTable(frame, currTaxon) |
|||
-- if the base page name is the same as the base taxon name, then italicization can be applied |
|||
local res = '' |
|||
local |
local baseTaxon = taxon |
||
if italicTitle ~= 'taxon' then baseTaxon = mw.ustring.gsub(baseTaxon, '%s+%b()$', '', 1) end |
|||
-- display all taxa above possible greatgreatgrandparent, without authority |
|||
baseTaxon = mw.ustring.gsub(baseTaxon, '/.*$', '', 1) |
|||
for i = topTaxonN, 6, -1 do |
|||
if italicTitle == '' and basePagename == baseTaxon then |
|||
res = res .. l.showTaxon(frame, taxonTable[i], taxonRankTable[i], topTaxonN==i, '', displayN >= i, '', virus) |
|||
italicTitle = 'yes' |
|||
end |
end |
||
-- italicize the page name (page title) if required |
|||
-- display all taxa above possible parent, with authority if given |
|||
if currentPagename.namespace == 0 and (italicTitle == 'yes' or italicTitle == 'taxon') then |
|||
for i = math.min(topTaxonN, 5), 2, -1 do |
|||
if italicTitle == 'taxon' or TaxonItalics.hasConnectingTerm(baseTaxon) then |
|||
res = res .. l.showTaxon(frame, taxonTable[i], taxonRankTable[i], topTaxonN==i, authTable[i], displayN >= i, '', virus) |
|||
res = res .. frame:expandTemplate{ title = 'Italic taxon title', args = {} } |
|||
italicTitle = 'yes' |
|||
else ItalicTitle._main({}) |
|||
end |
|||
end |
end |
||
-- set the taxobox name if not supplied, italicizing it if appropriate. |
|||
-- display target taxon, always displayed and emboldened |
|||
if name == '' then |
|||
res = res .. l.showTaxon(frame, taxonTable[1], taxonRankTable[1], topTaxonN==1, authTable[1], true, boldFirst, virus) |
|||
name = basePagename |
|||
return res |
|||
if italicTitle == 'yes' then |
|||
end |
|||
name = TaxonItalics.italicizeTaxonName(name, false, false) |
|||
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = |
|||
Show one taxon row in a taxobox. |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.showTaxon(frame, taxon, rank, isTopTaxon, auth, force, boldFirst, virus) |
|||
-- it's an error if this is the top taxon and it's not a top level taxon (e.g. "Life") |
|||
if isTopTaxon then |
|||
if l.topLevelTaxon(taxon) then |
|||
return '' -- don't display a top level taxon |
|||
elseif (mw.title.new('Taxonomy/'..taxon, 'வார்ப்புரு') or {}).exists then |
|||
-- taxonomy template for this taxon has no parent specified |
|||
return frame:expandTemplate{ title = 'வார்ப்புரு:Create taxonomy', args = {taxon, msg='Taxonomy template does not specify a parent'} } .. '\n' .. TableRow |
|||
else |
|||
-- no taxonomy template for this taxon |
|||
return frame:expandTemplate{ title = 'வார்ப்புரு:Create taxonomy', args = {taxon, msg='Missing taxonomy template'} } .. '\n' .. TableRow |
|||
end |
end |
||
-- name = name .. '/' .. baseTaxon .. '/' .. nameRank |
|||
end |
|||
-- determine taxobox colour |
|||
local colour = '' |
|||
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 |
else |
||
colour = Autotaxobox.getTaxoboxColour(frame, taxon) |
|||
-- if showing is not already forced, force if it's a principal rank or an authority is specified |
|||
force = force or frame:expandTemplate{ title = 'வார்ப்புரு:Principal rank', args = {rank} } == 'yes' or |
|||
auth ~= '' |
|||
if not force then |
|||
-- if showing is still not already forced, force if the taxonomy template has 'always_display' set |
|||
local ok, alwaysDisplay = p.getTaxonInfoItem(frame, taxon, 'always_display') |
|||
force = alwaysDisplay == 'yes' or alwaysDisplay == 'true' |
|||
end |
|||
if force then |
|||
local res = l.tableCell(frame:expandTemplate{ title = 'வார்ப்புரு:Anglicise rank', args = {rank} } .. ':') |
|||
local bold = 'no' |
|||
if boldFirst == 'bold' then bold = 'yes' end |
|||
if auth ~= '' then |
|||
auth = '<br><small>' .. auth .. '</small>' |
|||
end |
|||
local res = res .. l.tableCell(l.getTaxonLink(frame, taxon, rank, bold, '', '', virus) .. auth) -- italic, abbreviated |
|||
return res .. TableRow |
|||
else |
|||
return '' |
|||
end |
|||
end |
end |
||
-- fill in a missing subdivision_ranks parameter |
|||
end |
|||
if subdivision ~= '' and subdivisionRanks == '' and ok and taxonRank ~= '' then |
|||
subdivisionRanks = frame:expandTemplate{ title = 'Children rank', args = {taxonRank} } |
|||
--[[========================== taxonomyList ================================= |
|||
Returns the cells of the taxonomy table displayed on the right hand side of |
|||
"Template:Taxonomy...." pages. |
|||
Usage: {{#invoke:Autotaxobox|taxonomyList|TAXON}} |
|||
=============================================================================]] |
|||
function p.taxonomyList(frame) |
|||
local currTaxon = frame.args[1] or '' |
|||
if currTaxon == '' then |
|||
return '{|class="infobox biota"\n' .. TableRow .. l.tableCell('') .. l.tableCell('ERROR: no taxon supplied') .. TableEnd |
|||
end |
end |
||
-- set binomial parameters if the target taxon is (unusually) a species |
|||
local taxonTable, taxonRankTable = l.makeTable(frame, currTaxon) |
|||
local |
local genusAuthority = '' |
||
if binomial == '' then |
|||
local lastRankVal = 1000000 |
|||
if ok and taxonRank == 'species' then |
|||
local orderOk = true |
|||
binomial = TaxonItalics.italicizeTaxonName(taxon, false, false) |
|||
-- check whether the taxonomy is for viruses; use already determined taxon colour if possible |
|||
binomialAuthority = authority |
|||
local virus = 'no' |
|||
local taxoColour = colour |
|||
if taxoColour == '' then |
|||
if taxonTable[taxonTable.n] == 'Ichnos' or taxonTable[taxonTable.n] == 'Veterovata' then |
|||
taxoColour = frame:expandTemplate{ title = 'வார்ப்புரு:Taxobox colour', args = { taxonTable[taxonTable.n] } } |
|||
else |
|||
taxoColour = frame:expandTemplate{ title = 'வார்ப்புரு:Taxobox colour', args = { taxonTable[taxonTable.n - 1] } } |
|||
end |
end |
||
end |
end |
||
-- handle any manually set ranks |
|||
if taxoColour == frame:expandTemplate{ title = 'வார்ப்புரு:Taxobox colour', args = { 'virus' } } then |
|||
local boldFirst = '' |
|||
local offset = 0 |
|||
end |
|||
if speciesManual ~= '' then |
|||
-- add information message |
|||
offset = offset + 1 |
|||
local res = '<p style="float:right">Bold ranks show taxa that will be shown in taxoboxes<br>because rank is principal or <code>always_display=yes</code>.</p>\n' |
|||
binomialAuthority = authority |
|||
if binomial == '' then binomial = '<span class="error">Error: binomial parameter value is missing</span>' end |
|||
-- start table |
|||
res = res .. '{| class="infobox biota" style="text-align: left; font-size:100%"\n' .. TableRow .. '! colspan=4 style="text-align: center; color:inherit; background-color: ' |
|||
.. taxoColour .. '"|Ancestral taxa\n' |
|||
-- deal first with the top level taxon; if there are no errors, it should be Life/Veterovata/Ichnos, which are |
|||
-- not displayed |
|||
local taxon = taxonTable[taxonTable.n] |
|||
if not l.topLevelTaxon(taxon) then |
|||
local msg = 'Taxonomy template missing' |
|||
if mw.title.new('Taxonomy/'..taxon, 'வார்ப்புரு').exists then |
|||
msg = 'Parent taxon needed' |
|||
end |
|||
res = res .. TableRow .. l.tableCell('colspan=2', frame:expandTemplate{title = 'வார்ப்புரு:Create taxonomy', args = {taxon, msg = msg}}) |
|||
end |
end |
||
if genusManual ~= '' then |
|||
-- now output the rest of the table |
|||
boldFirst = 'link' |
|||
local currRankVal |
|||
offset = offset + 1 |
|||
for i = taxonTable.n-1, 1, -1 do |
|||
if offset == 1 then |
|||
-- check ranks are in right order in the hierarchy |
|||
genusAuthority = authority |
|||
taxon = taxonTable[i] |
|||
local rank = taxonRankTable[i] |
|||
currRankVal = l.lookupRankVal(rankValTable, rank) |
|||
if currRankVal then |
|||
orderOk = currRankVal < lastRankVal |
|||
if orderOk then lastRankVal = currRankVal end |
|||
else |
else |
||
genusAuthority = parentAuthority |
|||
orderOk = true |
|||
end |
end |
||
-- see if the row will be displayed in a taxobox; bold the rank if so |
|||
local boldRank = false |
|||
local ok, alwaysDisplay = p.getTaxonInfoItem(frame, taxon, 'always_display') |
|||
if ok and (alwaysDisplay == 'yes' or alwaysDisplay == 'true') then |
|||
boldRank = true |
|||
else |
|||
boldRank = frame:expandTemplate{ title = 'வார்ப்புரு:Principal rank', args = {rank} } == 'yes' |
|||
end |
|||
-- now return a row of the taxonomy table with anomalous ranks marked |
|||
local errorStr = '' |
|||
if not orderOk then errorStr = 'yes' end |
|||
local link = l.getTaxonLink(frame, taxon, rank, '', '', '', virus) -- bold, italic, abbreviated |
|||
res = res .. l.taxonomyListRow(frame, taxon, rank, link, boldRank, errorStr) |
|||
end |
end |
||
-- process type genus and type species if present; italicize if they seem not to have an authority attached |
|||
-- close table |
|||
local typeGenus = '' |
|||
res = res .. TableEnd |
|||
local typeGenusAuthority = '' |
|||
-- error-tracking for taxonomy templates |
|||
local typeSpecies = '' |
|||
-- if the last row has an anomalous rank, put the page in an error-tracking category |
|||
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 |
|||
-- ------------------------------------------------ |
|||
res = res .. frame:expandTemplate{ title = 'Taxobox/core', args = |
|||
{ ichnos = 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 = parentAuthority, |
|||
grandparent_authority = args['grandparent_authority'] or args['grandparent authority'] or '', |
|||
greatgrandparent_authority = args['greatgrandparent_authority'] or args['greatgrandparent authority'] or '', |
|||
greatgreatgrandparent_authority = args['greatgreatgrandparent_authority'] or args['greatgreatgrandparent authority'] or '', |
|||
name = name, |
|||
colour = colour, |
|||
status = args['status'] or '', |
|||
status_system = args['status_system'] or args['status system'] or '', |
|||
status_ref = args['status_ref'] or args['status ref'] or '', |
|||
status2 = args['status2'] or '', |
|||
status2_system = args['status2_system'] or args['status2 system'] or '', |
|||
status2_ref = args['status2_ref'] or args['status2 ref'] or '', |
|||
trend = args['trend'] or '', |
|||
extinct = args['extinct'] or '', |
|||
image = args['image'] or '', |
|||
upright = args['image_upright'] or args['image upright'] or '', |
|||
image_alt = args['image_alt'] or args['image alt'] or '', |
|||
image_caption = args['image_caption'] or args['image caption'] or '', |
|||
image2 = args['image2'] or '', |
|||
upright2 = args['image2_upright'] or args['image2 upright'] or '', |
|||
image2_alt = args['image2_alt'] or args['image2 alt'] or '', |
|||
image2_caption = args['image2_caption'] or args['image2 caption'] or '', |
|||
classification_status = args['classification_status'] or args['classification status'] or '', |
|||
diversity = args['diversity'] or '', |
|||
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 = typeGenus, |
|||
type_genus_authority = typeGenusAuthority, |
|||
type_species = typeSpecies, |
|||
type_species_authority = 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 '', |
|||
range_map_alt = args['range_map_alt'] or args['range map alt'] or '', |
|||
range_map_caption = args['range_map_caption'] or args['range map caption'] or '', |
|||
range_map2 = args['range_map2'] or args['range map2'] or '', |
|||
range_map2_upright = args['range_map2_upright'] or args['range map2 upright'] or '', |
|||
range_map2_alt = args['range_map2_alt'] or args['range map2 alt'] or '', |
|||
range_map2_caption = args['range_map2_caption'] or args['range map2 caption'] or '', |
|||
range_map3 = args['range_map3'] or args['range map3'] or '', |
|||
range_map3_upright = args['range_map3_upright'] or args['range map3 upright'] or '', |
|||
range_map3_alt = args['range_map3_alt'] or args['range map3 alt'] or '', |
|||
range_map3_caption = args['range_map3_caption'] or args['range map3 caption'] or '', |
|||
range_map4 = args['range_map4'] or args['range map4'] or '', |
|||
range_map4_upright = args['range_map4_upright'] or args['range map4 upright'] or '', |
|||
range_map4_alt = args['range_map4_alt'] or args['range map4 alt'] or '', |
|||
range_map4_caption = args['range_map4_caption'] or args['range map4 caption'] or '', |
|||
synonyms_ref = args['synonyms_ref'] or args['synonyms ref'] or '', |
|||
synonyms = args['synonyms'] or '' |
|||
} } |
|||
-- put page in error-tracking categories if required |
|||
local errCat1 = '' |
local errCat1 = '' |
||
if genusManual ~= '' or speciesManual ~= '' or binomial ~= '' then errCat1 = '[[Category:Automatic taxoboxes using manual parameters]]' end |
|||
if not orderOk then |
|||
errCat1 = '[[பகுப்பு:Taxonomy templates showing anomalous ranks]]\n' |
|||
end |
|||
-- if the last row has a taxon name in the page name that does not match the link text, |
|||
-- put the taxonomy template in a tracking category |
|||
local dummy, linkText = p.getTaxonInfoItem(frame, taxon, 'link_text') |
|||
local match = l.matchTaxonLink(taxon, linkText, currRankVal and currRankVal < rankValTable['genus']) |
|||
local errCat2 = '' |
local errCat2 = '' |
||
if taxonParaMissingError then errCat2 = '[[Category:Automatic taxoboxes relying on page title]]' end |
|||
if not match then |
|||
res = res .. frame:expandTemplate{ title = 'Main other', args = {errCat1..errCat2} } |
|||
errCat2 = '[[பகுப்பு:Taxonomy templates with name and link text not matching|' .. taxon .. ']]\n' |
|||
end |
|||
if errCat1..errCat2 ~= '' then |
|||
res = res .. frame:expandTemplate{ title = 'Template other', args = { errCat1..errCat2} } |
|||
end |
|||
return res |
return res |
||
end |
end |
||
-- |
-- ============================================================================= |
||
-- l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil) checks |
|||
Returns a single row of the taxonomy table displayed on the right hand side |
|||
-- the parameters that determine the fossil range, returning an appropriate |
|||
of "Template:Taxonomy...." pages. |
|||
-- range. |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
-- ============================================================================= |
|||
function l.taxonomyListRow(frame, taxon, rank, link, boldRank, error) |
|||
-- temporary public function for debugging |
|||
local res = '' |
|||
function p.chkFossilRange(frame) |
|||
if taxon == '' or rank == '' then return res end |
|||
local |
local args = frame.args |
||
local fossilRange = args['temporal_range'] or args['temporal range'] or args['fossil_range'] or args['fossil range'] or '' |
|||
-- if appropriate, make it clear that some taxa have been skipped via a ... row |
|||
local oldestFossil = args['oldest_fossil'] or args['oldest fossil'] or '' |
|||
if qualifier == '/skip' then |
|||
local youngestFossil = args['youngest_fossil'] or args['youngest fossil'] or '' |
|||
res = res .. TableRow .. l.tableCell('.....') .. l.tableCell('.....') |
|||
local fossilRange = l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil) |
|||
end |
|||
return fossilRange |
|||
-- now generate a row of the table |
|||
res = res .. TableRow |
|||
local cellContent = '' |
|||
local anglicizedRank = frame:expandTemplate{ title = 'வார்ப்புரு:Anglicise rank', args = { rank } } |
|||
if boldRank then |
|||
cellContent = cellContent .. '<b>' .. anglicizedRank .. '</b>:' |
|||
else |
|||
cellContent = cellContent .. anglicizedRank .. ':' |
|||
end |
|||
if error == 'yes' then |
|||
cellContent = '<span style="background-color:#FDD">' .. cellContent .. '</span>' |
|||
end |
|||
res = res .. l.tableCell(cellContent) |
|||
.. l.tableCell('<span style="white-space:nowrap;">' .. link .. '</span>') |
|||
.. l.tableCell('<span style="font-size:smaller;">' .. qualifier .. '</span>') |
|||
.. l.tableCell('<span style="white-space:nowrap;">' .. frame:expandTemplate{ title = 'வார்ப்புரு:Edit a taxon', args = { taxon } } .. '</span>') |
|||
return res |
|||
end |
end |
||
function l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil) |
|||
--[[========================= callTaxonomyKey =============================== |
|||
local res = '' |
|||
Prepares for, and then calls, Template:Taxonomy key to display a taxonomy |
|||
if fossilRange ~= '' then |
|||
template page. It does this by building up the information the template |
|||
if mw.ustring.find(frame:expandTemplate{ title = 'Period start', args = { fossilRange } }, '[Ee]rror') then |
|||
requires, following one 'same as' link, if required. |
|||
res = fossilRange |
|||
Usage: |
|||
else |
|||
{{#invoke:Autotaxobox|callTaxonomyKey |
|||
res = frame:expandTemplate{ title = 'Geological range', args = { fossilRange } } |
|||
|parent= |
|||
end |
|||
|rank= |
|||
elseif oldestFossil ~= '' then |
|||
|extinct= |
|||
if youngestFossil == '' then youngestFossil = 'Recent' end |
|||
|always_display= |
|||
if mw.ustring.find(frame:expandTemplate{ title = 'Period start', args = { oldestFossil } }, '[Ee]rror') or |
|||
|link_target=value of 'link' parameter in taxonomy template |
|||
mw.ustring.find(frame:expandTemplate{ title = 'Period start', args = { youngestFossil } }, '[Ee]rror') then |
|||
|link_text=value of parameter 2 in taxonomy template |
|||
res = oldestFossil..'–'..youngestFossil |
|||
|same_as= |
|||
}} |
|||
=============================================================================]] |
|||
local PARENT = 1 |
|||
local RANK = 2 |
|||
local LINK_TARGET = 3 |
|||
local LINK_TEXT = 4 |
|||
local ALWAYS_DISPLAY = 5 |
|||
local EXTINCT = 6 |
|||
local SAME_AS = 7 |
|||
local REFS = 8 |
|||
function p.callTaxonomyKey(frame) |
|||
local taxon = frame.args['taxon'] or '' |
|||
local parent = frame.args['parent'] or '' |
|||
local rank = frame.args['rank'] or '' |
|||
local extinct = string.lower(frame.args['extinct']) or '' |
|||
local alwaysDisplay = string.lower(frame.args['always_display']) or '' |
|||
local linkTarget = frame.args['link_target'] or '' |
|||
local linkText = frame.args['link_text'] or '' -- this is the "raw" link text, and can be '' |
|||
local refs = frame.args['refs'] or '' |
|||
local sameAsTaxon = frame.args['same_as'] or '' |
|||
if sameAsTaxon ~= '' then |
|||
-- try using the 'same as' taxon; it's an error if it doesn't exist |
|||
local ok, sameAsInfoStr = pcall(frame.expandTemplate, frame, { title = 'வார்ப்புரு:Taxonomy/' .. sameAsTaxon, args = {['machine code'] = 'all' } }) |
|||
if ok then |
|||
local sameAsInfo = mw.text.split(sameAsInfoStr, '$', true) |
|||
--'same as' taxon's taxonomy template must not have a 'same as' link |
|||
if sameAsInfo[SAME_AS] == '' then |
|||
if parent == '' then parent = sameAsInfo[PARENT] end |
|||
if rank == '' then rank = sameAsInfo[RANK] end |
|||
if extinct == '' then extinct = string.lower(sameAsInfo[EXTINCT]) end |
|||
if alwaysDisplay == '' then alwaysDisplay = string.lower(sameAsInfo[ALWAYS_DISPLAY]) end |
|||
if linkTarget == '' then linkTarget = sameAsInfo[LINK_TARGET] end |
|||
if linkText == '' then linkText = sameAsInfo[LINK_TEXT] end |
|||
if refs == '' and parent == sameAsInfo[PARENT] then refs = sameAsInfo[REFS] end |
|||
else |
|||
return '<span style="color:red; font-size:1.1em">Error: attempt to follow two "same as" links</span>: <code>same_as = ' .. sameAsTaxon .. '</code>, but [[Template:Taxonomy/' .. sameAsTaxon .. ']] also has a<code>same_as</code> parameter.' |
|||
end |
|||
else |
else |
||
res = frame:expandTemplate{ title = 'Geological range', args = { oldestFossil, youngestFossil } } |
|||
end |
end |
||
end |
end |
||
return res |
|||
local link = linkTarget |
|||
if linkText ~= '' and linkText ~= linkTarget then link = link .. "|" .. linkText end |
|||
-- check consistency of extinct status; if this taxon is not extinct, parent must not be either |
|||
local extinctError = 'no' |
|||
if parent ~= '' and (extinct == '' or extinct == 'no' or extinct == 'false') then |
|||
local ok, parentExtinct = p.getTaxonInfoItem(frame, parent, 'extinct') |
|||
if ok and (parentExtinct == 'yes' or parentExtinct == 'true') then extinctError = 'yes' end |
|||
end |
|||
return frame:expandTemplate{ title = 'வார்ப்புரு:Taxonomy key', |
|||
args = {taxon=taxon, parent=parent, rank=rank, extinct=extinct, always_display=alwaysDisplay, link_target=linkTarget, link=link, refs=refs, same_as=sameAsTaxon, extinct_error = extinctError} } |
|||
end |
end |
||
-- |
-- ============================================================================= |
||
-- l.italicizeTypeName(typeName) checks whether the name of a type genus or |
|||
Shows the refs field in a taxonomy template, handing incertae sedis taxa and |
|||
-- species should be italicized, because it appears to be a bare name. |
|||
using '–' for absent refs. |
|||
-- ============================================================================= |
|||
Usage: {{#invoke:Autotaxobox|showRefs|TAXON|REFS}} |
|||
=============================================================================]] |
|||
function p.showRefs(frame) |
|||
local taxonName = frame.args[1] or '' |
|||
local refs = frame.args[2] or '' |
|||
return l.doShowRefs(taxonName, refs) |
|||
end |
|||
function l.italicizeTypeName(typeName) |
|||
--[[= = = = = = = = = = = = = = doShowRefs = = = = = = = = = = = = = = = = = |
|||
if typeName and not (string.find(typeName, "<", 1, true) or string.find(typeName, ">", 1, true)) then |
|||
Show the refs field in a taxonomy template. |
|||
typeName = TaxonItalics.italicizeTaxonName(typeName, false, false) |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.doShowRefs(taxonName, refs) |
|||
if mw.text.split(taxonName, '/', true)[1] == 'Incertae sedis' then |
|||
refs = 'not applicable (<i>incertae sedis</i>)' |
|||
elseif refs == '' then |
|||
refs = '–' |
|||
end |
end |
||
return |
return typeName |
||
end |
end |
||
-- **************************** Speciesbox support ***************************** |
|||
--[[============================ taxonInfo ================================== |
|||
Extracts and returns information from Template:Taxonomy/TAXON, following |
|||
one 'same as' link if required. |
|||
Usage: {{#invoke:Autotaxobox|taxonInfo|TAXON|ITEM}} |
|||
ITEM is one of: 'parent', 'rank', 'link target', 'link text', 'extinct', |
|||
'always display', 'refs', 'same as' or 'all'. |
|||
If ITEM is not specified, the default is 'all' – all values in a single string |
|||
separated by '$'. |
|||
=============================================================================]] |
|||
function p.taxonInfo(frame) |
|||
local taxon = frame.args[1] or '' |
|||
local item = frame.args[2] or '' |
|||
if item == '' then item = 'all' end |
|||
local ok, info = p.getTaxonInfoItem(frame, taxon, item) |
|||
return info |
|||
end |
|||
-- |
-- ============================================================================= |
||
-- l.genusOf(str) extracts the genus from a string. Normally this will be the |
|||
Utility function to extract an item of information from a |
|||
-- first word of the string (e.g. given 'Bellis perennis' it returns 'Bellis'). |
|||
taxonomy template, following one 'same as' link if required. |
|||
-- It also handles a string containing a nothogenus with a spaced × (e.g. given |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
-- '× Heucherella tiarelloides' it returns '× Heucherella'). |
|||
function p.getTaxonInfoItem(frame, taxon, item) |
|||
-- ============================================================================= |
|||
local ok, info |
|||
-- item == 'dagger' is a special case |
|||
function l.genusOf(str) |
|||
if item == 'dagger' then |
|||
local res = mw.ustring.match(str, '^[^%s]*', 1) |
|||
ok, info = p.getTaxonInfoItem(frame, taxon, 'extinct') |
|||
if res == mw.ustring.char(215) then |
|||
res = res .. ' ' .. mw.ustring.match(str, '^[^%s]*', 3) |
|||
if info == 'yes' or info == 'true' then |
|||
info = '†' |
|||
else |
|||
info = '' |
|||
end |
|||
end |
|||
-- item ~= 'dagger' |
|||
else |
|||
ok, info = pcall(frame.expandTemplate, frame, { title = 'வார்ப்புரு:Taxonomy/' .. taxon, args = {['machine code'] = item } }) |
|||
if ok then |
|||
if info == '' then |
|||
-- try 'same as' |
|||
local sameAsTaxon = frame:expandTemplate{ title = 'வார்ப்புரு:Taxonomy/' .. taxon, args = {['machine code'] = 'same as' } } |
|||
if sameAsTaxon ~= '' then |
|||
ok, info = pcall(frame.expandTemplate, frame, { title = 'வார்ப்புரு:Taxonomy/' .. sameAsTaxon, args = {['machine code'] = item } }) |
|||
end |
|||
end |
|||
end |
|||
end |
end |
||
return res |
|||
if ok then |
|||
-- if item is 'link_text', trim info and check whether '(?)' needs to be added |
|||
if item == 'link_text' then |
|||
-- there is a newline at the end of linkText when taxonomy template has "|link = LINK_TARGET|LINK_TEXT" |
|||
info = mw.text.trim(info) |
|||
if string.sub(taxon, -2) == '/?' and not string.find(info, '?', 1, true) then |
|||
info = info .. '<span style="font-style:normal;font-weight:normal;"> (?)</span>' |
|||
end |
|||
end |
|||
else |
|||
info = '[[வார்ப்புரு:Taxonomy/' .. taxon .. ']]' --error indicator in code before conversion to Lua |
|||
end |
|||
return ok, info |
|||
end |
end |
||
-- |
-- ============================================================================= |
||
-- l.doSpeciesboxName(name, taxon, genus, species, basePageTitle, italicTitle) |
|||
Returns a wikilink to a taxon, if required including '†' before it and |
|||
-- returns a name for a taxobox created by Template:Speciesbox. The name will be |
|||
' (?)' after it, and optionally italicized or bolded without a wikilink. |
|||
-- italicized if appropriate. It also generates code to italicize the page title |
|||
Usage: |
|||
-- if appropropriate. In both cases the test for italicization is that the base |
|||
{{#invoke:Autotaxobox|taxonLink |
|||
-- taxon name (stripped of any disambiguation or qualifier) is the same as the |
|||
|taxon= : having '/?' at the end triggers the output of ' (?)' |
|||
-- base page title. |
|||
|extinct= : 'yes' or 'true' trigger the output of '†' |
|||
-- ============================================================================= |
|||
|bold= : 'yes' makes the core output bold and not wikilinked |
|||
|italic= : 'yes' makes the core output italic |
|||
|link_target= : target for the wikilink |
|||
|link_text= : text of the wikilink (may be same as link_target), without †, italics, etc. |
|||
}} |
|||
=============================================================================]] |
|||
function p.taxonLink(frame) |
|||
local taxon = frame.args['taxon'] or '' |
|||
local extinct = string.lower(frame.args['extinct'] or '') |
|||
local bold = frame.args['bold'] or '' |
|||
local italic = frame.args['italic'] or '' |
|||
local abbreviated = frame.args['abbreviated'] or '' |
|||
local linkTarget = frame.args['link_target'] or '' |
|||
local linkText = frame.args['link_text'] or frame.args['plain_link_text'] or '' --temporarily allow alternative args |
|||
return l.makeLink(taxon, extinct, bold, italic, abbreviated, linkTarget, linkText) |
|||
end |
|||
function p.speciesboxName(frame) |
|||
--[[= = = = = = = = = = = = = = getTaxonLink = = = = = = = = = = = = = = = = |
|||
local name = frame.args[1] or '' |
|||
Internal function to drive l.makeLink(). |
|||
local taxon = frame.args[2] or '' |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
local genus = frame.args[3] or '' |
|||
function l.getTaxonLink(frame, taxon, rank, bold, italic, abbreviated, virus) |
|||
local |
local species = frame.args[4] or '' |
||
local basePageTitle = frame.args[5] or '' |
|||
if italic == '' then |
|||
local italicTitle = frame.args[6] or '' |
|||
italic = frame:expandTemplate{ title = 'வார்ப்புரு:Is italic taxon', args = { rank, virus = virus } } |
|||
return l.doSpeciesboxName(name, taxon, genus, species, basePageTitle, italicTitle) |
|||
end |
|||
local ok, linkTarget = p.getTaxonInfoItem(frame, taxon, 'link_target') |
|||
local ok, linkText = p.getTaxonInfoItem(frame, taxon, 'link_text') |
|||
return l.makeLink(taxon, extinct, bold, italic, abbreviated, linkTarget, linkText) |
|||
end |
end |
||
function l.doSpeciesboxName(name, taxon, genus, species, basePageTitle, italicTitle) |
|||
--[[= = = = = = = = = = = = = = makeLink = = = = = = = = = = = = = = = = = = |
|||
if taxon ~= '' then |
|||
Actually make the link. |
|||
genus = mw.ustring.gsub(l.genusOf(taxon), '/.*$', '', 1) -- strip any qualifier |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.makeLink(taxon, extinct, bold, italic, abbreviated, linkTarget, linkText) |
|||
local dummy |
|||
-- if link text is missing, try to find a replacement |
|||
if linkText == '' then |
|||
if string.find(taxon, 'Incertae sedis', 1, true) then |
|||
linkText = "''incertae sedis''" |
|||
linkTarget = 'Incertae sedis' |
|||
else |
|||
linkText, dummy = l.stripExtra(taxon) |
|||
end |
|||
end |
|||
if linkTarget == '' then linkTarget = linkText end |
|||
if italic == 'yes' then linkText = TaxonItalics.italicizeTaxonName(linkText, false, abbreviated=='yes') end |
|||
local link = '' |
|||
if bold == 'yes' then link = '<b>' .. linkText .. '</b>' |
|||
else |
else |
||
genus = mw.ustring.gsub(mw.ustring.gsub(genus, '%s+%b()$', '', 1), '/.*$', '', 1) -- strip any disambig and qualifier |
|||
if linkTarget == linkText then link = linkText |
|||
if species == '' then taxon = genus |
|||
else link = linkTarget .. '|' .. linkText |
|||
else taxon = genus .. ' ' .. species |
|||
end |
end |
||
link = '[[' .. link .. ']]' |
|||
end |
end |
||
local italicizeP = italicTitle ~= 'no' and (basePageTitle == taxon or basePageTitle == genus) -- use basePageTitle to match taxon/genus |
|||
if (extinct == 'yes' or extinct == 'true') and not string.find(link, '†', 1, true) then |
|||
-- deal with taxobox name (i.e. its caption) |
|||
link = '<span style="font-style:normal;font-weight:normal;">†</span>' .. link |
|||
if name == '' then |
|||
name = basePageTitle |
|||
if italicizeP then name = TaxonItalics.italicizeTaxonName(name, false, false) end |
|||
end |
end |
||
-- deal with page title |
|||
if string.sub(taxon, -2) == '/?' and not string.find(link, '?', 1, true) then |
|||
if italicizeP then |
|||
link = link .. '<span style="font-style:normal;font-weight:normal;"> (?)</span>' |
|||
local pageTitle = mw.title.getCurrentTitle().text -- formatting the page title with DISPLAYTITLE needs the full page title |
|||
end |
|||
if italicTitle ~= 'test' then |
|||
return link |
|||
pageTitle = TaxonItalics.italicizeTaxonName(pageTitle, false, false, true) -- format pageTitle, not italicizing any parenthesized term |
|||
end |
|||
local nsText = mw.title.getCurrentTitle().nsText -- for drafts and other pages not in mainspace |
|||
if nsText ~= '' then |
|||
--[[========================== showRankTable ================================ |
|||
pageTitle = nsText .. ':' .. pageTitle |
|||
Returns a wikitable showing the ranks and their values as set up by |
|||
getRankTable(). |
|||
Usage: {{#invoke:Autotaxobox|showRankTable}} |
|||
=============================================================================]] |
|||
function p.showRankTable(frame) |
|||
local rankTable = l.getRankTable() |
|||
local res = '{| class="wikitable sortable"\n|+ Ranks checked in taxonomy templates\n! Rank !! Shown as !! Value\n' |
|||
for k, v in pairs(rankTable) do |
|||
local rankShown = frame:expandTemplate{ title = 'வார்ப்புரு:Anglicise rank', args = { k } } |
|||
res = res .. TableRow .. l.tableCell(k) .. l.tableCell(rankShown) .. l.tableCell(v) |
|||
end |
|||
return res .. TableEnd |
|||
end |
|||
--[[============================== find ===================================== |
|||
Returns the taxon above the specified taxon with a given rank. |
|||
Usage: {{#invoke:Autotaxobox|find|TAXON|RANK}} |
|||
=============================================================================]] |
|||
function p.find(frame) |
|||
local currTaxon = frame.args[1] or '' |
|||
if currTaxon == '' then return '<span class="error">no taxon supplied</span>' end |
|||
local rank = frame.args[2] or '' |
|||
if rank == '' then return '<span class="error">no rank supplied</span>' end |
|||
local inHierarchy = true -- still in the taxonomic hierarchy or off the top? |
|||
local searching = true -- still searching |
|||
while inHierarchy and searching do |
|||
local ok, parent = p.getTaxonInfoItem(frame, currTaxon, 'parent') |
|||
if ok and parent ~= '' then |
|||
currTaxon = parent |
|||
local ok, currRank = p.getTaxonInfoItem(frame, currTaxon, 'rank') |
|||
if currRank == rank then |
|||
searching = false |
|||
end |
end |
||
mw.getCurrentFrame():callParserFunction('DISPLAYTITLE', pageTitle) |
|||
else |
else |
||
name = name .. ' \\Italic title\\ ' .. pageTitle -- for testing and debugging |
|||
inHierarchy = false |
|||
end |
end |
||
end |
end |
||
return name |
|||
if inHierarchy and not searching then return currTaxon |
|||
else return '<span class="error">rank not found</span>' |
|||
end |
|||
end |
end |
||
-- |
-- ============================================================================= |
||
-- ============================================================================= |
|||
External utility function primarily intended for use in checking and debugging. |
|||
function p.infraspeciesboxName(frame) |
|||
Returns the nth level above a taxon in a taxonomic hierarchy, where the taxon |
|||
local name = frame.args[1] or '' |
|||
itself is counted as the first level. |
|||
local genus = frame.args[2] or '' |
|||
Usage: {{#invoke:Autotaxobox|nth|TAXON|n=N}} |
|||
local species = frame.args[3] or '' |
|||
=============================================================================]] |
|||
local ct = frame.args[4] or '' |
|||
function p.nth(frame) |
|||
local infraspecies = frame.args[5] or '' |
|||
local basePageTitle = frame.args[6] or '' |
|||
if currTaxon == '' then return 'ERROR: no taxon supplied' end |
|||
local |
local italicTitle = frame.args[7] or '' |
||
return l.doinfraspeciesboxName(name, genus, species, ct, infraspecies, basePageTitle, italicTitle) |
|||
if n > MaxSearchLevels then |
|||
return 'Exceeded maximum number of levels allowed (' .. MaxSearchLevels .. ')' |
|||
end |
|||
local i = 1 |
|||
local inHierarchy = true -- still in the taxonomic hierarchy or off the top? |
|||
while i < n and inHierarchy do |
|||
local ok, parent = p.getTaxonInfoItem(frame, currTaxon, 'parent') |
|||
if ok and parent ~= '' then |
|||
currTaxon = parent |
|||
i = i + 1 |
|||
else |
|||
inHierarchy = false |
|||
end |
|||
end |
|||
if inHierarchy then return currTaxon |
|||
else return 'Level ' .. n .. ' is past the top of the taxonomic hierarchy' |
|||
end |
|||
end |
end |
||
function l.doinfraspeciesboxName(name, genus, species, ct, infraspecies, basePageTitle, italicTitle) |
|||
--[[============================= nLevels =================================== |
|||
genus = mw.ustring.gsub(mw.ustring.gsub(genus, '%s+%b()$', '', 1), '/.*$', '', 1) -- strip any disambig and qualifier |
|||
External utility function primarily intended for use in checking and debugging. |
|||
local taxon = genus .. ' ' .. species |
|||
Returns number of levels in a taxonomic hierarchy, starting from |
|||
if ct == '' then taxon = taxon .. ' ' .. infraspecies |
|||
the supplied taxon as level 1. |
|||
else taxon = taxon .. ' ' .. ct .. ' ' .. infraspecies |
|||
Usage: {{#invoke:Autotaxobox|nLevels|TAXON}} |
|||
=============================================================================]] |
|||
function p.nLevels(frame) |
|||
local currTaxon = frame.args[1] or '' |
|||
if currTaxon == '' then return 'ERROR: no taxon supplied' end |
|||
local i = 1 |
|||
local inHierarchy = true -- still in the taxonomic hierarchy or off the top? |
|||
while inHierarchy and i < MaxSearchLevels do |
|||
local ok, parent = p.getTaxonInfoItem(frame, currTaxon, 'parent') |
|||
if ok and parent ~= '' then |
|||
currTaxon = parent |
|||
i = i + 1 |
|||
else |
|||
inHierarchy = false |
|||
end |
|||
end |
end |
||
local italicizeP = italicTitle ~= 'no' and (basePageTitle == taxon) -- use basePageTitle to match taxon |
|||
if inHierarchy then return MaxSearchLevels .. '+' |
|||
-- deal with taxobox name (i.e. its caption) |
|||
else return i |
|||
if name == '' then |
|||
name = basePageTitle |
|||
if italicizeP then name = TaxonItalics.italicizeTaxonName(name, false, false) end |
|||
end |
end |
||
-- deal with page title |
|||
end |
|||
if italicizeP then |
|||
local pageTitle = mw.title.getCurrentTitle().text -- formatting the page title with DISPLAYTITLE needs the full page title |
|||
--[[============================= listAll =================================== |
|||
pageTitle = TaxonItalics.italicizeTaxonName(pageTitle, false, false, true) -- format pageTitle, not italicizing any parenthesized term |
|||
External utility function primarily intended for use in checking and debugging. |
|||
if italicTitle ~= 'test' then |
|||
Returns a comma separated list of a taxonomic hierarchy, starting from |
|||
mw.getCurrentFrame():callParserFunction('DISPLAYTITLE', pageTitle) |
|||
the supplied taxon. |
|||
Usage: {{#invoke:Autotaxobox|listAll|TAXON}} |
|||
=============================================================================]] |
|||
function p.listAll(frame) |
|||
local currTaxon = frame.args[1] or '' |
|||
if currTaxon == '' then return 'ERROR: no taxon supplied' end |
|||
return l.doListAll(l.makeTable(frame, currTaxon)) |
|||
end |
|||
function l.doListAll(taxonTable, taxonRankTable) |
|||
local lst = taxonTable[1] .. '-' .. tostring(taxonRankTable[1]) |
|||
for i = 2, taxonTable.n, 1 do |
|||
lst = lst .. ', ' .. taxonTable[i] .. '-' .. taxonRankTable[i] |
|||
end |
|||
return lst |
|||
end |
|||
--[[=========================== removeQualifier ================================ |
|||
External utility function to remove a qualifier (any part after a "/") from a |
|||
taxon name. |
|||
Usage: {{#invoke:Autotaxobox|removeQualifier|TAXON}} |
|||
=============================================================================]] |
|||
function p.removeQualifier(frame) |
|||
local baseName, qualifier = l.stripExtra(frame.args[1]) |
|||
return baseName |
|||
end |
|||
--[[========================================================================= |
|||
Internal functions |
|||
=============================================================================]] |
|||
--[[= = = = = = = = = = = = stripExtra = = = = = = = = = = = = = = = = = = = |
|||
Internal utility function to strip off any extra parts of a taxon name, i.e. |
|||
anything after a '/'. Thus 'Felidae/?' would be split into 'Felidae' and '?'. |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.stripExtra(taxonName) |
|||
local i = mw.ustring.find(taxonName, '/', 1, true) |
|||
if i then |
|||
return mw.ustring.sub(taxonName, 1, i-1), mw.ustring.sub(taxonName, i, -1) |
|||
else |
|||
return taxonName, '' |
|||
end |
|||
end |
|||
--[[= = = = = = = = = = = = splitTaxonName = = = = = = = = = = = = = = = = = |
|||
Internal utility function to split a taxon name into its parts and return |
|||
them. Possible formats include: |
|||
* taxon |
|||
* taxon (disambig) |
|||
* taxon (Subgenus) |
|||
* taxon/qualifier |
|||
* combinations, e.g. taxon (disambig)/qualifier |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.splitTaxonName(taxon) |
|||
-- get any qualifier present |
|||
local qualifier = '' |
|||
local i = mw.ustring.find(taxon, '/', 1, true) |
|||
if i then |
|||
qualifier = mw.ustring.sub(taxon, i+1, -1) |
|||
taxon = mw.ustring.sub(taxon, 1, i-1) |
|||
end |
|||
-- get any disambiguator or subgenus |
|||
local disambig = '' |
|||
local subgenus = '' |
|||
i = mw.ustring.find(taxon, ' (', 1, true) |
|||
if i then |
|||
local parenTerm = mw.ustring.sub(taxon, i+2, -2) |
|||
taxon = mw.ustring.sub(taxon, 1, i-1) |
|||
local char1 = mw.ustring.sub(parenTerm, 1, 1) |
|||
if char1 == mw.ustring.lower(char1) then |
|||
disambig = parenTerm |
|||
else |
else |
||
name = name .. ' \\Italic title\\ ' .. pageTitle -- for testing and debugging |
|||
subgenus = parenTerm |
|||
end |
end |
||
end |
end |
||
return name |
|||
return taxon, disambig, subgenus, qualifier |
|||
end |
|||
--[[= = = = = = = = = = = = matchTaxonLink = = = = = = = = = = = = = = = = = |
|||
Function to determine whether the taxon name derived from the name of the |
|||
taxonomy template (passed in the parameter taxon) matches the link text |
|||
(passed in the parameter linkText). |
|||
The taxon name may have any of the formats: |
|||
* baseTaxon/qualifier |
|||
* baseTaxon (disambig) |
|||
* baseTaxon (Subgenus) [distinguished by the capital letter] |
|||
* a qualifier may be present after the previous two formats. |
|||
Examples of matches (baseTaxon ~ linkText): |
|||
* Pinus ~ Pinus |
|||
* Pinus sect. Trifoliae ~ Pinus sect. Trifoliae |
|||
* Pinus sect. Trifoliae ~ ''Pinus'' sect. ''Trifoliae'' [italic markers ignored] |
|||
* Pinus sect. Trifoliae ~ P. sect. Trifoliae [abbreviated genus name matches] |
|||
* Bombus (Pyrobombus) ~ Bombus (Pyrobombus) |
|||
* Bombus (Pyrobombus) ~ B. (Pyrobombus) |
|||
* Bombus (Pyrobombus) ~ Pyrobombus [link text may just be the subgenus] |
|||
* Heteractinida ~ "Heteractinida" [double-quotes are ignored in link text] |
|||
* "Heteractinida" ~ Heteractinida [double-quotes are ignored in base taxon name] |
|||
* Incertae sedis ~ anything [link text is ignored for matching in this case] |
|||
* Cetotheriidae with qualifier=? ~ Cetotheriidae (?) |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.matchTaxonLink(taxon, linkText, rankBelowGenus) |
|||
local dummy |
|||
linkText, dummy = mw.ustring.gsub(linkText, "''", '') -- remove any italic wikitext in the link text |
|||
linkText, dummy = mw.ustring.gsub(linkText, '<.->', '') -- strip all tags used to format the link text |
|||
linkText, dummy = mw.ustring.gsub(linkText, '"', '') -- remove any occurrences of " in the link text |
|||
local baseTaxon, disambig, subgenus, qualifier = l.splitTaxonName(taxon) -- split up the taxon name |
|||
baseTaxon, dummy = mw.ustring.gsub(linkText, '"', '') -- remove any occurrences of " in the base taxon name |
|||
local match = linkText == baseTaxon or |
|||
linkText == subgenus or |
|||
linkText == baseTaxon .. ' (' .. subgenus .. ')' or |
|||
linkText == mw.ustring.sub(baseTaxon, 1, 1) .. '. (' .. subgenus .. ')' or |
|||
baseTaxon == 'Incertae sedis' or |
|||
rankBelowGenus and linkText == mw.ustring.gsub(baseTaxon, '([A-Z]).- (.*)', '%1. %2') or |
|||
mw.ustring.find(qualifier, '?', 1, true) and mw.ustring.find(linkText, baseTaxon, 1, true) == 1 |
|||
return match |
|||
end |
|||
--[[= = = = = = = = = = = = = makeTable = = = = = = = = = = = = = = = = = = = |
|||
Internal utility function to return a table (array) constructed from a |
|||
taxonomic hierarchy stored in "Template:Taxonomy/..." templates. |
|||
TABLE.n holds the total number of taxa; TABLE[1]..TABLE[TABLE.n] the taxon |
|||
names. |
|||
The last taxon in the table will either (a) have a taxonomy template but with |
|||
no parent given (e.g. 'Life') or (b) not have a taxonomy template. |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.makeTable(frame, currTaxon) |
|||
local taxonTable = {} |
|||
local taxonRankTable = {} |
|||
local ok, rank, parent |
|||
local i = 1 |
|||
local topReached = false -- reached the top of the taxonomic hierarchy? |
|||
repeat |
|||
taxonTable[i] = currTaxon |
|||
ok, rank = p.getTaxonInfoItem(frame, currTaxon, 'rank') |
|||
if ok then taxonRankTable[i] = string.lower(rank) else taxonRankTable[i] = '' end |
|||
ok, parent = p.getTaxonInfoItem(frame, currTaxon, 'parent') |
|||
if ok and parent ~= '' then |
|||
currTaxon = parent |
|||
i = i + 1 |
|||
else |
|||
topReached = true -- reached the top of the hierarchy or tried to use a non-existent taxonomy template |
|||
end |
|||
until topReached or i > MaxSearchLevels |
|||
taxonTable.n = math.min(i, MaxSearchLevels) |
|||
return taxonTable, taxonRankTable |
|||
end |
|||
--[[= = = = = = = = = = = = getRankTable = = = = = = = = = = = = = = = = = = |
|||
Internal utility function to set up a table of numerical values corresponding |
|||
to 'Linnaean' ranks, with upper ranks having higher values. In a valid |
|||
taxonomic hierarchy, a lower rank should never have a higher value than a |
|||
higher rank. The actual numerical values are arbitrary so long as they are |
|||
ordered. |
|||
The ranks should correspond to those in Template:Anglicise ranks. |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.getRankTable() |
|||
return { |
|||
classis = 1400, |
|||
cohort = 1100, |
|||
divisio = 1500, |
|||
domain = 1700, |
|||
epifamilia = 802, |
|||
familia = 800, |
|||
forma = 100, |
|||
genus = 600, |
|||
grandordo = 1005, |
|||
['grandordo-mb'] = 1002, |
|||
hyperfamilia = 805; |
|||
infraclassis = 1397, |
|||
infralegio = 1197, |
|||
infraordo = 997, |
|||
infraphylum = 1497, |
|||
infraregnum = 1597, |
|||
infratribus = 697, |
|||
legio = 1200, |
|||
magnordo = 1006, |
|||
microphylum = 1495, |
|||
micrordo = 995, |
|||
mirordo = 1004, |
|||
['mirordo-mb'] = 1001, |
|||
nanophylum = 1494, |
|||
nanordo = 994, |
|||
ordo = 1000, |
|||
parafamilia = 800, |
|||
parvclassis = 1396; -- same as subterclassis |
|||
parvordo = 996, |
|||
phylum = 1500, |
|||
regnum = 1600, |
|||
sectio = 500, |
|||
--series = 400, used too inconsistently to check |
|||
species = 300, |
|||
subclassis = 1398, |
|||
subcohort = 1098, |
|||
subdivisio = 1498, |
|||
subfamilia = 798, |
|||
subgenus = 598, |
|||
sublegio = 1198, |
|||
subordo = 998, |
|||
subphylum = 1498, |
|||
subregnum = 1598, |
|||
subsectio = 498, |
|||
subspecies = 298, |
|||
subterclassis = 1396; -- same as parvclassis |
|||
subtribus = 698, |
|||
superclassis = 1403, |
|||
supercohort = 1103, |
|||
superdivisio = 1503, |
|||
superdomain = 1703, |
|||
superfamilia = 803, |
|||
superlegio = 1203, |
|||
superordo = 1003, |
|||
superphylum = 1503, |
|||
superregnum = 1603, |
|||
supersectio = 503, |
|||
supertribus = 703, |
|||
tribus = 700, |
|||
varietas = 200, |
|||
zoodivisio = 1300, |
|||
zoosectio = 900, |
|||
zoosubdivisio = 1298, |
|||
zoosubsectio = 898, |
|||
} |
|||
end |
|||
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = |
|||
Function to look up the arbitrary numerical value of a rank in a rank value |
|||
table. "Ichno" and "oo" ranks are not stored separately, so if present the |
|||
prefix is removed. |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.lookupRankVal(rankValTable, rank) |
|||
local rankVal = rankValTable[rank] |
|||
if not rankVal then |
|||
-- may be an "ichno" or "oo" rank; try removing "ichno-" or "oo-" |
|||
local baseRank = mw.ustring.gsub(mw.ustring.gsub(rank, '^ichno', ''), '^oo', '') |
|||
if baseRank == 'rdo' then baseRank = 'ordo' end |
|||
-- if an "ichno" or "oo" rank, lower rank value slightly so it is ok below the base rank |
|||
rankVal = rankValTable[baseRank] |
|||
if rankVal then |
|||
rankVal = rankVal - 0.1 |
|||
end |
|||
end |
|||
return rankVal |
|||
end |
|||
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = |
|||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]] |
|||
function l.tableCell(arg1, arg2) |
|||
local text, style |
|||
if arg2 then |
|||
style = arg1 |
|||
text = arg2 |
|||
else |
|||
style = '' |
|||
text = arg1 |
|||
end |
|||
local res = '|' |
|||
if style ~= '' then |
|||
res = res .. style .. '|' |
|||
end |
|||
return res .. text .. '\n' |
|||
end |
end |
||
14:55, 30 ஏப்பிரல் 2024 இல் நிலவும் திருத்தம்
This Lua module is used on approximately 1,21,000 pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Module:Autotaxobox (talk · · வார்ப்புரு:History · links · doc · subpages · sandbox · testcases)
The purpose of this module is to provide support for automated taxobox templates (such as {{Automatic taxobox}} or {{Speciesbox}}), avoiding Mediawiki template expansion depth errors in the traversal of the taxonomic hierarchies encoded in taxonomy templates.
Currently processing is arbitrarily limited to hierarchies containing at most Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'. levels.
taxoboxColour
Given a taxon name, this function returns the correct colour of an automated taxobox for that taxon. It does so by searching up the taxonomic hierarchy for a 'real' taxon (i.e. not incertae sedis) that sets the taxobox colour, and then returning that colour. If no 'real' taxon is found, then if an incertae sedis taxon was found, the incertae sedis colour is returned, otherwise "transparent" is returned. (If the taxonomic hierarchy is too deep to process, the error colour is returned.)
Usage:
{{#invoke:Autotaxobox|taxoboxColour|taxon_name}}
Parameters:
- The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/taxon_name" exists.
Examples:
- {{#invoke:Autotaxobox|taxoboxColour|Felis}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
- {{#invoke:Autotaxobox|taxoboxColour|Acacia}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
taxoboxList
Given a taxon name, this function returns the rows of taxa in an automated taxobox, based on the taxonomic hierarchy for the supplied taxon.
Usage:
{{#invoke:Autotaxobox|taxoboxList|taxon_name
|display_taxa = the number of taxa above taxon_name to force to be displayed
|authority = taxonomic authority for taxon_name
|parent_authority = taxonomic authority for taxon_name's parent
|gparent_authority = taxonomic authority for taxon_name's grandparent
|ggparent_authority = taxonomic authority for taxon_name's greatgrandparent
|ggparent_authority = taxonomic authority for taxon_name's greatgreatgrandparent
|bold_first = bold to embolden taxon_name in its row
}}
Parameters:
- The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/taxon_name" exists. The others are explained above.
Examples:
{| class="wikitable" {{#invoke:Autotaxobox|taxoboxList|Felis|authority=Linnaeus, 1758}} |}
→
Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.taxonomyList
Given a taxon name, this function returns the rows of the taxonomy table displayed on the "Template:Taxonomy/taxon_name" page, based on the taxonomic hierarchy for the supplied taxon name.
When descending the taxonomic hierarchy, if a rank is found that is either at the same level or higher than a rank already encountered (e.g. a family is found below a subfamily), the cell displaying the rank is given a reddish background. The numerical values defined in getRankTable()
are used to determine the correct sequence of ranks.
Usage:
{{#invoke:Autotaxobox|taxonomyList|taxon_name}}
Parameters:
- The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/taxon_name" exists.
Examples:
{| class="wikitable" {{#invoke:Autotaxobox|taxonomyList|Felis}} |}
→
Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.callTaxonomyKey
This function prepares for, and then calls, {{Taxonomy key}} to display a taxonomy
template page. It does this by building up the information the template
requires, following one same_as
link if present, and then calling it.
Usage:
{{#invoke:Autotaxobox|callTaxonomyKey
|parent=
|rank=
|extinct=
|always_display=
|link_target=value of 'link' parameter in the taxonomy template
|link_text=value of unnamed parameter in the taxonomy template
|same_as=
}}
taxonInfo
Given the names of a taxon and the required item of information stored in the taxon's taxonomy template, this function returns the value of the item, following one "same as" link if available and the value would otherwise be the empty string. The function would normally be used externally via {{Taxon info}}.
Usage:
{{#invoke:Autotaxobox|taxonInfo|taxon_name|item_name}}
Parameters:
- The first unnamed parameter should be the name of a taxon for which "Template:Taxonomy/taxon_name" exists.
- The possible values of the second unnamed parameter are given at {{Taxon info/doc}}.
Examples:
- {{#invoke:Autotaxobox|taxonInfo|Felis|rank}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
- {{#invoke:Autotaxobox|taxonInfo|Aves/skip|same_as}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
- {{#invoke:Autotaxobox|taxonInfo|Aves/skip|parent}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
taxonLink
Returns a wikilink to a taxon, if required including '†' before it and ' (?)' after it, and optionally italicized or bolded without a wikilink. It would normally be used via {{Taxon link}}. Some parameters can, under some circumstances, be omitted.
Usage:
{{#invoke:Autotaxobox|taxonLink
(having '/?' at the end triggers the output of ' (?)')
|taxon=
('yes' or 'true' trigger the output of '†')
|extinct=
('yes' makes the core output bold and not wikilinked)
|bold=
('yes' makes the core output italic)
|italic=
(without †, italics, etc.)
|link_target=target for the wikilink
|plain_link_text= text of the wikilink
}}
Examples:
- {{#invoke:Autotaxobox|taxonLink|taxon=Felis|italic=yes}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
- {{#invoke:Autotaxobox|taxonLink|taxon=Incertae sedis/Animalia}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
- {{#invoke:Autotaxobox|taxonLink|link_target=Pterosaur|plain_link_text=Pterosauromorpha|extinct=yes}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
- {{#invoke:Autotaxobox|taxonLink|taxon=Dinosauria/?|link_target=Dinosaur|plain_link_text=Dinosauria|extinct=yes}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
showRankTable
Returns a sortable wikitable containing the ranks and corresponding numerical values defined in getRankTable()
and used in checking the consistency of a taxonomic hierarchy. If a taxon has a value in the rank table, it should always be lower than one higher in the taxonomic hierarchy.
Usage:
{{#invoke:Autotaxobox|showRankTable}}
Utilities
These functions are intended to be used only in analysing taxonomic hierarchies, e.g. in testing and debugging, and not for direct use in templates used in the automated taxobox system.
nth
Given a taxon name, this function returns the nth taxon above it in the taxonomic hierarchy.
Usage:
{{#invoke:Autotaxobox|nth|taxon_name|n=integer}}
Parameters:
- The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/taxon_name" exists.
- n is the level whose taxon is to be found
Examples:
- {{#invoke:Autotaxobox|nth|Felis|n=1}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
- {{#invoke:Autotaxobox|nth|Felis|n=15}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
nLevels
Given a taxon name, this function returns the number of levels at and above it in the taxonomic hierarchy.
Usage:
{{#invoke:Autotaxobox|nLevels|taxon_name}}
Parameters:
- The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/taxon_name" exists.
Examples:
- {{#invoke:Autotaxobox|nLevels|Felis}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
- {{#invoke:Autotaxobox|nLevels|Pteranodon}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
listAll
Given a taxon name, this function returns a comma-separated list of all the levels at and above it in the taxonomic hierarchy.
Usage:
{{#invoke:Autotaxobox|listAll|taxon_name}}
Parameters:
- The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/taxon_name" exists.
Examples:
- {{#invoke:Autotaxobox|listAll|Plantae}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
- {{#invoke:Autotaxobox|listAll|Felis}} → Lua error in package.lua at line 95: loop or previous error loading module 'Module:Autotaxobox'.
require('strict')
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 and variables global to the module
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:
-- image_caption_align
-- image2_caption_align
-- binomial2
-- binomial2_authority
-- binomial3
-- binomial3_authority
-- binomial4
-- binomial4_authority
-- =============================================================================
function p.automaticTaxobox(frame)
local args
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;
-- most will be passed on unchanged
-- ---------------------------------------------------------------------
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 ''
local youngestFossil = args['youngest_fossil'] or args['youngest fossil'] or ''
local name = args['name'] or ''
local colourAs = args['color_as'] or args['color as'] or args['colour_as'] or args['colour as'] or ''
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 args['binomial_'..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
-- ------------------------------------------------------
fossilRange = l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil)
-- 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
local basePagename = pagename
if italicTitle ~= 'taxon' then basePagename = mw.ustring.gsub(basePagename, '%s+%b()$', '', 1) end
local taxonParaMissingError = false
if taxon == '' then
taxonParaMissingError = true
taxon = basePagename
end
-- decide if the page name and taxobox name need to be italicized;
-- if italic_title is not set, then if the names are the taxon, use its rank to decide
local ok, taxonRank = Autotaxobox.getTaxonInfoItem(frame, taxon, 'rank') -- taxonRank needed later if not here
if italicTitle == '' then
if not (ok and taxonRank ~= '' and
frame:expandTemplate{ title = 'Is italic taxon', args = {taxonRank} } == 'yes') then
italicTitle = 'no'
end
end
-- 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 = taxon
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' or italicTitle == 'taxon') then
if italicTitle == 'taxon' or TaxonItalics.hasConnectingTerm(baseTaxon) then
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.
if name == '' then
name = basePagename
if italicTitle == 'yes' then
name = TaxonItalics.italicizeTaxonName(name, false, false)
end
-- name = name .. '/' .. baseTaxon .. '/' .. nameRank
end
-- determine taxobox colour
local colour = ''
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)
end
-- fill in a missing subdivision_ranks parameter
if subdivision ~= '' and subdivisionRanks == '' and ok and taxonRank ~= '' then
subdivisionRanks = frame:expandTemplate{ title = 'Children rank', args = {taxonRank} }
end
-- set binomial parameters if the target taxon is (unusually) a species
local genusAuthority = ''
if binomial == '' then
if ok and taxonRank == 'species' then
binomial = TaxonItalics.italicizeTaxonName(taxon, false, false)
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
-- ------------------------------------------------
res = res .. frame:expandTemplate{ title = 'Taxobox/core', args =
{ ichnos = 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 = parentAuthority,
grandparent_authority = args['grandparent_authority'] or args['grandparent authority'] or '',
greatgrandparent_authority = args['greatgrandparent_authority'] or args['greatgrandparent authority'] or '',
greatgreatgrandparent_authority = args['greatgreatgrandparent_authority'] or args['greatgreatgrandparent authority'] or '',
name = name,
colour = colour,
status = args['status'] or '',
status_system = args['status_system'] or args['status system'] or '',
status_ref = args['status_ref'] or args['status ref'] or '',
status2 = args['status2'] or '',
status2_system = args['status2_system'] or args['status2 system'] or '',
status2_ref = args['status2_ref'] or args['status2 ref'] or '',
trend = args['trend'] or '',
extinct = args['extinct'] or '',
image = args['image'] or '',
upright = args['image_upright'] or args['image upright'] or '',
image_alt = args['image_alt'] or args['image alt'] or '',
image_caption = args['image_caption'] or args['image caption'] or '',
image2 = args['image2'] or '',
upright2 = args['image2_upright'] or args['image2 upright'] or '',
image2_alt = args['image2_alt'] or args['image2 alt'] or '',
image2_caption = args['image2_caption'] or args['image2 caption'] or '',
classification_status = args['classification_status'] or args['classification status'] or '',
diversity = args['diversity'] or '',
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 = typeGenus,
type_genus_authority = typeGenusAuthority,
type_species = typeSpecies,
type_species_authority = 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 '',
range_map_alt = args['range_map_alt'] or args['range map alt'] or '',
range_map_caption = args['range_map_caption'] or args['range map caption'] or '',
range_map2 = args['range_map2'] or args['range map2'] or '',
range_map2_upright = args['range_map2_upright'] or args['range map2 upright'] or '',
range_map2_alt = args['range_map2_alt'] or args['range map2 alt'] or '',
range_map2_caption = args['range_map2_caption'] or args['range map2 caption'] or '',
range_map3 = args['range_map3'] or args['range map3'] or '',
range_map3_upright = args['range_map3_upright'] or args['range map3 upright'] or '',
range_map3_alt = args['range_map3_alt'] or args['range map3 alt'] or '',
range_map3_caption = args['range_map3_caption'] or args['range map3 caption'] or '',
range_map4 = args['range_map4'] or args['range map4'] or '',
range_map4_upright = args['range_map4_upright'] or args['range map4 upright'] or '',
range_map4_alt = args['range_map4_alt'] or args['range map4 alt'] or '',
range_map4_caption = args['range_map4_caption'] or args['range map4 caption'] or '',
synonyms_ref = args['synonyms_ref'] or args['synonyms ref'] or '',
synonyms = args['synonyms'] or ''
} }
-- put page in error-tracking categories if required
local errCat1 = ''
if genusManual ~= '' or speciesManual ~= '' or binomial ~= '' then errCat1 = '[[Category:Automatic taxoboxes using manual parameters]]' end
local errCat2 = ''
if taxonParaMissingError then errCat2 = '[[Category:Automatic taxoboxes relying on page title]]' end
res = res .. frame:expandTemplate{ title = 'Main other', args = {errCat1..errCat2} }
return res
end
-- =============================================================================
-- l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil) checks
-- the parameters that determine the fossil range, returning an appropriate
-- range.
-- =============================================================================
-- temporary public function for debugging
function p.chkFossilRange(frame)
local args = frame.args
local fossilRange = args['temporal_range'] or args['temporal range'] or args['fossil_range'] or args['fossil range'] or ''
local oldestFossil = args['oldest_fossil'] or args['oldest fossil'] or ''
local youngestFossil = args['youngest_fossil'] or args['youngest fossil'] or ''
local fossilRange = l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil)
return fossilRange
end
function l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil)
local res = ''
if fossilRange ~= '' then
if mw.ustring.find(frame:expandTemplate{ title = 'Period start', args = { fossilRange } }, '[Ee]rror') then
res = fossilRange
else
res = frame:expandTemplate{ title = 'Geological range', args = { fossilRange } }
end
elseif oldestFossil ~= '' then
if youngestFossil == '' then youngestFossil = 'Recent' end
if mw.ustring.find(frame:expandTemplate{ title = 'Period start', args = { oldestFossil } }, '[Ee]rror') or
mw.ustring.find(frame:expandTemplate{ title = 'Period start', args = { youngestFossil } }, '[Ee]rror') then
res = oldestFossil..'–'..youngestFossil
else
res = frame:expandTemplate{ title = 'Geological range', args = { oldestFossil, youngestFossil } }
end
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
return p