మాడ్యూల్:Citation/CS1/Identifiers: కూర్పుల మధ్య తేడాలు

Content deleted Content added
చి en:Module:Citation/CS1/Identifiers నుండి కూర్పును దిగుమతి చేసాం: తెవికీలో తాజా
sync from sandbox;
పంక్తి 87:
if options.encode == true or options.encode == nil then
url_string = mw.uri.encode (url_string, 'PATH');
end
 
పంక్తి 242:
isxn_str = { isxn_str:byte(1, 13) }; -- make a table of byte values '0' → 0x30 .. '9' → 0x39
for i, v in ipairs (isxn_str) do
temp = temp + (3 - 2*(i % 2)) * tonumber (string.char (v) ); -- multiply odd index digits by 1, even index digits by 3 and sum; includes check digit
end
return temp % 10 == 0; -- sum modulo 10 is zero when ISBN-13/ISMN is correct
పంక్తి 351:
end
 
if err_cat then
options.coins_list_t['ARXIV'] = nil; -- when error, unset so not included in COinS
end
err_cat = err_cat and table.concat ({' ', set_message ('err_bad_arxiv')}) or ''; -- set error message if flag is true
Line 404 ⟶ 408:
err_type = cfg.err_msg_supl.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
Line 417 ⟶ 421:
if is_set (err_type) then -- if there was an error detected
text = text .. ' ' .. set_message ('err_bad_bibcode', {err_type});
options.coins_list_t['BIBCODE'] = nil; -- when error, unset so not included in COinS
 
end
return text;
Line 462 ⟶ 468:
end -- err_cat remains set here when no match
 
