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)
-- parameters that can be set without a value, e.g. |extinct= if parents.args['extinct'] and parents.args['extinct']
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)
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
'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
end -- add to category list info.parameterCategory = info.parameterCategory .. categoryString --return categoryStringend
return p