Module:Sandbox/Peter coxhead/Refgen explained

--

require('strict')local p = local l = -- separate out local functions

--Trim leading and trailing spaces, always returning a string. function l.trim(str) str = mw.text.trim(str) if str

nil then str = "" end return strend

--Ensure double .. is present if the mode is cs1 and the auth(ority) ends with . Deals with "bug" in citation templates. function p.authchk(frame) local auth = frame.args[1] or "" local mode = frame.args[2] or "cs1" return l.authchk(auth, mode)end

function l.authchk(auth, mode) if mode

"cs1" then if mw.ustring.sub(auth, -2)

".." then -- no action elseif mw.ustring.sub(auth, -1)

"." then auth = auth .. "." end elseif mode

"cs2" and mw.ustring.sub(auth, -2)

".." then auth = mw.ustring.sub(auth, 1, mw.ustring.len(auth)-1) end return authend

--Check arguments and generate a reference to the appropriate database given by "db". function l.refgen(db, frame) local taxon = frame.args[1] or "" if taxon

"" then return " ***ERROR: TAXON not supplied! " end taxon = mw.text.trim(taxon) local auth = frame.args[2] or "" auth = mw.text.trim(auth) local id = frame.args[3] or "" if id

"" then return " ***ERROR: ID not supplied! " end id = mw.text.trim(id) local mode = frame.args[4] or "cs1" mode = mw.text.trim(mode) auth = l.authchk(auth, mode) if db

"GCDsp" then return l.GCDsp(taxon, auth, id, mode) elseif db

"IPNI" then return l.IPNI(taxon, auth, id, mode) elseif db

"POWO" then return l.POWO(taxon, auth, id, mode) else return "***ERROR in l.refgen" endend

--Generate reference to the Global Compositae Database for a species. function p.GCDsp(frame) return l.refgen("GCDsp", frame)end

function l.GCDsp(taxon, auth, id, mode) --Example output: [1] local res = "[2] " return resend

--Generate reference to IPNI. function p.IPNI(frame) return l.refgen("IPNI", frame)end

function l.IPNI(taxon, auth, id, mode) --Example output: local res = "" return resend

--Generate reference to PoWO. function p.POWO(frame) return l.refgen("POWO", frame)end

function l.POWO(taxon, auth, id, mode) --Example output: [3] local res = "[4] " return resend

return p

Notes and References

  1. Teixeiranthus R.M.King & H.Rob... 1076597. 2023-05-17. cs1.
  2. " .. taxon .. " " .. auth res = res .. ". " .. id .. ". " .. os.date("%F") .. ". " .. mode .. ".
  3. Jacobaea lycopifolia (Desf. ex Poir.) Greuter & B.Nord.. 77086130-1. 2023-05-20.
  4. " .. taxon .. " " .. auth res = res .. ". " .. id .. ". " .. os.date("%F") .. ". " .. mode .. ".