Module:Sandbox/Jts1882/Biota infobox/auto explained

local p = -- local g = -- these are variables with global scope in this sub-moduleg.info =

--testing function to show automatic taxonomy within a table function p.showTaxonomyTable(frame) g.templateArgs = g.info.auto= false g.taxonTable = p.loadTaxonomyTable(frame) local output = '\n

- style="vertical-align:top;" ' --output = output .. '\n! Rank Taxon \n-' -- oldversion starting new row output = output .. '\n! Rank Taxon' -- don't start a new row here g.htmlTable = mw.html.create('table') :addClass('infobox'):addClass('biota') :cssText("text-align: left; width: 200px; font-size: 100%") output = output .. p.taxoboxList(frame) output = output .. '\n
' return tostring(g.htmlTable) .. output --return '\n' ..p.showTaxonomyHierarchyRaw(frame, g.taxonTable) --output --return outputend

--function p.getTaxonomyTableRows(frame, htmlTable, templateArgs, info) g.htmlTable = htmlTable g.templateArgs = templateArgs g.info = info g.taxonTable = p.loadTaxonomyTable(frame) return p.taxoboxList(frame)end--testing function to output the heirarchy table from the automatic taxonomy as a wikitablefunction p.showTaxonomyHierarchyRaw(frame, taxonTable) local output = '

' .. k end for i=1, #taxonTable, 1 do output = output .. '\n-' for k,v in pairs(taxonTable[i]) do output = output .. '\n' .. v end end output = output .. '\n
' --return mw.dumpObject(taxonTable) return outputend--

function p.loadTaxonomyTable(frame) local ok, taxonInfo local taxonTable= local i = 1 -- load authorities from template parameters local authorities = -- get the name of the first taxon local taxon = g.templateArgs['taxon'] or g.templateArgs['parent'] or "Felis" --taxon= 'Felis' --taxon= 'Worthenella' --taxon= 'Fereuungulata' --local authority = 'authority' -- the following section is an alternative method for adding rows for species, subspecies, etc -- if g.templateArgs['species_name'] then

if g.templateArgs['variety_name'] then taxonTable[i]= i=i+1 end if g.templateArgs['subspecies_name'] then taxonTable[i]= i=i+1 end -- TODO if subgenus

taxonTable[i]= i=i+1 taxon = g.templateArgs['parent'] end -- -- while i<100 do

ok, taxonTable[i] = g.getTaxonInfo(frame, taxon)

--if ok and taxonTable[i]['parent'] ~= "" then if ok then if taxonTable[i]['same_as'] and taxonTable[i]['same_as'] ~= "" then taxon = taxonTable[i]['same_as'] local ok, sameAsTable = g.getTaxonInfo(frame, taxon) if ok then for k,v in pairs(taxonTable[i]) do if v

"" then taxonTable[i][k] = sameAsTable[k] -- use same_as values if none set end end else break; end else -- we have what data for the taxon directly -- TODO do something end -- add taxon to the table row if taxonTable[i]['link_text'] and taxonTable[i]['link_text'] ~= "" then taxonTable[i]['taxon'] = taxonTable[i]['link_text'] else taxonTable[i]['taxon'] = taxonTable[i]['link_target'] end -- authority from parent authroity sequence taxonTable[i]['authority'] = (authorities[i] or "") if taxonTable[i]['parent']

"" then -- have we reached the top of the heirarchy? break else taxon = taxonTable[i]['parent'] -- set the taxon for the next loop end else break end i = i + 1 end --we have a complete table taxonTable.n = #taxonTable - 1 -- minus one as last one has parent=life and displays as Genus: Ursus

return taxonTableend

--function g.getTaxonInfo(frame, taxon) local ok, taxonInfo = pcall(frame.expandTemplate, frame,) if ok then local split= mw.text.split(taxonInfo, "$", true) -- all: returns "parent$rank$link_target$unnamed parameter$always_display$extinct$same_as$refs" local taxonRow = return ok, taxonRow endend

local res =

-- generic display to replace >6, 5,4,3,2,1 sections for i = taxonTable.n, 1, -1 do if i

1 then boldFirst = "bold" end res = res .. g.showTaxonRow(frame, i, boldFirst, virus) --res = res .. g.showTaxonRow(frame, i, taxonTable[i]['taxon'], taxonTable[i]['authority'], taxonTable[i]['always_display'], boldFirst, virus)

end return resend--function g.isPrincipalRank(rank) -- Remove "ichno" and "oo" and then check for a major taxon ("oordo" becomes "rdo"): rank = string.gsub(rank, "ichno", "") rank = string.gsub(rank, "oo", "") if rank

"regnum" or rank

"phylum" or rank

"divisio" or rank

"classis" or rank

"ordo" or rank

"rdo" or rank

"familia" or rank

"genus" or rank

"species" or rank

"subspecies" or rank

"variety" then return true else return false -- rank is an infrarank end --return not g.isInfraTaxon(rank)endfunction g.isInfraTaxon(rank) --Remove "ichno" and "oo" and then check for a major taxon ("oordo" becomes "rdo"): rank = string.gsub(rank, "ichno", "") rank = string.gsub(rank, "oo", "") if rank

"regnum" or rank

"phylum" or rank

"divisio" or rank

"classis" or rank

"ordo" or rank

"rdo" or rank

"familia" or rank

"genus" or rank

"species" or rank

"subspecies" or rank

"variety" then return false else return true -- rank is an infrarank endend--function g.showTaxonRow (frame, i, boldFirst, virus)

-- -- do we want to display the taxon? if g.taxonTable[i]['always_display']

"yes" -- the flag for whether to force display a taxon or g.taxonTable[i]['always_display']

"true" or g.isPrincipalRank(g.taxonTable[i]['rank']) then -- or major ranks -- continue else --if g.isInfraTaxon(g.taxonTable[i]['rank']) then -- or a major rank (=not a minor rank) return "" end

-- local bold = "no" if boldFirst

"bold" then bold = "yes" end --taxon name local taxonName = g.taxonTable[i]['taxon'] -- plain name local rank = g.taxonTable[i]['rank'] if rank

"species" or rank

"subspecies" or rank

"variety" then -- no processing of name necessary (already set to species_name, subspecies_name, etc) else taxonName = frame:expandTemplate end --rank local taxonRank = g.taxonTable[i]['rank'] taxonRank = frame:expandTemplate if g.taxonTable[i]['rank']

"virus_group" then taxonName = frame:expandTemplate -- taxonRank = "Group" -- handled by anglicise rank template end local authorityString = if g.taxonTable[i]['authority'] and g.taxonTable[i]['authority'] ~= "" then authorityString = '
'.. g.taxonTable[i]['authority'] ..'' end --now output the html the autotaxobox templates had already started a new row and ended with new row this was the stumbling block for the nodal approach uing the Lua html library (mw.html) which required the embedded table -- new method append row to the table structure using mw:html library local row =g.htmlTable:tag('tr') local cell = row:tag('td'):wikitext(taxonRank .. ":"..i) cell = row:tag('td'):wikitext(taxonName .. authorityString) -- old method: return wikitext for table row local rowWiki = '\n|-\n|'..taxonRank .. ':' .. i .. '||' .. taxonName .. authorityString --return row .. '\n|-' -- return with new row started return rowWiki -- so don't start the new row end

return p