Module:Citation/CS1/Identifiers: Difference between revisions

sy
m>Trappist the monk
m (Protected "Module:Citation/CS1/Identifiers": High-risk Lua module ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
m>Trappist the monk
(sy)
Line 627: Line 627:
return text
return text
end
--[[--------------------------< O C L C >----------------------------------------------------------------------
Validate and format an oclc id.  https://www.oclc.org/batchload/controlnumber.en.html
]]
local function oclc (id)
local handler = cfg.id_handlers['OCLC'];
local number;
local err_msg = ''; -- empty string for concatenation
if id:match('^ocm%d%d%d%d%d%d%d%d$') then -- ocm prefix and 8 digits; 001 field (12 characters)
number = id:match('ocm(%d+)'); -- get the number
elseif id:match('^ocn%d%d%d%d%d%d%d%d%d$') then -- ocn prefix and 9 digits; 001 field (12 characters)
number = id:match('ocn(%d+)'); -- get the number
elseif id:match('^on%d%d%d%d%d%d%d%d%d%d+$') then -- on prefix and 10 or more digits; 001 field (12 characters)
number = id:match('^on(%d%d%d%d%d%d%d%d%d%d+)$'); -- get the number
elseif id:match('^%(OCoLC%)[1-9]%d*$') then -- (OCoLC) prefix and variable number digits; no leading zeros; 035 field
number = id:match('%(OCoLC%)([1-9]%d*)'); -- get the number
if 9 < number:len() then
number = nil; -- contrain to 1 to 9 digits; change this when oclc issues 10-digit numbers
end
elseif id:match('^%d+$') then -- no prefix
number = id; -- get the number
if 9 < number:len() then
number = nil; -- contrain to 1 to 9 digits; change this when oclc issues 10-digit numbers
end
end
if number then -- proper format
id = number; -- exclude prefix, if any, from external link
else
err_msg = ' ' .. set_error( 'bad_oclc' ) -- add an error message if the id is malformed
end
local text = external_link_id({link=handler.link, label=handler.label,
prefix=handler.prefix, id=id, separator=handler.separator, encode=handler.encode}) .. err_msg;
return text;
end
end


Line 671: Line 713:
elseif k == 'PMID' then
elseif k == 'PMID' then
table.insert( new_list, {handler.label, pmid( v ) } );
table.insert( new_list, {handler.label, pmid( v ) } );
elseif k == 'OCLC' then
table.insert( new_list, {handler.label, oclc( v ) } );
elseif k == 'ISMN' then
elseif k == 'ISMN' then
table.insert( new_list, {handler.label, ismn( v ) } );
table.insert( new_list, {handler.label, ismn( v ) } );
Anonymous user