Module:Autotaxobox/doc: Difference between revisions

Content deleted Content added
update to tested sandbox version
another module that is used
 
(67 intermediate revisions by 7 users not shown)
Line 1:
{{High-risk}}
--[[
{{Module rating|protected}}
This module provides support to the automated taxobox system – the templates
{{Lua|Module:TaxonItalics|Module:Taxobox ranks}}
Automatic taxobox, Speciesbox, Subspeciesbox, Infraspeciesbox, etc.
<!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) -->
 
[[Module:Autotaxobox]] {{Toolbar|style=font-size:90% |separator=dot
In particular it provides a way of traversing the taxonomic hierarchy encoded
| 1 = [[:Module talk:Autotaxobox|talk]]
in taxonomy templates (templates with names of the form
| 2 = {{edit|1=Module:Autotaxobox|2=edit}}
"Template:Taxonomy/TAXON_NAME") without causing template expansion depth errors.
| 3 = {{history|Module:Autotaxobox|hist}}
]]
| 4 = [{{fullurl:Special:WhatLinksHere/:Module:Autotaxobox|limit=999}} links]
| 5 = [[Module:Autotaxobox/doc|doc]]
| 6 = [[Special:PrefixIndex/Module:Autotaxobox|subpages]]
| 7 = [[Module:Autotaxobox/sandbox|sandbox]]
| 8 = [[Module:Autotaxobox/testcases|testcases]]
}}
 
The purpose of this module is to provide support for the [[WP:Automated taxobox system|automated taxobox system]] (including templates such as {{tl|Speciesbox}} and {{tl|Automatic taxobox}}), avoiding Mediawiki template expansion depth errors in the traversal of the taxonomic hierarchies encoded in taxonomy templates.
local p = {}
 
