模組:Kovl/Authority control/links

文档图示 模块文档[创建]
local p = {}

require('Module:No globals')

function p.getCatForId( id )
    local title = mw.title.getCurrentTitle()
    local namespace = title.namespace
    if namespace == 0 then
        return '[[Category:Wikipedia articles with ' .. id .. ' identifiers]]'
    elseif namespace == 2 and not title.isSubpage then
        return '[[Category:User pages with ' .. id .. ' identifiers]]'
    else
        return '[[Category:Miscellaneous pages with ' .. id .. ' identifiers]]'
    end
end

function p.viafLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[https://viaf.org/viaf/' .. id .. ' ' .. id .. ']' .. getCatForId( 'VIAF' )
end

function p.kulturnavLink( id )
    return '[//kulturnav.org/language/en/' .. id .. ' id]' 
end

function p.sikartLink( id )
    return '[//www.sikart.ch/KuenstlerInnen.aspx?id=' .. id .. '&lng=en ' .. id .. ']' 
end

function p.tlsLink( id )
	local id2 = mw.ustring.gsub(id, '%s', function(s) return mw.uri.encode(s, 'WIKI') end)
    return '[//tls.theaterwissenschaft.ch/wiki/' .. id2 .. ' ' .. id .. ']' 
end


function p.ciniiLink( id )
    return '[//ci.nii.ac.jp/author/' .. id .. '?l=en ' .. id .. ']' 
end

function p.bneLink( id )
    return '[//catalogo.bne.es/uhtbin/authoritybrowse.cgi?action=display&authority_id=' .. id .. ' ' .. id .. ']' 
end


function p.uscongressLink( id )
    return '[//bioguide.congress.gov/scripts/biodisplay.pl?index=' .. id .. ' ' .. id .. ']' 
end

function p.narapersonLink( id )
    return '[//research.archives.gov/person/' .. id .. ' ' .. id .. ']' 
end

function p.naraorganizationLink( id )
    return '[//research.archives.gov/organization/' .. id .. ' ' .. id .. ']' 
end

function p.botanistLink( id )
	local id2 = mw.ustring.gsub(id, '%s', function(s) return mw.uri.encode(s, 'PATH') end)
    return '[//www.ipni.org/ipni/advAuthorSearch.do?find_abbreviation=' .. id2 .. ' ' .. id .. ']' 
end

function p.mgpLink( id )
    -- TODO Implement some sanity checking regex
    return '[//www.genealogy.ams.org/id.php?id=' .. id .. ' ' .. id .. ']' 
end

function p.rslLink( id )
    -- TODO Implement some sanity checking regex
    return '[//aleph.rsl.ru/F?func=find-b&find_code=SYS&adjacent=Y&local_base=RSL11&request=' .. id .. '&CON_LNG=ENG ' .. id .. ']'
end

function p.leonoreLink( id )
-- Identifiants allant de LH/1/1 à LH/2794/54 (légionnaires)
-- Identifiants allant de C/0/1 à C/0/84 (84 légionnaires célèbres)
-- Identifiants allant de 19800035/1/1 à 19800035/385/51670 (légionnaires décédés entre 1954 et 1977, et quelques dossiers de légionnaires décédés avant 1954)
    if not string.match( id, '^LH/%d%d?%d?%d?/%d%d?%d?$' ) and
       not string.match( id, '^C/0/%d%d?$' ) and
	   not string.match( id, '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?$' ) then
        return false
    end
    return '[//www.culture.gouv.fr/public/mistral/leonore_fr?ACTION=CHERCHER&FIELD_1=COTE&VALUE_1=' .. id .. ' ' .. id .. ']' 
end

function p.sbnLink( id )
    if not string.match( id, '^IT\\ICCU\\%d%d%d%d%d%d%d%d%d%d$' ) and not string.match( id, '^IT\\ICCU\\%u%u[%d%u]%u\\%d%d%d%d%d%d$' ) then
        return false
    end
    return '[//opac.sbn.it/opacsbn/opac/iccu/scheda_authority.jsp?bid=' .. id .. ' ' .. id .. ']'
end

function p.nkcLink( id )
	return '[//aleph.nkp.cz/F/?func=find-c&local_base=aut&ccl_term=ica=' .. id .. '&CON_LNG=ENG ' .. id .. ']' 
end

function p.nclLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[//aleweb.ncl.edu.tw/F/?func=accref&acc_sequence=' .. id .. '&CON_LNG=ENG ' .. id .. ']' 
end

function p.ndlLink( id )
	return '[//id.ndl.go.jp/auth/ndlna/' .. id .. ' ' .. id .. ']' 
end

function p.sudocLink( id )
    if not string.match( id, '^%d%d%d%d%d%d%d%d[%dxX]$' ) then
        return false
    end
    return '[//www.idref.fr/' .. id .. ' ' .. id .. ']' 
end

function p.hlsLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[//www.hls-dhs-dss.ch/textes/f/F' .. id .. '.php ' .. id .. ']'
end

function p.lirLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[//www.e-lir.ch/e-LIR___Lexicon.' .. id .. '.450.0.html ' .. id .. ']'
end

function p.splitLccn( id )
    if id:match( '^%l%l?%l?%d%d%d%d%d%d%d%d%d?%d?$' ) then
        id = id:gsub( '^(%l+)(%d+)(%d%d%d%d%d%d)$', '%1/%2/%3' )
    end
    if id:match( '^%l%l?%l?/%d%d%d?%d?/%d+$' ) then
         return mw.text.split( id, '/' )
    end
    return false
end

local function append(str, c, length)
    while str:len() < length do
        str = c .. str
    end
    return str
end

function p.lccnLink( id )
    local parts = splitLccn( id )
    if not parts then
        return false
    end
    local lccnType = parts[1] ~= 'sh' and 'names' or 'subjects'
    id = parts[1] .. parts[2] .. append( parts[3], '0', 6 )
    return '[//id.loc.gov/authorities/' .. lccnType .. '/' .. id .. ' ' .. id .. ']' .. getCatForId( 'LCCN' )
end

function p.mbLink( id )
    -- TODO Implement some sanity checking regex
    return '[//musicbrainz.org/artist/' .. id .. ' ' .. id .. ']' .. getCatForId( 'MusicBrainz' )
end

--Returns the ISNI check digit isni must be a string where the 15 first elements are digits
local function getIsniCheckDigit( isni )
    local total = 0
    for i = 1, 15 do
        local digit = isni:byte( i ) - 48 --Get integer value
        total = (total + digit) * 2
    end
    local remainder = total % 11
    local result = (12 - remainder) % 11
    if result == 10 then
        return "X"
    end
    return tostring( result )
end

--Validate ISNI (and ORCID) and retuns it as a 16 characters string or returns false if it's invalid
--See //support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier
function p.validateIsni( id )
    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
    if getIsniCheckDigit( id ) ~= string.char( id:byte( 16 ) ) then
        return false
    end
    return id
end

function p.isniLink( id )
    id = validateIsni( id )
    if not id then
        return false
    end
    return '[//isni-url.oclc.nl/isni/' .. id .. ' ' .. id:sub( 1, 4 ) .. ' ' .. id:sub( 5, 8 ) .. ' '  .. id:sub( 9, 12 ) .. ' '  .. id:sub( 13, 16 ) .. ']' .. getCatForId( 'ISNI' )
end

function p.orcidLink( id )
    id = validateIsni( id )
    if not id then
        return false
    end
    id = id:sub( 1, 4 ) .. '-' .. id:sub( 5, 8 ) .. '-'  .. id:sub( 9, 12 ) .. '-'  .. id:sub( 13, 16 )
    return '[//orcid.org/' .. id .. ' ' .. id .. ']' .. getCatForId( 'ORCID' )
end

function p.gndLink( id )
    return '[//d-nb.info/gnd/' .. id .. ' ' .. id .. ']' .. getCatForId( 'GND' )
end

function p.selibrLink( id )
	if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[//libris.kb.se/auth/' .. id .. ' ' .. id .. ']' .. getCatForId( 'SELIBR' )
end

function p.bnfLink( id )
    --Add cb prefix if it has been removed
    if not string.match( id, '^cb.+$' ) then
        id = 'cb' .. id
    end

    return '[//catalogue.bnf.fr/ark:/12148/' .. id .. ' ' .. id .. '] [//data.bnf.fr/ark:/12148/' .. id .. ' (data)]' .. getCatForId( 'BNF' )
end

function p.bpnLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[//www.biografischportaal.nl/en/persoon/' .. id .. ' ' .. id .. ']' .. getCatForId( 'BPN' )
end

function p.ridLink( id )
    return '[//www.researcherid.com/rid/' .. id .. ' ' .. id .. ']' .. getCatForId( 'RID' )
end

function p.bibsysLink( id )
    return '[//ask.bibsys.no/ask/action/result?cmd=&kilde=biblio&cql=bs.autid+%3D+' .. id .. '&feltselect=bs.autid ' .. id .. ']' .. getCatForId( 'BIBSYS' )
end

function p.ulanLink( id )
    return '[//www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=' .. id .. ' ' .. id .. ']' .. getCatForId( 'ULAN' )
end

function p.nlaLink( id )
	return '[//nla.gov.au/anbd.aut-an' .. id .. ' ' .. id .. ']' .. getCatForId( 'NLA' )
end

function p.rkdartistsLink( id )
	return '[https://rkd.nl/en/explore/artists/' .. id .. ' ' .. id .. ']' .. getCatForId( 'RKDartists' )
end

return p