Jump to content
Wikipedia The Free Encyclopedia

Module:Biota infobox/test

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Jts1882 (talk | contribs) at 07:55, 7 January 2023 (tidy up clearing of parameters (keep unhandled parameters e.g. parent authorities). The present address (URL) is a permanent link to this version.Revision as of 07:55, 7 January 2023 by Jts1882 (talk | contribs) (tidy up clearing of parameters (keep unhandled parameters e.g. parent authorities)
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Module documentation[create] [purge]
You might want to create a documentation page for this Scribunto module.
Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
 require('strict')
 localgetArgs=require('Module:Arguments').getArgs;

 localp={}-- exposed variables

 --local pargs = {} 
 localtemplate={}
 localargs={}

 -- parse the taxon list and get the taxon parameter and authority from the lowest rank (clear the parameters)
 functionp.get_taxon(frame,option)
 args['taxon']="taxon name"
 localranks=require('Module:Biota_infobox/data').taxonRanks;-- get the list of rank parameters used by manual taxoboxes

 -- interate throught the rank parameters, setting taxon to each in turn. 
 -- The lowest rank parameter should hold the taxon name for the taxoox 
 localrank
 fork,vinpairs(ranks)do
 ifargs[v]then-- if rank parameter
 rank=v
 args['taxon']=args[rank]:gsub("[%[%]%']","")-- strip wiki formatting and set taxon parameter 
 --args['rank'] = rank
 args['authority']=args[rank.."_authority"]or""-- set authority
 args[rank]=nil
 end
 end
 args[rank.."_authority"]=nil-- delete the authority of taxon (e.g. familia_authority for family) but keep parent taxon authorities if provided
 end

 -- remove the taxon parameters apart from genus and species
 functionp.clear_taxon_parameters(frame)
 localranks=require('Module:Biota_infobox/data').taxonRanks;-- get the list of rank parameters used by manual taxoboxes
 fork,vinpairs(ranks)do
 ifv~="genus"andv~="species"then
 args[v]=nil
 end
 end
 end

 -- add the parameter line with appropriate stripping of wikitext 
 functionp.addParam(param)

 ifargs[param]then
 localvalue=args[param]

 ifparam=='genus'then
 value=value:gsub("%'",""):gsub("%[",""):gsub("%]","")
 --value='Hypsiboas'
 elseifparam=='species'then
 --value = value:gsub("[%'%[%]]","")
 value=value:gsub("[%'%[]*[A-Za-z%.]* ([A-Za-z]*)[%]%']*","%1")
 --value='albopunctatus'
 elseifparam=='binomial_authority'then
 param='authority'
 args['binomial_authority']=nil
 args['binomial']=nil-- not needed
 end

 ifparam=='name'andargs['name']==args['taxon']then
 -- name parameter not need if same as taxon
 -- TODO not needed if page title either
 else
 table.insert(template,'| '..param..' = '..value);
 end
 args[param]=nil-- remove handled parameters
 end
 end

 functionp.convert(frame)
 --args = frame:getParent().args
 args=getArgs(frame);
 localmode="speciesbox"
 ifargs['genus']andargs['species']then
 table.insert(template,'{{Speciesbox ');
 p.clear_taxon_parameters(frame)
 else
 table.insert(template,'{{Automatic taxobox ');
 mode="auto"
 args['taxon']="test taxon"
 p.get_taxon(frame)
 end

 p.addParam('name')
 p.addParam('fossil range')
 p.addParam('status')
 p.addParam('status_system')
 p.addParam('status_ref')
 p.addParam('status2')
 p.addParam('status2_system')
 p.addParam('status2_ref')
 p.addParam('trend')
 p.addParam('image')
 p.addParam('image_upright')
 p.addParam('image_alt')
 p.addParam('image_caption')
 p.addParam('image2')
 p.addParam('image2_upright')
 p.addParam('image2_alt')
 p.addParam('image2_caption')
 p.addParam('classification_status')
 p.addParam('diversity')
 p.addParam('diversity_ref')
 p.addParam('diversity_link')
 p.addParam('extinct')

 p.addParam('taxon')
 p.addParam('authority')
 p.addParam('genus')
 p.addParam('species')
 p.addParam('binomial_authority')

 p.addParam('subdivision_ranks')
 p.addParam('subdivision')
 p.addParam('subdivision_ref')
 p.addParam('type_strain')
 p.addParam('type_strain_ref')
 p.addParam('range_map')
 p.addParam('range_map_upright')
 p.addParam('range_map_alt')
 p.addParam('range_map_caption')
 p.addParam('range_map2')
 p.addParam('range_map2_upright')
 p.addParam('range_map2_alt')
 p.addParam('range_map2_caption')
 p.addParam('range_map3')
 p.addParam('range_map3_upright')
 p.addParam('range_map3_alt')
 p.addParam('range_map3_caption')
 p.addParam('range_map4')
 p.addParam('range_map4_upright')
 p.addParam('range_map4_alt')
 p.addParam('range_map4_caption')
 p.addParam('synonyms_ref')
 p.addParam('synonyms')
 --p.addParam('')

 -- required parameters should have been set
 -- all others can be discarded
 localtesting=true
 fork,vinpairs(args)do
 iftesting==truethen
 ifk~="nosubst"then
 table.insert(template,table.concat({' | '..k..'=',v}));-- show any unhandled parameters
 end
 else
 ifk~="nosubst"then
 args[k]=nil-- discard unwanted parameters
 end
 end
 end

 table.insert(template,'}}');-- close the template

 --return '<pre>' .. table.concat (template, '\n') .. '</pre>';
 --return '\n<code><nowiki>{{Speciesbox' .. table.concat (template, '\n') .. '}}</nowiki></code>'

 localoutput=table.concat(template,'\n')
 ifargs['nosubst']=="yes"orargs['nosubst']=="code"then
 --return table.concat ({'<code>', frame:callParserFunction ('#tag:nowiki', output), '</code>'})
 returntable.concat({'<pre>',output,'</pre>'})
 elseifargs['nosubst']=="preview"then
 returnframe:preprocess(output);
 else
 returnoutput;
 end
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /