Module:Citation/CS1/Identifiers: Difference between revisions

Synch from sandbox;
m (1 revision imported: Help:Footnotes)
(Synch from sandbox;)
Line 28:
ext_link = mw.ustring.format ('[%s%s%s %s]', options.prefix, url_string, options.suffix or "", mw.text.nowiki(options.id));
if is_set(options.freeaccess) then
ext_link = substitute (cfg.presentation['free to read'options.access], ext_link); -- add the free-to-read / paywall lock
end
Line 147:
local text;
local valid_ismn = true;
local id_copy;
 
id_copy = id; -- save a copy because this testing is destructive
id=id:gsub( "[%s-–]", "" ); -- strip spaces, hyphens, and endashes from the ismn
 
Line 159 ⟶ 161:
-- prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode})
text="[[" .. handler.link .. "|" .. handler.label .. "]]" .. handler.separator .. idid_copy; -- because no place to link to yet
 
if false == valid_ismn then
Line 323 ⟶ 325:
 
text = external_link_id({link = handler.link, label = handler.label,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, freeaccess=handler.freeaccess}) .. err_cat;
 
if is_set (class) then
Line 334 ⟶ 336:
end
 
--[[--------------------------< B I O R X I V >-----------------------------------------------------------------
 
Format bioRxiv id and do simple error checking. BiorXiv ids are exactly 6 digits.
The bioRxiv id is the number following the last slash in the bioRxiv-issued DOI:
http://dx.doi.org/10.1101/078733 -> 078733
 
]]
 
local function biorxiv(id)
local handler = cfg.id_handlers['BIORXIV'];
local err_cat = ''; -- presume that bioRxiv id is valid
if nil == id:match("^%d%d%d%d%d%d$") then -- if bioRxiv id has anything but six digits
err_cat = ' ' .. set_error( 'bad_biorxiv'); -- set an error message
end
return external_link_id({link = handler.link, label = handler.label,
prefix=handler.prefix,id=id,separator=handler.separator,
encode=handler.encode, access=handler.access}) .. err_cat;
end
 
--[[--------------------------< N O R M A L I Z E _ L C C N >--------------------------------------------------
Line 499 ⟶ 521:
 
local function pmc(id, embargo)
local test_limit = 50000006000000; -- update this value as PMCs approach
local handler = cfg.id_handlers['PMC'];
local err_cat = ''; -- presume that PMC is valid
Line 515 ⟶ 537:
if is_set (embargo) then -- is PMC is still embargoed?
text="[[" .. handler.link .. "|" .. handler.label .. "]]:" .. handler.separator .. id .. err_cat; -- still embargoed so no external link
else
text = external_link_id({link = handler.link, label = handler.label, -- no embargo date or embargo has expired, ok to link to article
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, freeaccess=handler.freeaccess}) .. err_cat;
end
return text;
Line 541 ⟶ 563:
]]
 
local function doi(id, inactive, access)
local cat = ""
local handler = cfg.id_handlers['DOI'];
Line 557 ⟶ 579:
else
text = external_link_id({link = handler.link, label = handler.label,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, access=access})
inactive = ""
end
Line 585 ⟶ 607:
]]
 
local function hdl(id, access)
local handler = cfg.id_handlers['HDL'];
local text = external_link_id({link = handler.link, label = handler.label,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, access=access})
 
if nil == id:match("^[^%s–]-/[^%s–]-[^%.,]$") then -- hdl must contain a fwd slash, must not contain spaces, endashes, and must not end with period or comma
Line 604 ⟶ 626:
]]
 
local function openlibrary(id, access)
local code = id:match("^%d+([AMW])$"); -- only digits followed by 'A', 'M', or 'W'
local handler = cfg.id_handlers['OL'];
Line 611 ⟶ 633:
return external_link_id({link=handler.link, label=handler.label,
prefix=handler.prefix .. 'authors/OL',
id=id, separator=handler.separator, encode = handler.encode}),
access = access})
elseif ( code == "M" ) then
return external_link_id({link=handler.link, label=handler.label,
prefix=handler.prefix .. 'books/OL',
id=id, separator=handler.separator, encode = handler.encode}),
access = access})
elseif ( code == "W" ) then
return external_link_id({link=handler.link, label=handler.label,
prefix=handler.prefix .. 'works/OL',
id=id, separator=handler.separator, encode = handler.encode}),
access = access})
else
return external_link_id({link=handler.link, label=handler.label,
prefix=handler.prefix .. 'OL',
id=id, separator=handler.separator, encode = handler.encode}) .. ' ' .. set_error( 'bad_ol' );,
access = access}) .. ' ' .. set_error( 'bad_ol' );
end
end
Line 710 ⟶ 736:
]]
 
