Difference between revisions of "Module:Biota infobox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Jts1882
(use color_as for manual taxonomies)
blackwiki>Jts1882
(update to sandbox version)
Line 2: Line 2:
 
-- All Lua modules on Wikipedia must begin by defining a variable that will hold their
 
-- 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.
 
-- externally accessible functions. They can have any name and may also hold data.
local p = {}
+
local p = {} -- exposed variables
 +
local g = {}  -- these are variables with global scope in this module
  
 +
local info = {}          -- contains general purpose information (e.g. header background colour)
 +
info.debug  = true -- ONLY SET THIS WHILE TESTING
  
local data = require( 'Module:Biota infobox/data' ) -- contains the taxon ranks in order
+
--local paramData = require( 'Module:Sandbox/Jts1882/Biota Infobox/data' ) -- contains the taxon ranks in order
local autotaxa = require("Module:Autotaxobox")
+
--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' )  
  
local parent = mw.getCurrentFrame():getParent()
+
-- ######################### PARAMETER HANDLING ############################
--[[TODO some preliminary processing of arguments
+
 
      could check for empty strings and remove from list, but what if using as flag (e.g. "|parent=")
+
local templateArgs = {}  -- contains preprocessed arguments from calling template
      want to check for alternatives, e.g. "regnum authority" or "regnum_authority" (replace space with underscore)
+
                          --TODO use info.args instead of templateArgs?
      e.g. param = mw.ustring.gsub(param, "_", " ");
+
 
 +
 
 +
-- ########################### MAIN AND OTHER ENTRY FUNCTIONS ##################################
 +
 
 +
--[[ main function callable in Wikipedia via the #invoke command.
 +
        creates a taxobox-style infobox
 +
        handles preliminary parameter handling enulating taxobox and automatic taxobox templates
 +
          -- the parameters are also checked for content, alias, valid names and valid combinations
 +
          -- the parameter handling is in subpage Module:Sandbox/Jts1882/Biota Infobox/param
 +
        these are passed the core function
 +
          -- the core function emulates the template {{Taxobox/core})
 +
          -- the function is found in subpage Module:Sandbox/Jts1882/Biota Infobox/core
 +
          -- the core them creates the taxobox
 +
                creates main table and header section (with header, subheader and fossil ranges)
 +
            adds addition rows for template arguments with following subsidiary functions:
 +
        p.addImageSection() - images and range maps
 +
        p.addStatusSection() - conservation status
 +
        p.addTaxonomySection() - listing of taxonomic heirarchy (manuel or using automatic taxonomy system)
 +
        p.addTaxonSection() - adds section with taxonomic information (binomial or trinomials; type genus or species; diversity)
 +
        p.addListSection()    - section containing list if subdivisions, synonyms, included or excluded groups
 
--]]
 
--]]
function p.preprocessArgs(frame)                       --TODO test fully
+
p.main = function(frame)
 +
 +
--p.getArgs(frame)
 +
parameters.getArgs(frame, templateArgs, info)  -- 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
 +
else
 +
