"Module:Citation/CS1/Identifiers": अवतरणों में अंतर

Content deleted Content added
willing to deploy out of cycle given these were just updated
updated per enwiki
पंक्ति 1:
--[[
History of changes since last sync: 2020-01-11
 
2020-02-02: Update PMID to 33000000
2020-02-05: support new biorxiv id format; see Help_talk:Citation_Style_1#Protected_edit_request_on_5_February_2020:_New_biorxiv_format
 
]]
 
 
--[[--------------------------< F O R W A R D D E C L A R A T I O N S >--------------------------------------
Line 120 ⟶ 128:
local function is_valid_isxn (isxn_str, len)
local temp = 0;
isxn_str = { isxn_str:byte(1, len) }; -- make a table of byte values '0' → 0x30 .. '9' → 0x39, 'X' → 0x58
len = len+1; -- adjust to be a loop counter
for i, v in ipairs( isxn_str ) do -- loop through all of the bytes and calculate the checksum
if v == string.byte( "X" ) then -- if checkdigit is X (compares the byte value of 'X' which is 0x58)
temp = temp + 10*( len - i ); -- it represents 10 decimal
else
temp = temp + tonumber( string.char(v) )*(len-i);
end
end
return temp % 11 == 0; -- returns true if calculation result is zero
end
 
Line 297 ⟶ 305:
if 19 ~= id:len() then
err_type = 'cfg.err_msg_supl.length';
-- err_type = 'length';
else
year = id:match ("^(%d%d%d%d)[%a][%w&%.][%w&%.][%w&%.][%w.]+[%a%.]$") --
if not year then -- if nil then no pattern match
err_type = 'cfg.err_msg_supl.value'; -- so value error
-- err_type = 'value'; -- so value error
else
local next_year = tonumber(os.date ('%Y'))+1; -- get the current year as a number and add one for next year
year = tonumber (year); -- convert year portion of bibcode to a number
if (1000 > year) or (year > next_year) then
err_type = 'cfg.err_msg_supl.year'; -- year out of bounds
-- err_type = 'year'; -- year out of bounds
end
if id:find('&%.') then
err_type = 'cfg.err_msg_supl.journal'; -- journal abbreviation must not have '&.' (if it does its missing a letter)
-- err_type = 'journal'; -- journal abbreviation must not have '&.' (if it does its missing a letter)
end
end
Line 323 ⟶ 335:
--[[--------------------------< B I O R X I V >-----------------------------------------------------------------
 
Format bioRxiv id and do simple error checking. BiorXivBefore 2019-12-11, biorXiv ids arewere exactly 6 digits. After
2019-12-11, biorXiv ids retained the six-digit identifier but prefixed that with a yyyy.mm.dd. date and suffixed
The bioRxiv id is the number following the last slash in the bioRxiv-issued DOI:
with an optional version identifier.
https://doi.org/10.1101/078733 -> 078733
 
The bioRxiv id is the numberstring of characters following the last slash in the bioRxiv-issued DOI:
https://doi.org/10.1101/078733 -> 078733
or a date followed by a six-digit number followed by an optional version indicator 'v' and one or more digits:
https://www.biorxiv.org/content/10.1101/2019.12.11.123456v2 -> 2019.12.11.123456v2
see https://www.biorxiv.org/about-biorxiv
]]
 
local function biorxiv(id)
local handler = cfg.id_handlers['BIORXIV'];
local err_cat = ' ' .. set_error( 'bad_biorxiv'); -- presumeassume that bioRxivthere will idbe isan validerror
local patterns = {
if nil == id:match("^%d%d%d%d%d%d$") then -- if bioRxiv id has anything but six digits
'^%d%d%d%d%d%d$', -- simple 6-digit identifier (before 2019-12-11)
err_cat = ' ' .. set_error( 'bad_biorxiv'); -- set an error message
'^(20[1-9]%d)%.([01]%d)%.([0-3]%d)%.%d%d%d%d%d%dv%d+$', -- y.m.d. date + 6-digit identifier + version (after 2019-12-11)
end
'^(20[1-9]%d)%.([01]%d)%.([0-3]%d)%.%d%d%d%d%d%d$', -- y.m.d. date + 6-digit identifier (after 2019-12-11)
}
for _, pattern in ipairs (patterns) do -- spin through the patterns looking for a match
if id:match (pattern) then
local y, m, d = id:match (pattern); -- found a match, attempt to get year, month and date from the identifier
 
if m then -- m is nil when id is the six-digit form
if (2019 > tonumber (y)) or (12 < tonumber (m)) or (1 > tonumber (d)) or (31 < tonumber (d)) then -- crude date validation; each of these is error condition; ignore leap year and actual month length
break; -- break out early so we don't unset the error message
end
end
err_cat = ''; -- we found a match so unset the error message
break; -- and done
end
end -- err_cat remains set here when no match
 
return external_link_id({link = handler.link, label = handler.label, q = handler.q,
prefix=handler.prefix,id=id,separator=handler.separator,
Line 482 ⟶ 516:
local function isbn( isbn_str )
if nil ~= isbn_str:match("[^%s-0-9X]") then
return false, 'invalid character'cfg.err_msg_supl.char; -- fail if isbn_str contains anything but digits, hyphens, or the uppercase X
end
isbn_str = isbn_str:gsub( "-", "" ):gsub( " ", "" ); -- remove hyphens and spaces
Line 488 ⟶ 522:
if len ~= 10 and len ~= 13 then
return false, 'cfg.err_msg_supl.length'; -- fail if incorrect length
end
 
if len == 10 then
if isbn_str:match( "^%d*X?$" ) == nil then -- fail if isbn_str has 'X' anywhere but last position
return false, 'invalid cfg.err_msg_supl.form';
end
return is_valid_isxn(isbn_str, 10), 'checksum'cfg.err_msg_supl.check;
else
if isbn_str:match( "^%d+$" ) == nil then
return false, 'invalid character'cfg.err_msg_supl.char; -- fail if isbn13 is not all digits
end
if isbn_str:match( "^97[89]%d*$" ) == nil then
return false, 'invalid cfg.err_msg_supl.prefix'; -- fail when isbn13 does not begin with 978 or 979
end
if isbn_str:match ('^9790') then
return false, 'invalid cfg.err_msg_supl.group id'; -- group identifier '0' is reserved to ismn
end
return is_valid_isxn_13 (isbn_str), 'checksum'cfg.err_msg_supl.check;
end
end