local function bibcode (id, access)
local handler = cfg.id_handlers['BIBCODE'];
local err_type;
Line 716 ⟶ 742:
 
local text = external_link_id({link=handler.link, label=handler.label,
prefix=handler.prefix, id=id, separator=handler.separator, encode=handler.encode});,
access=access});
if 19 ~= id:len() then
Line 742 ⟶ 769:
end
 
--[[--------------------------< C I T E S E E R X >------------------------------------------------------------
 
CiteSeerX use their own notion of "doi" (not to be confused with the identifiers resolved via doi.org).
 
The description of the structure of this identifier can be found at Help_talk:Citation_Style_1#CiteSeerX_id_structure
]]
 
local function citeseerx (id)
local handler = cfg.id_handlers['CITESEERX'];
local matched;
local text = external_link_id({link=handler.link, label=handler.label,
prefix=handler.prefix, id=id, separator=handler.separator, encode=handler.encode,
access=handler.access});
matched = id:match ("^10%.1%.1%.[1-9]%d?%d?%d?%.[1-9]%d?%d?%d?$");
if not matched then
text = text .. ' ' .. set_error( 'bad_citeseerx' );
end
return text;
end
 
--[[--------------------------< B U I L D _ I D _ L I S T >--------------------------------------------------------
Line 759 ⟶ 807:
for k, v in pairs( id_list ) do -- k is uc identifier name as index to cfg.id_handlers; e.g. cfg.id_handlers['ISBN'], v is a table
-- fallback to read-only cfg
handler = setmetatable( { ['id'] = v, ['access'] = options.IdAccessLevels[k] }, fallback(k) );
 
if handler.mode == 'external' then
Line 769 ⟶ 818:
error( cfg.messages['unknown_ID_mode'] );
elseif k == 'BIBCODE' then
table.insert( new_list, {handler.label, bibcode( v, handler.access ) } );
elseif k == 'BIORXIV' then
table.insert( new_list, {handler.label, biorxiv( v ) } );
elseif k == 'CITESEERX' then
table.insert( new_list, {handler.label, citeseerx( v ) } );
elseif k == 'DOI' then
table.insert( new_list, {handler.label, doi( v, options.DoiBroken, handler.access ) } );
elseif k == 'HDL' then
table.insert( new_list, {handler.label, hdl( v, handler.access ) } );
elseif k == 'ARXIV' then
table.insert( new_list, {handler.label, arxiv( v, options.Class ) } );
Line 781 ⟶ 834:
table.insert( new_list, {handler.label, lccn( v ) } );
elseif k == 'OL' or k == 'OLA' then
table.insert( new_list, {handler.label, openlibrary( v, handler.access ) } );
elseif k == 'PMC' then
table.insert( new_list, {handler.label, pmc( v, options.Embargo ) } );
Line 847 ⟶ 900:
end
return id_list;
end
 
--[[--------------------------< E X T R A C T _ I D _ A C C E S S _ L E V E L S >--------------------------------------
 
Fetches custom id access levels from arguments using configuration settings.
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.
 
]]
 
local function extract_id_access_levels( args, id_list )
local id_accesses_list = {};
for k, v in pairs( cfg.id_handlers ) do
local access_param = v.custom_access;
local k_lower = string.lower(k);
if is_set(access_param) then
local access_level = args[access_param];
if is_set(access_level) then
if not in_array (access_level:lower(), cfg.keywords['id-access']) then
table.insert( z.message_tail, { set_error( 'invalid_param_val', {access_param, access_level}, true ) } );
access_level = nil;
end
if not is_set(id_list[k]) then
table.insert( z.message_tail, { set_error( 'param_access_requires_param', {k_lower}, true ) } );
end
if is_set(access_level) then
access_level = access_level:lower();
end
id_accesses_list[k] = access_level;
end
end
end
return id_accesses_list;
end
 
Line 874 ⟶ 960:
build_id_list = build_id_list,
extract_ids = extract_ids,
extract_id_access_levels = extract_id_access_levels,
is_embargoed = is_embargoed;
set_selected_modules = set_selected_modules;
Anonymous user