Module:Sandbox/Jts1882/Biota infobox/param explained

require('strict')

local p = local templateArgs = local info =

local paramData = require('Module:Sandbox/Jts1882/Biota infobox/data') -- contains the taxon ranks in order

-- call parameter checking independently of taxobox displayfunction p.main(frame) p._getArgs(frame) return info.parameterCategory end-- get parameters for calling functionfunction p.getArgs(frame, args, localinfo) templateArgs = args info = localinfo p._getArgs(frame)end-- get the arguments and check them in vaious waysfunction p._getArgs(frame) local parents = mw.getCurrentFrame:getParent local tempArgs= -- local copy of arguments that will be checked (empty, aliases, invalid) -- get copy of parent arguments, aliasing spaces for underscores for k,v in pairs(parents.args) do if type (k)

'string' then -- no positional parameters --v = v:match('^%s*(.-)%s*$') -- include trimming (only needed for positional parameters) if v and (v ~= "") then -- check for content local j = k:gsub(" ", "_") -- substitute spaces with underscore (aliases) tempArgs[j]=v -- parents.args[k] end end end -- do we need to check frame args? for k,v in pairs(frame.args) do if v and v ~= "" then --check for content tempArgs[k]=v end end

-- parameters that can be set without a value, e.g. |extinct= if parents.args['extinct'] and parents.args['extinct']

"" then templateArgs['extinct'] = "" end

if parents.args['auto'] or frame.args['auto'] then info.auto = parents.args['auto'] or frame.args['auto'] -- keep template parameters seperate from control flow arguments end p.preprocessArgs(tempArgs) -- check aliases, check valid parameters for calling templateend

function p.preprocessArgs(tempArgs) -- handles aliases ajc validates parameters info.parameterCategory = "" -- initialise empty string for tracking categories p.aliasParams(tempArgs) -- check parameters for aliases p.validateParams(tempArgs) -- check parameters for invalid parameters (from allowed list) p._checkParameters(tempArgs) -- check manual taxon ranks, orphaned parameters and invalid combinationsend--------------------------------------------------------------------- function p.aliasParams(tempArgs) -- alias of spaces to underscores handled in getArgs -- uses alias list from the data subpage (param.aliasmap) -- e.g. local aliasMap = function p.aliasParams(tempArgs)

-- change parameters using alias map for k,v in pairs(paramData.aliasMap) do if tempArgs[k] then -- if templateArgs has parameter with alias name tempArgs[v] = tempArgs[k]; -- create new element with alias' value as key tempArgs[k] = nil; -- delete the alias end end

--

end--------------------------------------------------------------------------------------------- function p.validateParams(tempArgs) - uses list of valid parametere accepted by template (from data subpage) params.validList = - invalid parameters are retaining in tempArgsfunction p.validateParams(tempArgs)

local validParamsList = paramData.validList[info.auto] if type(validParamsList)

'table' then -- if checklist for valid parameters for k,v in pairs(validParamsList) do if tempArgs[v] then -- v contains the name of valid parameter key templateArgs[v] = tempArgs[v] tempArgs[v] = nil -- delete so only invalid arguments left in tempArgs end -- TODO use these for tracking categories (partially done) end tempArgs['auto'] = nil -- this if not on tracking list but used internally if #tempArgs then -- table not empty -- if next(tempArgs) ~= nil then templateArgs['debug'] = mw.dumpObject(tempArgs) info.parameterCategory = info.parameterCategory .. "" end

else -- checklist for valid parameters not available for this option for k,v in pairs(tempArgs) do templateArgs[k] = v end end --DISABLE the parameter checking is currently being call from the template (this is temporary) -- this function checks for bad combinations (e.g. genus without species) --info.parameterCategory = p._checkParameters(frame)end

-------------------------------------- CATEGORY FUNCTIONS ---------------------------------- function for external invokefunction p.checkParameters(frame) p.getArgs(frame) -- populates templateArgs[] with parameters, after alias checking and validation of supported parameters -- then calls p._checkParameters for addition parameter checking return info.parameterCategory -- return tracking categoriesend-- function that checks for extraneous parametersfunction p._checkParameters(tempArgs) local categoryString = "" -- (1) check for speciesbox with taxon and (genus or species) if info.auto

"speciesbox" then if templateArgs['taxon'] and (templateArgs['genus'] or templateArgs['species']) then categoryString = categoryString .. "" end end -- (2) check for manual taxobox parameters for k,v in pairs(paramData.taxonRanks) do --run through manual taxobox parameter list if v

'genus' then break end -- don't check at genus and below if tempArgs[v] then -- use tempArgs as these won't have been validated (produces redundant category?) categoryString = categoryString .. "" end end local orphan = false local dependentParams = for k,v in pairs(dependentParams) do if templateArgs[k] and not templateArgs[v] then orphan = true end --templateArgs[k] = nil -- delete orphaned variable end if orphan then categoryString = categoryString .. "" end -- paraphyletic groups using manual taxonomy --categoryString = categoryString .. "" if mw.getCurrentFrame:getParent:getTitle

"Template:Paraphyletic group" then if info.auto ~= "yes" and info.auto ~= "virus" then categoryString = categoryString .. "" end --categoryString = categoryString .. ""

end -- add to category list info.parameterCategory = info.parameterCategory .. categoryString --return categoryStringend

return p