require('strict')
local p = local templateArgs = local info =
local paramData = require('Module:Biota infobox/data') -- contains the taxon ranks in orderlocal autotaxa = require("Module:Autotaxobox")local parameters = require('Module:Biota infobox/param')
--p.main = function(frame) -- this function emulates Template:Taxobox/core when called from taxobox feeder templates -- i.e. Taxobox, Automatic taxobox, Speciesbox, etc parameters.getArgs(frame) templateArgs['image_upright'] = templateArgs['upright'] or 1 templateArgs['image2_upright'] = templateArgs['upright2'] or 1 info.headerColor = templateArgs['colour'] return p._core --TODO check it worksend-- this is the core function, called either from main or autop.core = function(frame, args, localinfo) templateArgs = args info = localinfo return p._core(frame) end
p._core = function(frame)
-- TODO use mw.title.getCurrentTitle.basePageTitle info.name = templateArgs['name'] or tostring(mw.title.getCurrentTitle) --.rootPageTitle)
if not info.headerColor then info.headerColor = p.getTaxoboxColor(frame) -- so only transverse taxobox heirarchy once end --create table (two versions) 1. use mwhtml library to build table in taxoboxTable 2. use wikitest to build table in wikitextTable local taxoboxTable = mw.html.create('table'):addClass('infobox'):addClass('biota') :addClass('biota-infobox') local wikitextTable = '\n
-\n! colspan="2" class="section-header" style="background:' .. info.headerColor .. ';" ' .. ' | ' .. info.name .. info.subheader .. temporalRange -- add images wikitextTable = wikitextTable .. p.addImageSection(frame, taxoboxTable, 'image') .. p.addImageSection(frame, taxoboxTable, 'image2') --add conservation status wikitextTable = wikitextTable .. p.addStatusSection(frame, taxoboxTable, 'status') .. p.addStatusSection(frame, taxoboxTable, 'status2') -- add taxonomy table (uses entered parameters or automatic taxonomy system) wikitextTable = wikitextTable .. p.addTaxonomySection(frame, taxoboxTable) -- add sections with binomial, trinomial, type species/genus (with authorities) wikitextTable = wikitextTable .. p.addTaxonSection(frame, taxoboxTable, 'binomial', 'Binomial 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) wikitextTable = wikitextTable .. p.addListSection(frame, taxoboxTable, 'subdivision', templateArgs['subdivision_ranks'] or 'Subdivisions') .. p.addListSection(frame, taxoboxTable, 'possible_subdivision', templateArgs['possible_subdivision_ranks'] or 'Possible subdivisions') -- diversity section (TODO consider how best to handle) wikitextTable = wikitextTable .. p.addTaxonSection(frame, taxoboxTable, 'diversity', 'Diversity') -- show included groups (accepts 'included' or 'includes') [used for paraphyletic taxa] wikitextTable = wikitextTable .. p.addListSection(frame, taxoboxTable, 'includes', 'Groups included') --p.addListSection(frame, taxoboxTable, 'included', 'Groups included') -- use alias --add range map (should this be below binomial/trinomial?) wikitextTable = wikitextTable .. p.addImageSection(frame, taxoboxTable, 'range_map') -- show excluded groups (accepts 'excluded' or 'excludes') [used for paraphyletic taxa] local excludedHeaderText = 'Cladistically included but traditionally excluded taxa' wikitextTable = wikitextTable .. p.addListSection(frame, taxoboxTable, 'excludes', excludedHeaderText) -- add addition binomials, trinomial and range maps wikitextTable = wikitextTable .. p.addTaxonSection(frame, taxoboxTable, 'binomial2', 'Binomial name (2)') --p.addTaxonSection(frame, taxoboxTable, 'trinomial2', 'Trionomial name (2)') .. p.addImageSection(frame, taxoboxTable, 'range_map2') .. p.addTaxonSection(frame, taxoboxTable, 'binomial3', 'Binomial name (3)') --p.addTaxonSection(frame, taxoboxTable, 'trinomial3', 'Trionomial name (3)') .. p.addImageSection(frame, taxoboxTable, 'range_map3') .. p.addTaxonSection(frame, taxoboxTable, 'binomial4', 'Binomial name (4)') --p.addTaxonSection(frame, taxoboxTable, 'trinomial4', 'Trionomial name (4)') .. p.addImageSection(frame, taxoboxTable, 'range_map4') -- add synonyms section wikitextTable = wikitextTable .. p.addListSection(frame, taxoboxTable, 'synonyms', 'Synonyms') -- add debug/tracking info section if info.debug then wikitextTable = wikitextTable ..p.addListSection(frame, taxoboxTable, 'debug', 'Debug/tracking info') end ------------------add templateSyles and return taxobox table--------------------------- local src = "Template:Biota infobox/styles.css" -- TemplateStyles file wikitextTable = wikitextTable .. '\n |
local output = wikitextTable -- output the wikitext table --local output = tostring(taxoboxTable) -- output the mw.html table return output .. p.templateStyle(frame, src) .. info.parameterCategory --return '
' .. output .. p.templateStyle(frame, src) .. info.parameterCategory .. '
' end -- End the main function.
--|||extinct= }} }} --function p.addStatusSection(frame, taxoboxTable, status)
-- must use table container to handle template output -- don't use header or content cells; the 'taxobox/species' template handles it -- just need to add background colour on the row local wikiText = "" if templateArgs[status] and templateArgs[status] ~= "" then local statusText = frame:expandTemplate local row = taxoboxTable:tag('tr') --:cssText('background:' .. p.getTaxoboxColor(frame) .. ';') local cell = row:tag('td'):attr('colspan', '2') :wikitext('\n
- style="background:' .. info.headerColor .. ';"') :wikitext('\n'..tostring(statusText)) :wikitext('\n |
' .. statusText .. '') if status
--
-- custom processing section --if target
'binomial2' or target
'binomial4' then if target
'trinomial' or target
'trinomial3' or target
'trinomial' then local trinomenLink = "Trinomen" -- for zoological or default if info.auto
'binomial2' or target
'binomial4' or target
'trinomial3' or target
'diversity' then headerText = '' .. headerText .. '' else --TODO is any handling needed for other option headerText = '' .. headerText .. '' end if templateArgs[target..'_ref'] then headerText = headerText .. templateArgs[target..'_ref'] .. '\n' end local contentString = -- content for the content cell if target
inserted end -- add table rows if templateArgs[target] and templateArgs[target] ~= then if showHeader then local rowHeader = taxoboxTable:tag('tr') rowHeader :tag('th') :attr('colspan', '2') :addClass('section-header') :cssText('background:' .. info.headerColor .. ';') :wikitext(headerText) wikiText = wikiText .. '\n|- \n! colspan="2" class="section-header" style="background:' .. info.headerColor .. ';" ' .. '|' .. headerText
end local rowList = taxoboxTable:tag('tr') rowList :tag('td') :attr('colspan', '2') --:addClass('section-content') :addClass('taxon-section') --:cssText('text-align:center;') --font-weight:bold;') :wikitext(contentString) wikiText = wikiText .. '\n|- \n| colspan="2" class="taxon-section" |' .. contentString end return wikiTextend
--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 parameterfunction p.addListSection(frame, taxoboxTable, target, headerText) if not templateArgs[target] or templateArgs[target]
local rowList = taxoboxTable:tag('tr') rowList :tag('td') :attr('colspan', '2') :addClass('section-content') :wikitext('\n' .. templateArgs[target] .. '\n') wikiText = wikiText .. '\n|- \n| colspan="2" class="section-content" ' .. '|' .. '\n' .. templateArgs[target] .. '\n'
end return wikiTextend-------------------------------------------------------------------------------------------------
' .. templateArgs[target .. '_caption'] .. '
' --imageCaptionString = '
' .. templateArgs[target .. '_caption'] .. '
' imageCaptionString = templateArgs[target .. '_caption'] end local imageAltString = if templateArgs[target..'_alt'] then imageAltString = templateArgs[target..'_alt'] elseif templateArgs[target..'_caption'] then imageAltString = templateArgs[target..'_caption'] -- use caption for alt text if none provided end local upright = templateArgs['image_upright'] or 1 local InfoboxImage = require('Module:InfoboxImage') --, parent.args[target]) local params = local image = InfoboxImage.InfoboxImage(params) --local rowImage = taxoboxTable:tag('tr') local rowImage = mw.html.create('tr') rowImage:tag('td') :attr('colspan', '2') :addClass("image-section") :wikitext(image) --:wikitext(imageCaptionString) taxoboxTable:node(rowImage) wikiText= wikiText .. '\n|- \n|colspan="2" class="image-section" |' .. image if imageCaptionString ~= "" then -- only insert row if caption string local rowImageCaption = mw.html.create('tr') rowImageCaption:tag('td') :attr('colspan', '2') :addClass("image-section") --:wikitext(image) :wikitext(imageCaptionString) taxoboxTable:node(rowImageCaption) wikiText = wikiText .. '\n|- \n|colspan="2" class="image-section" |' .. imageCaptionString end end -- TODO handle upright return wikiTextend
--
(' .. templateArgs['classification_status'] .. ')' if templateArgs['classification_ref'] then status = status .. templateArgs['classification_ref'] end status = status .. '
' end local rowTaxonomyHeader = taxoboxTable:tag('tr') rowTaxonomyHeader:tag('th') :attr('colspan', '2') :addClass('section-header') :cssText('background:' .. info.headerColor .. ';') :wikitext(taxonomyHeader) :wikitext(editLink) :wikitext(status) wikiText = wikiText .. '\n|- \n! colspan="2" class="section-header" style="min-width:15em;text-align:center;background:' .. info.headerColor .. ';" ' .. '|' .. taxonomyHeader .. editLink .. status -- -- shows ranks of genus or above for all auto modes if info.db
"wikidata" then --wikiText = wikiText ..'\n|-|\n|' .. p.addWikidataTaxonomy(frame, taxoboxTable) -- use wikidata local wdModule = require('Module:Biota infobox/Wikidata')
wikiText = wikiText .. wdModule.addWikidataTaxonomy(frame, taxoboxTable, templateArgs) -- use wikidata -- TODO need to handle colour -- the default is class="section-header" colspan="2" style="background:rgb(250,240,230);" -- wikiText = wikiText:gsub('style="background:rgb%(250,240,230%);"', 'style="background:red;"') -- gsub must be applied to wikitextTable -- use more generally to avoid traversing the hierarchy twice) elseif info.auto then -- wikiText = wikiText ..'\n|-|\n|' .. p.addAutomaticTaxonomy(frame, taxoboxTable) -- use #invoke of module end if info.auto then -- use manual taxobox for subgeneric ranks: subgenus,species, subspecies, variety (also for informal group) -- ranks below genys using manual taxobox code local taxonRanks = wikiText = wikiText .. p.addManualTaxonomy(frame, taxoboxTable, taxonRanks) else wikiText = wikiText .. p.addManualTaxonomy(frame, taxoboxTable, paramData.taxonRanks) -- just add rows manually end return wikiTextend-------------------------------------------------AUTOMATIC TAXONOMY (using invoke of module function) -----------function p.addAutomaticTaxonomy(frame, taxoboxTable) -- use invoke of module function --emulate template: --which uses