require('strict')-- All Lua modules on Wikipedia must begin by defining a variable that will hold their-- externally accessible functions. They can have any name and may also hold data.local p = -- exposed variableslocal g = -- these are variables with global scope in this module
local info = -- contains general purpose information (e.g. header background colour)info.debug = false -- ONLY SET THIS WHILE TESTING
--local paramData = require('Module:Sandbox/Jts1882/Biota Infobox/data') -- contains the taxon ranks in order--local autotaxa = require("Module:Sandbox/Jts1882/Biota Infobox/Autotaxobox")--local autotaxa = require("Module:Autotaxobox")local parameters = require('Module:Biota infobox/param') local core = require('Module:Biota infobox/core')
-- ######################### PARAMETER HANDLING ############################
local templateArgs = -- contains preprocessed arguments from calling template --TODO use info.args instead of templateArgs?
-- ########################### MAIN AND OTHER ENTRY FUNCTIONS ##################################
--genus|species|binomial name colour = p.getTaxoboxColor(frame) ]] end
--return p._core(frame) return core.core(frame, templateArgs, info)end
-- this functions emulates Template:automatic taxobox and uses Template:Taxobox/corep.auto = function(frame) --info.auto = frame.args.auto or "automatictaxobox" p.getArgs(frame) -- gets arguments, checks for value, aliases, and against valid parameter list
if info.auto then p.AutomaticTaxoboxOptions(frame) -- this emulates the automatic taxobox templates that feed the core end -- additional parameters needed by Template:Taxobox/core templateArgs['edit link']="edit taxonomy" templateArgs['colour'] = p.getTaxoboxColor(frame) templateArgs['upright'] = templateArgs['image_upright'] or 1 templateArgs['upright2'] = templateArgs['image2_upright'] or 1 -- use Template:Taxobox/core return tostring(frame:expandTemplate) end
--
-- ################## AUTOMATIC TAXOBOX SYSTEM HANDLING ################################-------------------------------------------------------------------------------------------------- handle specific requirements of different options: auto, speciesbox etcfunction p.AutomaticTaxoboxOptions(frame) --TODO replace genus with first word (genus) to strip parenthetic term -- done in speciesbox? templateArgs['display_taxa'] = templateArgs['display_parents'] or 1 -- note change of parameter name
local extinct = "" if templateArgs['extinct'] or templateArgs['status']
---------------------variables for SPECIESBOX, SUBSPECIESBOX and INFRASPECIESBOX--------------------- if info.auto
local subspecies1, subspecies2, subspecies3 = "", "", "" --if (templateArgs['subspecies1'] and templateArgs['subspecies2']) if templateArgs['subspecies1'] or templateArgs['subspecies2'] or (templateArgs['father_subspecies'] and templateArgs['mother_subspecies']) then subspecies1 = " " .. ((templateArgs['subspecies1'] or templateArgs['father_subspecies']) or "") subspecies2 = " " .. ((templateArgs['subspecies2'] or templateArgs['mother_subspecies']) or "") if templateArgs['subspecies3'] then subspecies3 = " " .. templateArgs['subspecies3'] species3 = species1 end end local link1 = templateArgs['link1'] or templateArgs['father_link'] or (genus1 .. " " .. species1 .. subspecies1) local link2 = templateArgs['link2'] or templateArgs['mother_link'] or (genus2 .. " " .. species2 .. subspecies2) local link3 = templateArgs['link3'] or (genus3 .. " " .. species3 .. subspecies3)
if not templateArgs['parent'] then templateArgs['parent'] = genus1 end --TODO disambiguate genus pages -- not needed unless using page name --genus1 = frame:expandTemplate -- genus2 = frame:expandTemplate if not templateArgs['genus2'] and not templateArgs['father_genus'] then genus1 = string.sub(genus1,1,1) .. "." -- shorten generic names for intrageneric hybrids genus2 = string.sub(genus2,1,1) .. "." genus3 = string.sub(genus3,1,1) .. "." end -- shorten species name if subspecies of same species if subspecies1 ~= "" and not templateArgs['species2'] then species1 = string.sub(species1,1,1) .. "." -- shorten specific epithet for intraspecific hybrids species2 = string.sub(species2,1,1) .. "." if subspecies3 ~= "" then species3 = string.sub(species3,1,1) .. "." end end
local maleSymbol, femaleSymbol = "", "" if templateArgs['father'] or templateArgs['father_genus'] or templateArgs['father_species'] or templateArgs['father_subspecies'] then maleSymbol = "♂" end if templateArgs['mother'] or templateArgs['mother_genus'] or templateArgs['mother_species'] or templateArgs['mother_subspecies'] then femaleSymbol = "♀" end templateArgs['hybrid'] = "" .. genus1 .. " " .. species1 .. subspecies1 .."" .. maleSymbol .. " × " .. "" .. genus2 .. " " .. species2 .. subspecies2 .. "" .. femaleSymbol
if species3 ~= "" then templateArgs['hybrid'] = templateArgs['hybrid'] .. " × " .. "" .. genus3 .. " " .. species3 .. subspecies3 .. "" end --templateArgs['hybrid species'] = templateArgs['hybrid'] if subspecies1 ~= "" and not templateArgs['species2'] then templateArgs['species'] = "" .. genus1 .. " " .. templateArgs['species'] .. "" else templateArgs['species'] = nil end templateArgs['offset'] = 1 --
This logic is handled using, and code doing similar is in an older version of this page --
local genus, species = "", "" genus = frame:expandTemplate genus = frame:expandTemplate species = frame:expandTemplate if not templateArgs['parent'] or templateArgs['parent']"" then templateArgs['parent'] = templateArgs['genus'] or genus -- set parent to genus (with disambiguation if given) end
templateArgs['genus'] = genus -- set to genus without diambiguation templateArgs['species'] = species templateArgs['taxon'] = genus .. ' ' .. species
templateArgs['name'] = frame:expandTemplate templateArgs['binomial'] = "" .. templateArgs['taxon'] .. "" templateArgs['binomial_authority'] = templateArgs['authority'] or nil -- set species_name e.g. Panthera leo -> P. leo templateArgs['species_name'] = extinct .. "" .. string.sub(templateArgs['genus'],1,1) .. '. ' .. templateArgs['species'] .. "" templateArgs['species'] = templateArgs['species_name'] templateArgs['display_taxa'] = templateArgs['display_taxa'] -1 templateArgs['offset'] = 1 if templateArgs['subgenus'] and templateArgs['subgenus'] ~= "" then templateArgs['offset'] = templateArgs['offset'] + 1 templateArgs['subgenus_authority'] = templateArgs['parent_authority'] or "" end
templateArgs['taxon'] = nil -- For auto module --
= set-up for SUBSPECIESBOX or INTRASPECIESBOX
"subspeciesbox" or info.auto
"infraspeciesbox" then separator = " subsp. " -- separator for plants etc end -- set abbreviated name, full name, and trinomial abbr_subspecies_name = string.sub(templateArgs['genus'],1,1) .. '. ' .. string.sub(templateArgs['species'],1,1) .. '.' .. separator .. templateArgs['subspecies'] fullName = templateArgs['genus'] .. ' ' .. templateArgs['species'] .. separator .. templateArgs['subspecies'] templateArgs['trinomial'] = extinct .. "" .. fullName .. "" --templateArgs['subspecies_authority'] = templateArgs['authority'] -- replicates authoity in trinomial (unwanted?) templateArgs['subspecies_name']= extinct .. "" .. abbr_subspecies_name .. "" end -- handle population (of a species or subspecies) if templateArgs['population'] then if templateArgs['subspecies'] then -- link subspecies name when using population if templateArgs['subspecies_link'] then templateArgs['subspecies_name'] = "" .. abbr_subspecies_name .. "" else templateArgs['subspecies_name'] = "" .. abbr_subspecies_name .. "" end end if not templateArgs['name'] then templateArgs['name'] = templateArgs['population'] -- set taxobox name to population end if templateArgs['population_rank_name'] and templateArgs['population_rank_abbrev'] then templateArgs['trinomial'] = templateArgs['trinomial'] .. ' ' .. templateArgs['population_rank_abbrev'] .. ' ' .. templateArgs['population'] else templateArgs['trinomial'] = nil -- don't show trinomial with population unless it has morpha or other suffix end --templateArgs['binomial'] = nil -- don't show binomial with population (when population of species); nver set if templateArgs['population_extinct']
"true" then extinct = frame:expandTemplate -- use template to get tooltip end templateArgs['population'] = extinct .. "" .. templateArgs['population'] .. "" end -- handle variety if templateArgs['variety'] or templateArgs['varietas'] then -- should now be aliased local vSeparator = " var. " --alias done? templateArgs['variety']= templateArgs['variety'] or templateArgs['varietas'] -- will use variety as parameter TODO alias this templateArgs['variety_name'] = extinct .. "" .. string.sub(templateArgs['genus'],1,1) .. '. ' .. string.sub(templateArgs['species'],1,1) .. '.' .. vSeparator .. templateArgs['variety'] .. "" templateArgs['trinomial'] = "" .. templateArgs['genus'] .. ' ' .. templateArgs['species'] .. vSeparator .. templateArgs['variety'] .. "" --templateArgs['variety_authority'] = templateArgs['authority'] -- replicates authority in trinomial if templateArgs['subspecies'] then -- subspecies needs to linked [TODO: add subspecies_link] local redirectName = templateArgs['genus'] .. ' ' .. templateArgs['species'] .. " subsp. " .. templateArgs['subspecies'] local shortName = "" .. string.sub(templateArgs['genus'],1,1) .. '. ' .. string.sub(templateArgs['species'],1,1) .. '.' .. separator .. templateArgs['subspecies'] .. "" templateArgs['subspecies_name'] = "' .. shortName .. "" offset = offset + 1 -- offset when susbpecies AND variety templateArgs['subspecies_authority'] = templateArgs['parent_authority'] end end -- handle customisable infraspecies ranks -- alias (TODO move to parameter section when parameter name conversion complete; see talk page) if templateArgs['infraspecies1_name'] or templateArgs['infraspecies_rank1'] then templateArgs['infraspecies1_name1'] = templateArgs['infraspecies1_name'] or templateArgs['infraspecies_rank1'] end if templateArgs['infraspecies2_name'] or templateArgs['infraspecies_rank2'] then templateArgs['infraspecies2_name'] = templateArgs['infraspecies2_name'] or templateArgs['infraspecies_rank2'] end if templateArgs['infraspecies_rank1'] then if templateArgs['subspecies'] then -- link subspecies --templateArgs['subspecies_name'] = "" .. abbr_subspecies_name .. "" templateArgs['subspecies_name'] = "" .. abbr_subspecies_name .. "" end local binomial = "" .. templateArgs['genus'] .. ' ' .. templateArgs['species'] .. "" local abbrSpeciesName = string.sub(templateArgs['genus'],1,1) .. '. ' .. string.sub(templateArgs['species'],1,1) .. '. ' abbrSpeciesName = "" .. abbrSpeciesName .. "" -- italicise if templateArgs['infraspecies_rank2'] then local isrSeparator = " " if templateArgs['infraspecies_rank2_abbrev'] then isrSeparator = " " .. templateArgs['infraspecies_rank2_abbrev'] .. " " end templateArgs['trinomial'] = binomial .. isrSeparator .. templateArgs['infraspecies_rank2'] templateArgs['infraspecies_rank2'] = abbrSpeciesName .. isrSeparator .. templateArgs['infraspecies_rank2'] templateArgs['infraspecies_rank2'] = "" .. templateArgs['infraspecies_rank2'] .. "" -- bold infraspecific name else local isrSeparator = " " if templateArgs['infraspecies_rank1_abbrev'] then isrSeparator = " " .. templateArgs['infraspecies_rank1_abbrev'] .. " " end templateArgs['trinomial'] = binomial .. isrSeparator .. templateArgs['infraspecies_rank1'] templateArgs['infraspecies_rank1'] = abbrSpeciesName .. isrSeparator .. templateArgs['infraspecies_rank1'] templateArgs['infraspecies_rank1'] = "" .. templateArgs['infraspecies_rank1'] .. "" -- bold first infraspecific name end end --TODO what else do subspeciesbox and infraspeciesbox cover?)
--trinomial_authority = infraspeciesbox: |species_authority = subspeciesbox: | species_authority = note: subspeciesbox doesn't recognise patent_authority with underscore monthly reports on subspeciesbox and infraspeciesbox no uses of parent_authority, binomial_authority or trinomial authority no uses of grandparent, greatgrandparent etc authorites templateArgs['trinomial_authority'] = templateArgs['authority'] or nil
if not templateArgs['name'] or templateArgs['name']
4 then -- when subgenus, species, subspecies and variety templateArgs['subgenus_authority'] = templateArgs['subgenus_authority'] or templateArgs['greatgrandparent_authority'] or "" templateArgs['species_authority'] = templateArgs['grandparent_authority'] or "" elseif offset
3 then -- species, subspecies and variety templateArgs['species_authority'] = templateArgs['grandparent_authority'] or "" templateArgs['subspecies_authority'] = templateArgs['parent_authority'] or "" elseif offset
--elseif info.auto
"virus" or info.auto
-- "the automated taxobox first looks for the taxonomy template that matches the supplied |taxon= parameter " -- "(or, if none is supplied, the article's title, ignoring any parenthetical expressions). " if not templateArgs['taxon'] or templateArgs['taxon']
end
-------------------------------------------------------------------function p.templateStyle(frame, src) return frame:extensionTag('templatestyles', ,); end
-----------------------------------------function p.testTables(frame) if 1
local row = root:tag('tr') -- add row using lua library local cell = row:tag('td') cell:wikitext('row A:') cell = row:tag('td'):wikitext('content A')
row = root:tag('tr') -- add row using lua library cell = row:tag('td'):wikitext('row B:') cell = row:tag('td') :wikitext('\n
-\n | P\n | Q\n |
-- row:done --root=mw.html:allDone root:wikitext('
row=root:tag('tr'):node('
root:node('\n
-\n | Xx\n | Yx\n |
--frame:preprocess return tostring(root)
--end
-- --------------------------- TEST AUTO TAXONOMY FUNCTIONS -----------------------------function p.test(frame) local a = require("Module:Sandbox/Jts1882/Biota Infobox/auto")
--local taxonTable = a.loadTaxonomyTable(frame) now done in showTaxonomyTable return a.showTaxonomyTable(frame)end
-- All modules end by returning the variable containing its functions to Wikipedia.return p