Module:Citation/CS1/Identifiers: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
m (45 revisions imported: Country infobox) |
(sync from sandbox;) |
||
Line 8: | Line 8: | ||
local cfg; -- table of configuration tables that are defined in Module:Citation/CS1/Configuration |
local cfg; -- table of configuration tables that are defined in Module:Citation/CS1/Configuration |
||
local wd_int_lang = (mw.site.server:match ('wikidata') and mw.getCurrentFrame():preprocess('{{int:lang}}')) or ''; |
|||
Line 283: | Line 281: | ||
1–4 must be digits and must represent a year in the range of 1000 – next year |
1–4 must be digits and must represent a year in the range of 1000 – next year |
||
5 must be a letter |
5 must be a letter |
||
6–8 must be letter, digit, ampersand, or dot (ampersand cannot directly precede a dot; &. ) |
|||
7–8 must be letter, digit, ampersand, or dot (ampersand cannot directly precede a dot; &. ) |
|||
9–18 must be letter, digit, or dot |
9–18 must be letter, digit, or dot |
||
19 must be a letter or dot |
19 must be a letter or dot |
||
Line 302: | Line 299: | ||
err_type = 'length'; |
err_type = 'length'; |
||
else |
else |
||
year = id:match ("^(%d%d%d%d)[%a][% |
year = id:match ("^(%d%d%d%d)[%a][%w&%.][%w&%.][%w&%.][%w.]+[%a%.]$") -- |
||
if not year then -- if nil then no pattern match |
if not year then -- if nil then no pattern match |
||
err_type = 'value'; -- so value error |
err_type = 'value'; -- so value error |
||
Line 393: | Line 390: | ||
if is_set(inactive) then |
if is_set(inactive) then |
||
local inactive_year = inactive:match("%d%d%d%d") or ''; -- try to get the year portion from the inactive date |
local inactive_year = inactive:match("%d%d%d%d") or ''; -- try to get the year portion from the inactive date |
||
local inactive_month, good; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if 4 < inactive:len() then -- inactive date has more than just a year (could be anything) |
|||
local lang_obj = mw.getContentLanguage(); -- get a language object for this wiki |
|||
good, inactive_month = pcall (lang_obj.formatDate, lang_obj, 'F', inactive); -- try to get the month name from the inactive date |
|||
⚫ | |||
inactive_month = nil; -- something went wrong so make sure this is unset |
|||
⚫ | |||
⚫ | |||
else |
else |
||
inactive_year = nil; -- |doi-broken= has something but it isn't a date |
|||
⚫ | |||
end |
end |
||
⚫ | |||
if is_set(inactive_year) and is_set (inactive_month) then |
|||
table.insert( z.error_categories, 'Pages with DOIs inactive as of ' .. inactive_year .. ' ' .. inactive_month); -- use inactive month in category name |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
end |
end |
||
text = external_link_id({link = handler.link, label = handler.label, q = handler.q, |
text = external_link_id({link = handler.link, label = handler.label, q = handler.q, |
||
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, access=access}) .. (inactive or '') |
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, access=access}) .. (inactive or '') |
||
if nil == id:match("^10%.[^%s–]-/[^%s–]-[^%.,]$") |
if nil == id:match("^10%.[^%s–]-/[^%s–]-[^%.,]$") or -- doi must begin with '10.', must contain a fwd slash, must not contain spaces or endashes, and must not end with period or comma |
||
id: match ('^10.5555') then -- test doi will never resolve |
|||
cat = ' ' .. set_error( |
cat = ' ' .. set_error ('bad_doi'); |
||
end |
end |
||
Line 834: | Line 849: | ||
local function pmc(id, embargo) |
local function pmc(id, embargo) |
||
local test_limit = |
local test_limit = 7000000; -- update this value as PMCs approach |
||
local handler = cfg.id_handlers['PMC']; |
local handler = cfg.id_handlers['PMC']; |
||
local err_cat = ''; -- presume that PMC is valid |
local err_cat = ''; -- presume that PMC is valid |
||
Line 961: | Line 976: | ||
A numerical identifier in the form nnnn.nnnnn - leading zeros in the first quartet optional |
A numerical identifier in the form nnnn.nnnnn - leading zeros in the first quartet optional |
||
format described here: http://emis.mi.sanu.ac.rs/ZMATH/zmath/en/help/search/ |
|||
temporary format is apparently eight digits. Anything else is an error |
|||
]] |
]] |
||
Line 966: | Line 985: | ||
local function zbl (id) |
local function zbl (id) |
||
local handler = cfg.id_handlers['ZBL']; |
local handler = cfg.id_handlers['ZBL']; |
||
local id_num; |
|||
local err_cat = ''; |
local err_cat = ''; |
||
if id:match('^%d%d%d%d%d%d%d%d$') then -- is this identifier using temporary format? |
|||
add_maint_cat ('zbl'); -- yes, add maint cat |
|||
⚫ | |||
if is_set (id_num) then |
|||
⚫ | |||
add_maint_cat ('zbl_format'); |
|||
else -- plain number without zbl prefix |
|||
id_num = id; -- if here id does not have prefix |
|||
⚫ | |||
⚫ | |||
id = id_num; -- id matches pattern |
|||
⚫ | |||
⚫ | |||
end |
end |
||
Line 1,111: | Line 1,121: | ||
Parameters which have a predefined access level (e.g. arxiv) do not use this |
Parameters which have a predefined access level (e.g. arxiv) do not use this |
||
function as they are directly rendered as free without using an additional parameter. |
function as they are directly rendered as free without using an additional parameter. |
||
access-level values must match the case used in cfg.keywords['id-access'] (lowercase unless there is some special reason for something else) |
|||
]] |
]] |
||
Line 1,117: | Line 1,129: | ||
local id_accesses_list = {}; |
local id_accesses_list = {}; |
||
for k, v in pairs( cfg.id_handlers ) do |
for k, v in pairs( cfg.id_handlers ) do |
||
local access_param = v.custom_access; |
local access_param = v.custom_access; -- name of identifier's access-level parameter |
||
local k_lower = string.lower(k); |
|||
if is_set(access_param) then |
if is_set(access_param) then |
||
local access_level = args[access_param]; |
local access_level = args[access_param]; -- get the assigned value if there is one |
||
if is_set(access_level) then |
if is_set (access_level) then |
||
if not in_array (access_level |
if not in_array (access_level, cfg.keywords['id-access']) then -- exact match required |
||
table.insert( z.message_tail, { set_error( 'invalid_param_val', {access_param, access_level}, true ) } ); |
table.insert( z.message_tail, { set_error( 'invalid_param_val', {access_param, access_level}, true ) } ); |
||
access_level = nil; |
access_level = nil; -- invalid so unset |
||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
if not is_set(id_list[k]) then -- identifer access-level must have a matching identifier |
|||
⚫ | |||
⚫ | |||
access_level = access_level:lower(); |
|||
end |
end |
||
id_accesses_list[k] = access_level; |
id_accesses_list[k] = access_level; |