Module:Authority control/auxiliary
Appearance
From Wikipedia, the free encyclopedia
Wikipedia authority control |
---|
Usage
This contains auxiliary functions used by Module:Authority control. They are accessed by using the valid and customlink parameters in Module:Authority control/config. Please refer to the documentation for that module.
The above documentation is transcluded from Module:Authority control/auxiliary/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
require('strict') localp={} --[[======================================================]] --[[ Format validation functions ]] --[[======================================================]] functionp.botanistV(id) returnmw.ustring.match(id,"^[%u%l%d%. '-]+$") end -- NCDA: NOID Check Digit Algorithm; see [[wikipedia:Check digit#NCDA]] localncda-- leave this as a local since NCDA is commonly used among ARK identifiers and could be useful for validating other identifiers later do-- initialize these constants only once but scope them in a block so local namespace doesn't get cluttered with these localr29s=[[0123456789bcdfghjkmnpqrstvwxz]]-- radix 29 "betanumeric" digit string localr29n=r29s:len() localr29v2d,r29d2v={},{} fori=1,r29ndo localv,d=i-1,r29s:sub(i,i) r29v2d[v],r29d2v[d]=d,v end functionncda(sid) localn,sum=sid:len(),0 fori=1,ndo sum=sum+i*(r29d2v[sid:sub(i,i)]or0) end returnr29v2d[sum%r29n] end end functionp.validateBNF(id) localFRBNF=id:sub(1,-2) returnFRBNF:match('^%d%d%d%d%d%d%d%d$')~=nilandncda('cb'..FRBNF)==id:sub(-1)andid end functionp.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() ifnotid:match('^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$')then returnfalse end localtotal=0 fori=1,15do localdigit=id:byte(i)-48--Get integer value total=(total+digit)*2 end localremainder=total%11 localresult=(12-remainder)%11 localcheckdigit ifresult==10then checkdigit='X' else checkdigit=tostring(result) end ifcheckdigit~=string.char(id:byte(16))then returnfalse end returnid end functionp.orcidV(id) id=p.validateIsni(id) ifnotidthen returnfalse end returnid:sub(1,4)..'-'..id:sub(5,8)..'-'..id:sub(9,12)..'-'..id:sub(13,16) end functionp.tlsV(id) id=id:gsub(' +','_') localidlen=mw.ustring.len(id) ifidlen<4oridlen>90then returnfalse end localregex='^%u'..string.rep("[%w_',%.%-%(%)%*%/–&]",idlen-1)..'$' ifnotmw.ustring.match(id,regex)then returnfalse end returnid end --[[======================================================]] --[[ Custom link functions ]] --[[======================================================]] functionp.ISILlink(id,label) ifnotid:match('^%D%D?%D?%D?%-.+$')then returnfalse end for_,prefixinipairs({'AT','AU','BE','CA','CH','DE','FI','FR','IT','KR','NZ','US','ZDB'})do ifid:match('^'..prefix..'%-')then return'[https://w3id.org/isil/'..id..' '..(labelor'ISIL')..']' end end return'[[International Standard Identifier for Libraries and Related Organizations|ISIL]]: '..id end functionp.uscgLink(id) localid2=id:match('^[1-7]%-%d%d?%d?%d?%d?$')orid:match('^[1-7]%-%d%d?%d?%d?%d?%.%d*[1-9]$') ifid2then return'[https://www.navcen.uscg.gov/pdf/lightlists/LightList%20V'..mw.ustring.sub(id2,1,1)..'.pdf '..id2..']' else returnfalse end end functionp.ccg(id) id=id:match('^[NAIP]?[1-9]%d*$')orid:match('^[NAIP]?[1-9]%d*%.%d+$') ifnotidthenreturnfalseend locallink='https://www.notmar.gc.ca/' localprefix=string.sub(id,1,1)-- get first character of id localsuffix=string.sub(id,2)-- remove first character of id localinterval=require('Module:Interval')._main localv ifprefix=='N'then localint=interval({1,7.5,14.4,100,121,173,211,235,269.99,326,396,450.1,471.7,499,n=suffix}) ifint=='1-2'thenv=1 elseifint=='2-3'thenv=75 elseifint=='3-4'thenv=144 elseifint=='4-5'thenv=100 elseifint=='5-6'thenv=121 elseifint=='6-7'thenv=173 elseifint=='7-8'thenv=211 elseifint=='8-9'thenv=235 elseifint=='9-10'thenv=26999 elseifint=='10-11'thenv=326 elseifint=='11-12'thenv=396 elseifint=='12-13'thenv=4501 elseifint=='13-14'thenv=4717 elseifint=='14-15'thenv=499 end link=link..'publications/list-lights/newfoundland/n'..v..'-en' elseifprefix=='A'then localint=interval({5,114.5,145,163,268,271,301.5,327,686.5,704.85,883.2,942,1085,1169.1,1584.5,1773,1823.55,2190,2369,2389,n=suffix}) ifint=='1-2'thenv=5 elseifint=='2-3'thenv=1145 elseifint=='3-4'thenv=145 elseifint=='4-5'thenv=162 elseifint=='5-6'thenv=268 elseifint=='6-7'thenv=271 elseifint=='7-8'thenv=3015 elseifint=='8-9'thenv=327 elseifint=='9-10'thenv=6865 elseifint=='10-11'thenv=7048 elseifint=='11-12'thenv=883 elseifint=='12-13'thenv=942 elseifint=='13-14'thenv=1085 elseifint=='14-15'thenv=11691 elseifint=='15-16'thenv=15845 elseifint=='16-17'thenv=1773 elseifint=='17-18'thenv=182355 elseifint=='18-19'thenv=2190 elseifint=='19-20'thenv=2369 elseifint=='20-21'thenv=2389 end link=link..'publications/list-lights/atl/a'..v..'-en' elseifprefix=='I'then localint=interval({0.05,401.1,403.4,551.06,552,624,708,731.2,768,814,983,1046,1059.6,1082,1162,1204.7,1233.3,1328,1330,1346.2,1377.8,1408,1410,1420,1445,1470,1520,1534,1540.6,1554,1557.7,1558.8,1563.1,1625.5,1671.7,1716.96,2545,n=suffix}) ifint=='1-2'thenv='01' elseifint=='2-3'thenv=4011 elseifint=='3-4'thenv=4034 elseifint=='4-5'thenv=55106 elseifint=='5-6'thenv=552 elseifint=='6-7'thenv=624 elseifint=='7-8'thenv=708 elseifint=='8-9'thenv=7312 elseifint=='9-10'thenv=768 elseifint=='10-11'thenv=814 elseifint=='11-12'thenv=983 elseifint=='12-13'thenv=1046 elseifint=='13-14'thenv=10596 elseifint=='14-15'thenv=1082 elseifint=='15-16'thenv=1162 elseifint=='16-17'thenv=12047 elseifint=='17-18'thenv=12333 elseifint=='18-19'thenv=1328 elseifint=='19-20'thenv=1330 elseifint=='20-21'thenv=13462 elseifint=='21-22'thenv=13778 elseifint=='22-23'thenv=1408 elseifint=='23-24'thenv=1410 elseifint=='24-25'thenv=1420 elseifint=='25-26'thenv=1445 elseifint=='26-27'thenv=1470 elseifint=='27-28'thenv=1520 elseifint=='28-29'thenv=1534 elseifint=='29-30'thenv=15406 elseifint=='30-31'thenv=1554 elseifint=='31-32'thenv=15577 elseifint=='32-33'thenv=15588 elseifint=='33-34'thenv=1562 elseifint=='34-35'thenv=16255 elseifint=='35-36'thenv=16717 elseifint=='36-37'thenv=171696 elseifint=='37-38'thenv=2545 end link=link..'publications/list-lights/inland-waters/i'..v..'-en' elseifprefix=='P'then link=link..'publications/list-lights/pac/p' else link=link..'list-lights' end return'[[CCG (identifier)|CCG]]: ['..link..' '..id..']' end returnp