Currently, processing is arbitrarily limited to hierarchies containing at most {{#invoke:Autotaxobox|getMaxSearchLevels}} levels.
--[[=========================================================================
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 MaxSearchLevels = 100
 
See the [[WP:Automated taxobox system/map|automated taxobox system map]] for information on how the module's functions are used in the system.
function p.getMaxSearchLevels()
return MaxSearchLevels
end
 
== taxoboxColour ==
--[[============================ taxonInfo ==================================
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.)
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', 'link', '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
 
Usage:
--[[========================== taxoboxColour ================================
 
Determines the correct colour for a taxobox, by searching up the taxonomic
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|taxoboxColour|''taxon_name''}}</code>
hierarchy from the supplied taxon for the first taxon (other than
 
'incertae sedis') that sets a taxobox colour. It is assumed that a valid
Parameters:
taxobox colour is defined using CSS rgb() syntax.
 
If no taxon that sets a taxobox colour is found, then 'transparent' is
:The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/''taxon_name''" exists.
returned unless the taxonomic hierarchy is too deep, when the error colour is
 
returned.
Examples:
Usage: {{#invoke:Autotaxobox|taxoboxColour|TAXON}}
 
=============================================================================]]
:<nowiki>{{#invoke:Autotaxobox|taxoboxColour|Felis}}</nowiki> → {{#invoke:Autotaxobox|taxoboxColour|Felis}}
function p.taxoboxColour(frame)
:<nowiki>{{#invoke:Autotaxobox|taxoboxColour|Acacia}}</nowiki> → {{#invoke:Autotaxobox|taxoboxColour|Acacia}}
local currTaxon = frame.args[1] or ''
 
local i = 1 -- count levels processed
== taxoboxList ==
local searching = currTaxon ~= '' -- still searching for a colour?
Given the name of a taxon, this function returns the rows of taxa in an automated taxobox, based on the taxonomic
local foundICTaxon = false -- record whether 'incertae sedis' found
hierarchy for the supplied taxon. If the lowest taxon displayed in the taxobox is below the rank of genus, the
local colour = '' -- default is no colour
supplied taxon will usually be at a higher rank than the taxobox's target taxon, so that there is an offset to be
while searching and i <= MaxSearchLevels do
taken into account.
local plainCurrTaxon = p.stripExtra(currTaxon) -- remove trailing text after /
if string.lower(plainCurrTaxon) == 'incertae sedis' then
foundICTaxon = true
else
local possibleColour = frame:expandTemplate{ title = 'Template: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
return colour
elseif foundICTaxon then
return frame:expandTemplate{ title = 'Template:Taxobox colour', args = { 'incertae sedis' } }
elseif searching then
-- hierarchy exceeds MaxSearchLevels levels
return frame:expandTemplate{ title = 'Template:Taxobox/Error colour', args = { } }
else
return 'transparent'
end
end
 
--[[=========================== taxoboxList =================================
Returns the rows of taxa in an automated taxobox, based on the taxonomic
hierarchy for the supplied taxon.
Usage:
{{#invoke:Autotaxobox|taxoboxList|TAXON
|display_taxa = the number of taxa *above* TAXON to force to be displayed
|authority = taxonomic authority for TAXON
|parent_authority = taxonomic authority for TAXON's parent
|gparent_authority = taxonomic authority for TAXON's grandparent
|ggparent_authority = taxonomic authority for TAXON's greatgrandparent
|ggparent_authority = taxonomic authority for TAXON's greatgreatgrandparent
|bold_first = 'bold' to bold TAXON in its row
}}
=============================================================================]]
function p.taxoboxList(frame)
local currTaxon = frame.args[1] or ''
local displayN = (tonumber(frame.args['display_taxa']) or 1) + 1
local auth = frame.args['authority'] or ''
local parentAuth = frame.args['parent_authority'] or ''
local gParentAuth = frame.args['gparent_authority'] or ''
local ggParentAuth = frame.args['ggparent_authority'] or ''
local gggParentAuth = frame.args['gggparent_authority'] or ''
local boldFirst = frame.args['bold_first'] or 'link' -- values 'link' or 'bold'
local taxonTable = p.makeTable(frame, currTaxon)
local res = ''
-- display all taxa above possible greatgreatgrandparent
for i = taxonTable.n, 6, -1 do
res = res .. frame:expandTemplate{ title = 'Template:Taxobox/showtaxon', args = { taxonTable[i], fc = tostring(displayN >= i) } }
end
-- display greatgreatgrandparent, if it exists
if taxonTable.n >= 5 then
res = res .. frame:expandTemplate{ title = 'Template:Taxobox/showtaxon', args = { taxonTable[5], authority = gggParentAuth, fc = tostring(displayN >= 5) } }
end
-- display greatgrandparent, if it exists; force the display if an infrataxon is below
if taxonTable.n >= 4 then
local force = tostring(displayN >= 4) or
frame.expandTemplate{ title = 'Template:Infrataxon()', args = { taxonTable[3] } } == 'true' or
frame.expandTemplate{ title = 'Template:Infrataxon()', args = { taxonTable[2] } } == 'true'
res = res .. frame:expandTemplate{ title = 'Template:Taxobox/showtaxon', args = { taxonTable[4], authority = ggParentAuth, fc = tostring(force) } }
end
-- display grandparent, if it exists; force the display if an infrataxon is below
if taxonTable.n >= 3 then
local force = tostring(displayN >= 3) or
frame.expandTemplate{ title = 'Template:Infrataxon()', args = { taxonTable[2] } } == 'true'
res = res .. frame:expandTemplate{ title = 'Template:Taxobox/showtaxon', args = { taxonTable[3], authority = gParentAuth, fc = tostring(force) } }
end
-- display parent, if it exists
if taxonTable.n >= 2 then
res = res .. frame:expandTemplate{ title = 'Template:Taxobox/showtaxon', args = { taxonTable[2], authority = parentAuth, fc = tostring(displayN >= 2) } }
end
-- display target taxon
res = res .. frame:expandTemplate{ title = 'Template:Taxobox/showtaxon', args = { taxonTable[1], authority = auth, fc = 'true', format = boldFirst } }
return res
end
 
<code><nowiki>{{</nowiki>#invoke:Autotaxobox|taxoboxList<br>
--[[========================== taxonomyList =================================
Returns |''the cellsname of taxon upwards from which the taxonomytaxonomic tablehierarchy is to be displayed onby this "Template:Taxonomy...."function''<br>
|display_taxa = ''the number of taxa above taxon to force to be displayed''<br>
pages.
|authority = ''taxonomic authority for the lowest level taxon in the taxobox (the taxobox_target) (see also offset below)''<br>
Usage: {{#invoke:Autotaxobox|taxonomyList|TAXON}}
|parent_authority = ''taxonomic authority for taxobox_target's parent''<br>
=============================================================================]]
|gparent_authority = ''taxonomic authority for taxobox_target's grandparent''<br>
function p.taxonomyList(frame)
|ggparent_authority = ''taxonomic authority for taxobox_target's greatgrandparent''<br>
local currTaxon = frame.args[1] or ''
|gggparent_authority = ''taxonomic authority for taxobox_target's greatgreatgrandparent''<br>
if currTaxon == '' then return '| ||ERROR: no taxon supplied\n|-' end
|bold_first = ''bold to embolden taxon in its row''<br>
local taxonTable = p.makeTable(frame, currTaxon)
|offset = ''the offset of taxon from taxobox_target – the number of steps from taxobox_target to taxon''<br>
local rankTable = p.getRankTable()
}}</code>
local lastRankVal = 1000000
 
local orderOk
Parameters:
local res = ''
 
for i = taxonTable.n, 1, -1 do
:The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/''taxon_name''" exists. The others are explained above.
-- check ranks are in right order in the hierarchy
 
local ok, rank = p.getTaxonInfoItem(frame, taxonTable[i], 'rank')
Examples:
local currRankVal = rankTable[rank]
 
if currRankVal then
<pre>{| class="wikitable"
orderOk = currRankVal < lastRankVal
{{#invoke:Autotaxobox|taxoboxList|Felis|authority=Linnaeus, 1758}}
if orderOk then lastRankVal = currRankVal end
|}</pre> →
else
{| class="wikitable"
orderOk = true
{{#invoke:Autotaxobox|taxoboxList|Felis|authority=Linnaeus, 1758}}
end
|}
-- now return a row of the taxonomy table with anomalous ranks marked
 
if orderOk then
== taxonomyList ==
res = res .. frame:expandTemplate{ title = 'Template:Taxonomy links', args = { taxonTable[i] } }
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.
else
 
if i ~= 1 then
When <em>descending</em> 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 <code>getRankTable()</code> are used to determine the correct sequence of ranks. Ranks without values in this table do not have their order checked.
res = res .. frame:expandTemplate{ title = 'Template:Taxonomy links', args = { taxonTable[i], error = 'true' } }
else
res = res .. frame:expandTemplate{ title = 'Template:Taxonomy links', args = { taxonTable[i], error = 'true', last_error = 'true' } }
end
end
end
return res
end
 
--[[========================= callTaxonomyKey ===============================
Prepares for, and then calls, Template: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 required.
Usage:
{{#invoke:Autotaxobox|callTaxonomyKey
|parent=
|rank=
|extinct=
|always_display=
|link_target=value of 'link' parameter in taxonomy template
|link_text=value of parameter 2 in taxonomy template
|same_as=
}}
=============================================================================]]
function p.callTaxonomyKey(frame)
local parent = frame.args['parent'] or ''
local rank = frame.args['rank'] or ''
local extinct = frame.args['extinct'] or ''
local alwaysDisplay = frame.args['always_display'] or ''
local linkTarget = frame.args['link_target'] or ''
local linkText = frame.args['link_text'] or ''
local sameAsTaxon = frame.args['same_as'] or ''
if sameAsTaxon ~= '' then
local sameAsInfoStr = frame:expandTemplate{ title = 'Template:Taxonomy/' .. sameAsTaxon, args = {['machine code'] = 'all' } }
local sameAsInfo = mw.text.split(sameAsInfoStr, '$', true)
if parent == '' then parent = sameAsInfo[1] end
if rank == '' then rank = sameAsInfo[2] end
if extinct == '' then extinct = sameAsInfo[6] end
if alwaysDisplay == '' then alwaysDisplay = sameAsInfo[5] end
if linkTarget == '' then linkTarget = sameAsInfo[3] end
if linkText == '' then linkText = sameAsInfo[4] end
end
local link = linkTarget
if linkText ~= '' then link = link .. "|" .. linkText end
return frame:expandTemplate{ title = 'Template:Taxonomy key',
args = {parent=parent, rank=rank, extinct=extinct, always_display=alwaysDisplay, link_target=linkTarget, link=link} }
end
 
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|taxonomyList|''taxon_name''}}</code>
--[[========================== showRankTable ================================
Returns a wikitable showing the ranks and their values as set up by
getRankTable().
Usage: {{#invoke:Autotaxobox|showRankTable}}
=============================================================================]]
 
Parameters:
function p.showRankTable(frame)
local rankTable = p.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 = 'Template:Anglicise rank', args = { k } }
res = res .. '|-\n|' .. k .. '||' .. rankShown .. '||' .. v .. '\n'
end
return res .. '|}\n'
end
 
:The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/''taxon_name''" exists.
--[[=============================== nth =====================================
External utility function primarily intended for use in checking and debugging.
Returns the nth level above a taxon in a taxonomic hierarchy, where the taxon
itself is counted as the first level.
Usage: {{#invoke:Autotaxobox|nth|TAXON|n=N}}
=============================================================================]]
function p.nth(frame)
local currTaxon = frame.args[1] or ''
if currTaxon == '' then return 'ERROR: no taxon supplied' end
local n = tonumber(frame.args['n'] or 1)
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
 
Examples:
--[[============================= nLevels ===================================
<pre>{{#invoke:Autotaxobox|taxonomyList|Felis}}</pre> →
External utility function primarily intended for use in checking and debugging.
{| class="wikitable"
Returns number of levels in a taxonomic hierarchy, starting from
|{{#invoke:Autotaxobox|taxonomyList|Felis}}
the supplied taxon as level 1.
|}
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
if inHierarchy then return MaxSearchLevels .. '+'
else return i
end
end
 
== callTaxonomyKey ==
--[[============================= listAll ===================================
This function prepares for, and then calls, {{tl|Taxonomy key}} to display a taxonomy
External utility function primarily intended for use in checking and debugging.
template page (which in turn invokes [[#taxonomyList|<code>taxonomyList</code>]] from this module). It does this by building up the information the template
Returns a comma separated list of a taxonomic hierarchy, starting from
requires, following one <code>same_as</code> link if present, and then calling it.
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 p.listTaxa(p.makeTable(frame, currTaxon))
end
 
It is used by {{tl|Don't edit this line}}.
--[[=========================================================================
Internal functions
=============================================================================]]
 
Usage:
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Internal 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
 
<code><nowiki>{{</nowiki>#invoke:Autotaxobox|callTaxonomyKey<br>
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
|taxon= <br>
Internal utility function to convert a taxon table to a comma-separated list.
|parent= <br>
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]]
|rank= <br>
function p.listTaxa(taxonTable)
|extinct= <br>
local lst = taxonTable[1]
|always_display= <br>
for i = 2, taxonTable.n, 1 do
|link_target=value of the 'link' parameter in the taxonomy template<br>
lst = lst .. ', ' .. taxonTable[i]
|link_text=value of the unnamed parameter in the taxonomy template<br>
end
|refs= <br>
return lst
|same_as= <br>
end
}}</code>
 
== showRefs ==
Shows the refs field in a taxonomy template, handing incertae sedis taxa and using '–' for absent refs.
 
Usage:
:<nowiki>{{</nowiki>#invoke:Autotaxobox|showRefs|''taxon_name''|''refs''}}
 
Examples:
:<nowiki>{{</nowiki>#invoke:Autotaxobox|showRefs|Neoscona|<nowiki>{{</nowiki>Taxon info|Neoscona|refs}}}} → {{#invoke:Autotaxobox|showRefs|Neoscona|{{Taxon info|Neoscona|refs}}}}
:<nowiki>{{</nowiki>#invoke:Autotaxobox|showRefs|Incertae sedis/Characidae|}} → {{#invoke:Autotaxobox|showRefs|Incertae sedis/Characidae|}}
 
== 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 {{tl|Taxon link}}. Some parameters can, under
some circumstances, be omitted.
 
Usage:
 
<code><nowiki>{{</nowiki>#invoke:Autotaxobox|taxonLink<br>
|taxon= </code>(having '/?' at the end triggers the output of ' (?)')<code><br>
|extinct= </code>('yes' or 'true' triggers the output of '†')<code><br>
|bold= </code>('yes' makes the core output bold and not wikilinked)<code><br>
|italic= </code>('yes' makes the core output italic)<code><br>
|link_target=''target for the wikilink''<br>
|plain_link_text= ''text of the wikilink'' </code>(without †, italics, etc.)<code><br>
}}</code>
 
Examples:
 
:<nowiki>{{#invoke:Autotaxobox|taxonLink|taxon=Felis|italic=yes}}</nowiki> → {{#invoke:Autotaxobox|taxonLink|taxon=Felis|italic=yes}}
:<nowiki>{{#invoke:Autotaxobox|taxonLink|taxon=Incertae sedis/Animalia}}</nowiki> → {{#invoke:Autotaxobox|taxonLink|taxon=Incertae sedis/Animalia}}
:<nowiki>{{#invoke:Autotaxobox|taxonLink|link_target=Pterosaur|plain_link_text=Pterosauromorpha|extinct=yes}}</nowiki> → {{#invoke:Autotaxobox|taxonLink|link_target=Pterosaur|plain_link_text=Pterosauromorpha|extinct=yes}}
:<nowiki>{{#invoke:Autotaxobox|taxonLink|taxon=Dinosauria/?|link_target=Dinosaur|plain_link_text=Dinosauria|extinct=yes}}</nowiki> → {{#invoke:Autotaxobox|taxonLink|taxon=Dinosauria/?|link_target=Dinosaur|plain_link_text=Dinosauria|extinct=yes}}
 
==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:
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|taxonInfo|''taxon_name''|''item_name''}}</code>
 
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 {{tl|Taxon info/doc}}.
 
Examples:
:<nowiki>{{#invoke:Autotaxobox|taxonInfo|Felis|rank}}</nowiki> → {{#invoke:Autotaxobox|taxonInfo|Felis|rank}}
:<nowiki>{{#invoke:Autotaxobox|taxonInfo|Aves/skip|same_as}}</nowiki> → {{#invoke:Autotaxobox|taxonInfo|Aves/skip|same_as}}
:<nowiki>{{#invoke:Autotaxobox|taxonInfo|Aves/skip|parent}}</nowiki> → {{#invoke:Autotaxobox|taxonInfo|Aves/skip|parent}}
 
==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:
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|getMaxSearchLevels}}</code> → {{#invoke:Autotaxobox|getMaxSearchLevels}}
 
===find===
Given a taxon name and a rank, this function returns the taxon's ancestor of the given rank.
 
Usage:
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|find|''taxon_name''|''rank''}}</code>
 
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:
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|find|Felis|ordo}}</code> → {{#invoke:Autotaxobox|find|Felis|ordo}}
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|find|Felis|classis}}</code> → {{#invoke:Autotaxobox|find|Felis|classis}}
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|find|Pteranodon|phylum}}</code> → {{#invoke:Autotaxobox|find|Pteranodon|phylum}}
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|find|Pteranodon|classis}}</code> → {{#invoke:Autotaxobox|find|Pteranodon|classis}}
 
===nth===
Given a taxon name, this function returns the ''n''th taxon above it in the taxonomic hierarchy.
 
Usage:
 
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|nth|''taxon_name''|n=''integer''}}</code>
 
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:
 
:<nowiki>{{#invoke:Autotaxobox|nth|Felis|n=1}}</nowiki> → {{#invoke:Autotaxobox|nth|Felis|n=1}}
:<nowiki>{{#invoke:Autotaxobox|nth|Felis|n=15}}</nowiki> → {{#invoke:Autotaxobox|nth|Felis|n=15}}
 
===nLevels===
Given a taxon name, this function returns the number of levels at and above it in the taxonomic hierarchy.
 
Usage:
 
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|nLevels|''taxon_name''}}</code>
 
Parameters:
 
:The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/''taxon_name''" exists.
 
Examples:
 
:<nowiki>{{#invoke:Autotaxobox|nLevels|Felis}}</nowiki> → {{#invoke:Autotaxobox|nLevels|Felis}}
:<nowiki>{{#invoke:Autotaxobox|nLevels|Pteranodon}}</nowiki> → {{#invoke:Autotaxobox|nLevels|Pteranodon}}
 
===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:
 
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|listAll|''taxon_name''}}</code>
 
Parameters:
 
:The unnamed parameter should be the name of a taxon for which "Template:Taxonomy/''taxon_name''" exists.
 
Examples:
 
:<nowiki>{{#invoke:Autotaxobox|listAll|Plantae}}</nowiki> → {{#invoke:Autotaxobox|listAll|Plantae}}
:<nowiki>{{#invoke:Autotaxobox|listAll|Felis}}</nowiki> → {{#invoke:Autotaxobox|listAll|Felis}}
 
===removeQualifier===
Given a taxon name, this function returns the name with any qualifier (i.e. any part after a "/") removed.
 
Usage:
 
:<code><nowiki>{{</nowiki>#invoke:Autotaxobox|removeQualifier|''taxon_name''}}</code>
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
{{#invoke:Autotaxobox|taxonInfoItem|ITEM VALUE|ITEM|SAME AS TAXON}}
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]]
function p.taxonInfoItem(frame)
local itemVal = frame.args[1]
if itemVal == '' then
local item = frame.args[2]
local sameAsTaxon = frame.args[3]
if sameAsTaxon ~= '' then
itemVal = frame:expandTemplate{ title = 'Template:Taxonomy/' .. sameAsTaxon, args = {['machine code'] = item } }
end
end
return itemVal
end
 
Examples:
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Internal utility function to extract an item of information from a
taxonomy template, following one 'same as' link if required.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]]
function p.getTaxonInfoItem(frame, taxon, item)
local ok, info = pcall(frame.expandTemplate, frame, { title = 'Template:Taxonomy/' .. taxon, args = {['machine code'] = item } })
if ok then
if info == '' then
-- try 'same as'
local sameAsTaxon = frame:expandTemplate{ title = 'Template:Taxonomy/' .. taxon, args = {['machine code'] = 'same as' } }
if sameAsTaxon ~= '' then
ok, info = pcall(frame.expandTemplate, frame, { title = 'Template:Taxonomy/' .. sameAsTaxon, args = {['machine code'] = item } })
if not ok then
info = '[[Template:Taxonomy/' .. sameAsTaxon .. ']]'
end
end
end
else
info = '[[Template:Taxonomy/' .. taxon .. ']]'
end
return ok, info
end
 
:<nowiki>{{#invoke:Autotaxobox|removeQualifier|Eukaryota/display}}</nowiki> → {{#invoke:Autotaxobox|removeQualifier|Eukaryota/display}}
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
:<nowiki>{{#invoke:Autotaxobox|removeQualifier|Felis}}</nowiki> → {{#invoke:Autotaxobox|removeQualifier|Felis}}
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.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]]
function p.makeTable(frame, currTaxon)
local i = 1
local inHierarchy = true -- still in the taxonomic hierarchy or off the top?
local taxonTable = {}
taxonTable[1] = currTaxon;
while i < MaxSearchLevels and inHierarchy do
local ok, parent = p.getTaxonInfoItem(frame, currTaxon, 'parent')
if ok and parent ~= '' then
currTaxon = parent
i = i + 1
taxonTable[i] = currTaxon
else
inHierarchy = false -- run off the top of the hierarchy or tried to use non-existent taxonomy template
end
end
taxonTable.n = i
return taxonTable
end
 
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
<!-- Categories below this line, please; interwikis at Wikidata -->
Internal utility function to set up a table of numerical values corresponding
[[Category:Taxobox templates]]
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 p.getRankTable()
return {
classis = 1400,
cohort = 1100,
divisio = 1500,
___domain = 1700,
familia = 800,
genus = 600,
grandordo = 1005,
['grandordo-mb'] = 1002,
infraclassis = 1397,
infralegio = 1197,
infraordo = 997,
infraphylum = 1497,
infraregnum = 1597,
infratribus = 697,
legio = 1200,
magnordo = 1006,
micrordo = 995,
mirordo = 1004,
['mirordo-mb'] = 1001,
nanordo = 999,
ordo = 1000,
parafamilia = 800,
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,
subtribus = 698,
superclassis = 1403,
supercohort = 1103,
superdivisio = 1503,
superdomain = 1703,
superfamilia = 803,
superlegio = 1203,
superordo = 1003,
superphylum = 1503,
superregnum = 1603,
supertribus = 703,
tribus = 700,
varietas = 200,
zoodivisio = 1300,
zoosectio = 900,
zoosubdivisio = 1298,
zoosubsectio = 898,
}
end
 
}}</includeonly>
return p
<noinclude>
[[Category:Module documentation pages]]
</noinclude>