require('strict')local p = ----Format validation functions --function p.botanistV(id) return mw.ustring.match(id,"^[%u%l%d%. '-]+$")end
-- NCDA: NOID Check Digit Algorithm; see local ncda -- leave this as a local since NCDA is commonly used among ARK identifiers and could be useful for validating other identifiers laterdo -- initialize these constants only once but scope them in a block so local namespace doesn't get cluttered with these local r29s = 0123456789bcdfghjkmnpqrstvwxz -- radix 29 "betanumeric" digit string local r29n = r29s:len local r29v2d, r29d2v =, for i = 1, r29n do local v, d = i-1, r29s:sub(i, i) r29v2d[v], r29d2v[d] = d, v end function ncda(sid) local n, sum = sid:len, 0 for i = 1, n do sum = sum + i * (r29d2v[sid:sub(i, i)] or 0) end return r29v2d[sum % r29n] endendfunction p.validateBNF(id) local FRBNF = id:sub(1, -2) return FRBNF:match('^%d%d%d%d%d%d%d%d$') ~= nil and ncda('cb'..FRBNF)
function p.validateIsni(id) --Validate ISNI (and ORCID) and returns it as a 16 characters string or returns false if it's invalid. See http://support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier id = id:gsub('[%-]', ):upper if not id:match('^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$') then return false end local total = 0 for i = 1, 15 do local digit = id:byte(i) - 48 --Get integer value total = (total + digit) * 2 end local remainder = total % 11 local result = (12 - remainder) % 11 local checkdigit if result
function p.orcidV(id) id = p.validateIsni(id) if not id then return false end return id:sub(1, 4)..'-'..id:sub(5, 8)..'-'..id:sub(9, 12)..'-'..id:sub(13, 16)end
function p.tlsV(id) id = id:gsub(' +', '_') local idlen = mw.ustring.len(id) if idlen < 4 or idlen > 90 then return false end local regex = '^%u'..string.rep("[%w_',%.%-%(%)%*%/–&]", idlen - 1)..'$' if not mw.ustring.match(id,regex) then return false end return idend
----Custom link functions --function p.ISILlink(id,label) if not id:match('^%D%D?%D?%D?%-.+$') then return false end for _,prefix in ipairs do if id:match('^'..prefix..'%-') then return '
' .. (label or 'ISIL') .. '' end end return 'ISIL\n**' .. id .. ''endfunction p.uscgLink(id) local id2 = id:match('^[1-7]%-%d%d?%d?%d?%d?$') or id:match('^[1-7]%-%d%d?%d?%d?%d?%.%d*[1-9]$') if id2 then return '
'..id2..'' else return false endendfunction p.ccg(id) id = id:match('^[NAIP]?[1-9]%d*$') or id:match('^[NAIP]?[1-9]%d*%.%d+$') if not id then return false end local link = 'https://www.notmar.gc.ca/' local prefix = string.sub(id, 1, 1) -- get first character of id local suffix = string.sub(id, 2) -- remove first character of id local interval = require('Module:Interval')._main local v if prefix
'1-2' then v = 1 elseif int
'3-4' then v = 144 elseif int
'5-6' then v = 121 elseif int
'7-8' then v = 211 elseif int
'9-10' then v = 26999 elseif int
'11-12' then v = 396 elseif int
'13-14' then v = 4717 elseif int
'A' then local int = interval if int
'2-3' then v = 1145 elseif int
'4-5' then v = 162 elseif int
'6-7' then v = 271 elseif int
'8-9' then v = 327 elseif int
'10-11' then v = 7048 elseif int
'12-13' then v = 942 elseif int
'14-15' then v = 11691 elseif int
'16-17' then v = 1773 elseif int
'18-19' then v = 2190 elseif int
'20-21' then v = 2389 end link = link .. 'publications/list-lights/atl/a' .. v .. '-en' elseif prefix
'1-2' then v = '01' elseif int
'3-4' then v = 4034 elseif int
'5-6' then v = 552 elseif int
'7-8' then v = 708 elseif int
'9-10' then v = 768 elseif int
'11-12' then v = 983 elseif int
'13-14' then v = 10596 elseif int
'15-16' then v = 1162 elseif int
'17-18' then v = 12333 elseif int
'19-20' then v = 1330 elseif int
'21-22' then v = 13778 elseif int
'23-24' then v = 1410 elseif int
'25-26' then v = 1445 elseif int
'27-28' then v = 1520 elseif int
'29-30' then v = 15406 elseif int
'31-32' then v = 15577 elseif int
'33-34' then v = 1562 elseif int
'35-36' then v = 16717 elseif int
'37-38' then v = 2545 end link = link .. 'publications/list-lights/inland-waters/i' .. v .. '-en' elseif prefix
[' .. link .. ' ' .. id .. ']'endreturn p