--[[TODO manual taxobox options:
 +
            name or use Template:Taxonomy name |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/core
 +
p.auto = function(frame)
 +
--info.auto = frame.args.auto or "automatictaxobox"
 
 
--local params = parent.args                      -- TODO how to do without full list of parameters
+
p.getArgs(frame)  -- gets arguments, checks for value, aliases, and against valid parameter list
local params = { 'image upright', 'image caption', 'type genus' }
 
  
for k,v in pairs(params) do
+
if info.auto then
if parent.args[v] then -- and mw.ustring.match(parent.args[v], " ") then
+
p.AutomaticTaxoboxOptions(frame) -- this emulates the automatic taxobox templates that feed the core
  --params[v] = string.gsub(params[v], ".+(%s).+", "%_");
 
  local u = string.gsub(v, "%s+", "_")-- v = "param name" --> u = "param_name"
 
  parent.args[u] = parent.args[v]
 
end
 
 
end
 
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{ title = 'taxobox/core',  args = templateArgs  } )
 +
 
end
 
end
 +
 +
--[[ ##################### CORE FUNCTIONS ###################################
 +
 +
      this core function emulates Template:Taxobox/core
 +
      it is followed by functions handling the different type of entry
 +
      MOVED to subpage Module:Sandbox/Jts1882/Biota_Infobox/core
 +
]]
 +
 +
 +
-- ################## AUTOMATIC TAXOBOX SYSTEM HANDLING ################################
 
------------------------------------------------------------------------------------------------
 
------------------------------------------------------------------------------------------------
-- handle specific requirements of different options: manual, auto, speciesbox etc
+
-- handle specific requirements of different options: auto, speciesbox etc
function p.specialTaxoboxOptions(frame)
+
function p.AutomaticTaxoboxOptions(frame)
 
    
 
    
     -- "the automated taxobox first looks for the taxonomy template that matches the supplied |taxon= parameter "
+
     --TODO replace genus with first word (genus) to strip parenthetic term
     --       "(or, if none is supplied, the article's title, ignoring any parenthetical expressions). "
+
     -- done in speciesbox?
     if not parent.args['taxon'] or parent.args['taxon'] == "" then
+
   
    parent.args['taxon'] = parent.args['name'] or tostring( mw.title.getCurrentTitle())
+
   
    --TODO strip name of parenthetical terms off page title
+
     templateArgs['display_taxa']  = templateArgs['display_parents'] or 1  -- note change of parameter name
 +
 
 +
    local extinct = ""
 +
if  templateArgs['extinct'] then
 +
--extinct = "†"
 +
extinct = frame:expandTemplate{ title = 'extinct' }  -- use template to get tooltip
 +
-- speciesbox also checks the genus taxonomy template for extinct parameter
 
     end
 
     end
  -- parent.args['parent'] = parent.args['taxon'] -- cannot set here as speciesbox uses parent to override genus as parent
 
   
 
    --[[ possible extra option: use genus and species to set parent
 
if parent.args['genus'] and parent.args['species'] then
 
    parent.args['taxon'] = parent.args['genus'] .. ' ' .. parent.args['species']
 
    parent.args['parent'] = parent.args['genus']
 
end
 
--]]
 
  
     parent.args['display_taxa']  = parent.args['display_parents'] or 1  -- confusing change of parameter name
+
     ---------------------variables for SPECIESBOX, SUBSPECIESBOX and INFRASPECIESBOX---------------------
 
    
 
    
  local extinct = ""
+
    -- ======================= setup for SPECIESBOX =============================
  --if  parent.args['extinct']  then extinct = "†" end
+
  if  parent.args['extinct']  then extinct = frame:expandTemplate{ title = 'extinct' } end -- use template to get tooltip
+
if info.auto == "speciesbox" then
   
+
       
    -- ------------------------variables for SPECIESBOX, SUBSPECIESBOX and INFRASPECIESBOX------------------------------
+
         --[[ {{speciesbox}} gets genus and species from taxon, genus+species or page name
    -- setup for speciesbox (including set binomial)
+
                1. uses 'taxon' paramter ( given as binomial) if available
if parent.args['auto'] == "speciesbox" then
+
                2. otherwise uses 'genus' and 'species' parameters
 
+
                3. uses page name
         -- string handling testing on "Panthera leo" speciesbox
+
            the genus is used for the 'parent' taxon  
        --parent.args['genus'] = string.match(parent.args['taxon'] , "^(%a+)%s" ) -- Panthera
+
            unless the parent is supplied (e.g. for subgenus)
         --parent.args['species'] = string.gsub(parent.args['taxon'] , "^(%a+)%s" , "") -- leo and reference
+
            else use genus (from taxon or genus parameter or page name)
        --parent.args['species'] = string.match(parent.args['taxon'] , "%s(%a+)$" ) -- leo and reference
+
           
        --parent.args['species'] = string.match(parent.args['taxon'] , "%s(%a+)." ) -- leo without reference
+
          {{Speciesbox}} now using {{Speciesbox/getGenus}} and  {Speciesbox/getSpecies}}
      -- mw.text.split( s, pattern, plain
+
                code doing similar is commented out below
 +
         
 +
          TODO use {{{{Speciesbox/name}}
 +
         --]]
 +
      local genus, species = "", ""
 +
     
 +
      genus = frame:expandTemplate{ title = 'Speciesbox/getGenus' , args = {templateArgs['taxon'], templateArgs['genus']} }
 +
      species = frame:expandTemplate{ title = 'Speciesbox/getSpecies' , args = {templateArgs['taxon'], templateArgs['genus']} }
 
        
 
        
       -- speciesbox assumes taxon given as binomial (in documentation), but also takes genus and species (which priority?)
+
if templateArgs['taxon'] then
      if parent.args['genus'] and parent.args['species'] then
+
         
    --TODO strip off (disambiguater) to handle multi-kingdom genus e.g.| genus = Acanthocarpus (plant)
+
          -- following line disableas using getGenus/getSpecies templates        
    local genus =mw.text.split( parent.args['genus'], " ", true )
+
          -- genus, species = string.match(templateArgs['taxon'], "(%S+)%s(%S+)") -- %S: All characters not in %s
    if genus[1] ~= "" then  
+
     
    parent.args['parent']=parent.args['genus']  -- set parent
+
      templateArgs['genus'] = genus                
    parent.args['genus'] = genus[1]  
+
      templateArgs['species'] = species          
 +
 
 +
    elseif templateArgs['genus'] and templateArgs['species'] then
 +
   
 +
    --[[strip off (disambiguator) to handle multi-kingdom genus e.g.| genus = Acanthocarpus (plant)
 +
    local genusParts =mw.text.split( templateArgs['genus'], " ", true )    -- string.match( s, '^%a*'', 1 )
 +
                                       
 +
    if genusParts[1] ~= "" then  
 +
    --templateArgs['parent']=templateArgs['genus']  -- set parent (NO, parent should override)
 +
    genus = genusParts[1]  
 
    end
 
    end
    parent.args['taxon'] = parent.args['genus'] .. ' ' .. parent.args['species']
+
    now handled by getGenus/getSpecies templates --]]
+
   
elseif parent.args['taxon'] then
+
    templateArgs['taxon'] = genus .. ' ' .. templateArgs['species']
      local  genus, species = string.match(parent.args['taxon'], "(%S+)%s(%S+)") -- %S: All characters not in %s
+
      parent.args['genus'] = genus
 
      parent.args['species'] = species
 
 
    else
 
    else
    -- no valid taxon yet
+
    -- TODO no valid taxon yet; use page name
    --TODO need to get out of here or use 'name' or page title
+
    -- use first word of pagename - handled by {{Speciesbox/getGenus}}
 
    end
 
    end
 
      
 
      
         if not parent.args['parent'] or parent.args['parent'] == "" then
+
         if not templateArgs['parent'] or templateArgs['parent'] == "" then
         parent.args['parent'] = parent.args['genus']      -- set parent to genus if not already
+
         templateArgs['parent'] = templateArgs['genus']      -- set parent to genus if not supplied
        end
 
        if not parent.args['name'] or parent.args['name'] == "" then -- if page name not set
 
        parent.args['name'] = "''" .. parent.args['taxon'] .. "''"
 
 
         end
 
         end
 +
        --[[if not templateArgs['name'] or templateArgs['name'] == "" then -- if page name not set
 +
        templateArgs['name'] = "''" .. templateArgs['taxon'] .. "''"
 +
        end    ]]   
 +
        --TODO use {{Speciesbox/name}}
 +
        templateArgs['name']  = frame:expandTemplate{ title = 'Speciesbox/name' ,
 +
                                  args = { templateArgs['name'], templateArgs['taxon'],
 +
                                            templateArgs['genus'], templateArgs['species'],
 +
                                            mw.title.getCurrentTitle().baseText,
 +
                                            templateArgs['italic_title' or 'yes'] 
 +
                 
 +
                  } }
 +
           
 +
 +
       
 
          
 
          
 
-- set binomial : the speciesbox template seems to use genus and species before taxon name
 
-- set binomial : the speciesbox template seems to use genus and species before taxon name
 
-- "| binomial = ''{{Str letter/trim|{{{genus|{{{taxon|<includeonly>{{PAGENAME}}</includeonly><noinclude>Acacia</noinclude>}}}}}}}} {{{species|{{remove first word|{{{taxon|<includeonly>{{PAGENAMEBASE}}</includeonly><noinclude>Acacia aemula</noinclude>}}}}}}}}''"
 
-- "| binomial = ''{{Str letter/trim|{{{genus|{{{taxon|<includeonly>{{PAGENAME}}</includeonly><noinclude>Acacia</noinclude>}}}}}}}} {{{species|{{remove first word|{{{taxon|<includeonly>{{PAGENAMEBASE}}</includeonly><noinclude>Acacia aemula</noinclude>}}}}}}}}''"
 
-- documentation suggest taxon, which is followed here
 
-- documentation suggest taxon, which is followed here
parent.args['binomial'] = "''" .. parent.args['taxon'] .. "''"
+
templateArgs['binomial'] = "''" .. templateArgs['taxon'] .. "''"
parent.args['binomial_authority'] = parent.args['authority'] or nil
+
templateArgs['binomial_authority'] = templateArgs['authority'] or nil
 
 
  
 
     -- set species_name e.g. Panthera leo -> P. leo
 
     -- set species_name e.g. Panthera leo -> P. leo
     parent.args['species_name'] = extinct .. "'''''" .. string.sub(parent.args['genus'],1,1) .. '. ' .. parent.args['species'] .. "'''''"
+
     templateArgs['species_name'] = extinct .. "'''''" .. string.sub(templateArgs['genus'],1,1) .. '. ' .. templateArgs['species'] .. "'''''"
 
+
        templateArgs['species']=templateArgs['species_name']
         parent.args['display_taxa']  = parent.args['display_taxa'] -1
+
       
    --shift authorities for speciesbox (two steps if subgenus set)
+
         templateArgs['display_taxa']  = templateArgs['display_taxa'] -1
    if parent.args['subgenus'] and parent.args['subgenus'] ~= ""  then
+
        templateArgs['offset'] = 1
parent.args['subgenus_authority']              = parent.args['parent_authority'] or ""
+
    if templateArgs['subgenus'] and templateArgs['subgenus'] ~= ""  then
parent.args['authority']                      = parent.args['grandparent_authority'] or ""
+
    templateArgs['offset'] =  templateArgs['offset'] + 1
parent.args['parent_authority']                = parent.args['greatgrandparent_authority'] or ""
+
templateArgs['subgenus_authority']              = templateArgs['parent_authority'] or ""
parent.args['grandparent_authority']          = parent.args['greatgreatgrandparent_authority'] or ""
+
    end
parent.args['greatgrandparent_authority']      = parent.args['greatgreatgreatgrandparent_authority'] or ""
+
    --templateArgs['species_authority']  = templateArgs['authority'] or "" -- don't show species_authority as duplicates binomial authority
parent.args['greatgreatgrandparent_authority'] = parent.args['greatgreatgreatgreatgrandparent_authority'] or ""
+
   
 +
   
 +
    --[[shift authorities for speciesbox (two steps if subgenus set)
 +
    if templateArgs['subgenus'] and templateArgs['subgenus'] ~= ""  then
 +
templateArgs['subgenus_authority']              = templateArgs['parent_authority'] or ""
 +
templateArgs['authority']                      = templateArgs['grandparent_authority'] or ""
 +
templateArgs['parent_authority']                = templateArgs['greatgrandparent_authority'] or ""
 +
templateArgs['grandparent_authority']          = templateArgs['greatgreatgrandparent_authority'] or ""
 +
templateArgs['greatgrandparent_authority']      = templateArgs['greatgreatgreatgrandparent_authority'] or ""
 +
templateArgs['greatgreatgrandparent_authority'] = templateArgs['greatgreatgreatgreatgrandparent_authority'] or ""
 
else                                                                 
 
else                                                                 
 
-- note: must set to "" if 'parent_authority's don't exist, otherwise the value of 'authority' is unchanged
 
-- note: must set to "" if 'parent_authority's don't exist, otherwise the value of 'authority' is unchanged
parent.args['authority']                      = parent.args['parent_authority'] or ""   
+
templateArgs['authority']                      = templateArgs['parent_authority'] or ""   
parent.args['parent_authority']                = parent.args['grandparent_authority'] or ""
+
templateArgs['parent_authority']                = templateArgs['grandparent_authority'] or ""
parent.args['grandparent_authority']          = parent.args['greatgrandparent_authority'] or ""
+
templateArgs['grandparent_authority']          = templateArgs['greatgrandparent_authority'] or ""
parent.args['greatgrandparent_authority']      = parent.args['greatgreatgrandparent_authority'] or ""
+
templateArgs['greatgrandparent_authority']      = templateArgs['greatgreatgrandparent_authority'] or ""
parent.args['greatgreatgrandparent_authority'] = parent.args['greatgreatgreatgrandparent_authority'] or ""
+
templateArgs['greatgreatgrandparent_authority'] = templateArgs['greatgreatgreatgrandparent_authority'] or ""
 
end
 
end
   
+
        ]]
     -- set-up for subspecies or infraspecies
+
        templateArgs['taxon'] = nil -- For auto module
elseif parent.args['auto'] == "subspeciesbox" or parent.args['auto'] == "infraspeciesbox" then
+
 +
       
 +
     -- =====================  set-up for SUBSPECIESBOX or INTRASPECIESBOX =================
 +
 +
elseif info.auto == "subspeciesbox" or info.auto == "infraspeciesbox" then
 
 
--TODO set trinomial name
+
  --[[ From template description:
    --[[According to subspsecisbox and infraspeciesbox documentation "The genus name, species name and subspecies name must be supplied separately: the combined taxon parameter cannot be used".
+
          "The genus name, species name and subspecies name"
            This means the trinomial can be constructed and the parameter ignored.
+
            [or "genus name, specific epithet and infraspecific epithet"]
 +
                "
 +
                must be supplied separately: the combined taxon parameter cannot be used.""
 +
              "The genus name is then the entry into the taxonomic hierarchy.""
 +
             
 +
    The trinomial name is set from these parameters and the parameter ignored.
 +
  --NOTE no infraspeciebox is currently using trinomial parameter
 
         --]]
 
         --]]
        parent.args['parent'] = parent.args['genus'] -- genus must be supplied
 
 
          
 
          
         local fullName = parent.args['genus'] .. ' ' .. parent.args['species']
+
         -- Parameter checking. This could be here or moved to parameter checking function
parent.args['species_name']= "''[[" .. fullName  .. '|'.. string.sub(parent.args['genus'],1,1) .. '. ' .. parent.args['species'] .. "]]''"
+
        if templateArgs['genus'] and templateArgs['species'] and templateArgs['subspecies'] then
 +
        -- valid parameters for subspecies (may have variety as well)
 +
        elseif templateArgs['genus'] and templateArgs['species'] and templateArgs['variety'] then
 +
        -- valid parameters for infraspecies (variety without subspecies)
 +
        else
 +
        -- insufficient parameters
 +
        -- TODO add error message and return
 +
        end
 +
        local offset = 2  -- authority offset when subpecies OR variety
 +
       
 +
        --TODO strip genus of disambiguator (need to check this works)
 +
        local genus =mw.text.split( templateArgs['genus'], " ", true )
 +
    if genus[1] ~= "" then
 +
    templateArgs['genus'] = genus[1]
 +
    end
 +
        templateArgs['parent'] = templateArgs['genus'] -- genus must be supplied
 
          
 
          
         --local bold = "'''"
+
         local fullName = templateArgs['genus'] .. ' ' .. templateArgs['species']
         local separator = " " -- subspecies separator (default zoological)
+
templateArgs['species_name'] = "''[[" .. fullName  .. '|'.. string.sub(templateArgs['genus'],1,1) .. '. ' .. templateArgs['species'] .. "]]''"
    if parent.args['subspecies'] then -- might not be if variety
+
 
         if parent.args['auto'] == "infraspeciesbox"  then separator = " ''<small>subsp.</small>'' "  end
+
        -- if subspecies is set (could be with or without variety)
parent.args['subspecies_name']= extinct .. "'''''" .. string.sub(parent.args['genus'],1,1) .. '. ' .. string.sub(parent.args['species'],1,1) .. '.' .. separator .. parent.args['subspecies'] .. "'''''"
+
         local separator = " "                               -- subspecies separator (default zoological)
   fullName = parent.args['genus'] .. ' ' .. parent.args['species'] .. separator .. parent.args['subspecies']  
+
    if templateArgs['subspecies'] then                 -- might not be if variety
parent.args['trinomial'] = "''" .. fullName .. "''"
+
         if info.auto == "infraspeciesbox"  then separator = " ''<small>subsp.</small>'' "  end
-- TODO if there is also a variety, this should be linked and not bolded (but would such an article exist)
+
templateArgs['subspecies_name']= extinct .. "'''''" .. string.sub(templateArgs['genus'],1,1) .. '.&nbsp;' .. string.sub(templateArgs['species'],1,1) .. '.' .. separator .. templateArgs['subspecies'] .. "'''''"
 +
   fullName = templateArgs['genus'] .. ' ' .. templateArgs['species'] .. separator .. templateArgs['subspecies']  
 +
templateArgs['trinomial'] = "''" .. fullName .. "''"
 +
            --templateArgs['subspecies_authority'] = templateArgs['authority']  -- replicates authoity in trinomial (unwanted?)
 
         end
 
         end
         if parent.args['variety'] or parent.args['varietas'] then  
+
       
 +
         if templateArgs['variety'] or templateArgs['varietas'] then -- should now be aliased
 
             local vSeparator = " ''<small>var.</small>'' "  
 
             local vSeparator = " ''<small>var.</small>'' "  
             parent.args['variety']= parent.args['variety'] or parent.args['varietas'] -- will use variety as parameter
+
             --alias done? templateArgs['variety']= templateArgs['variety'] or templateArgs['varietas'] -- will use variety as parameter TODO alias this
parent.args['variety_name']= extinct .. "'''''" .. string.sub(parent.args['genus'],1,1) .. '. ' .. string.sub(parent.args['species'],1,1) .. '.' .. vSeparator .. parent.args['variety'] .. "'''''"
+
templateArgs['variety_name'] = extinct .. "'''''" .. string.sub(templateArgs['genus'],1,1) .. '.&nbsp;' .. string.sub(templateArgs['species'],1,1) .. '.' .. vSeparator .. templateArgs['variety'] .. "'''''"
parent.args['trinomial'] = "''" .. parent.args['genus'] .. ' ' .. parent.args['species'] .. vSeparator .. parent.args['variety'] .. "''"
+
  templateArgs['trinomial'] = "''" .. templateArgs['genus'] .. ' ' .. templateArgs['species'] .. vSeparator .. templateArgs['variety'] .. "''"
         if parent.args['subspecies'] then -- subspecies needs to linked instead of bold  
+
            --templateArgs['variety_authority'] = templateArgs['authority'] -- replicates authority in trinomial
  fullName = parent.args['genus'] .. ' ' .. parent.args['species'] .. " ''subsp.'' " .. parent.args['subspecies']  
+
       
parent.args['subspecies_name'] = "''[[" .. fullName .. '|' .. string.sub(parent.args['genus'],1,1) .. '. ' .. string.sub(parent.args['species'],1,1) .. '.' .. separator .. parent.args['subspecies'] .. "]]''"
+
         if templateArgs['subspecies'] then -- subspecies needs to linked instead of bold  
 +
  local redirectName = templateArgs['genus'] .. ' ' .. templateArgs['species'] .. " subsp. " .. templateArgs['subspecies']  
 +
local shortName = "''" .. string.sub(templateArgs['genus'],1,1) .. '.&nbsp;' .. string.sub(templateArgs['species'],1,1) .. '.' .. separator .. templateArgs['subspecies'] .. "''"
 +
templateArgs['subspecies_name'] =  "[[" .. redirectName .. '|' .. shortName .. "]]"
 +
offset = offset + 1 -- offset when susbpecies AND variety
 +
                templateArgs['subspecies_authority'] = templateArgs['parent_authority']
 
         end
 
         end
 
         end
 
         end
   
+
       
 +
        --TODO what else do subspeciesbix and infraspeciesbox cover?)
  
parent.args['trinomial_authority'] = parent.args['authority'] or nil
+
      --[[ code from templates
 +
            both:            |trinomial_authority = {{{authority|{{{trinomial authority|{{{trinomial_authority|}}} }}} }}}
 +
            infraspeciesbox: |species_authority = {{{parent_authority|{{{parent authority|{{{binomial authority|{{{binomial_authority|}}}}}}}}}}}}
 +
            subspeciesbox: | species_authority = {{{parent authority|{{{binomial authority|{{{binomial_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 parent.args['name'] or parent.args['name'] == "" then -- if page name not set
+
         if not templateArgs['name'] or templateArgs['name'] == "" then -- if page name not set
         parent.args['name'] = parent.args['trinomial']
+
         templateArgs['name'] = templateArgs['trinomial']
 
         end
 
         end
 
          
 
          
         parent.args['display_taxa']   = (parent.args['display_taxa'] or 1) -2
+
         -- these are used by manual taxobox to complete the taxonomy table
    --shift authorities for subspeciesbox (two steps or three if subgenus set)
+
        templateArgs['species'] = templateArgs['species_name']
    if parent.args['subgenus'] and parent.args['subgenus'] ~= ""  then
+
        templateArgs['subspecies'] = templateArgs['subspecies_name']
parent.args['subgenus_authority']             = parent.args['grandparent_authority'] or ""
+
templateArgs['variety'] =templateArgs['variety_name']
parent.args['authority']                       = parent.args['greatgrandparent_authority'] or ""
+
       
parent.args['parent_authority']               = parent.args['greatgreatgrandparent_authority'] or ""
+
        --QUESTION what happens to parent taxa when subspecies and variety?
parent.args['grandparent_authority']          = parent.args['greatgreatgreatgrandparent_authority'] or ""
+
        -- set species and subgenus authorities
parent.args['greatgrandparent_authority']     = parent.args['greatgreatgreatgreatgrandparent_authority'] or ""
+
    if templateArgs['subgenus'] then
parent.args['greatgreatgrandparent_authority'] = parent.args['greatgreatgreatgreatgreatgrandparent_authority'] or ""
+
    offset = offset + 1
else
+
    if offset == 4  then    -- when subgenus, species, subspecies and variety
parent.args['authority']                      = parent.args['grandparent_authority'] or ""
+
    templateArgs['subgenus_authority'] = templateArgs['subgenus_authority'] or templateArgs['greatgrandparent_authority'] or ""
parent.args['parent_authority']               = parent.args['greatgrandparent_authority'] or ""
+
    templateArgs['species_authority']   = templateArgs['grandparent_authority'] or ""
parent.args['grandparent_authority']           = parent.args['greatgreatgrandparent_authority'] or ""
+
        elseif offset == 3  then -- when subgenus, species, (subspecies OR variety)
parent.args['greatgrandparent_authority']     = parent.args['greatgreatgreatgrandparent_authority'] or ""
+
    templateArgs['subgenus_authority'] = templateArgs['subgenus_authority'] or templateArgs['grandparent_authority'] or ""
parent.args['greatgreatgrandparent_authority'] = parent.args['greatgreatgreatgreatgrandparent_authority'] or ""
+
    templateArgs['species_authority']   = templateArgs['parent_authority'] or ""
 +
    end
 +
else -- only need to set species authority or subspecues (if also variety)
 +
    if offset == 3 then    -- species, subspecies and variety
 +
    templateArgs['species_authority']   = templateArgs['grandparent_authority'] or ""
 +
    templateArgs['subspecies_authority']   = templateArgs['parent_authority'] or ""
 +
    elseif offset == 2 then  -- species, (subspecies or variety)
 +
        templateArgs['species_authority']   = templateArgs['parent_authority'] or ""
 +
    end    
 
end
 
end
else
+
     
  parent.args['parent'] = parent.args['taxon']
+
        templateArgs['display_taxa']   = (templateArgs['display_taxa'] or 1) -2
end
+
        templateArgs['offset'] = offset
 
-- check taxonomy templates for automatic taxobox systtem
 
--{{#ifexist:Template:Taxonomy/{{{taxon|<includeonly>{{PAGENAME}}</includeonly><noinclude>Acacia</noinclude>}}}
 
--      |<noinclude><!--do nothing if it exists--></noinclude>
 
--      |{{Automatic taxobox/floating intro|taxon={{{taxon|{{PAGENAME}}}}} }}
 
-->}}
 
 
 
end
 
------------------------------------------------------------------------------------------
 
--[[ main function callable in Wikipedia via the #invoke command.
 
        creates a taxobox-style infobox
 
        creates main table and header section (with header, subheader and fossil ranges)
 
        the creates addition rows for template arguments with following subsidiary functions:
 
        p.addImageSection() - images and range maps
 
        p.addStatusSection() - conservation status
 
        p.addTaxonomySection() - listing of taxonomic heirarchy (manuel or using automatic taxonomy system)
 
        p.addTaxonSection() - adds section with taxonomic information (binomial or trinomials; type genus or species; diversity)
 
            p.addListSection()    - section containing list if subdivisions, synonyms, included or excluded groups
 
--]]
 
p.main = function(frame)
 
 
--p.preprocessArgs(frame)  -- preprocess frame arguments (handle alias and empty parameters?)
 
 
 
if parent.args['auto'] then
 
p.specialTaxoboxOptions(frame)
 
end
 
local name = parent.args['name'] or tostring( mw.title.getCurrentTitle() )
 
 
 
-- create table
 
local taxoboxTable = mw.html.create('table'):addClass('infobox'):addClass('biota')
 
                :addClass('taxobox-paraphyletic')
 
    local subheader = ''
 
    if parent.args['subheader'] and parent.args['subheader'] ~= '' then
 
subheader='<div style="font-weight:normal;font-size:smaller;">'..parent.args['subheader']..'</div>'
 
    end
 
   
 
    local fossilRange = ''
 
    if parent.args['fossil_range']  then
 
    fossilRange = '<div><small>Temporal range: ' .. parent.args['fossil_range'] .. '</small></div>' -- use <div> rather than <br/>
 
    end
 
   
 
    local rowHeader = taxoboxTable:tag('tr'):tag('th'):attr('colspan', '2'):addClass('section-header')
 
                :cssText('background:' ..  p.getTaxoboxColor(frame) .. ';')
 
:wikitext(name .. subheader .. fossilRange)
 
   
 
    -- add images
 
    p.addImageSection(frame, taxoboxTable, 'image')
 
    p.addImageSection(frame, taxoboxTable, 'image2')
 
   
 
    --add conservation status
 
p.addStatusSection(frame, taxoboxTable, 'status')
 
p.addStatusSection(frame, taxoboxTable, 'status2')
 
 
-- add taxonomy table (uses entered parameters or automatic taxonomy system)
 
p.addTaxonomySection(frame, taxoboxTable)
 
   
 
-- add sections with binomial, trinomial, type species/genus (with authorities)
 
p.addTaxonSection(frame, taxoboxTable, 'binomial', 'Bionomial name')
 
p.addTaxonSection(frame, taxoboxTable, 'trinomial', 'Trionomial name')
 
p.addTaxonSection(frame, taxoboxTable, 'type_genus', 'Type genus')
 
--TODO type_ichnogenus, type_oogenus
 
p.addTaxonSection(frame, taxoboxTable, 'type_species', 'Type species')
 
--TODO type_ichnospecies, type_oospecies
 
    p.addTaxonSection(frame, taxoboxTable, 'type_strain', 'Type strain')
 
 
 
-- add sections showing subdivisions (i.e. child taxa)
 
    p.addListSection(frame, taxoboxTable, 'subdivision', parent.args['subdivision_ranks'] or 'Subdivisions')
 
p.addListSection(frame, taxoboxTable, 'possible_subdivision', parent.args['possible_subdivision_ranks'] or 'Possible subdivisions')
 
   
 
    p.addTaxonSection(frame, taxoboxTable, 'diversity', 'Diversity') -- diversity section
 
 
 
-- show included groups (accepts 'included' or 'includes') [used for paraphyletic tax]
 
p.addListSection(frame, taxoboxTable, 'includes', 'Groups included')
 
p.addListSection(frame, taxoboxTable, 'included', 'Groups included')
 
 
 
    --add range map (should this be below binomial/trinomial?)
 
    p.addImageSection(frame, taxoboxTable, 'range_map')
 
 
 
-- show excluded groups (accepts 'excluded' or 'excludes') [used for paraphyletic tax]
 
local excludedHeaderText = '[[Cladistics|Cladistically]] included but traditionally excluded taxa'
 
p.addListSection(frame, taxoboxTable, 'excludes', excludedHeaderText)
 
p.addListSection(frame, taxoboxTable, 'excluded', excludedHeaderText)
 
   
 
    -- add addition binomials, trinomial and range maps
 
p.addTaxonSection(frame, taxoboxTable, 'binomial2', 'Bionomial name (2)')
 
--p.addTaxonSection(frame, taxoboxTable, 'trinomial2', 'Trionomial name (2)')
 
    p.addImageSection(frame, taxoboxTable, 'range_map2')
 
p.addTaxonSection(frame, taxoboxTable, 'binomial3', 'Bionomial name (3)')
 
--p.addTaxonSection(frame, taxoboxTable, 'trinomial3', 'Trionomial name (3)')
 
    p.addImageSection(frame, taxoboxTable, 'range_map3')
 
p.addTaxonSection(frame, taxoboxTable, 'binomial4', 'Bionomial name (4)')
 
--p.addTaxonSection(frame, taxoboxTable, 'trinomial4', 'Trionomial name (4)')
 
    p.addImageSection(frame, taxoboxTable, 'range_map4')
 
 
 
-- add synonyms section
 
p.addListSection(frame, taxoboxTable, 'synonyms', '[[Synonym (taxonomy)|Synonyms]]')
 
  
------------------add templateSyles and return taxobox table---------------------------
 
 
 
local src = "Template:Paraphyletic group/sandbox/styles.css" -- TemplateStyles file
 
   
 
return p.templateStyle( frame, src ) ..  tostring(taxoboxTable)
 
 
end  -- End the main function.
 
  
-------------------------------------------------------------------------------------------
+
    -- need to set subgenus_authority, species_authority, subspecies_authority and variety_authority
--[[ function to add conservation sections
 
        uses template {{taxobox/species|{{{status_system|}}}|{{{status|}}}|{{{status_ref|}}}|extinct={{{extinct|}}} }} }}
 
 
          
 
          
--]]
+
    --[[shift authorities for subspeciesbox (two steps or three if subgenus set)
function p.addStatusSection(frame, taxoboxTable, status)
+
    if templateArgs['subgenus'] and templateArgs['subgenus'] ~= "" then
 
+
templateArgs['subgenus_authority']              = templateArgs['grandparent_authority'] or ""
    -- must use table container to handle template output
+
templateArgs['authority']                       = templateArgs['greatgrandparent_authority'] or ""
    -- don't use header or content cells; the 'taxobox/species' template handles it
+
templateArgs['parent_authority']               = templateArgs['greatgreatgrandparent_authority'] or ""
    -- just need to add background colour on the row
+
templateArgs['grandparent_authority']           = templateArgs['greatgreatgreatgrandparent_authority'] or ""
 
+
templateArgs['greatgrandparent_authority']     = templateArgs['greatgreatgreatgreatgrandparent_authority'] or ""
    if parent.args[status] and parent.args[status] ~= "" then
+
templateArgs['greatgreatgrandparent_authority'] = templateArgs['greatgreatgreatgreatgreatgrandparent_authority'] or ""
 
local row = taxoboxTable:tag('tr')
 
                                  --:cssText('background:' ..  p.getTaxoboxColor(frame) .. ';')
 
local cell = row:tag('td'):attr('colspan', '2')
 
          :wikitext('\n{|\n|- style="background:' ..  p.getTaxoboxColor(frame) .. ';"')
 
          :wikitext('\n'..tostring(frame:expandTemplate{ title = 'taxobox/species',
 
                      args = {parent.args[status..'_system'] or '',
 
                            parent.args[status] or '',
 
                            parent.args[status..'_ref'] or '',
 
                            extinct=parent.args['extinct'] or '' 
 
                            }
 
                                                      }))
 
              :wikitext('\n|}')
 
    end
 
end
 
 
 
--[[ function to add sections for taxonomic information with authorities ('_authority' suffix)
 
        e.g. binomial, trinomial, type_species, type_genus; diversity also handled here
 
--]]
 
function p.addTaxonSection(frame, taxoboxTable, target, headerText)
 
 
    -- return if we don't have value
 
if not parent.args[target]  or parent.args[target] == '' then return end
 
 
local bold = "" -- variable for bolding binomial and trinomial (type genus/species etc are not bolded)
 
-- custom processing section
 
if target == 'binomial' or target == 'binomial2' or target == 'binomial3' or target == 'binomial4' then
 
headerText = '[[Binomial nomenclature|' .. headerText .. ']]'
 
bold ="'''"
 
elseif target == 'trinomial' or target == 'trinomial2' or target == 'trinomial3' or target == 'trinomial4' then
 
local trinomenLink = "Trinomen" -- for zoological or default
 
if parent.args['auto'] ==  "infraspeciesbox" then trinomenLink = "Infraspecific name (botany)" end -- regnum contains plant/fung/Archaeplastida"
 
headerText = '[['.. trinomenLink .. '|' .. headerText .. ']]'
 
bold ="'''"
 
else
 
  --TODO is any handling needed for binomial2/3/4, diversity etc
 
  headerText = '[[' .. headerText .. ']]'
 
end
 
   
 
if parent.args[target..'_ref'] then
 
headerText = headerText .. parent.args[target..'_ref'] .. '\n'
 
end
 
 
local contentString = ''  -- content for the content cell
 
if target == 'diversity' and parent.args['diversity'] ~= "" then
 
if parent.args[target..'_link'] and parent.args[target..'_link'] ~= "" then
 
    contentString =  '\n[[' .. parent.args[target..'_link'] .. '|' .. parent.args[target] .. ']]\n'
 
 
else
 
else
contentString = '\n' .. parent.args[target] .. '\n'
+
templateArgs['authority']                      = templateArgs['grandparent_authority'] or ""
 +
templateArgs['parent_authority']                = templateArgs['greatgrandparent_authority'] or ""
 +
templateArgs['grandparent_authority']          = templateArgs['greatgreatgrandparent_authority'] or ""
 +
templateArgs['greatgrandparent_authority']      = templateArgs['greatgreatgreatgrandparent_authority'] or ""
 +
templateArgs['greatgreatgrandparent_authority'] = templateArgs['greatgreatgreatgreatgrandparent_authority'] or ""
 
end
 
end
else
+
]]
-- taxon name and authority (binomial, type species, etc)
 
local authorityString = ''
 
if parent.args[target..'_authority'] then
 
authorityString = '<br/><small>' .. parent.args[target..'_authority'] .. '</small>\n'
 
end
 
contentString = '\n' .. bold .. parent.args[target] .. bold .. authorityString .. '\n'
 
    end
 
 
 
-- add table rows
+
-- ========================= setup for AUTOMATIC TAXOBOX ================================
if parent.args[target] and parent.args[target] ~= '' then
+
        -- CHECK authomatic taxobox pagename overrides taxon (e.g. Tortrix? destructus) for header
local rowHeader = taxoboxTable:tag('tr')
+
        --        it does but no italics in header for Tortrix? destructus
rowHeader  :tag('th')
 
          :attr('colspan', '2')
 
          :addClass('section-header')
 
          :cssText('background:' ..  p.getTaxoboxColor(frame) .. ';')
 
          :wikitext( headerText )                 
 
  
local rowList = taxoboxTable:tag('tr')
+
    --elseif info.auto == "automatictaxobox" then
rowList    :tag('td')
 
          :attr('colspan', '2')
 
          :addClass('section-content')
 
          :cssText('text-align:center;') --font-weight:bold;')
 
          :wikitext( contentString )
 
 
 
end
 
end
 
----------------------------------------------------------------------------------------
 
--[[ function to produce sections for included taxa (subdivisions), synonyms, etc
 
      - each consists of two rows containing a header and the content
 
      - for paraphyletic groups it has include(d|s) and exclude(d|s) groups
 
      - for general taxobox it has subdivision and possible subdivision (disabled here)
 
      - any can be modified for other purposes (e.g. sisters) by changing the header taxt with a -text parameter
 
  ]]
 
function p.addListSection(frame, taxoboxTable, target, headerText)
 
 
 
    local refString = ''
 
if parent.args[target..'_ref'] then
 
  --add '_ref' option for 'synonym_ref' (the rest get it as a bonus) TODO check example
 
refString = parent.args[target..'_ref'] .. '\n'
 
end
 
 
 
-- add table rows
+
elseif info.auto == "virus" then
if parent.args[target] and parent.args[target] ~= ''then
+
templateArgs['virus'] = "yes"
local rowHeader = taxoboxTable:tag('tr')
+
templateArgs['color_as'] = "Virus"
rowHeader  :tag('th')
+
if not templateArgs['parent'] then
          :attr('colspan', '2')
+
if templateArgs['taxon'] then
          :addClass('section-header')
+
        templateArgs['parent'] = templateArgs['taxon']
          :cssText('background:' .. p.getTaxoboxColor(frame) .. ';')
+
    elseif templateArgs['species'] then  
          :wikitext(parent.args[target..'-text'] or headerText .. refString)                 
+
    templateArgs['parent'] = templateArgs['species']  
 
+
    templateArgs['species'] = nil
local rowList = taxoboxTable:tag('tr')
+
    else
rowList    :tag('td')
+
    templateArgs['parent'] = tostring( mw.title.getCurrentTitle()) or ""
          :attr('colspan', '2')
+
    end
          :addClass('section-content')
+
else
          :wikitext('\n' .. parent.args[target] .. '\n' )
+
templateArgs['link_parent'] = "yes"            -- if parent given, we want to link it
end
+
end
end
+
   
-----------------------------------------------------------------------------------------------
+
else
--[[ function to add image section
 
    used for images at top and for range maps
 
--]]
 
function p.addImageSection(frame, taxoboxTable, target)
 
 
 
if parent.args[target] and parent.args[target] ~= '' then
 
 
        local imageWidth = ''
 
        local imageCaptionString = ''
 
        if parent.args[target..'_caption'] then  
 
        imageCaptionString = '<br /><small><div style="text-align:center">'..parent.args[target ..'_caption']..'</div></small>'
 
        end
 
        local imageAltString = ''
 
        if parent.args[target..'_alt'] then
 
        imageAltString = parent.args[target..'_alt']
 
        elseif parent.args[target..'_caption'] then
 
        imageAltString = parent.args[target..'_caption'] -- use caption for alt text if none provided
 
        end
 
        local upright = parent.args['image_upright'] or 1
 
       
 
        local InfoboxImage = require( 'Module:InfoboxImage' ) --, parent.args[target]  )
 
        local params = { args = { image = parent.args[target],
 
        size = parent.args[target..'_width'],
 
        sizedefault = 'frameless',
 
        alt = imageAltString,
 
        upright = parent.args[target..'_upright'] or upright
 
        }
 
    }
 
   
 
        local image = InfoboxImage.InfoboxImage(  params )
 
       
 
    --local rowImage = taxoboxTable:tag('tr')
 
    local rowImage = mw.html.create('tr')
 
rowImage:tag('td')
 
:attr('colspan', '2')
 
            :addClass(target)
 
            :wikitext(image)
 
            :wikitext(imageCaptionString)
 
       
 
        taxoboxTable:node(rowImage)
 
    end
 
   
 
    -- TODO handle upright
 
 
end  
 
-----------------------------------------------------------------------
 
--[[  adds a table showing the taxonomy
 
      uses either manual parameters or the automatic taxonomy system
 
      currently adds a table inside a cell (like paraphyletic group) rather than just adding rows (core taxobox system)
 
--]]   
 
       
 
function p.addTaxonomySection(frame, taxoboxTable)
 
  
local taxonomyHeader = '[[Taxonomy_(biology)|Scientific classification]]'
+
    -- "the automated taxobox first looks for the taxonomy template that matches the supplied |taxon= parameter "
if parent.args['virus_group'] then  
+
    --      "(or, if none is supplied, the article's title, ignoring any parenthetical expressions). "
taxonomyHeader = '[[Virus classification]]'
+
    if not templateArgs['taxon'] or  templateArgs['taxon'] == "" then
else
+
    --templateArgs['taxon'] = templateArgs['name'] or tostring( mw.title.getCurrentTitle())
-- TODO add other options
+
    templateArgs['taxon'] = tostring( mw.title.getCurrentTitle()) or ""
end
+
    --TODO strip name of parenthetical terms off page title
 +
    if templateArgs['taxon'] ~= "" then
 +
    --TODO error message and exit
 +
    end
 +
    end
 +
    if templateArgs['parent'] then
 +
    templateArgs['link_parent'] = "yes"              -- if parent given, we want to link it
 +
    else
 +
    templateArgs['parent'] = templateArgs['taxon']   -- otherwise set parent
 +
  end
 +
  --TODO set name if parameter no supplies
 +
 
 +
  --[[ TODO if no taxonomy template, then call setup taxonomy template
 +
    {{#ifexist:Template:Taxonomy/{{{taxon|<includeonly>{{PAGENAME}}
 +
    {{Automatic taxobox/floating intro|taxon={{{taxon|{{PAGENAME}}}}} }}
 +
  ]]
 
 
-- add symbol and link to taxonomy editor
+
end -- end special handling for speciesbox, subspeciesbox, and automatic taxobox
local editLink = ''
 
if parent.args['auto'] then
 
    local tooltip = parent.args['edit link'] or "Edit this classification"
 
editLink  = '<span class="plainlinks" style="font-size:smaller; float:right; padding-right:0.4em; margin-left:-3em;">'
 
.. '[[File:Red Pencil Icon.png|link=Template:Taxonomy/' .. parent.args['parent']
 
.. '|' .. tooltip  .. ']]</span>'
 
end
 
 
 
local rowTaxonomyHeader = taxoboxTable:tag('tr')
+
-- check taxonomy templates for automatic taxobox systtem
rowTaxonomyHeader:tag('th')
+
--{{#ifexist:Template:Taxonomy/{{{taxon|<includeonly>{{PAGENAME}}</includeonly><noinclude>Acacia</noinclude>}}}
          :attr('colspan', '2')
+
--       |<noinclude><!--do nothing if it exists--></noinclude>
          :addClass('section-header')
+
--       |{{Automatic taxobox/floating intro|taxon={{{taxon|{{PAGENAME}}}}} }}
          :cssText('background:' ..  p.getTaxoboxColor(frame) .. ';')
+
-->}}
          :wikitext(taxonomyHeader)
 
          :wikitext(editLink)
 
 
 
if parent.args['auto'] then
 
    --p.addAutomaticTaxonomy(frame, taxoboxTable)  -- use #invoke of module
 
    p.addAutomaticTaxonomy2(frame, taxoboxTable)  -- use expandTemplate
 
else
 
p.addManualTaxonomy(frame, taxoboxTable, data.taxonRanks) -- just add rows
 
    end
 
end
 
-------------------------------------------------AUTOMATIC TAXONOMY (using invoke of module function) -----------
 
function p.addAutomaticTaxonomy(frame, taxoboxTable) -- use invoke of module function
 
--emulate template: {{taxobox/taxonomy}}
 
--which uses {{#invoke:Autotaxobox|taxoboxList
 
 
 
 
 
    local bold_first = 'bold'
 
    if parent.args['species'] then bold_first = 'link'    end
 
 
 
    local localFrame = frame -- this may not work as intended; it just creates another reference to the same table object
 
    localFrame.args[1] = parent.args['parent'] or tostring( mw.title.getCurrentTitle() )
 
localFrame.args['display_taxa']        = (parent.args['display_taxa'] or 1 )
 
localFrame.args['authority']          = parent.args['parentauthority']
 
localFrame.args['parent_authority']    = parent.args['grantparent_authority']
 
localFrame.args['gparent_authority']  = parent.args['greatgrandparent_authority']
 
localFrame.args['ggparent_authority']  = parent.args['greatgreatgrandparent_authority']
 
localFrame.args['gggparent_authority'] = parent.args['greatgreatgreatgrandparent_authority']
 
localFrame.args['bold_first']          = bold_first
 
 
 
 
 
local autotaxa = require("Module:Autotaxobox")
 
local autoTaxonomy = autotaxa.taxoboxList(localFrame)
 
   
 
    local row = taxoboxTable:tag('tr')  --  incompatible with the templates called
 
                        :wikitext('\n|rank ||taxon name ') 
 
                        :wikitext('\n'.. autoTaxonomy )  -- autoTaxonomy ends with a new row (|-)at end
 
                        :wikitext('\n|x ||y ')                -- so add blank cells to complete extra row
 
                                                              --  this and affects spacing in taxonomy rows
 
                        --:wikitext('\n')                      -- spacing fine, newline for table wikitext
 
                       
 
                   
 
    --[[ note:  the output of {{taxobox/showtaxon}} [used by invoke:Autotaxobox|taxoboxList] ends with a newline token
 
                this and affects spacing in taxonomy rows
 
                leaving the empty row results in spurious paragraphs above the table
 
                t his and affects spacing in taxonomy rows
 
          it is present in current taxoboxes but not visible
 
          results in
 
 
 
      ]]
 
return
 
end
 
----------------------------------------------------AUTOMATIC TAXONOMY (using template) ------------------------
 
function p.addAutomaticTaxonomy2(frame, taxoboxTable)  -- use template and expand
 
--emulate template: {{taxobox/taxonomy}}
 
--which uses {{#invoke:Autotaxobox|taxoboxList
 
 
 
    local bold_first = 'bold'
 
    if parent.args['species_name'] then bold_first = 'link'    end
 
                                                -- defaults are now handled earlier
 
    local templateArgs = { parent.args['parent'],  -- or tostring( mw.title.getCurrentTitle() ),
 
parent.args['display_taxa'], -- or 1,
 
authority=parent.args['authority'],
 
                parent_authority=parent.args['parent_authority'],
 
                grandparent_authority=parent.args['grandparent_authority'],
 
                greatgrandparent_authority=parent.args['greatgrandparent_authority'],
 
                greatgreatgrandparent_authority=parent.args['greatgreatgrandparent_authority'],
 
                bold_first
 
                }
 
templateArgs['bold first']= bold_first
 
 
 
    local autoTaxonomy = frame:expandTemplate{ title = 'taxobox/taxonomy', args = templateArgs }
 
 
 
    --[[ NOTE: the auto taxonomy system uses wikitext for the table
 
    mixing the mw.html and wikitext causes problems with table structure
 
    therefore the automatic taxonomy is embedded as a table table
 
    --]]
 
    local row = taxoboxTable:tag('tr')
 
    local cell = row:tag('td'):attr('colspan', '2')
 
    cell:wikitext('\n{|\n|-')
 
              --:wikitext('\n|rank \n|taxon name ')
 
              :wikitext('\n|-\n' .. autoTaxonomy )  -- autoTaxonomy ends with a new row (|-)at end
 
    if parent.args['species_name'] then                  -- so add species or blanks to complete extra row
 
        --TODO add subgenus handling
 
        cell:wikitext('\n|Species: ||' .. parent.args['species_name']) -- so add blank cells to complete extra row
 
        if parent.args['subspecies_name'] then
 
        cell:wikitext('\n|-\n|Subspecies: ||' .. parent.args['subspecies_name']) -- add subspecies/infraspecies
 
        end
 
        if parent.args['variety_name'] then
 
        cell:wikitext('\n|-\n|Variety: ||' .. parent.args['variety_name']) -- add subspecies/infraspecies
 
        end
 
        --TODO handle authority (or do we need to repeat it as shown in binomial/trinomial?)
 
        -- cell:wikitext(' authority')
 
    else
 
    --cell:wikitext('\n|x ||y ')
 
    end
 
    cell:wikitext('\n|}')                      -- end embedded table for automatic taxonomy
 
                       
 
return
 
end
 
 
 
----------------------------------------MANUAL TAXONOMY--------------------------------
 
 
 
function p.addManualTaxonomy(frame,taxoboxTable, taxonRanks)
 
 
--local parent = mw.getCurrentFrame():getParent()
 
--local taxonRanks = data.taxonRanks
 
 
-- following {{Paraphyletic group, a table is add to the cell in the classification row
 
--local taxonomyTable = mw.html.create('table'):addClass('taxonomy')
 
 
-- an alternative is to dispense with the extra table and just add the rows (like taxobox/core),
 
--    which would need colspan=2 on other rows (DONE)
 
local taxonomyTable = taxoboxTable 
 
 
for k,v in pairs(taxonRanks) do
 
 
if parent.args[v] then
 
    local row = taxonomyTable:tag('tr')
 
    local taxonName = parent.args[v]
 
   
 
    local taxonRank = frame:expandTemplate{ title = "anglicise rank", args = {taxonRanks[k]} }
 
 
 
    if taxonRanks[k] == "virus_group" then
 
    taxonName = frame:expandTemplate{ title = "Virus group", args = {parent.args[v]} }
 
    -- taxonRank = "Group" -- handled by anglicise rank template
 
    end
 
    local authorityString = ''
 
    if parent.args[taxonRanks[k]..'_authority'] then
 
    authorityString = '<br /><small>'..parent.args[taxonRanks[k]..'_authority']..'</small>'
 
    end
 
    row:tag('td'):wikitext(taxonRank..':')
 
    row:tag('td'):wikitext('<span class="'.. taxonRanks[k] ..'">'..taxonName..'</span>'..authorityString)
 
    --:wikitext('<br /><small>'..parent.args[taxonRanks[k]..'_authority']..'</small>')
 
  
end
 
end -- end for loop
 
 
return tostring(taxonomyTable)
 
 
end
 
end
  
-----------------------------------------------TAXOBOX COLOUR--------------------------------------
 
 
function p.getTaxoboxColor(frame)
 
 
if  parent.args['auto'] then
 
--[[TODO add autotaxobox colours as option
 
  (1) if color_as|colour_as|color as|colour as set, use template {{Taxobox colour|color_as}}
 
    (2) use the auto taxonnomy tree to find colour: {{#invoke:Autotaxobox|taxoboxColour| }}
 
    {{#invoke:Autotaxobox|taxoboxColour|{{{parent|{{{genus|{{first word|{{{taxon|{{PAGENAME}} }}
 
--]]
 
if (parent.args['color_as'] and parent.args['color_as'] ~= "") or
 
  (parent.args['colour_as'] and parent.args['colour_as'] ~= "") or
 
  (parent.args['color as'] and parent.args['color as'] ~= "") or
 
  (parent.args['colour as'] and parent.args['colour as'] ~= "") then
 
   
 
  local colorAs = ""
 
  if parent.args['color_as'] then colorAs = parent.args['color_as']  end
 
  if parent.args['colour_as']  then colorAs =  parent.args['colour_as'] end
 
  if parent.args['color as'] then colorAs =  parent.args['color as'] end
 
  if parent.args['colour as']  then colorAs =  parent.args['colour as']  end
 
   
 
    return frame:expandTemplate{ title = 'Taxobox colour', args = {colorAs} }
 
   
 
else
 
-- us #invoke:Autotaxobox|taxoboxColour|{{{parent}}} [parent should be set]
 
 
frame.args[1] = parent.args['parent']
 
        return autotaxa.taxoboxColour(frame)
 
--return "palegreen"
 
end
 
else -- use manual taxobox colours
 
--{{Taxobox colour|{{{regnum|{{{virus_group|{{{unranked_phylum|{{{phylum|''[[Incertae sedis]]''}}}}}}}}}}}}}}
 
  
local group =''
 
if (parent.args['color_as'] and parent.args['color_as'] ~= "") then
 
group = parent.args['color_as']
 
elseif parent.args['regnum'] then
 
group = parent.args['regnum']
 
elseif parent.args['virus_group'] then
 
group = parent.args['virus_group']
 
elseif parent.args['unranked_phylum'] then
 
group = parent.args['unranked_phylum']
 
elseif parent.args['phylum'] then
 
group = parent.args['phylum']
 
else
 
group = "''[[Incertae sedis]]''"          -- TODO check if this is what was desired
 
end
 
 
 
    return frame:expandTemplate{ title = 'Taxobox colour', args = {group} }
 
end
 
end
 
  
 +
-------------------------------------------------------------------
 
function p.templateStyle( frame, src )
 
function p.templateStyle( frame, src )
 
   return frame:extensionTag( 'templatestyles', '', { src = src } );
 
   return frame:extensionTag( 'templatestyles', '', { src = src } );
Line 673: Line 405:
  
 
-----------------------------------------
 
-----------------------------------------
function p.test(frame)
+
function p.testTables(frame)
 
if 1==1 then return end  -- disable
 
if 1==1 then return end  -- disable
 
local root = mw.html.create('table'):addClass('wikitable')
 
local root = mw.html.create('table'):addClass('wikitable')
Line 718: Line 450:
 
]]
 
]]
 
end
 
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.
 
-- All modules end by returning the variable containing its functions to Wikipedia.
 
return p
 
return p

Revision as of 14:29, 19 January 2019

This module started out as a quick module for template {{paraphyletic group}}, but has morphed into a module to emulate the {{taxobox/core}}. Handling for templates that call the core has been added for {{taxobox}}, {{Automatic taxobox}} and {{Speciesbox}}, but is incomplete.

Data subpages

Examples:

Sandbox version at Module:Sandbox/Jts1882/Biota infobox.

Usage

{{#invoke:Biota infobox|function_name}}



require('Module:No globals')
-- 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 variables
local g = {}  -- these are variables with global scope in this module

local info = {}          -- contains general purpose information (e.g. header background colour)
info.debug  = true -- 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 ##################################

--[[ main function callable in Wikipedia via the #invoke command.
        creates a taxobox-style infobox
        handles preliminary parameter handling enulating taxobox and automatic taxobox templates
           -- the parameters are also checked for content, alias, valid names and valid combinations
           -- the parameter handling is in subpage Module:Sandbox/Jts1882/Biota Infobox/param
        these are passed the core function
           -- the core function emulates the template {{Taxobox/core})
           -- the function is found in subpage Module:Sandbox/Jts1882/Biota Infobox/core
           -- the core them creates the taxobox
                 creates main table and header section (with header, subheader and fossil ranges)
	             adds addition rows for template arguments with following subsidiary functions:
			        p.addImageSection() - images and range maps 
			        p.addStatusSection() - conservation status
			        p.addTaxonomySection() - listing of taxonomic heirarchy (manuel or using automatic taxonomy system)
			        p.addTaxonSection() - adds section with taxonomic information (binomial or trinomials; type genus or species; diversity)
			        p.addListSection()     - section containing list if subdivisions, synonyms, included or excluded groups
--]]
p.main = function(frame) 
	
	--p.getArgs(frame)
	parameters.getArgs(frame, templateArgs, info)  -- 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
	else
		--[[TODO manual taxobox options:
		            name or use Template:Taxonomy name |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/core
p.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{ title = 'taxobox/core',  args = templateArgs   } ) 
 	
end

--[[ ##################### CORE FUNCTIONS ###################################

       this core function emulates Template:Taxobox/core 
       it is followed by functions handling the different type of entry
       MOVED to subpage Module:Sandbox/Jts1882/Biota_Infobox/core
]]


-- ################## AUTOMATIC TAXOBOX SYSTEM HANDLING ################################
------------------------------------------------------------------------------------------------
-- handle specific requirements of different options: auto, speciesbox etc
function 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']  then 
		--extinct = "†"
		extinct = frame:expandTemplate{ title = 'extinct' }  -- use template to get tooltip
		-- speciesbox also checks the genus taxonomy template for extinct parameter
    end

    ---------------------variables for SPECIESBOX, SUBSPECIESBOX and INFRASPECIESBOX---------------------
   
    -- ======================= setup for SPECIESBOX =============================
	
	if info.auto == "speciesbox" then
        
        --[[ {{speciesbox}} gets genus and species from taxon, genus+species or page name
                1. uses 'taxon' paramter ( given as binomial) if available
                2. otherwise uses 'genus' and 'species' parameters
                3. uses page name
             the genus is used for the 'parent' taxon 
            	unless the parent is supplied (e.g. for subgenus)
            	else use genus (from taxon or genus parameter or page name)
            	
           {{Speciesbox}} now using {{Speciesbox/getGenus}} and  {Speciesbox/getSpecies}}
                code doing similar is commented out below
           
           TODO use {{{{Speciesbox/name}}
        --]]
       local genus, species = "", ""
       
       genus = frame:expandTemplate{ title = 'Speciesbox/getGenus' , args = {templateArgs['taxon'], templateArgs['genus']} }
       species = frame:expandTemplate{ title = 'Speciesbox/getSpecies' , args = {templateArgs['taxon'], templateArgs['genus']} }
       
		if templateArgs['taxon'] then
           
           -- following line disableas using getGenus/getSpecies templates	       
           -- genus, species = string.match(templateArgs['taxon'], "(%S+)%s(%S+)") -- %S: All characters not in %s
	       
	       templateArgs['genus'] = genus                 
	       templateArgs['species'] = species            
	   
	    elseif templateArgs['genus'] and templateArgs['species'] then
	    	
	    	--[[strip off (disambiguator) to handle multi-kingdom genus e.g.| genus = Acanthocarpus (plant)
	    	local genusParts =mw.text.split( templateArgs['genus'], " ", true )     -- string.match( s, '^%a*'', 1 )
	    	                                    
	    	if genusParts[1] ~= "" then 
	    		--templateArgs['parent']=templateArgs['genus']  -- set parent (NO, parent should override)
	    		genus = genusParts[1] 
	    	end
	    	now handled by getGenus/getSpecies templates --]]
	    	
	    	templateArgs['taxon'] = genus .. ' ' .. templateArgs['species']
	
	    else
	    	-- TODO no valid taxon yet; use page name
	    	-- use first word of pagename - handled by {{Speciesbox/getGenus}}
	    end
    
        if not templateArgs['parent'] or templateArgs['parent'] == "" then
        	templateArgs['parent'] = templateArgs['genus']       -- set parent to genus if not supplied
        end
        --[[if not templateArgs['name'] or templateArgs['name'] == "" then -- if page name not set
        	templateArgs['name'] = "''" .. templateArgs['taxon'] .. "''"
        end    ]]    	
        --TODO use {{Speciesbox/name}}
        templateArgs['name']  = frame:expandTemplate{ title = 'Speciesbox/name' , 
        	                           args = { templateArgs['name'], templateArgs['taxon'], 
        	                                    templateArgs['genus'], templateArgs['species'],
        	                                    mw.title.getCurrentTitle().baseText,
        	                                    templateArgs['italic_title' or 'yes']  
        	          	
        	          } }
            

        
        
		-- set binomial : the speciesbox template seems to use genus and species before taxon name
		-- "| binomial = ''{{Str letter/trim|{{{genus|{{{taxon|<includeonly>{{PAGENAME}}</includeonly><noinclude>Acacia</noinclude>}}}}}}}} {{{species|{{remove first word|{{{taxon|<includeonly>{{PAGENAMEBASE}}</includeonly><noinclude>Acacia aemula</noinclude>}}}}}}}}''"
		-- documentation suggest taxon, which is followed here
		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['species_authority']   = templateArgs['authority'] or "" -- don't show species_authority as duplicates binomial authority
	    
	    
	    --[[shift authorities for speciesbox (two steps if subgenus set)
	    if templateArgs['subgenus'] and templateArgs['subgenus'] ~= ""  then
			templateArgs['subgenus_authority']              = templateArgs['parent_authority'] or ""
			templateArgs['authority']                       = templateArgs['grandparent_authority'] or ""
			templateArgs['parent_authority']                = templateArgs['greatgrandparent_authority'] or ""
			templateArgs['grandparent_authority']           = templateArgs['greatgreatgrandparent_authority'] or ""
			templateArgs['greatgrandparent_authority']      = templateArgs['greatgreatgreatgrandparent_authority'] or ""
			templateArgs['greatgreatgrandparent_authority'] = templateArgs['greatgreatgreatgreatgrandparent_authority'] or ""
		else                                                                
			-- note: must set to "" if 'parent_authority's don't exist, otherwise the value of 'authority' is unchanged
			templateArgs['authority']                       = templateArgs['parent_authority'] or ""  
			templateArgs['parent_authority']                = templateArgs['grandparent_authority'] or ""
			templateArgs['grandparent_authority']           = templateArgs['greatgrandparent_authority'] or ""
			templateArgs['greatgrandparent_authority']      = templateArgs['greatgreatgrandparent_authority'] or ""
			templateArgs['greatgreatgrandparent_authority'] = templateArgs['greatgreatgreatgrandparent_authority'] or ""	
		end
        ]]
        templateArgs['taxon'] = nil -- For auto module
 
        
    -- =====================  set-up for SUBSPECIESBOX or INTRASPECIESBOX =================
	
	elseif info.auto == "subspeciesbox" or info.auto == "infraspeciesbox" then
	
	   --[[ From template description:
	          "The genus name, species name and subspecies name" 
	             [or "genus name, specific epithet and infraspecific epithet"] 
                 "
                 must be supplied separately: the combined taxon parameter cannot be used.""
              "The genus name is then the entry into the taxonomic hierarchy.""
              
		    The trinomial name is set from these parameters and the parameter ignored.
		   --NOTE no infraspeciebox is currently using trinomial parameter
        --]]
        
        -- Parameter checking. This could be here or moved to parameter checking function
        if templateArgs['genus'] and templateArgs['species'] and templateArgs['subspecies'] then
        	-- valid parameters for subspecies (may have variety as well)
        elseif templateArgs['genus'] and templateArgs['species'] and templateArgs['variety'] then
        	-- valid parameters for infraspecies (variety without subspecies)
        else
        	-- insufficient parameters
        	-- TODO add error message and return
        end
        local offset = 2  -- authority offset when subpecies OR variety 
        
        --TODO strip genus of disambiguator (need to check this works)
        	local genus =mw.text.split( templateArgs['genus'], " ", true )
	    	if genus[1] ~= "" then 
	    		templateArgs['genus'] = genus[1] 
	    	end
        templateArgs['parent'] = templateArgs['genus'] -- genus must be supplied
        
        local fullName = templateArgs['genus'] .. ' ' .. templateArgs['species']
 		templateArgs['species_name'] = "''[[" .. fullName  .. '|'.. string.sub(templateArgs['genus'],1,1) .. '. ' .. templateArgs['species'] .. "]]''"

        -- if subspecies is set (could be with or without variety)
        local separator = " "                               -- subspecies separator (default zoological)
	    if templateArgs['subspecies'] then                  -- might not be if variety
        	if info.auto == "infraspeciesbox"   then separator = " ''<small>subsp.</small>'' "   end
			templateArgs['subspecies_name']= extinct .. "'''''" .. string.sub(templateArgs['genus'],1,1) .. '.&nbsp;' .. string.sub(templateArgs['species'],1,1) .. '.' .. separator .. templateArgs['subspecies'] .. "'''''"
  			fullName = templateArgs['genus'] .. ' ' .. templateArgs['species'] .. separator .. templateArgs['subspecies'] 
			templateArgs['trinomial'] = "''" .. fullName .. "''"
            --templateArgs['subspecies_authority'] = templateArgs['authority']  -- replicates authoity in trinomial (unwanted?)
        end
        
        if templateArgs['variety'] or templateArgs['varietas'] then  -- should now be aliased
            local vSeparator = " ''<small>var.</small>'' " 
            --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) .. '.&nbsp;' .. 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 instead of bold 
	  			local redirectName = templateArgs['genus'] .. ' ' .. templateArgs['species'] .. " subsp. " .. templateArgs['subspecies'] 
				local shortName = "''" .. string.sub(templateArgs['genus'],1,1) .. '.&nbsp;' .. string.sub(templateArgs['species'],1,1) .. '.' .. separator .. templateArgs['subspecies'] .. "''" 
				templateArgs['subspecies_name'] =  "[[" .. redirectName .. '|' .. shortName .. "]]"
				offset = offset + 1 -- offset when susbpecies AND variety
                templateArgs['subspecies_authority'] = templateArgs['parent_authority']
        	end
        end
        
        --TODO what else do subspeciesbix and infraspeciesbox cover?)

       --[[ code from templates
            both:            |trinomial_authority = {{{authority|{{{trinomial authority|{{{trinomial_authority|}}} }}} }}}
            infraspeciesbox: |species_authority = {{{parent_authority|{{{parent authority|{{{binomial authority|{{{binomial_authority|}}}}}}}}}}}}
            subspeciesbox: | species_authority = {{{parent authority|{{{binomial authority|{{{binomial_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'] == "" then -- if page name not set
        	templateArgs['name'] = templateArgs['trinomial']
        end
        
        -- these are used by manual taxobox to complete the taxonomy table
        templateArgs['species'] = templateArgs['species_name']
        templateArgs['subspecies'] = templateArgs['subspecies_name']
		templateArgs['variety'] =templateArgs['variety_name']
        
        --QUESTION what happens to parent taxa when subspecies and variety? 
        -- set species and subgenus authorities
	    if templateArgs['subgenus'] then 
	    	offset = offset + 1
		    if offset == 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 -- when subgenus, species, (subspecies OR variety)
		    	templateArgs['subgenus_authority']  = 	templateArgs['subgenus_authority'] or templateArgs['grandparent_authority'] or ""
		    	templateArgs['species_authority']   = templateArgs['parent_authority'] or ""
		    end
		else -- only need to set species authority or subspecues (if also variety)
		    if offset == 3 then    -- species, subspecies and variety
		    	templateArgs['species_authority']   = templateArgs['grandparent_authority'] or ""
		    	templateArgs['subspecies_authority']   = templateArgs['parent_authority'] or ""
		    elseif offset == 2 then  -- species, (subspecies or variety)
		        templateArgs['species_authority']   = templateArgs['parent_authority'] or ""
		    end	    
		end
       
        templateArgs['display_taxa']   = (templateArgs['display_taxa'] or 1) -2
        templateArgs['offset'] = offset

	

	    -- need to set subgenus_authority, species_authority, subspecies_authority and variety_authority
        
	    --[[shift authorities for subspeciesbox (two steps or three if subgenus set)
	    if templateArgs['subgenus'] and templateArgs['subgenus'] ~= ""  then
			templateArgs['subgenus_authority']              = templateArgs['grandparent_authority'] or ""
			templateArgs['authority']                       = templateArgs['greatgrandparent_authority'] or ""
			templateArgs['parent_authority']                = templateArgs['greatgreatgrandparent_authority'] or ""
			templateArgs['grandparent_authority']           = templateArgs['greatgreatgreatgrandparent_authority'] or ""
			templateArgs['greatgrandparent_authority']      = templateArgs['greatgreatgreatgreatgrandparent_authority'] or ""
			templateArgs['greatgreatgrandparent_authority'] = templateArgs['greatgreatgreatgreatgreatgrandparent_authority'] or ""
		else
			templateArgs['authority']                       = templateArgs['grandparent_authority'] or ""
			templateArgs['parent_authority']                = templateArgs['greatgrandparent_authority'] or ""
			templateArgs['grandparent_authority']           = templateArgs['greatgreatgrandparent_authority'] or ""
			templateArgs['greatgrandparent_authority']      = templateArgs['greatgreatgreatgrandparent_authority'] or ""
			templateArgs['greatgreatgrandparent_authority'] = templateArgs['greatgreatgreatgreatgrandparent_authority']	 or ""
		end
		]]
	
	-- ========================= setup for AUTOMATIC TAXOBOX ================================
	        -- CHECK authomatic taxobox pagename overrides taxon (e.g. Tortrix? destructus) for header
        --         it does but no italics in header for Tortrix? destructus

    --elseif info.auto == "automatictaxobox" then
	
	elseif info.auto == "virus" then
			templateArgs['virus'] = "yes"
			templateArgs['color_as'] = "Virus"
			if not templateArgs['parent'] then
				if templateArgs['taxon'] then
			        templateArgs['parent'] = templateArgs['taxon']  
			    elseif templateArgs['species'] then 
			    	templateArgs['parent'] = templateArgs['species'] 
			    	templateArgs['species'] = nil
			    else
			    	templateArgs['parent'] = tostring( mw.title.getCurrentTitle()) or ""
			    end
			else
				templateArgs['link_parent'] = "yes"            -- if parent given, we want to link it
			end
		    
	else 

    	-- "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'] == "" then
    		--templateArgs['taxon'] = templateArgs['name'] or tostring( mw.title.getCurrentTitle())
    		templateArgs['taxon'] = tostring( mw.title.getCurrentTitle()) or ""
    		--TODO strip name of parenthetical terms off page title
    		if templateArgs['taxon'] ~= "" then
    			--TODO error message and exit
    		end
    	end		
    	if templateArgs['parent'] then
    		templateArgs['link_parent'] = "yes"              -- if parent given, we want to link it
    	else
  		   templateArgs['parent'] = templateArgs['taxon']   -- otherwise set parent
  		end
  		--TODO set name if parameter no supplies
  		
  		--[[ TODO if no taxonomy template, then call setup taxonomy template 
  		   {{#ifexist:Template:Taxonomy/{{{taxon|<includeonly>{{PAGENAME}}
  		   {{Automatic taxobox/floating intro|taxon={{{taxon|{{PAGENAME}}}}} }}
  		]]
	
	end	-- end special handling for speciesbox, subspeciesbox, and automatic taxobox
	
	-- check taxonomy templates for automatic taxobox systtem
	--{{#ifexist:Template:Taxonomy/{{{taxon|<includeonly>{{PAGENAME}}</includeonly><noinclude>Acacia</noinclude>}}}
	--       |<noinclude><!--do nothing if it exists--></noinclude>
	--       |{{Automatic taxobox/floating intro|taxon={{{taxon|{{PAGENAME}}}}} }}
-->}}

end



-------------------------------------------------------------------
function p.templateStyle( frame, src )
   return frame:extensionTag( 'templatestyles', '', { src = src } );
   
end	

-----------------------------------------
function p.testTables(frame)
	if 1==1 then return end  -- disable
	local root = mw.html.create('table'):addClass('wikitable')

	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|-\n|P\n|Q\n|}') --but include a wikitxt table in one cell
	         -- :done()

   -- row:done()
    --root=mw.html:allDone()
    root:wikitext('<tr><td>a</td><td>b</td></tr>') -- add row to root using html 
    root:wikitext('\n|-\n|X\n|Y\n')              -- add row to root using wikitext (FAILS) 
    
    root:wikitext('\r|-\r|I\r|J\r')              -- FAIL output |- |X |Y 
	
	root:wikitext(frame:preprocess('\n|-\n|U\n|V\n')) -- FAIL output |- |U |V 
	
	root:wikitext('<tr>\n|M\n|N\n</tr>')    
	

	row=root:tag('tr'):node('<td>c</td><td>d</td>')    -- adds row successfully
	row=root:tag('tr'):node('\n|Xc\n|Xd\n')    -- fails to adds row
	
	
	row = root:tag('tr')                       -- add another row using lua library
	cell = row:tag('td'):wikitext('row C:')
	cell = row:tag('td'):wikitext('content C')

	root:node('\n{|\n|-\n|Xx\n|Yx\n|}\n')    -- adds new table after

	--frame:preprocess
	return 	 tostring(root)

--[[ CONCLUSION: cannot mix wikitext freely in the node structure
           A complete wikitext table can be included in a cell (e.g. used for automatic taxonomy now)
           An alternative is to use wikitext for the whole taxobox table
]]
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