Difference between revisions of "Module:TaxonList"
blackwiki>Peter coxhead |
blackwiki>Peter coxhead |
||
| Line 22: | Line 22: | ||
else | else | ||
if string.sub(taxon,1,5) == '<span' then | if string.sub(taxon,1,5) == '<span' then | ||
| − | taxon = string. | + | taxon = string.gsub(taxon, '^.*</span>', '', 1) |
dagger = '†' | dagger = '†' | ||
debugMsg = debugMsg .. '<p>stripped taxon=>' .. taxon .. '<</p>' | debugMsg = debugMsg .. '<p>stripped taxon=>' .. taxon .. '<</p>' | ||
Revision as of 11:13, 11 November 2017
| 40px | This Lua module is used on approximately 11,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages. Consider discussing changes on the talk page before implementing them.
Transclusion count updated automatically (see documentation). |
| 40x40px | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Module:TaxonList Template:Toolbar
The purpose of this module is to provide support for a set of templates that produce a list of taxon names and their authorities, with the taxon names possibly italicized, wikilinked or emboldened. It allows these templates to have an indefinite number of arguments of the form taxonName1|authority1|taxonName2|authority2| ... |taxonNameN|authorityN. Templates supported are: {{Bold species list}}, {{Linked species list}}, {{Linked taxon list}}, {{Species list}} and {{Taxon list}}.
Usage
The main function in this module must only be invoked from within a template that itself is transcluded from a page that supplies taxon name/authority pairs as arguments, since main picks up these arguments from the parent frame.
{{#invoke:TaxonList|main|PARAMETERS}}
where PARAMETERS may be
italic– set toyesto italicize each taxon namelinked– set toyesto wikilink each taxon namebold– set toyesto embolden each taxon name (also turns off wikilinking)incomplete– set toyesto output "(incomplete)" at the end of the list
Examples
{{Taxon list}} contains {{#invoke:TaxonList|main|incomplete={{{incomplete|no}}}}}. Hence:
{{Taxon list |Asparagales|Bromhead |Iridales|Dumortier}} →
Template:Taxon list
{{Linked species list}} contains {{#invoke:TaxonList|main|linked=yes|italic=yes|incomplete={{{incomplete|no}}}}}. Hence:
{{Linked species list |Poecilotheria fasciata|(Latreille, 1804) |Poecilotheria ornata|Pocock, 1899 |Poecilotheria rajaei|Nanayakkara et al., 2012 |incomplete=yes}} →
- Nanayakkara et al., 2012 (Latreille, 1804)
- Poecilotheria ornata Poecilotheria fasciata
- Pocock, 1899 Poecilotheria rajaei (incomplete list)
taxon=N_a_n_a_y_a_k_k_a_r_a_ _e_t_ _a_l_._,_ _2_0_1_2_ _
taxon=P_o_e_c_i_l_o_t_h_e_r_i_a_ _o_r_n_a_t_a_
taxon=P_o_c_o_c_k_,_ _1_8_9_9_ _
local p = {}
local debugMsg = ''
function p.rawStr(str)
local result = ''
for i = 1, #str do
result = result .. string.sub(str,i,i) .. '_'
end
return result
end
function p.stripDagger(taxon)
debugMsg = debugMsg .. '<p>taxon=' .. p.rawStr(taxon) .. '</p>'
local dagger = ''
if mw.ustring.sub(taxon,1,1) == '†' then
taxon = mw.ustring.sub(taxon,2,#taxon)
dagger = '†'
else
if string.sub(taxon,1,8) == '†' then
taxon = string.sub(taxon,9,#taxon)
dagger = '†'
else
if string.sub(taxon,1,5) == '<span' then
taxon = string.gsub(taxon, '^.*</span>', '', 1)
dagger = '†'
debugMsg = debugMsg .. '<p>stripped taxon=>' .. taxon .. '<</p>'
end
end
end
return taxon, dagger
end
function p.main(frame)
local italic = frame.args['italic'] == 'yes'
local linked = frame.args['linked'] == 'yes'
local incomplete = frame.args['incomplete'] == 'yes'
local taxonArgs = frame:getParent().args
local result = ''
local num
-- iterate over unnamed variables
local taxon
local dagger
local first = true
for name, value in pairs(taxonArgs) do
if tonumber(name) then
if first then
taxon = value
if linked or italic then
taxon, dagger = p.stripDagger(taxon)
else
dagger = ''
end
if linked then
taxon = '[[' .. taxon .. ']]'
end
if italic then
taxon = '<i>' .. taxon .. '</i>'
end
result = result .. '<li>' .. dagger .. taxon
else
result = result .. ' <small>' .. value .. '</small></li>'
end
first = not first
end
end
if incomplete then
result = result .. '<small>(incomplete list)</small>'
end
return '<ul style="plainlist">' .. result .. '</ul>' .. debugMsg
end
return p