"Module:Autotaxobox": अवतरणों में अंतर

मुक्त ज्ञानकोश विकिपीडिया से
Content deleted Content added
छो en:Module:Autotaxobox से 74 अवतरण आयात किये गए
No edit summary
पंक्ति 1: पंक्ति 1:
require('Module:No globals')
--[[
local TaxonItalics = require('Module:TaxonItalics')
This module provides support to the automated taxobox system – the templates
local Autotaxobox = require('Module:Autotaxobox')
Automatic taxobox, Speciesbox, Subspeciesbox, Infraspeciesbox, etc.
local ItalicTitle = require('Module:Italic title')
local p = {} -- functions made public
local l = {} -- internal functions, kept separate


-- =============================================================================
In particular it provides a way of traversing the taxonomic hierarchy encoded
-- automaticTaxobox implements Template:Automatic taxobox; see the documentation
in taxonomy templates (templates with names of the form
-- of that template for details.
"Template:Taxonomy/TAXON_NAME") without causing template expansion depth errors.
-- 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 p = {}
local args

if frame.args['direct'] == 'yes' then args = frame.args
--[[=========================================================================
else args = frame:getParent().args end
Limit the maximum depth of a taxonomic hierarchy that can be traversed;
-- ---------------------------------------------------------------------
avoids excessive processing time and protects against incorrectly set up
-- pick up taxobox parameters from the caller that need to be processed;
hierarchies, e.g. loops.
-- most will be passed on unchanged
=============================================================================]]
-- ---------------------------------------------------------------------
local MaxSearchLevels = 100
local pagename = args['pagename'] or '' -- for testing and debugging only

local italicTitle = args['italic_title'] or args['italic title'] or ''
function p.getMaxSearchLevels()
local fossilRange = args['fossil_range'] or args['fossil range'] or args['temporal_range'] or args['temporal range'] or ''
return MaxSearchLevels
local oldestFossil = args['oldest_fossil'] or args['oldest fossil'] or ''
end
local youngestFossil = args['youngest_fossil'] or args['youngest fossil'] or ''

local name = args['name'] or ''
--[[========================== taxoboxColour ================================
local colourAs = args['color_as'] or args['color as'] or args['colour_as'] or args['colour as'] or ''
Determines the correct colour for a taxobox, by searching up the taxonomic
hierarchy from the supplied taxon for the first taxon (other than
local taxon = args['taxon'] or ''
local authority = args['authority'] or ''
'incertae sedis') that sets a taxobox colour. It is assumed that a valid
local parentAuthority = args['parent_authority'] or args['parent authority'] or ''
taxobox colour is defined using CSS rgb() syntax.
local subdivision = args['subdivision'] or ''
If no taxon that sets a taxobox colour is found, then 'transparent' is
local subdivisionRef = args['subdivision_ref'] or args['subdivision ref'] or ''
returned unless the taxonomic hierarchy is too deep, when the error colour is
local subdivisionRanks = args['subdivision_ranks'] or args['subdivision ranks'] or ''
returned.
local manualFlag = 'text' -- marks manually specified ranks
Usage: {{#invoke:Autotaxobox|taxoboxColour|TAXON}}
local binomial = args['binomial'] or args['binomial_'..manualFlag] or args['binomial '..manualFlag] or ''
=============================================================================]]
local binomialAuthority = args['binomial_authority'] or args['binomial_authority'] or''
function p.taxoboxColour(frame)
local currTaxon = frame.args[1] or ''
local genusManual = args['genus_'..manualFlag] or args['genus '..manualFlag] or''
local speciesManual = args['species_'..manualFlag] or args['species '..manualFlag] or''
local i = 1 -- count levels processed
-- ------------------------------------------------------
local searching = currTaxon ~= '' -- still searching for a colour?
-- set the taxobox parameters determined by this function
local foundICTaxon = false -- record whether 'incertae sedis' found
-- ------------------------------------------------------
local colour = '' -- default is no colour
fossilRange = l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil)
while searching and i <= MaxSearchLevels do
-- use the base page name as the taxon if the taxon parameter is missing
local plainCurrTaxon = p.stripExtra(currTaxon) -- remove trailing text after /
local currentPagename = mw.title.getCurrentTitle()
if string.lower(plainCurrTaxon) == 'incertae sedis' then
if pagename == '' then pagename = currentPagename.text end -- pagename para only used in testing and debugging
foundICTaxon = true
local basePagename = mw.ustring.gsub(pagename, '%s+%b()$', '', 1)
else
local taxonParaMissingError = false
local possibleColour = frame:expandTemplate{ title = 'Template:Taxobox colour', args = { plainCurrTaxon } }
if string.sub(possibleColour,1,3) == 'rgb' then
if taxon == '' then
taxonParaMissingError = true
colour = possibleColour
taxon = basePagename
searching = false
end
end
-- decide if the page name and taxobox name need to be italicized;
end
-- if italic_title is not set, then if the names are the taxon, use its rank to decide
if searching then
local ok, parent = p.getTaxonInfoItem(frame, currTaxon, 'parent')
local ok, taxonRank = Autotaxobox.getTaxonInfoItem(frame, taxon, 'rank') -- taxonRank needed later if not here
if ok and parent ~= '' then
if italicTitle == '' then
if not (ok and taxonRank ~= '' and
currTaxon = parent
frame:expandTemplate{ title = 'Is italic taxon', args = {taxonRank} } == 'yes') then
i = i + 1
italicTitle = 'no'
else
searching = false -- run off the top of the hierarchy or tried to use non-existent taxonomy template
end
end
end
end
end
-- remove any " (DISAMBIG)" or "/MODIFIER" from the taxon's name;
if colour ~= '' then
-- if the base page name is the same as the base taxon name, then italicization can be applied
return colour
local baseTaxon = mw.ustring.gsub(mw.ustring.gsub(taxon, '%s+%b()$', '', 1), '/.*$', '', 1)
elseif foundICTaxon then
if italicTitle == '' and basePagename == baseTaxon then
return frame:expandTemplate{ title = 'Template:Taxobox colour', args = { 'incertae sedis' } }
italicTitle = 'yes'
elseif searching then
-- hierarchy exceeds MaxSearchLevels levels
return frame:expandTemplate{ title = 'Template:Taxobox/Error colour', args = { } }
else
return 'transparent'
end
end
-- italicize the page name (page title) if required
end
if italicTitle == 'yes' and currentPagename.namespace == 0 then

ItalicTitle._main({})
--[[=========================== 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
end
-- set the taxobox name if not supplied, italicizing it if appropriate.
-- display greatgreatgrandparent, if it exists
if taxonTable.n >= 5 then
if name == '' then
name = basePagename
res = res .. frame:expandTemplate{ title = 'Template:Taxobox/showtaxon', args = { taxonTable[5], authority = gggParentAuth, fc = tostring(displayN >= 5) } }
if italicTitle == 'yes' then
end
name = TaxonItalics.italicizeTaxonName(name, false, false)
-- 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

--[[========================== taxonomyList =================================
Returns the cells of the taxonomy table displayed on "Template:Taxonomy...."
pages.
Usage: {{#invoke:Autotaxobox|taxonomyList|TAXON}}
=============================================================================]]
function p.taxonomyList(frame)
local currTaxon = frame.args[1] or ''
if currTaxon == '' then return '| ||ERROR: no taxon supplied\n|-' end
local taxonTable = p.makeTable(frame, currTaxon)
local rankTable = p.getRankTable()
local lastRankVal = 1000000
local orderOk
local res = ''
for i = taxonTable.n, 1, -1 do
-- check ranks are in right order in the hierarchy
local ok, rank = p.getTaxonInfoItem(frame, taxonTable[i], 'rank')
local currRankVal = rankTable[rank]
if currRankVal then
orderOk = currRankVal < lastRankVal
if orderOk then lastRankVal = currRankVal end
else
orderOk = true
end
-- now return a row of the taxonomy table with anomalous ranks marked
if orderOk then
res = res .. frame:expandTemplate{ title = 'Template:Taxonomy links', args = { taxonTable[i] } }
else
if i ~= 1 then
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
-- name = name .. '/' .. baseTaxon .. '/' .. nameRank
end
end
-- determine taxobox colour
return res
local colour = ''
end
if colourAs ~= '' then

colour = frame:expandTemplate{ title = 'Taxobox colour', args = {colourAs} }
--[[========================= 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=
}}
=============================================================================]]
local SAME_AS = 7
local PARENT = 1
local RANK = 2
local LINK_TARGET = 3
local LINK_TEXT = 4
local ALWAYS_DISPLAY = 5
local EXTINCT = 6
local REFS = 8

function p.callTaxonomyKey(frame)
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 = 'Template: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
return frame:expandTemplate{ title = 'Template:Taxonomy key/missing template', args = {taxon=sameAsTaxon, msg='given as the value of <code>same as</code>'} }
end
end
local link = linkTarget
if linkText ~= '' and linkText ~= linkTarget 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, refs=refs, same_as=sameAsTaxon} }
end

--[[============================ 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', '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

--[[============================ taxonLink ==================================
Returns a wikilink to a taxon, if required including '†' before it and
' (?)' after it, and optionally italicized or bolded without a wikilink.
Usage:
{{#invoke:Autotaxobox|taxonLink
|taxon= : having '/?' at the end triggers the output of ' (?)'
|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 linkTarget = frame.args['link_target'] or ''
local linkText = frame.args['link_text'] or frame.args['plain_link_text'] or '' --temporarily allow alternative args
-- 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 = p.stripExtra(taxon)
end
end
local link = ''
if bold == 'yes' then link = '<b>' .. linkText .. '</b>'
else
else
colour = Autotaxobox.getTaxoboxColour(frame, taxon)
if linkTarget == linkText or linkTarget == '' then link = linkText
else link = linkTarget .. '|' .. linkText
end
link = '[[' .. link .. ']]'
end
end
-- fill in a missing subdivision_ranks parameter
if italic == 'yes' and not string.find(link, "''", 1, true) then link = '<i>' .. link .. '</i>' end
if (extinct == 'yes' or extinct == 'true') and not string.find(link, '†', 1, true) then
if subdivision ~= '' and subdivisionRanks == '' and ok and taxonRank ~= '' then
subdivisionRanks = frame:expandTemplate{ title = 'Children rank', args = {taxonRank} }
link = '<span style="font-style:normal;font-weight:normal;">†</span>' .. link
end
end
-- set binomial parameters if the target taxon is (unusually) a species
if string.sub(taxon, -2) == '/?' and not string.find(link, '?', 1, true) then
local genusAuthority = ''
link = link .. '<span style="font-style:normal;font-weight:normal;"> (?)</span>'
if binomial == '' then
end
if ok and taxonRank == 'species' then
return link
binomial = TaxonItalics.italicizeTaxonName(taxon, false, false)
end
binomialAuthority = authority

--[[========================== showRankTable ================================
Returns a wikitable showing the ranks and their values as set up by
getRankTable().
Usage: {{#invoke:Autotaxobox|showRankTable}}
=============================================================================]]

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

--[[=============================== 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
end
end
-- handle any manually set ranks
if inHierarchy then return currTaxon
local boldFirst = ''
else return 'Level ' .. n .. ' is past the top of the taxonomic hierarchy'
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
end
if genusManual ~= '' then
end
boldFirst = 'link'

offset = offset + 1
--[[============================= nLevels ===================================
if offset == 1 then
External utility function primarily intended for use in checking and debugging.
genusAuthority = authority
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] 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
else
genusAuthority = parentAuthority
inHierarchy = false
end
end
end
end
-- ------------------------------------------------
if inHierarchy then return MaxSearchLevels .. '+'
-- now call Taxobox/core with all of its parameters
else return i
-- ------------------------------------------------
end
local res = frame:expandTemplate{ title = 'Taxobox/core', args =
{ ['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 = args['type_genus'] or args['type genus'] or '',
type_genus_authority = args['type_genus_authority'] or args['type genus authority'] or '',
type_species = args['type_species'] or args['type species'] or '',
type_species_authority = args['type_species_authority'] or args['type species authority'] or '',
subdivision = subdivision,
subdivision_ref = subdivisionRef,
subdivision_ranks = subdivisionRanks,
type_strain = args['type_strain'] or args['type strain'] 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
end


--[[============================= listAll ===================================
-- =============================================================================
-- l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil) checks
External utility function primarily intended for use in checking and debugging.
-- the parameters that determine the fossil range, returning an appropriate
Returns a comma separated list of a taxonomic hierarchy, starting from
-- range.
the supplied taxon.
-- =============================================================================
Usage: {{#invoke:Autotaxobox|listAll|TAXON}}
-- temporary public function for debugging
=============================================================================]]
function p.listAll(frame)
function p.chkFossilRange(frame)
local currTaxon = frame.args[1] or ''
local args = frame.args
local fossilRange = args['temporal_range'] or args['temporal range'] or args['fossil_range'] or args['fossil range'] or ''
if currTaxon == '' then return 'ERROR: no taxon supplied' end
local oldestFossil = args['oldest_fossil'] or args['oldest fossil'] or ''
return p.listTaxa(p.makeTable(frame, currTaxon))
local youngestFossil = args['youngest_fossil'] or args['youngest fossil'] or ''
local fossilRange = l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil)
return fossilRange
end
end


function l.setfossilRange(frame, fossilRange, oldestFossil, youngestFossil)
--[[=========================================================================
local res = ''
Internal functions
if fossilRange ~= '' then
=============================================================================]]
if mw.ustring.find(frame:expandTemplate{ title = 'Period start', args = { fossilRange } }, '[Ee]rror') then

res = fossilRange
--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
else
Internal utility function to strip off any extra parts of a taxon name, i.e.
res = frame:expandTemplate{ title = 'Geological range', args = { fossilRange } }
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

--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Internal utility function to convert a taxon table to a comma-separated list.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]]
function p.listTaxa(taxonTable)
local lst = taxonTable[1]
for i = 2, taxonTable.n, 1 do
lst = lst .. ', ' .. taxonTable[i]
end
return lst
end

--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
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)
-- item == 'link' is a special case
if item == 'link' then
return p.getTaxonInfoLink(frame, taxon)
end
-- item ~= 'link'
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 } })
end
end
end
elseif oldestFossil ~= '' then
end
if youngestFossil == '' then youngestFossil = 'Recent' end
if ok then
if mw.ustring.find(frame:expandTemplate{ title = 'Period start', args = { oldestFossil } }, '[Ee]rror') or
-- if item is 'link_text' check whether '(?)' needs to be added
mw.ustring.find(frame:expandTemplate{ title = 'Period start', args = { youngestFossil } }, '[Ee]rror') then
if item == 'link_text' and string.sub(taxon, -2) == '/?' and not string.find(info, '?', 1, true) then
res = oldestFossil..'–'..youngestFossil
info = info .. '<span style="font-style:normal;font-weight:normal;"> (?)</span>'
end
else
info = '[[Template:Taxonomy/' .. taxon .. ']]' --error indicator in code before conversion to Lua
end
return ok, info
end

function p.getTaxonInfoLink(frame, taxon)
local ok, linkText, linkTarget
local link = ''
ok, linkText = p.getTaxonInfoItem(frame, taxon, 'link_text')
if ok then
ok, linkTarget = p.getTaxonInfoItem(frame, taxon, 'link_target')
if ok then
if linkText == linkTarget then link = linkText
else link = linkTarget .. '|' .. linkText
end
end
end
return ok, link
end

--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
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
else
res = frame:expandTemplate{ title = 'Geological range', args = { oldestFossil, youngestFossil } }
inHierarchy = false -- run off the top of the hierarchy or tried to use non-existent taxonomy template
end
end
end
end
return res
taxonTable.n = i
return taxonTable
end

--[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
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 p.getRankTable()
return {
classis = 1400,
cohort = 1100,
divisio = 1500,
domain = 1700,
familia = 800,
forma = 100,
genus = 600,
grandordo = 1005,
['grandordo-mb'] = 1002,
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 = 1499,
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
end



11:09, 21 सितंबर 2020 का अवतरण

require('Module:No globals')
local TaxonItalics = require('Module:TaxonItalics')
local Autotaxobox = require('Module:Autotaxobox')
local ItalicTitle = require('Module:Italic title')
local p = {} -- functions made public
local l = {} -- internal functions, kept separate

-- =============================================================================
-- automaticTaxobox implements Template:Automatic taxobox; see the documentation
-- of that template for details.
-- 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
	-- ---------------------------------------------------------------------
	-- 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 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 debugging
	local basePagename = mw.ustring.gsub(pagename, '%s+%b()$', '', 1)
	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 = mw.ustring.gsub(mw.ustring.gsub(taxon, '%s+%b()$', '', 1), '/.*$', '', 1)
	if italicTitle == '' and basePagename == baseTaxon then
		italicTitle = 'yes'
	end
	-- italicize the page name (page title) if required
	if italicTitle == 'yes' and currentPagename.namespace == 0 then
		ItalicTitle._main({})
	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} }
	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
	-- ------------------------------------------------
	-- now call Taxobox/core with all of its parameters
	-- ------------------------------------------------
	local res = frame:expandTemplate{ title = 'Taxobox/core', args =
		{ ['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 = args['type_genus'] or args['type genus'] or '',
		  type_genus_authority = args['type_genus_authority'] or args['type genus authority'] or '',
		  type_species = args['type_species'] or args['type species'] or '',
		  type_species_authority = args['type_species_authority'] or args['type species authority'] or '',
		  subdivision = subdivision,
		  subdivision_ref = subdivisionRef,
		  subdivision_ranks = subdivisionRanks,		  
		  type_strain = args['type_strain'] or args['type strain'] 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

return p