Module:Autotaxobox/sandbox
![]() | This is the module sandbox page for Module:Autotaxobox (diff). See also the companion subpage for test cases. |
![]() | This Lua module is used on approximately 584,000 pages, or roughly 1% of all 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 rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | 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. |
![]() | This module depends on the following other modules: |
Module:Autotaxobox (talk · · hist · links · doc · subpages · sandbox · testcases)
The purpose of this module is to provide support for the automated taxobox system (including templates such as {{Speciesbox}} and {{Automatic taxobox}}), 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 100 levels.
See the automated taxobox system map for information on how the module's functions are used in the system.
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}} → rgb(235,235,210)
- {{#invoke:Autotaxobox|taxoboxColour|Acacia}} → rgb(180,250,180)
taxoboxList
Given the name of a taxon, this function returns the rows of taxa in an automated taxobox, based on the taxonomic hierarchy for the supplied taxon. If the lowest taxon displayed in the taxobox is below the rank of genus, the supplied taxon will usually be at a higher rank than the taxobox's target taxon, so that there is an offset to be taken into account.
Usage:
{{#invoke:Autotaxobox|taxoboxList
|the name of taxon upwards from which the taxonomic hierarchy is to be displayed by this function
|display_taxa = the number of taxa above taxon to force to be displayed
|authority = taxonomic authority for the lowest level taxon in the taxobox (the taxobox_target) (see also offset below)
|parent_authority = taxonomic authority for taxobox_target's parent
|gparent_authority = taxonomic authority for taxobox_target's grandparent
|ggparent_authority = taxonomic authority for taxobox_target's greatgrandparent
|gggparent_authority = taxonomic authority for taxobox_target's greatgreatgrandparent
|bold_first = bold to embolden taxon in its row
|offset = the offset of taxon from taxobox_target – the number of steps from taxobox_target to taxon
}}
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}} |}→
Domain: | Eukaryota |
Kingdom: | Animalia |
Phylum: | Chordata |
Class: | Mammalia |
Order: | Carnivora |
Suborder: | Feliformia |
Family: | Felidae |
Subfamily: | Felinae |
Genus: | Felis Linnaeus, 1758 |
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 at either the same or a higher level than a rank already encountered (e.g. a family is found below a subfamily), the cell displaying the rank is given a reddish background; if it's the supplied taxon, the article is put into the tracking category Category:Taxonomy templates showing anomalous ranks. The numerical values defined in getRankTable()
are used to determine the correct sequence of ranks. Ranks without values in this table do not have their order checked.
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:
{{#invoke:Autotaxobox|taxonomyList|Felis}}→
callTaxonomyKey
This function prepares for, and then calls, {{Taxonomy key}} to display a taxonomy
template page (which in turn invokes taxonomyList
from this module). It does this by building up the information the template
requires, following one same_as
link if present, and then calling it.
It is used by {{Don't edit this line}}.
Usage:
{{#invoke:Autotaxobox|callTaxonomyKey
|taxon=
|parent=
|rank=
|extinct=
|always_display=
|link_target=value of the 'link' parameter in the taxonomy template
|link_text=value of the unnamed parameter in the taxonomy template
|refs=
|same_as=
}}
showRefs
Shows the refs field in a taxonomy template, handing incertae sedis taxa and using '–' for absent refs.
Usage:
- {{#invoke:Autotaxobox|showRefs|taxon_name|refs}}
Examples:
- {{#invoke:Autotaxobox|showRefs|Neoscona|{{Taxon info|Neoscona|refs}}}} → "Gen. Neoscona Simon, 1864", World Spider Catalog Version 16.5, retrieved 2018-12-31
- {{#invoke:Autotaxobox|showRefs|Incertae sedis/Characidae|}} → not applicable (incertae sedis)
taxonLink
Returns a wikilink to a taxon, if required including '†' before it and ' (?)' after it, and optionally italicized or bolded without a wikilink. It can be used externally 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' triggers 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}} → Felis
- {{#invoke:Autotaxobox|taxonLink|taxon=Incertae sedis/Animalia}} → incertae sedis
- {{#invoke:Autotaxobox|taxonLink|link_target=Pterosaur|plain_link_text=Pterosauromorpha|extinct=yes}} → †Pterosauromorpha
- {{#invoke:Autotaxobox|taxonLink|taxon=Dinosauria/?|link_target=Dinosaur|plain_link_text=Dinosauria|extinct=yes}} → †Dinosauria (?)
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.
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}} → genus
- {{#invoke:Autotaxobox|taxonInfo|Aves/skip|same_as}} → Aves
- {{#invoke:Autotaxobox|taxonInfo|Aves/skip|parent}} → Chordata
Utilities
These functions are intended to be used only in analysing and understanding the automated taxobox system, including the taxonomic hierarchies encoded in taxonomy templates – for example in testing and debugging. They are not part of the functioning of the automated taxobox system.
getMaxSearchLevels
Returns the maximum number of levels of a taxonomic hierarchy encoded in taxonomy templates that the system will search.
Usage:
{{#invoke:Autotaxobox|getMaxSearchLevels}}
→ 100
find
Given a taxon name and a rank, this function returns the taxon's ancestor of the given rank.
Usage:
{{#invoke:Autotaxobox|find|taxon_name|rank}}
Parameters:
- The first unnamed parameter should be the name of a taxon for which "Template:Taxonomy/taxon_name" exists.
- The second unnamed parameter should be the Latinized name of a rank.
Examples:
{{#invoke:Autotaxobox|find|Felis|ordo}}
→ Carnivora{{#invoke:Autotaxobox|find|Felis|classis}}
→ Mammalia/skip{{#invoke:Autotaxobox|find|Pteranodon|phylum}}
→ Chordata{{#invoke:Autotaxobox|find|Pteranodon|classis}}
→ rank not found
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}} → Felis
- {{#invoke:Autotaxobox|nth|Felis|n=15}} → Boreoeutheria
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}} → 42
- {{#invoke:Autotaxobox|nLevels|Pteranodon}} → 43
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}} → Plantae-regnum, Archaeplastida-clade, CAM-clade, Diaphoretickes-cladus, Eukaryota-domain, Life-
- {{#invoke:Autotaxobox|listAll|Felis}} → Felis-genus, Felinae-subfamilia, Felidae-familia, Feloidea-superfamilia, Aeluroidea-infraordo, Feliformia-subordo, Carnivora-ordo, Carnivoraformes-clade, Carnivoramorpha-clade, Pan-Carnivora-clade, Ferae-mirordo-mb, Ferungulata-grandordo-mb, Scrotifera-clade, Laurasiatheria-superordo, Boreoeutheria-magnordo, Placentalia-infraclassis, Eutheria-clade, Theria/skip-subclassis, Mammalia/skip-classis, Amniota-clade, Reptiliomorpha-clade, Tetrapoda-cladus, Teleostomi-clade, Eugnathostomata-clade, Gnathostomata-infraphylum, Vertebrata-subphylum, Olfactores-clade, Chordata-phylum, Deuterostomia-superphylum, Nephrozoa-clade, Bilateria-clade, ParaHoxozoa-cladus, Eumetazoa-subregnum, Animalia-regnum, Choanozoa-cladus, Filozoa-clade, Holozoa-clade, Opisthokonta-clade, Obazoa-cladus, Amorphea-cladus, Eukaryota/displayed-domain, Life-
removeQualifier
Given a taxon name, this function returns the name with any qualifier (i.e. any part after a "/") removed.
Usage:
{{#invoke:Autotaxobox|removeQualifier|taxon_name}}
Examples:
- {{#invoke:Autotaxobox|removeQualifier|Eukaryota/display}} → Eukaryota
- {{#invoke:Autotaxobox|removeQualifier|Felis}} → Felis
--[[
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.
]]
local p = {}
--[[
Limit the maximum depth of a taxonomic hierarchy that can be traversed;
avoids excessive processing time and protects against incorrectly set up
hierarchies, e.g. loops.
]]
local maxN = 100
--[[
Utility function to strip off any extra parts of a taxon name, i.e. anything
after a '/'. Thus "Felidae/?" would be reduced to "Felidae".
]]
function p.stripExtra(taxonName)
local i = string.find(taxonName,'/')
if i then
return string.sub(taxonName,1,i-1)
else
return taxonName
end
end
--[[
Utility function primarily intended for use in checking and debugging.
Returns the nth ancestor of a taxon, where the parent is counted as the 1st
ancestor.
Usage: {{#invoke:Autotaxobox|nth|TAXON|n=N}}
]]
function p.nth(frame)
local currTaxon = frame.args[1]
local n = tonumber(frame.args['n'])
if n > maxN then return 'Exceeded maximum number of levels allowed (' .. maxN .. ')' end
local i = 1
local searching = true
while i < n and searching do
local currCall = 'Template:Taxonomy/' .. currTaxon
local parent = frame:expandTemplate{ title = currCall, args = {['machine code'] = 'parent' } }
if parent ~= '' then
currTaxon = parent
i = i + 1
else
searching = false
end
end
if searching then return currTaxon
else return 'Nothing at level ' .. n
end
end
--[[
Utility function primarily intended for use in checking and debugging.
Returns number of levels in a taxonomic hierarchy, starting from
the supplied taxon as level 1.
Usage: {{#invoke:Autotaxobox|nLevels|TAXON}}
]]
function p.nLevels(frame)
local currTaxon = frame.args[1]
local i = 1
local searching = true
while searching and i < maxN do
local parent = frame:expandTemplate{ title = 'Template:Taxonomy/' .. currTaxon, args = {['machine code'] = 'parent' } }
if parent ~= '' then
currTaxon = parent
i = i + 1
else
searching = false
end
end
if searching then return maxN .. '+'
else return i
end
end
--[[
Utility function primarily intended for use in checking and debugging.
Returns a comma separated list of a taxonomic hierarchy, starting from
the supplied taxon.
Usage: {{#invoke:Autotaxobox|listAll|TAXON}}
]]
function p.listAll(frame)
local currTaxon = frame.args[1]
local i = 1
local searching = true
local lst = currTaxon
while i < maxN and searching do
local currCall = 'Template:Taxonomy/' .. currTaxon
local parent = frame:expandTemplate{ title = currCall, args = {['machine code'] = 'parent' } }
if parent ~= '' then
currTaxon = parent
lst = lst .. ', ' .. currTaxon
i = i + 1
else
searching = false
end
end
if searching then lst = lst .. '...' end
return lst
end
--[[ probably not for ultimate release
function p.taxoboxColourList(frame)
local currTaxon = frame.args[1]
local i = 1
local searching = currTaxon ~= ''
local lst = ''
while i < maxN and searching do
local colour = frame:expandTemplate{ title = 'Template:Taxobox colour', args = { currTaxon } }
if string.sub(colour,1,3) == 'rgb' then
lst = lst .. ', ' .. currTaxon
end
local parent = frame:expandTemplate{ title = 'Template:Taxonomy/' .. currTaxon, args = {['machine code'] = 'parent' } }
if parent ~= '' then
currTaxon = parent
i = i + 1
else
searching = false
end
end
return lst
end
]]
--[[
Determines the correct colour for a taxobox, by searching up the taxonomic
hierarchy from the supplied taxon for the first taxon (other than
'incertae sedis') that sets a taxobox colour. It is assumed that a valid
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)
local currTaxon = frame.args[1]
local i = 1
local searching = currTaxon ~= ''
local colour = ''
local foundICTaxon = false -- record whether 'incertae sedis' found
while searching and i < maxN do
local plainCurrTaxon = p.stripExtra(currTaxon)
if string.lower(plainCurrTaxon) == 'incertae sedis' then
foundICTaxon = true
else
local possColour = frame:expandTemplate{ title = 'Template:Taxobox colour', args = { plainCurrTaxon } }
if string.sub(possColour,1,3) == 'rgb' then
colour = possColour
searching = false
end
end
local parent = frame:expandTemplate{ title = 'Template:Taxonomy/' .. currTaxon, args = {['machine code'] = 'parent' } }
if parent ~= '' then
currTaxon = parent
i = i + 1
else
searching = false
end
end
if colour ~= '' then
return colour
elseif foundICTaxon then
return frame:expandTemplate{ title = 'Template:Taxobox colour', args = { 'incertae sedis' } }
elseif searching then
return frame:expandTemplate{ title = 'Template:Taxobox/Error colour', args = { } }
else
return 'transparent'
end
end
return p