Module:eFloras
Appearance
![]() | This Lua module is used on approximately 1,400 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
Usage
This module performs tasks for Template:eFloras. The first task is taking the flora_id
and the name of the family (or tribe of Asteraceae) and converting them to the corresponding volume numbers for the Floras of North America, China, and Chile. The second is taking the flora_id
from the URL and returning the corresponding flora or list name. The data used for these two tasks is in Module:eFloras/data. The third is detecting what type of scientific name is in the third parameter of the template, and applying the correct italicization. For this purpose, the module strips initial and final whitespace, and any italicization or bolding.
{{#invoke:EFloras|volume|1|family=Rosaceae}} or {{#invoke:EFloras|volume|1|Rosaceae}} {{#invoke:EFloras|resource|1}} {{#invoke:eFloras|volumeDate|1||Rosaceae}} {{#invoke:eFloras|volumeDate|1|9|}} {{#invoke:eFloras|volumeName|1||Rosaceae}} {{#invoke:eFloras|volumeName|1|9|}}
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
{{#invoke:eFloras|name|Asteraceae}}
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
{{#invoke:eFloras|name|Aster}}
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
{{#invoke:eFloras|name|Aster ericoides}}
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
{{#invoke:eFloras|name|Aster ericoides var. ericoides}}
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
{{#invoke:eFloras|name|Aster ericoides'' var. ''ericoides}}
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
{{#invoke:eFloras|name|Acer tataricum subsp. ginnala}}
- Lua error in package.lua at line 80: module 'Module:No globals' not found.
Tracking
require('Module:No globals')
local p = {}
local data -- Load [[Module:eFloras/data]] if needed and assign to this variable.
local function getResource(floraID)
data = data or mw.loadData("Module:eFloras/data")
return data.resources[floraID]
end
function p.resource(frame)
local floraID = string.match(frame.args[1], "%d+")
if floraID == nil then
return "<span style=\"color: red;\">Please provide a resource number (<code>flora_id</code>). See the list of supported resource numbers at [[Module:eFloras/doc]]</span>"
else
local flora = getResource(floraID)
if flora == nil then
return "<span style=\"color: red;\">The resource number (<code>flora_id</code>) <code>" .. floraID .. "</code> is not recognized. See the list of supported resource numbers at [[Module:eFloras/doc]]</span>[[Category:Pages using eFloras template with unsupported parameter values]]"
else
return flora
end
end
end
local function getVolumeAndVolumeName(args)
local floraID = string.match(args[1], "%d+")
data = data or mw.loadData("Module:eFloras/data")
local family = args[2] or args.family
local floraData = data.volumeTable[floraID]
local volume = floraData and floraData[family]
return volume,
volume and data.volumeNames and data.volumeNames[floraID]
and data.volumeNames[floraID][tonumber(volume)]
end
function p.volume(frame)
local volume, volumeName = getVolumeAndVolumeName(frame.args)
if volume == "error" then
return "19–21 [[Category:Pages using eFloras template with unsupported parameter values]]"
elseif volume == nil then
return ""
else
if volumeName then
return ("'''%s''': %s"):format(volume, volumeName)
else
return volume
end
end
end
-- Italicize if name requires it.
function p.italicize(name)
local orig = name
name = string.gsub(name, "^%s*(.*)%s*$", "%1")
local count
name, count = string.gsub(name, "\'\'\'?", "")
if count > 0 then
-- A tracking method used on Wiktionary: [[wikt:Module:debug]].
-- To see the results:
-- [[Special:WhatLinksHere/Template:tracking/eFloras/italics or bolding]]
local frame = mw.getCurrentFrame()
pcall(frame.expandTemplate, frame, { title = 'tracking/eFloras/italics or bolding' })
mw.log("Italics in parameter of {{eFloras}}:", orig)
end
local rank = ""
if name == "" or name == nil then
rank = ""
elseif string.find(name, "%u%l+eae$") then
if string.find(name, "aceae$") then
rank = "family"
elseif string.find(name, "oideae$") then
rank = "subfamily"
else
rank = "tribe"
end
elseif string.find(name, "%u%l+inae$") then
rank = "subtribe"
elseif string.find(name, "subsp.", nil, true) then
rank = "subspecies"
elseif string.find(name, "subg.", nil, true) then
rank = "subgenus"
elseif string.find(name, "var.", nil, true) then
rank = "variety"
elseif string.find(name, "sect.", nil, true) then
rank = "section"
elseif string.find(name, "^%a+%s%a+$") or string.find(name, "^%a+%s×%s%a+$") then
rank = "species"
elseif string.find(name, "^%a+$") then
rank = "genus"
else
mw.log("Module:eFloras could not determine a taxonomic rank for the input that it received: " .. name)
end
if not rank then
return orig
end
if rank == "genus" or rank == "subgenus" or rank == "species"
or rank == "subspecies" or rank == "variety" or rank == "section" then
name = "<i>" .. name .. "</i>"
local hybrid = "×"
local abbreviations = {
["subsp."] = true, ["ssp."] = true, ["var."] = true, ["f."] = true,
["sect."] = true, ["subsect."] = true, ["subg."] = true,
}
local unrecognized
name = name:gsub(
"%s+(%S+%.)%s+",
function (abbreviation)
if abbreviations[abbreviation] then
return "</i> " .. abbreviation .. " <i>"
else
unrecognized = unrecognized or {}
table.insert(unrecognized, abbreviation)
end
end)
name = name:gsub("%s+" .. hybrid .. "%s+", "</i> " .. hybrid .. " <i>")
if unrecognized then
error("Abbreviations "
.. table.concat(
unrecognized,
", ")
.. " are not recognized.")
end
end -- Else do not modify name.
return name
end
function p.name(frame)
local name = frame.args[1]
return p.italicize(name)
end
p.get_volume = p.volume
return p