Module:Citation/CS1: Difference between revisions

ISSN error detection; Expand uncategorized namespaces; Reg/Sub required msg tweak; Trap coauthors without authors; Hide error messages;
m>Trappist the monk
(Subscription/Registration help; Via cat fix; identifier protocol relative urls; PMC identifier fix; iso639-1 support;)
m>Trappist the monk
(ISSN error detection; Expand uncategorized namespaces; Reg/Sub required msg tweak; Trap coauthors without authors; Hide error messages;)
Line 295: Line 295:
     end
     end
end
end
--[[
Validate and format an issn.  This code fixes the case where an editor has included an ISSN in the citation but has separated the two groups of four
digits with a space.  When that condition occurred, the resulting link looked like this:
|issn=0819 4327 gives: [http://www.worldcat.org/issn/0819 4327 0819 4327]  -- can't have spaces in an external link
This code now prevents that by inserting a hyphen at the issn midpoint.  It also validates the issn for length and makes sure that the checkdigit agrees
with the calculated value.  Incorrect length (8 digits), characters other than 0-9 and X, or checkdigit / calculated value mismatch will all cause a check issn
error message.  The issn is always displayed with a hyphen, even if the issn was given as a single group of 8 digits.
]]
function issn(id)
local clean_issn;
local issn_copy = id; -- save a copy of unadulterated issn; use this version for display if issn does not validate
local handler = cfg.id_handlers['ISSN'];
local temp = 0;
local text;
local valid_issn = true;
id=id:gsub( "[%s-–]", "" ); -- strip spaces, hyphens, and ndashes from the issn
clean_issn=string.sub( id, 1, 4 ) .. "-" .. string.sub( id, 5 ); -- make a copy with a hyphen after 4 digits; use this version for display if issn validates
if 8 ~= id:len() or nil == id:match( "^%d*X?$" ) then -- validate the issn: 8 didgits long, containing only 0-9 or X in the last position
valid_issn=false; -- wrong length or improper character
else
id = { id:byte(1, 8) }; -- table of individual bytes
for i, v in ipairs( id ) do -- loop through all of the byte an calculate the checksum
if v == string.byte( "X" ) then -- if checkdigit is X
temp = temp + 10*( 9 - i ); -- it represents 10 decimal
else
temp = temp + tonumber( string.char(v) )*(9-i);
end
end
valid_issn = temp % 11 == 0; -- checksum must be zero for valid issn
end
if true == valid_issn then
id = clean_issn; -- if valid, use the cleaned-up version for the display
else
id = issn_copy; -- if not valid, use the show the invalid issn with error message
end
text = externallinkid({link = handler.link, label = handler.label,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode})
if false == valid_issn then
text = text .. ' ' .. seterror( 'bad_issn' ) -- add an error message if the issn is invalid
end
return text
end


--[[
--[[
Line 641: Line 693:
         elseif k == 'PMC' then
         elseif k == 'PMC' then
             table.insert( new_list, {handler.label, pmc( v, options.Embargo ) } );
             table.insert( new_list, {handler.label, pmc( v, options.Embargo ) } );
        elseif k == 'ISSN' then
        table.insert( new_list, {handler.label, issn( v ) } );
         elseif k == 'ISBN' then
         elseif k == 'ISBN' then
             local ISBN = internallinkid( handler );
             local ISBN = internallinkid( handler );
Line 1,042: Line 1,096:
         Authors = listpeople(control, a)  
         Authors = listpeople(control, a)  
     end
     end
if not is_set(Authors) and is_set(Coauthors) then -- coauthors aren't displayed if one of authors=, authorn=, or lastn= isn't specified
table.insert( z.message_tail, { seterror('coauthors_missing_author', {}, true) } ); -- emit error message
end


     local EditorCount
     local EditorCount
Anonymous user