require('strict')
local p = local data = local templateArgs = -- contains arguments passed to cite weblocal target = -- short cut to target table, e.g. fishbase, cof, etc
local function firstToUpper(str) return (str:gsub("^%l", string.upper))end-- define citation template and custom parameters for various sources
--####################### Default functions ##########################data.default = -- currently being tested on Avibase, but Fossilworks, Tropicos, FNA and a few others are candidatesdata.default.id = function (id, source) local title = id local url = source.customArgs['baseURL'] .. (source.customArgs['searchStr'] or "") .. id return title, urlenddata.default.error = function return "Minimal requirement is two of id, url and title parameters"enddata.default.search = function (search, source) local title = "Search for " .. search local url = source.customArgs['baseURL'] .. source.customArgs['searchString'] .. search .. source.customArgs['searchSuffix'] return title, urlend
--handling for ID only (unused, original concept) p.genericIdCitation = function(frame, title, url)
if not templateArgs['id'] then return "no id parameter detected" end templateArgs['url']= target.CustomArgs['baseURL'] .. target.CustomArgs['searchStr'] .. templateArgs['id'] return p.citeWeb(frame, title, url)end
--####################### FISH #####################################--local title = genus .. " " .. species local url = data.fishbase.customArgs['baseURL'] .. "summary/SpeciesSummary.php?genusname=" .. genus .. "&speciesname=" .. species if subspecies then url = url .. "+" .. subspecies title = title .. " " .. subspecies end title = "" .. title .. "" return title, urlenddata.fishbase.genus = function(genus) local title = "Species in genus " .. firstToUpper(genus) .. "" local url = data.fishbase.customArgs['baseURL'] .. "identification/SpeciesList.php?genus=" .. genus return title, urlenddata.fishbase.order = function(order) local title = "Order " .. firstToUpper(order) local url = data.fishbase.customArgs['baseURL'] .. "Summary/OrdersSummary.php?order=" .. order return title, urlenddata.fishbase.family = function(family) local title = "Family " .. firstToUpper(family) local url = data.fishbase.customArgs['baseURL'] .. "Summary/FamilySummary.php?family=" .. family return title, urlenddata.fishbase.error = function return "No recognised taxon options: order, family, genus, species, subspecies."enddata.fishbase.custom = function --TODO decide what to do with default date local version = "April 2006 version" -- Should we have a default (probably not) if templateArgs['month'] then version = templateArgs['month'] end if templateArgs['year'] then version = templateArgs['year'] .. " version" end if templateArgs['month'] then version = templateArgs['month'] .. " " .. version end templateArgs['version'] = versionend--
= data.fotw5 = "Cite book", citationArgs =, customArgs =, GoogleBooks = . data.fotw5.default2 = function(targs) local title = data.fotw5.citationArgs['work'] local url = data.fotw5.customArgs['baseURL'] local chapterParams = --return title, url, chapterParamsend
data.BentonVP4 = "Cite book", citationArgs =, customArgs =, GoogleBooks = .
--
TODO FishWisePro
data.fishwisepro =
-- #################### AMPHIBIA and REPTILES ###############################--
data.ASW6.species = function(genus, species, subspecies)
-- search for genus+species local title = "Search for taxon: " .. "" .. genus .. " " .. species .. "" --local search = ""?action=names&taxon="" -- old version (pre ASW6) --local search = "amphib/basic_search?basic_query=" -- basic search local search = "content/search?taxon=" -- guided search for taxon name local url = data.ASW6.customArgs['baseURL'] .. search -- .. genus .. '+AND+' .. species .. '"' .. genus .. '+' .. species .. '"' return title, urlenddata.ASW6.genus = function(genus) return data.ASW6.taxon(genus) -- use genus as alias of taxonenddata.ASW6.taxon = function(taxon) local title = "Search for Taxon: " .. taxon local url= data.ASW6.customArgs['baseURL'] .. "content/search?taxon=" .. taxon return title, urlenddata.ASW6.family = function(family) local order = data.ASW6.checkOrder(family) local url= data.ASW6.customArgs['baseURL'] .. "Amphibia/" .. order .. "/" .. firstToUpper(family) local title = firstToUpper(family) return title, urlenddata.ASW6.checkOrder = function(family)
local gymnophiona= local caudata = for k,v in pairs(caudata) do if v
family then return "Gymnophiona" end end return "Anura"end
--
--
data.reptileDB.species = function(genus, species) local title = "" .. genus .. " " .. species .. "" --http://reptile-database.reptarium.cz/species?genus=Loxocemus&species=bicolor local url = data.reptileDB.customArgs['baseURL'] .. "species?genus=" .. genus .. "&species=" .. species return title, urlenddata.reptileDB.genus = function(genus) local title = "" .. genus .. "" --http://reptile-database.reptarium.cz/advanced_search?genus=Malayopython&submit=Search local url = data.reptileDB.customArgs['baseURL'] .. "advanced_search?genus=" .. genus .. "&exact%5B0%5D=taxon&submit=search" return title, urlenddata.reptileDB.family = function(family) return data.reptileDB.taxon(family)enddata.reptileDB.order = function(order) return data.reptileDB.taxon(order)enddata.reptileDB.taxon = function(taxon) local title = taxon --http://reptile-database.reptarium.cz/advanced_search?taxon=Viperidae&exact%5B0%5D=taxon&submit=Search local url = data.reptileDB.customArgs['baseURL'] .. "advanced_search?taxon=" .. taxon .. "&exact%5B0%5D=taxon&submit=search" return title, urlend
--################################### BIRDS ########################################--
Handbook of the Birds of the World Alive (HBW Alive)
--data.IOC = data.IOC.version = function local version = templateArgs['version'] local old = false if version then version = string.gsub(version, "[Vv]ersion ", "") local versionNumber = tonumber(version) if versionNumber < 10.1 then old = true end else local Date = require('Module:Date')._Date if Date(templateArgs['access-date']) < Date('1 January 2020') then old = true end end if old then data.IOC.citationArgs['editor3-last'] = nil data.IOC.citationArgs['editor3-first'] = nil endenddata.IOC.order = function(order) data.IOC.version local IOCorders = -- passeriformes link not very useful
local title = "Order " .. firstToUpper(order) local url = data.IOC.customArgs['baseURL'] .. "/bow/" .. IOCorders[order] return title, url enddata.IOC.family = function(family) data.IOC.version local IOCfamilies = -- temporary partial list for testing local title = "Family " .. firstToUpper(family) --https://www.worldbirdnames.org/Family/Struthionidae local url = data.IOC.customArgs['baseURL'] .. "Family/" .. family -- old version (might be resurrected by IOC) -- https://www.worldbirdnames.org/new/bow/babblers/#1338626516R24989 if IOCfamilies[family] then -- test version local partial list url = data.IOC.customArgs['baseURL'] .. "new/bow/" .. IOCfamilies[family][1] .. "/#1338626516R" .. IOCfamilies[family][2] end return title, urlend data.IOC.default = function(title, url) data.IOC.version return title, urlend
data.BOW = -- function not needed of not adding anything elsedata.BOW.default2 = function(title, url) --data.BOW.citationArgs['version'] = "Version 1" mw.addWarning("testing BOW.default function") return title, urlend-- id works with the default function data.default.id (id, source)data.BOW.id2 = function(id) local url = data.IOC.customArgs['baseURL'] ..id local title = "BOW id=" .. id end
--BOW|citation=CITATION}} vesrion 1 (family): Winkler, D. W., S. M. Billerman, and I.J. Lovette (2020). Bulbuls (Pycnonotidae), version 1.0. In Birds of the World (S. M. Billerman, B. K. Keeney, P. G. Rodewald, and T. S. Schulenberg, Editors). Cornell Lab of Ornithology, Ithaca, NY, USA. https://doi.org/10.2173/bow.pycnon4.01 version 2 (species): Limparungpatthanakij, W. L., L. Fishpool, and J. Tobias (2020). Buff-vented Bulbul (Iole crypta), version 2.0. In Birds of the World (S. M. Billerman and B. K. Keeney, Editors). Cornell Lab of Ornithology, Ithaca, NY, USA. https://doi.org/10.2173/bow.buvbul1.02data.BOW.citation = function(value) local citation = templateArgs['citation']
data.BOW.citationArgs['year'] = citation:match ('^%D+(%d%d%d%d)') data.BOW.citationArgs['doi'] = citation:match ('10%.2173/bow%..+') -- https://doi.org/10.2173/bow.pycnon4.01 --data.BOW.citationArgs['version'] = citation:match ('version %d%.%d') -- version applies to page, not whole BOW local title = citation:match ('%d%d%d%d%)%.(.*, version %d%.%d)'); -- include version number in title local suffix = citation:match ('10%.2173/bow%.(.+%d)%.'); -- https://doi.org/10.2173/bow.pycnon4.01 local version = "/cur/" -- for the current version version = citation:match ('version (%d%.%d)') -- for the cited version local url = data.BOW.customArgs['baseURL'] .. suffix .. '/' .. version .. '/' title = title:gsub('%((%D+) (%D+)%)', "(%1 %2)") local authors = citation:match ('^(%D+) %(%d%d%d%d%)') if authors then -- split authors with modified code from make cite iucn local list = mw.addWarning ("author string: " .. authors) authors = authors:gsub(", Jr.", "XYZJrX") -- protect author name from splitting on comma authors = authors:gsub(", and ", ", ") -- for 3 or more authors authors = authors:gsub(" and ", ", ") -- for 2 editors list = mw.text.split (authors, ','); -- split the string on the commas into entries in list if #list
1 then --note the first name has last name followed by initials after comma, so takes fill first two parts of the split data.BOW.citationArgs['last1'] = name elseif i
2 then mw.addWarning ("last" .. tostring(i-1) .. "=" .. data.BOW.citationArgs['last'..i-1]) mw.addWarning ("first".. tostring(i-1) .. "=" .. data.BOW.citationArgs['first'..i-1]) end end for i, name in ipairs (list) do -- for each author in list if data.BOW.citationArgs['last'..i] then mw.addWarning ("check " .. i .. "=" .. data.BOW.citationArgs['last'..i]) data.BOW.citationArgs['last'..i] =string.gsub(data.BOW.citationArgs['last'..i], "XYZJrX", ", Jr.") -- restored protected string end end end end -- now parse editors local editors = citation:match ('In Birds of the World %((.-), Editors?%)') -- omit editors as cite web psoitioning is weird if editors then -- split editors with modified code from make cite iucn local list = --mw.addWarning ("editor string: " .. editors) editors = editors:gsub(", and ", ", ") -- for 3 or more authors editors = editors:gsub(" and ", ", ") -- for 2 editors list = mw.text.split (editors, ','); -- split the string on the commas into entries in list if #list
2 then mw.addWarning ("editor-last" .. tostring(i) .. "=" .. data.BOW.citationArgs['editor-last'..i]) mw.addWarning ("editor-first".. tostring(i) .. "=" .. data.BOW.citationArgs['editor-first'..i]) end end end end
--if not url then url = data.BOW.customArgs['baseURL'] end --if not title then title = "Title parameter required" end return title, urlend
-- basic handling for Taxonomy in Flux websitedata.tif = --data.avibase = --
--
--
data.asm.species2 = function(genus, species) -- use species function below -- old url = https://mammaldiversity.org/species-account.php?genus=ursus&species=arctos -- new url = https://www.mammaldiversity.org/explore.html#genus=Dipodomys&species=deserti&id=1001892 (only id required) local title = "" .. genus .. " " .. species .. "" local url = data.asm.customArgs['baseURL'] .. "explore.html#genus=" .. genus .. "&species=" .. species if templateArgs['id'] then url = url .. "&id=" .. templateArgs['id'] end return title, urlend data.asm.id = function(id) --local url = data.asm.customArgs['baseURL'] .. "species-account/species-id=" .. templateArgs['id'] -- new format https://www.mammaldiversity.org/explore.html#species-id=1006310 --local url = data.asm.customArgs['baseURL'] .. "explore.html#species-id=" .. id -- templateArgs['id'] -- newer format https://www.mammaldiversity.org/explore.html#genus=Leopardus&species=colocola&id=1005993 (genus and species can be blank) -- newer (Mar 2024) https://www.mammaldiversity.org/taxon/1006020 local title = "Species-id=" .. id local hashString = "genus=&species=&id=" .. id -- if id only, requires blank genus and species (superceded by /taxon/link) if templateArgs['genus'] and templateArgs['species'] then title = "" .. templateArgs['genus'] .. " " .. templateArgs['species'] .. " (id=" .. id ..")" hashString = "genus=" .. templateArgs['genus'] .. "&species=" .. templateArgs['species'] .. "&id=" .. id end --local url = data.asm.customArgs['baseURL'] .. "explore.html#genus=&species=&id=" .. id -- templateArgs['id'] -- url = data.asm.customArgs['baseURL'] .. "explore.html#" .. hashString local url = data.asm.customArgs['baseURL'] .. "taxon/" .. id
return title, urlenddata.asm.species = function(genus, species) if templateArgs['id'] then return data.asm.id(templateArgs['id']) -- use the ASM explore page if ID given (as permalink) end if genus and species then -- otherwisee use the treeview page with the species info local title = "" .. firstToUpper(genus) .. " " .. species .. "" local url = data.asm.customArgs['baseURL'] .. "tree.html#genus=" .. genus .. "&species=" .. species return title, url end end
data.asm.genus = function(genus) return data.asm.taxon(genus, "genus", "TITLE_ITALICS") enddata.asm.family = function(family) return data.asm.taxon(family, "family") enddata.asm.order = function(order) return data.asm.taxon(order, "order") enddata.asm.taxon = function(taxon, rank, titleItalics) --https://mammaldiversity.org/#ZmVsaWRhZSZnbG9iYWxfc2VhcmNoPXRydWUmbG9vc2U9dHJ1ZQ -- Base64.encode(felidae&global_search=true&loose=true) local title = firstToUpper(taxon) if titleItalics then title = "" .. title .. "" end local url = data.asm.customArgs['baseURL'] .. "tree.html" if rank then -- no rank if taxon called directly url = url .. "#" .. rank .. "=" .. taxon end return title, urlend --############################## Base64 encode and decode (used for ASM#####################local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'-- encodingdata.asm.Base64 = data.asm.Base64.encode = function(data) return ((data:gsub('.', function(x) local r,b=,x:byte for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end return r; end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x) if (#x < 6) then return end local c=0 for i=1,6 do c=c+(x:sub(i,i)
'=') then return end local r,f=,(b:find(x)-1) for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end return r; end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x) if (#x ~= 8) then return end local c=0 for i=1,8 do c=c+(x:sub(i,i)
enddata.WoRMS.default = function if templateArgs['db'] then data.WoRMS.db (templateArgs['db']) endenddata.WoRMS.db = function(db) -- if database hosted by WoRMS
db = string.lower(db) if db
"copepoda" or db
"copepod" then templateArgs['author'] = "World of Copepods Database" templateArgs['editor-last1']="Walter"; templateArgs['editor-first1']="T.C." templateArgs['editor-last2']="Boxshall"; templateArgs['editor-first2']="G." -- year ? (2022). elseif db
"amphipoda" or db
"world isopoda database" or db
"isopod"then templateArgs['author'] = "World Marine, Freshwater and Terrestrial Isopod Crustaceans database" templateArgs['editor-last1']="Boyko"; templateArgs['editor-first1']="C.B." templateArgs['editor-last2']="Bruce"; templateArgs['editor-first2']="N.L." templateArgs['editor-last3']="Hadfield"; templateArgs['editor-first3']="K.A." templateArgs['editor-last4']="Merrin"; templateArgs['editor-first4']="K.L." templateArgs['editor-last5']="Ota."; templateArgs['editor-first5']="Y." templateArgs['editor-last6']="Poore"; templateArgs['editor-first6']="G.C.B." templateArgs['editor-last7']="Taiti"; templateArgs['editor-first7']="S." elseif db
"diplopoda" or db
"molluscabase" or db
"mollusc" then templateArgs['author'] = "MolluscaBase" else templateArgs['author'] = templateArgs['db'] -- this is recommended by WoRMS endend
--
data.speciesfile = data.speciesfile.id = function(id) -- e.g. https://plecoptera.speciesfile.org/otus/890815/overview local db = data.speciesfile.db -- customise for speciesfile local title = firstToUpper(db) .. " Species File id=" .. id -- use entity = for = to avoid missing pipe CS1 warning --local url = data.speciesfile.customArgs['baseURL'] .. data.speciesfile.customArgs['searchStr'] .. id .. data.speciesfile.customArgs['defaultSuffix '] local url = "https://" ..db .. ".speciesfile.org/otus/" .. id .. "/overview" return title, url enddata.speciesfile.default = function local db = data.speciesfile.db local title = firstToUpper(db) .. " Species File" local url = "https://" ..db .. ".speciesfile.org/" return title, url enddata.speciesfile.db = function local db = string.lower(templateArgs['db']) templateArgs['editor-last1']="Hopkins"; templateArgs['editor-first1']="H." if db
"dermaptera" then -- eds: Hopkins, H., Haas, F. & Deem, L.S. templateArgs['editor-last1']="Hopkins"; templateArgs['editor-first1']="H." templateArgs['editor-last2']="Johnson"; templateArgs['editor-first2']="K.P." templateArgs['editor-last3']="Smith"; templateArgs['editor-first3']="V.S." elseif db
"orthoptera " then --eds: Cigliano, M.M., H. Braun, D.C. Eades & D. Otte. templateArgs['editor-last1']="Cigliano"; templateArgs['editor-first1']="M.M." templateArgs['editor-last2']="Braun"; templateArgs['editor-first2']="H." templateArgs['editor-last3']="Eades"; templateArgs['editor-first3']="D.C." templateArgs['editor-last4']="Otte"; templateArgs['editor-first4']="D." elseif db
"mantophasmatodea" then -- ed: Hopkins, H. templateArgs['editor-last1']="Hopkins"; templateArgs['editor-first1']="H." elseif db
"phasmida" then -- eds: Brock PD, Büscher TH, Baker E. templateArgs['editor-last1']="Brock"; templateArgs['editor-first1']="P.D." templateArgs['editor-last2']="Büscher"; templateArgs['editor-first2']="T.H." templateArgs['editor-last3']="Baker"; templateArgs['editor-first3']="E." elseif db
"cockroach" then -- ed: Beccaloni, G.W. templateArgs['editor-last1']="Beccaloni"; templateArgs['editor-first1']="G.W." elseif db
"psocodea" then --eds: Hopkins, H., Johnson, K.P., & Smith, V.S. templateArgs['editor-last1']="Hopkins"; templateArgs['editor-first1']="H." templateArgs['editor-last2']="Johnson"; templateArgs['editor-first2']="K.P." templateArgs['editor-last3']="Smith"; templateArgs['editor-first3']="V.S." elseif db
"coleorrhyncha" then -- ed: Hopkins, H. templateArgs['editor-last1']="Hopkins"; templateArgs['editor-first1']="H." elseif db
"lygaeoidea" then -- eds: Dellapé, Pablo M. & Thomas J. Henry templateArgs['editor-last1']="Dellapé"; templateArgs['editor-first1']="Pablo M." templateArgs['editor-last2']="Henry"; templateArgs['editor-first2']="Thomas J." elseif db
"hoppers" then data.speciesfile.citationArgs['website'] = "World Auchenorrhyncha Database" else data.speciesfile.citationArgs['website'] = firstToUpper(db) .. data.speciesfile.citationArgs['website'] end return dbend
--Lepindex
data.lepindex = data.lepindex.id = function(id) -- https://www.nhm.ac.uk/our-science/data/lepindex/detail/?taxonno=51506
local title = "Lepindex id=" .. id local url = data.lepindex.customArgs['baseURL'] .. data.lepindex.customArgs['suffixStr'] .. id return title, url end
--Global Lepidoptra Indexdata.gli = data.gli.id = function(id) -- https://www.checklistbank.org/dataset/55434/taxon/233256 -- https://www.checklistbank.org/dataset/DATASET_ID/taxon/TAXON_ID -- the dataset ID will change with version so need version handling or just use URL
local title = "GLI id=" .. id local url = data.gli.customArgs['baseURL'] .. data.gli.customArgs['suffixStr'] .. id return title, url enddata.gli.default2 = function local title = "" local url = "" return title, url end
--
data.carabcat = data.carabcat.id = function(id)
local title = "CarabCat on ChecklistBank id=" .. id local url = data.carabcat.customArgs['baseURL'] .. data.carabcat.customArgs['searchStr'] .. id return title, url end
--
data.itis = data.itis.id = function(id)
local title = "ITIS id=" .. id local url = data.itis.customArgs['baseURL'] .. data.itis.customArgs['searchStr'] .. id return title, url end
--data.col = data.col.id = function(id) -- local title = "Catalogue of Life taxonKey " .. id local url = data.col.customArgs['baseURL'] -- some new CoL are numbers e.g. 64553 in https://www.catalogueoflife.org/data/taxon/64553 if not tonumber(id) and string.find(id, "^[0-9abcdef]+$") then -- if old-style id local year = "2019" -- last old-style version available if templateArgs['version'] and string.find(templateArgs['version'], "^%d%d%d%d$") then --if version specied year = templateArgs['version'] end if templateArgs['option']
"browse" then url = url .. "browse?taxonKey=" .. id else -- default to option=taxon url = url .. "taxon/" .. id end end
return title, url end--data.col.default = function(mode) -- this handles the old style template with positional parameters (mode unused?) local para1 = templateArgs[2] local para2 = templateArgs[3] local para3 = templateArgs[4] local para4 = templateArgs[5] if para1 then para1 = mw.text.trim(para1) end if para2 then para2 = mw.text.trim(para2) end if para3 then para3 = mw.text.trim(para3) end if para4 then para4 = mw.text.trim(para4) end local title, url if para1 then --local match = "7539827da517bd6273a4a3836578cb24" local match = "^[0-9abcdef]+$" if string.find(para1, match) then url = "http://www.catalogueoflife.org/col/details/species/id/" .. para1 -- ""Old style id" --url ="https://www.catalogueoflife.org/data/search?q=" .. para1 if para2 then title = para2 else title = "Oldstyle id: " .. para1 end else
--https://www.catalogueoflife.org/data/search?q=" Chinchilla+chinchilla&type=EXACT if para1 ~= "" then url = "https://www.catalogueoflife.org/data/search?q=" .. para1 title = "" .. para1 if para2 then url = url .. "+" .. para2 title = title .. " " .. para2 end url = url .. "&type=EXACT" title = title .. "" end end if para3 then title = title .. " " .. para3 end -- add authority if para4
--
data.fossilworks = data.fossilworks.id = function(id)--http://fossilworks.org/cgi-bin/bridge.pl?a=taxonInfo&taxon_no=83087 if not templateArgs['id'] then return "no id parameter detected" end local searchStr = "bridge.pl?a=taxonInfo&taxon_no=" .. templateArgs['id'] templateArgs['url']= target.CustomArgs['baseURL'] .. searchStr local title = "PaleoDB taxon number: " .. id local url = data.fossilworks.customArgs['baseURL'] .. data.fossilworks.customArgs['searchStr'] .. id return title, url enddata.fossilworks.collection = function(collection) -- http://fossilworks.org/bridge.pl?a=collectionSearch&collection_no=20072 local title = "PaleoDB collection number: " .. collection local url = data.fossilworks.customArgs['baseURL'] .. "bridge.pl?a=collectionSearch&collection_no=" .. collection return title, url enddata.fossilworks.error = function return "Requires id and title parameters"end
--
data.paleobiodb = data.paleobiodb.id = function(id)-- local title = "PaleoDB taxon number: " .. id local url = data.paleobiodb.customArgs['baseURL'] .. data.paleobiodb.customArgs['searchStr'] .. id return title, url enddata.paleobiodb.collection = function(collection) -- https://paleobiodb.org/classic/basicCollectionSearch?collection_no=24193 local title = "PaleoDB collection number: " .. collection local url = data.paleobiodb.customArgs['baseURL'] .. "basicCollectionSearch?collection_no=" .. collection return title, url enddata.paleobiodb.error = function return "Requires id and title parameters"end--
--data.worldplants = data.worldplants.genus = function(genus) local title = addAuthority("" .. genus .. "") local genusString = genus if templateArgs['authority'] then genusString = genus .. "-" .. templateArgs['authority'] end local url = data.worldplants.customArgs['baseURL'] .. "?deeplink=" .. genusString return title, url enddata.worldplants.species = function(genus, species) local title = addAuthority("" .. genus .. " " .. species .. "") local url = data.worldplants.customArgs['baseURL'] .. "?deeplink=" .. genus .. "-" .. species .. " " .. (templateArgs['authority'] or "") return title, url end--experimental, don't leave live
data.worldplants.taxon = function(taxon) local title = taxon .. " " .. (templateArgs['authority'] or "") local url = data.worldplants.customArgs['baseURL'] .. "?deeplink=" .. taxon return title, url end
data.worldplants.family = function(family) local title = family .. " " .. (templateArgs['authority'] or "") local url = data.worldplants.customArgs['baseURL'] .. "?deeplink=" .. family return title, url end--
data.worldferns = data.worldferns.genus = function(genus) local title = addAuthority("" .. genus .. "") local genusString = genus if templateArgs['authority'] then genusString = genus .. "-" .. templateArgs['authority'] end local url = data.worldferns.customArgs['baseURL'] .. data.worldferns.customArgs['searchStr'] .. genusString return title, url enddata.worldferns.species = function(genus, species) local title = addAuthority("" .. genus .. " " .. species .. "") local url = data.worldferns.customArgs['baseURL'] .. data.worldferns.customArgs['searchStr'] .. genus .. "-" .. species .. " " .. (templateArgs['authority'] or "") return title, url end--data.POWO = --http://powo.science.kew.org/taxon/urn:lsid:ipni.org:names:30003057-2 data.POWO.id = function(id) local id = data.POWO.getValidID if not id then return data.POWO.error end local title = id -- as default value local url = data.POWO.customArgs['baseURL'] .. data.POWO.customArgs['searchStr'] .. id return title, url enddata.POWO.family = function(family) local title = addAuthority(family) local id = templateArgs['id'] if not id then return data.POWO.error end local url = data.POWO.customArgs['baseURL'] .. data.POWO.customArgs['searchStr'] .. id return title, url enddata.POWO.genus = function(genus) local title = addAuthority("" .. genus .. "") local id = data.POWO.getValidID if not id then return data.POWO.error end local url = data.POWO.customArgs['baseURL'] .. data.POWO.customArgs['searchStr'] .. id return title, url enddata.POWO.species = function(genus,species) local title = addAuthority("" .. genus .. " " .. species .. "") local id = data.POWO.getValidID if not id then return data.POWO.error end local url = data.POWO.customArgs['baseURL'] .. data.POWO.customArgs['searchStr'] ..id return title, url enddata.POWO.getValidID = function local id = templateArgs['id'] if id then return string.gsub(id, "urn:lsid:ipni.org:names:", "") -- don't want this twice end return nilenddata.POWO.error = function return '
Requires id and one of title, family, genus or species parameters'end--
data.bromeliad = --data.bromeliad.search = function(search)
local title = search -- as default value local url = data.bromeliad.customArgs['baseURL'] .. data.bromeliad.customArgs['searchStr'] .. search return title, url end--http://bromeliad.nl/species/Bromeliaceae data.bromeliad.taxon = function(taxon)
local title = addAuthority(taxon) -- as default value local url = data.bromeliad.customArgs['baseURL'] .. "species/" .. taxon return title, url end--genus data.bromeliad.genus = function(genus)
local title = addAuthority("" .. genus .. "") -- as default value local url = data.bromeliad.customArgs['baseURL'] .. "species/" .. genus if templateArgs['list']
local title = addAuthority("" .. genus .. " " .. species .. "") -- as default value local url = data.bromeliad.customArgs['baseURL'] .. "species/" .. genus .. "/" .. species return title, url end
--data.bromeliad.id = function(id)
local title = id -- as default value local url = data.bromeliad.customArgs['baseURL'] .. "encyclopedia/brome.php?action=showTaxon&id=" .. id return title, url end
--data.GRIN = data.GRIN.id = function(id) local title = data.GRIN.customArgs['defaultTitle'] .. ' ' .. id local url = data.GRIN.customArgs['baseURL'] .. data.GRIN.customArgs['searchStr'] .. id return title, url end
-- IPNI--→ "Meconopsis Vig." International Plant Names Index (IPNI). Royal Botanic Gardens, Kew.--- https://www.ipni.org/n/30149252-2--- as
data.IPNI = data.IPNI.id = function(id) local title = id local url = data.IPNI.customArgs['baseURL'] .. data.IPNI.customArgs['searchStr'] .. id return title, url enddata.IPNI.species = function(genus, species) return data.IPNI.taxon(genus .. " " .. species, "TITLE_ITALICS") enddata.IPNI.genus = function(genus) return data.IPNI.taxon(genus, "TITLE_ITALICS") enddata.IPNI.taxon = function(taxon, italics) local title = taxon if italics then title = "" .. title .. "" end title = addAuthority(title)--if templateArgs['authority'] then title = title .. " " .. templateArgs['authority'] title = string.gsub(title, "(.*%.)$", "((%1))") -- if authority ends in "." enclose ((title)) to prevent removal end local url = data.IPNI.customArgs['baseURL'] .. data.IPNI.customArgs['searchStr'] .. templateArgs['id'] return title, url end
--
data.WFO = data.WFO.id = function(id)--http://www.worldfloraonline.org/taxon/wfo-4000012284 local title = id local url = data.WFO.customArgs['baseURL'] .. data.WFO.customArgs['searchStr'] .. id return title, url enddata.WFO.family = function(family) local title = addAuthority(family) local url = data.WFO.customArgs['baseURL'] .. data.WFO.customArgs['searchStr'] .. templateArgs['id'] return title, url enddata.WFO.genus = function(genus) local title = addAuthority("" .. genus .. "") local url = data.WFO.customArgs['baseURL'] .. data.WFO.customArgs['searchStr'] .. templateArgs['id'] return title, url enddata.WFO.species = function(genus,species) local title = addAuthority("" .. genus .. " " .. species .. "") local url = data.WFO.customArgs['baseURL'] .. data.WFO.customArgs['searchStr'] .. templateArgs['id'] return title, url enddata.WFO.error = function return "Requires id and title parameters"end
data.Tropicos = data.Tropicos.id = function(id)-- local title = id local url = data.Tropicos.customArgs['baseURL'] .. data.Tropicos.customArgs['searchStr'] .. id return title, url enddata.Tropicos.error = function return "Requires id and title parameters"end
data.FNA = data.FNA.id = function(id)--http://www.efloras.org/florataxon.aspx?flora_id=1&taxon_id=125683 local title = id local url = data.FNA.customArgs['baseURL'] .. data.FNA.customArgs['searchStr'] .. id return title, url enddata.FNA.error = function return "Requires id and title parameters"end-- ATRP: Australian Tropical Rainforest Plants
data.ATRP = data.ATRP.species = function(genus,species)-- local title = addAuthority("" .. genus .. " " .. species .. "") --"" .. genus .. " " .. species .. "" local url = data.ATRP.customArgs['baseURL'] .. data.ATRP.customArgs['searchStr'] .. genus .. "_" .. species .. data.ATRP.customArgs['defaultSuffix'] return title, url enddata.ATRP.error = function return "Requires genus and species parameters"end
--
"GENUS" or rank
--data.AlgaeBase = data.AlgaeBase.id = function(id)-- local title = id local url = data.AlgaeBase.customArgs['baseURL'] .. data.AlgaeBase.customArgs['searchStr'] .. id return title, url enddata.AlgaeBase.genid = function(genid)-- local title = genid local url = data.AlgaeBase.customArgs['baseURL'] .. "search/genus/detail/?genus_id=" .. genid return title, url enddata.AlgaeBase.spid = function(spid)-- local title = spid local url = data.AlgaeBase.customArgs['baseURL'] .. "search/species/detail/?species_id=" .. spid return title, url enddata.AlgaeBase.error = function return "Requires id and title parameters"end
--
data.ictv.error = function return "Requires id and title parameters"end--############################## General Functions ########################################
local function getArgs (frame, args) local parents = mw.getCurrentFrame:getParent for k,v in pairs(parents.args) do --check content if v and v ~= "" then args[k]=v --parents.args[k] end end for k,v in pairs(frame.args) do --check content if v and v ~= "" then args[k]=v end endendlocal function initialise(frame, sourceDB) target=sourceDB templateArgs = sourceDB.citationArgs -- get custom arguments for target (fishbase, cof etc getArgs(frame, templateArgs) -- get template arguments from parent frame and frane local url = (target.customArgs['baseURL'] or "") .. (target.customArgs['defaultSuffix'] or "") local title = target.customArgs['defaultTitle'] or "" return title, urlend -- moved up top for scopelocal function firstToUpper2(str) return (str:gsub("^%l", string.upper))end-- clear template arguments that won't be recognised by Web site: local function clearCustomArgs local excludeTable = -- add defaults ? if target.customArgs['exclude'] then local customTable = mw.text.split (target.customArgs['exclude'], "%s*,%s*"); for k,v in pairs(customTable) do table.insert (excludeTable, v) end end for k,v in pairs(excludeTable) do if tonumber (v) then v = tonumber (v) --convert positional parameters (numbers as string) to a number end templateArgs[v]=nil --clear content endend
-- function handling the cite web templatep.citeWeb = function(frame, title, url) -- set url and title if not provided (template parameters override above) if not templateArgs['url'] and url then templateArgs['url']= url end if not templateArgs['title'] and title then templateArgs['title'] = title end
clearCustomArgs--blank template parameters not for cite web local citeTemplate = 'cite web' -- use Template:Cite web unless specified --if target.citeTemplate then citeTemplate = target.citeTemplate end return frame:expandTemplate
end-- p.CiteBook-- for reasons of consisitency within BioRef/FishRef the title parameter is the section-title of Book: p.citeBook = function(frame, title, url, chapterParams) -- very much a msw3 function --if (1
-- if the chapter/section is linked, we can link the main book chapter differently if target.customArgs['altTitle'] then -- if we are using a chapter/section, we can wikilink the book title templateArgs['title'] = target.customArgs['altTitle'] -- alternative to allow wikilink elseif target.customArgs['altURL'] then templateArgs['url'] = target.customArgs['altURL'] end
end -- end if using supplied title for chapter/section
clearCustomArgs--blank template parameters not for cite web local citeTemplate = 'cite book' -- use Template:Cite web unless specified --if target.citeTemplate then citeTemplate = target.citeTemplate end return frame:expandTemplate
end
-- common function for genus and specieslocal function getGenusSpecies --TODO standardise genus species handling local genus, species, subspecies if (templateArgs['genus'] or templateArgs[2]) then genus = templateArgs['genus'] or templateArgs[2] genus = firstToUpper(mw.text.trim(genus)) end if (templateArgs['species'] or templateArgs[3]) then species = templateArgs['species'] or templateArgs[3] species = mw.text.trim(species) end if (templateArgs['subspecies'] or templateArgs[4]) then subspecies = templateArgs['subspecies'] or templateArgs[4] subspecies = mw.text.trim(subspecies) end return genus, species, subspeciesend
--#################### MSW3 -- uses cite bookp.MSW3 = function(frame) local msw = require('Module:FishRef/MSW') initialise(frame, msw.MSW3) return msw.MSW3.main(frame,templateArgs)endp.MSW3merged = function(frame) local data = require('Module:FishRef/MSW') return p._main(frame, data.MSW3)endp.MSW3_standalone = function(frame) local data = require('Module:FishRef/MSW') initialise(frame, data.MSW3) local url = target.CustomArgs['baseURL'] if templateArgs['title'] and templateArgs['id'] then templateArgs['chapter-url']= url .. target.CustomArgs['searchStr'] .. templateArgs['id'] templateArgs['chapter'] = templateArgs['title'] templateArgs['title'] = target.CustomArgs['bookTitle'] if templateArgs['page'] then templateArgs['url'] = target.CustomArgs['googleBooksURL'] .. templateArgs['page'] else --return "Page number for google books required" end elseif templateArgs['order'] then templateArgs['chapter'] = "Order " .. templateArgs['order'] local chapter = target.chapters[templateArgs['order']] for k,v in pairs(chapter) do -- add chapter specific parameters templateArgs[k] = v end templateArgs['chapter-url']= url .. target.CustomArgs['searchStr'] .. templateArgs['id'] templateArgs['url']= target.CustomArgs['googleBooksURL'] .. templateArgs['page'] if templateArgs['pages'] and templateArgs['page'] then templateArgs['page'] = nil end else -- default output templateArgs['url']= target.CustomArgs['googleBooksURL'] .. "1" -- default to book templateArgs['url']= url end -- using cite book clearCustomArgs--blank template parameters not for cite web return frame:expandTemplateend
--########################### Functions for access (using invoke) ##############################################
--
=p.fishbase = function(frame) return p._main(frame, data.fishbase) endp.cof = function(frame) return p._main(frame, data.cof) end p.fotw5 = function(frame) return p._main(frame, data.fotw5) end --
= Birdsp.HBWa = function(frame) return p._main(frame, data.HBWalive) endp.HBWalive = function(frame) return p._main(frame, data.HBWalive) endp.IOC = function(frame) return p._main(frame, data.IOC) endp.BOW = function(frame) return p._main(frame, data.BOW) end--
= Otherp.fossilworks = function(frame) return p._main(frame, data.fossilworks) endp.worms = function(frame) return p._main(frame, data.WoRMS) endp.WoRMS = function(frame) return p._main(frame, data.WoRMS) endp.col = function(frame) return p._main(frame, data.col) end --fallback = function return "hello" end--#########################################################p.main = function(frame) local source = mw.text.trim(frame.args[1]) --TODO force to lower case and use lower case for all functions above if source
"ref" or source
"Reference" then return p.Reference(frame) end if source
"powo" then source = "POWO" end -- aliases if source
"mdd" then source = "asm" end -- aliases --return p[source]['test'] if source
"cof" or source
"Fotw5" or source
"amphibiaweb" or source
"ASW6" or source
"HBWalive" or source
"fossilworks" or source
"worms" or source
"powo" or source
"wfo" or source
--TODO in modular version source will be provided in frame arguments --local source = mw.getCurrentFrame:getParent.args[1] local chapterParams = -- used for cite book (only MSW3 at moment) if not source then return "Error: unrecognised source." end local title, url = initialise(frame, source) --taxon related parameters local genus, species, subspecies if source.db ~= "col" then -- col legacy uses positional parameters differently genus, species, subspecies = getGenusSpecies end local family = templateArgs['family'] local order = templateArgs['order'] local taxon = templateArgs['taxon'] local id = templateArgs['id'] --id related parameters local spid = templateArgs['spid'] or templateArgs['species_id'] local genid = templateArgs['genid'] or templateArgs['genus_id'] local citation = templateArgs['citation'] local collection = templateArgs['collection'] or templateArgs['collection_no'] local search = templateArgs['search'] local mode, value -- the functions if genus and species and source.species then title, url = source.species(genus,species,subspecies) else -- functions with just their own name as parameter if taxon then mode = "taxon"; value = taxon elseif order then mode = "order"; value = order elseif family then mode = "family"; value = family elseif genus then mode = "genus"; value = genus elseif id then mode = "id"; value = id elseif spid then mode = "spid"; value = spid elseif genid then mode = "genid"; value = genid elseif search then mode = "search"; value = search elseif citation then mode = "citation"; value = citation elseif collection then mode = "collection"; value = collection else -- no suitable parameter (use default page) if source.default then title, url, chapterParams = source.default(title, url) end end end if mode then if source[mode] then title, url, chapterParams = source[mode](value) elseif data.default[mode] then title, url, chapterParams = data.default[mode](value, source) else if source.error then return source.error end -- custom error message return "Error: parameter not supported for this source" .. " (" .. mode .. ")" end else -- if no mode then use the default title and url set by initialize end
if source.citeTemplate
p.Reference = function(frame) local refs = require('Module:FishRef/refs') getArgs(frame, templateArgs) if templateArgs[2] then local reference = mw.text.trim(templateArgs[2]) if reference ~= "" and refs[reference] then if templateArgs['pages'] then refs[reference] = refs[reference]:gsub("}}", "|pages="..templateArgs['pages'].."}}") refs[reference] = refs[reference]:gsub("|pages=[^|{}%[%]]*(|[^|{}}%[%]]*|pages=)", "%1") end if templateArgs['reftags']
'no' or templateArgs['raw'] then return refs[reference] else return frame:preprocess(refs[reference]) end else return 'Reference not found: "' .. templateArgs[2] .. '"' end end return "Reference parameter missing."end -- End the function.
-- All modules end by returning the variable containing its functions to Wikipedia.return p