if err_cat then
options.coins_list_t['BIORXIV'] = nil; -- when error, unset so not included in COinS
end
return external_link_id ({link = handler.link, label = handler.label, q = handler.q, redirect = handler.redirect,
prefix = handler.prefix, id = id, separator = handler.separator,
Line 487 ⟶ 497:
if not matched then
text = text .. ' ' .. set_message ('err_bad_citeseerx' );
options.coins_list_t['CITESEERX'] = nil; -- when error, unset so not included in COinS
end
return text;
Line 548 ⟶ 559:
local registrant_err_patterns = { -- these patterns are for code ranges that are not supported
'^[^1-3]%d%d%d%d%.%d%d*$', -- 5 digits with subcode (0xxxx, 40000+); accepts: 10000–39999
'^[^1-45]%d%d%d%d$', -- 5 digits without subcode (0xxxx, 4000060000+); accepts: 10000–4999910000–59999
'^[^1-9]%d%d%d%.%d%d*$', -- 4 digits with subcode (0xxx); accepts: 1000–9999
'^[^1-9]%d%d%d$', -- 4 digits without subcode (0xxx); accepts: 1000–9999
Line 558 ⟶ 569:
 
if not ignore_invalid then
if registrant then -- when DOI has proper form
for i, pattern in ipairs (registrant_err_patterns) do -- spin through error patterns
if registrant:match (pattern) then -- to validate registrant codes
err_cat = ' ' .. set_message ('err_bad_doi'); -- when found, mark this DOI as bad
break; -- and done
end
end
else
err_cat = ' ' .. set_message ('err_bad_doi'); -- invalid directory or malformed
end
else
Line 572 ⟶ 583:
end
 
if err_cat then
options.coins_list_t['DOI'] = nil; -- when error, unset so not included in COinS
end
text = external_link_id ({link = handler.link, label = handler.label, q = handler.q, redirect = handler.redirect,
prefix = handler.prefix, id = id, separator = handler.separator, encode = handler.encode, access = access,
Line 641 ⟶ 656:
if nil == id:match("^[^%s–]-/[^%s–]-[^%.,]$") then -- HDL must contain a forward slash, must not contain spaces, endashes, and must not end with period or comma
text = text .. ' ' .. set_message ('err_bad_hdl' );
options.coins_list_t['HDL'] = nil; -- when error, unset so not included in COinS
end
return text;
Line 664 ⟶ 680:
else -- here when not ignoring
if not check then -- and there is an error
options.coins_list_t['ISBN'] = nil; -- when error, unset so not included in COinS
return ISBN .. set_message ('err_bad_isbn', {err_type}, false, ' '); -- display an error message
end
Line 686 ⟶ 703:
return return_result (false, cfg.err_msg_supl.form);
end
returnif return_resultnot (is_valid_isxn (id, 10), cfg.err_msg_supl.check);then -- test isbn-10 for numerical validity
return return_result (false, cfg.err_msg_supl.check); -- fail if isbn-10 is not numerically valid
end
if id:find ('^63[01]') then -- 630xxxxxxx and 631xxxxxxx are (apparently) not valid isbn group ids but are used by amazon as numeric identifiers (asin)
return return_result (false, cfg.err_msg_supl.group); -- fail if isbn-10 begins with 630/1
end
return return_result (true, cfg.err_msg_supl.check); -- pass if isbn-10 is numerically valid
else
if id:match ('^%d+$') == nil then
Line 709 ⟶ 732:
Error message if not 10 characters, if not ISBN-10, if mixed and first character is a digit.
 
|asin=630....... isand |asin=631....... are (apparently) not a legitimate ISBN though it checksums as one; these do not cause this
do not cause this function to emit the maint_asin message
 
This function is positioned here because it calls isbn()
Line 720 ⟶ 743:
local domain = options.ASINTLD;
local err_cat = ""''
 
if not id:match("^[%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u]$") then
Line 726 ⟶ 749:
else
if id:match("^%d%d%d%d%d%d%d%d%d[%dX]$") then -- if 10-digit numeric (or 9 digits with terminal X)
if isbnis_valid_isxn (optionsid, 10) then -- see if ASIN value is or validates as ISBN-10
if not id:find ('^63063[01]') then -- 630xxxxxxx isand 631xxxxxxx are (apparently) not a valid isbn prefixprefixes but isare used by amazon as a numeric identifier
err_cat = ' ' .. set_message ('maint_asinerr_bad_asin'); -- ASIN has ISBN-10 form but begins with something other than 630/1 so possiblyprobably an isbn
end
elseif not is_set (err_cat) then
Line 737 ⟶ 760:
end
end
if (not is_set (domain)) or in_array (domain, {'us'}) then -- default: United States
domain = "com";
elseif in_array (domain, {'jp', 'uk'}) then -- Japan, United Kingdom
domain = "co." .. domain;
elseif in_array (domain, {'au', 'br', 'mxz.cn'}) then -- Australia, Brazil, MexicoChina
domain = "cn";
elseif in_array (domain, {'au', 'br', 'mx', 'sg', 'tr'}) then -- Australia, Brazil, Mexico, Singapore, Turkey
domain = "com." .. domain;
elseif not in_array (domain, {'ae', 'ca', 'cn', 'de', 'es', 'fr', 'in', 'it', 'nl', 'pl', 'sa', 'se', 'co.jp', 'co.uk', 'com', 'com.au', 'com.br', 'com.mx', 'com.sg', 'com.tr'}) then -- Arabic Emirates, Canada, China, Germany, Spain, France, Indonesia, Italy, Netherlands, Poland, Saudi Arabia, Sweden (as of 2021-03 Austria (.at), Liechtenstein (.li) and Switzerland (.ch) still redirect to the German site (.de) with special settings, so don't maintain local ASINs for them)
err_cat = ' ' .. set_message ('err_bad_asin_tld'); -- unsupported asin-tld value
end
 
local handler = options.handler;
 
if not is_set (err_cat) then
options.coins_list_t['ASIN'] = handler.prefix .. domain .. "/dp/" .. id; -- experiment for asin coins
else
options.coins_list_t['ASIN'] = nil; -- when error, unset so not included in COinS
end
return external_link_id ({link = handler.link, label = handler.label, q = handler.q, redirect = handler.redirect,
prefix = handler.prefix .. domain .. "/dp/",
Line 757 ⟶ 790:
same check digit calculations. See http://www.ismn-international.org/download/Web_ISMN_Users_Manual_2008-6.pdf
section 2, pages 9–12.
 
ismn value not made part of COinS metadata because we don't have a url or isn't a COinS-defined identifier (rft.xxx)
or an identifier registered at info-uri.info (info:)
 
]]
Line 787 ⟶ 823:
 
if false == valid_ismn then
options.coins_list_t['ISMN'] = nil; -- when error, unset so not included in COinS; not really necessary here because ismn not made part of COinS
text = text .. ' ' .. set_message ('err_bad_ismn' ) -- add an error message if the ISMN is invalid
end
Line 839 ⟶ 876:
else
if false == valid_issn then
options.coins_list_t['ISSN'] = nil; -- when error, unset so not included in COinS
text = text .. ' ' .. set_message ('err_bad_issn', (options.hkey == 'EISSN') and 'e' or ''); -- add an error message if the ISSN is invalid
end
Line 871 ⟶ 909:
else
err_cat = ' ' .. set_message ('err_bad_jfm' ); -- set an error message
options.coins_list_t['JFM'] = nil; -- when error, unset so not included in COinS
end
Line 892 ⟶ 931:
if id:find ('[Jj][Ss][Tt][Oo][Rr]') or id:find ('^https?://') or id:find ('%s') then
err_msg = ' ' .. set_message ('err_bad_jstor'); -- set an error message
options.coins_list_t['JSTOR'] = nil; -- when error, unset so not included in COinS
end
Line 950 ⟶ 990:
if not is_set (err_cat) and nil ~= lccn:find ('%s') then
err_cat = ' ' .. set_message ('err_bad_lccn'); -- lccn contains a space, set an error message
end
 
if is_set (err_cat) then
options.coins_list_t['LCCN'] = nil; -- when error, unset so not included in COinS
end
 
Line 983 ⟶ 1,027:
else
err_cat = ' ' .. set_message ('err_bad_mr'); -- set an error message
options.coins_list_t['MR'] = nil; -- when error, unset so not included in COinS
end
Line 1,025 ⟶ 1,070:
else
err_msg = ' ' .. set_message ('err_bad_oclc') -- add an error message if the id is malformed
options.coins_list_t['OCLC'] = nil; -- when error, unset so not included in COinS
end
Line 1,057 ⟶ 1,103:
ident = id; -- copy id to ident so that we display the flawed identifier
error_msg = ' ' .. set_message ('err_bad_ol');
end
 
if not is_set (error_msg) then
options.coins_list_t['OL'] = handler.prefix .. prefix[code] .. ident; -- experiment for ol coins
else
options.coins_list_t['OL'] = nil; -- when error, unset so not included in COinS
end
 
Line 1,084 ⟶ 1,136:
if id:match("[^%d]") then -- if OSTI has anything but digits
err_cat = ' ' .. set_message ('err_bad_osti'); -- set an error message
options.coins_list_t['OSTI'] = nil; -- when error, unset so not included in COinS
else -- OSTI is only digits
local id_num = tonumber (id); -- convert id to a number for range testing
if 1018 > id_num or handler.id_limit < id_num then -- if OSTI is outside test limit boundaries
err_cat = ' ' .. set_message ('err_bad_osti'); -- set an error message
options.coins_list_t['OSTI'] = nil; -- when error, unset so not included in COinS
end
end
Line 1,151 ⟶ 1,205:
text = external_link_id ({link = handler.link, label = handler.label, q = handler.q, redirect = handler.redirect, -- no embargo date or embargo has expired, ok to link to article
prefix = handler.prefix, id = id, separator = handler.separator, encode = handler.encode, access = handler.access,
auto_link = not err_cat and 'pmc' or nil -- do not auto-link when PMC has error
}) .. (err_cat and err_cat or ''); -- parentheses required
end
 
if err_cat then
options.coins_list_t['PMC'] = nil; -- when error, unset so not included in COinS
end
 
return text;
end
Line 1,173 ⟶ 1,232:
if id:match("[^%d]") then -- if PMID has anything but digits
err_cat = ' ' .. set_message ('err_bad_pmid'); -- set an error message
options.coins_list_t['PMID'] = nil; -- when error, unset so not included in COinS
else -- PMID is only digits
local id_num = tonumber (id); -- convert id to a number for range testing
if 1 > id_num or handler.id_limit < id_num then -- if PMID is outside test limit boundaries
err_cat = ' ' .. set_message ('err_bad_pmid'); -- set an error message
options.coins_list_t['PMID'] = nil; -- when error, unset so not included in COinS
end
end
Line 1,202 ⟶ 1,263:
if id:match("[^%d]") then -- if RFC has anything but digits
err_cat = ' ' .. set_message ('err_bad_rfc'); -- set an error message
options.coins_list_t['RFC'] = nil; -- when error, unset so not included in COinS
else -- RFC is only digits
local id_num = tonumber (id); -- convert id to a number for range testing
if 1 > id_num or handler.id_limit < id_num then -- if RFC is outside test limit boundaries
err_cat = ' ' .. set_message ('err_bad_rfc'); -- set an error message
options.coins_list_t['RFC'] = nil; -- when error, unset so not included in COinS
end
end
Line 1,238 ⟶ 1,301:
if handler.id_limit < id_num then -- if S2CID is outside test limit boundaries
err_cat = ' ' .. set_message ('err_bad_s2cid'); -- set an error message
options.coins_list_t['S2CID'] = nil; -- when error, unset so not included in COinS
end
 
else -- when id format incorrect
err_cat = ' ' .. set_message ('err_bad_s2cid'); -- set an error message
options.coins_list_t['S2CID'] = nil; -- when error, unset so not included in COinS
end
 
Line 1,254 ⟶ 1,319:
 
9-digit form of ISBN-10; uses same check-digit validation when SBN is prefixed with an additional '0' to make 10 digits
 
sbn value not made part of COinS metadata because we don't have a url or isn't a COinS-defined identifier (rft.xxx)
or an identifier registered at info-uri.info (info:)
 
]]
Line 1,266 ⟶ 1,334:
if not ignore_invalid then -- if not ignoring SBN errors
if not check then
options.coins_list_t['SBN'] = nil; -- when error, unset so not included in COinS; not really necessary here because sbn not made part of COinS
return SBN .. set_message ('err_bad_sbn', {err_type}, false, ' '); -- display an error message
end
Line 1,278 ⟶ 1,347:
end
 
local ident = id:gsub ('[%s-]', ''); -- remove hyphens and whitespace; they interfere with the rest of the tests
 
if 9 ~= ident:len() then
Line 1,315 ⟶ 1,384:
if 100 > id_num or handler.id_limit < id_num then -- if SSRN is outside test limit boundaries
err_cat = ' ' .. set_message ('err_bad_ssrn'); -- set an error message
options.coins_list_t['SSRN'] = nil; -- when error, unset so not included in COinS
end
else -- when id format incorrect
err_cat = ' ' .. set_message ('err_bad_ssrn'); -- set an error message
options.coins_list_t['SSRN'] = nil; -- when error, unset so not included in COinS
end
Line 1,343 ⟶ 1,414:
if not id:match('^.+@.+$') or not id:match('^[^<].*[^>]$') then -- doesn't have '@' or has one or first or last character is '< or '>'
text = text .. ' ' .. set_message ('err_bad_usenet_id') -- add an error message if the message id is invalid
options.coins_list_t['USENETID'] = nil; -- when error, unset so not included in COinS
end
Line 1,368 ⟶ 1,440:
elseif not id:match('^%d?%d?%d?%d%.%d%d%d%d%d$') then -- not temporary, is it normal format?
err_cat = ' ' .. set_message ('err_bad_zbl'); -- no, set an error message
options.coins_list_t['ZBL'] = nil; -- when error, unset so not included in COinS
end
Line 1,414 ⟶ 1,487:
if is_set (access_level) then
if not in_array (access_level, cfg.keywords_lists['id-access']) then -- exact match required
table.insert (z.message_tail, { set_message ('invalid_param_valerr_invalid_param_val', {access_param, access_level}, true) } );
access_level = nil; -- invalid so unset
end
Line 1,432 ⟶ 1,505:
render the identifiers into a sorted sequence table
 
<id_list_tID_list_coins_t> is a table of k/v pairs where k is same as key in cfg.id_handlers and v is the assigned value
<options_t> is a table of is a table of various k/v option pairs provided in the call to new_build_id_list();
modified by this function and passed to all identifier rendering functions
<access_levels_t> is a table of k/v pairs where k is same as key in cfg.id_handlers and v is the assigned value (if valid)
 
returns a sequence table of sorted (by hkey - 'handler' key) rendered identifier strings
 
]]
 
local function build_id_list (id_list_tID_list_coins_t, options_t, access_levels_t)
local new_list_tID_list_t = {};
local accept;
local func_map = { --function map points to functions associated with hkey identifier
Line 1,473 ⟶ 1,546:
}
 
for hkey, v in pairs (id_list_tID_list_coins_t) do
v, accept = has_accept_as_written (v); -- remove accept-as-written markup if present; accept is boolean true when markup removed; false else
-- every function gets the options table with value v and accept boolean
Line 1,481 ⟶ 1,554:
options_t.access = access_levels_t[hkey]; -- add the access level for those that have an |<identifier-access= parameter
options_t.handler = cfg.id_handlers[hkey];
options_t.coins_list_t = ID_list_coins_t; -- pointer to ID_list_coins_t; for |asin= and |ol=; also to keep erroneous values out of the citation's metadata
if func_map[hkey] then
table.insert (new_list_tID_list_t, {hkey, func_map[hkey] (options_t)}); -- call the function and add the results to the output sequence table
 
-- TODO: also retrieve identifier validity status, OL A/M/W/X type and ASIN TLD info from the corresponding function call for improved metadata generation in COinS() in ~/COinS
 
else
error (cfg.messages['unknown_ID_key'] .. ' ' .. hkey); -- here when func_map doesn't have a function for hkey
Line 1,495 ⟶ 1,567:
end
 
table.sort (new_list_tID_list_t, comp); -- sequence table of tables sort
for k, v in ipairs (new_list_tID_list_t) do -- convert sequence table of tables to simple sequence table of strings
ID_list_t[k] = v[2]; -- v[2] is the identifier rendering from the call to the various functions in func_map{}
new_list_t[k] = v[2];
end
return new_list_tID_list_t;
end
 
 
--[[--------------------------< O P T I O N S _ C H E C K >----------------------------------------------------
 
check that certain option parameters have their associated identifier parameters with values
 
<ID_list_coins_t> is a table of k/v pairs where k is same as key in cfg.id_handlers and v is the assigned value
<ID_support_t> is a sequence table of tables created in citation0() where each subtable has four elements:
[1] is the support parameter's assigned value; empty string if not set
[2] is a text string same as key in cfg.id_handlers
[3] is cfg.error_conditions key used to create error message
[4] is original ID support parameter name used to create error message
returns nothing; on error emits an appropriate error message
 
]]
 
local function options_check (ID_list_coins_t, ID_support_t)
for _, v in ipairs (ID_support_t) do
if is_set (v[1]) and not ID_list_coins_t[v[2]] then -- when support parameter has a value but matching identifier parameter is missing or empty
table.insert (z.message_tail, {set_message (v[3], (v[4]))}); -- emit the appropriate error message
end
end
end
 
Line 1,512 ⟶ 1,608:
]]
 
local function identifier_lists_get (args, options_t, ID_support_t)
local ID_list_coins_t = extract_ids (args); -- get a table of identifiers and their values for use locally and for use in COinS
options_check (ID_list_coins_t, ID_support_t); -- ID support parameters must have matching identifier parameters
local ID_access_levels_t = extract_id_access_levels (args, ID_list_coins_t); -- get a table of identifier access levels
local ID_list_t = build_id_list (ID_list_coins_t, options_t, ID_access_levels_t); -- get a sequence table of rendered identifier strings
 
-- TODO: add code to retrieve identifier validity status, OL A/M/W/X type and ASIN TLD info from ID_list_t and add this to ID_list_coins_t for improved metadata generation in COinS() in ~/COinS
 
return ID_list_t, ID_list_coins_t; -- return the tables
"https://te.wikipedia.org/wiki/మాడ్యూల్:Citation/CS1/Identifiers" నుండి వెలికితీశారు