Changes
sync from sandbox;
--[[--------------------------< F O R W A R D D E C L A R A T I O N S >--------------------------------------
local url_string = options.id;
local ext_link;
local this_wiki_code; -- wikipedia subdomain; 'en' for en.wikipedia.org
local wd_article; -- article title from wikidata
if options.encode == true or options.encode == nil then
url_string = mw.uri.encode( url_string );
end
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.access) then
ext_link = substitute (cfg.presentation['ext-link-access-signal'], {ext_linkcfg.presentation[options.access].class, cfg.presentation[options.access].title, ext_link}); -- add the free-to-read / paywall lock
end
this_wiki_code = mw.language.getContentLanguage():getCode(); -- get this wikipedia's language code (subdomain)
if string.match (mw.site.server, 'wikidata') then
this_wiki_code = mw.getCurrentFrame():preprocess('{{int:lang}}'); -- on wikidata so use interface language setting instead
end
if is_set (options.q) and mw.wikibase then -- wikibase test here avoids script errors in third party wikis that aren't using mw.wikibase extension
wd_article = mw.wikibase.getEntity (options.q):getSitelink (this_wiki_code .. 'wiki'); -- fetch article title from wd
if wd_article then
wd_article = table.concat ({':', this_wiki_code, ':', wd_article}); -- make interwiki link if taken from wd; leading colon required
end
end
return table.concat ({
make_wikilink (wd_article or options.link, options.label), -- wikidata link or locally specified
options.separator or ' ',
ext_link
local function internal_link_id(options)
local id = mw.ustring.gsub (options.id, '%d', cfg.date_names.local_digits); -- translate 'local' digits to Western 0-9
return table.concat (
{
options.prefix,
options.suffix or ''
}),
substitute (cfg.presentation['bdi'], {'', mw.text.nowiki (options.id)}) -- bdi tags to prevent Latn script identifiers from being reversed at rtl language wikis ); -- nowiki because MediaWiki still has magic links for ISBN and the like; TODO: is it really required?
});
end
where:
<archive> is a string of alpha characters - may be hyphenated; no other punctuation
<class> is a string of alpha characters - may be hyphenated; no other punctuation; not the same as |class= parameter which is not supported in this form
<date code> is four digits in the form YYMM where YY is the last two digits of the four-digit year and MM is the month number January = 01
first digit of YY for this form can only 9 and 0
local handler = cfg.id_handlers['ARXIV'];
local year, month, version;
local err_cat = ''false; -- assume no error message local text; -- output text
if id:match("^%a[%a%.%-]+/[90]%d[01]%d%d%d%d$") or id:match("^%a[%a%.%-]+/[90]%d[01]%d%d%d%dv%d+$") then -- test for the 9108-0703 format w/ & w/o version
if ((not (90 < year or 8 > year)) or (1 > month or 12 < month)) or -- if invalid year or invalid month
((91 == year and 7 > month) or (7 == year and 3 < month)) then -- if years ok, are starting and ending months ok?
err_cat = ' ' .. set_error( 'bad_arxiv' )true; -- set flag for error message
end
elseif id:match("^%d%d[01]%d%.%d%d%d%d$") or id:match("^%d%d[01]%d%.%d%d%d%dv%d+$") then -- test for the 0704-1412 w/ & w/o version
year, month = id:match("^(%d%d)([01]%d)%.%d%d%d%d[v%d]*$");
if ((7 > year) or (14 < year) or (1 > month or 12 < month)) or -- is year invalid or is month invalid? (doesn't test for future years)
((7 == year) and (4 > month)) then --or -- when year is 07, is month invalid (before April)?
err_cat = ' ' .. set_error( 'bad_arxiv' )true; -- set flag for error message
end
elseif id:match("^%d%d[01]%d%.%d%d%d%d%d$") or id:match("^%d%d[01]%d%.%d%d%d%d%dv%d+$") then -- test for the 1501- format w/ & w/o version
year, month = id:match("^(%d%d)([01]%d)%.%d%d%d%d%d[v%d]*$");
month = tonumber(month);
if ((15 > year) or (1 > month or 12 < month)) then -- is year invalid or is month invalid? (doesn't test for future years)
end
else
err_cat = ' ' .. set_error( 'bad_arxiv' )true; -- arXiv id doesn't match any not a recognized format; flag for error message
end
err_cat = err_cat and table.concat ({' ', set_error ('bad_arxiv')}) or ''; -- set error message if flag is true 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=handler.access}) .. err_cat;
if is_set (class) then
end
end
1–4 must be digits and must represent a year in the range of 1000 – next year
5 must be a letter
9–18 must be letter, digit, or dot
19 must be a letter or dot
local year;
local 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});
err_type = 'length';
else
year = id:match ("^(%d%d%d%d)[%a][%aw&%.][%aw&%.%d][%aw&%.%d][%a%d%w.]+[%a%.]$") --
if not year then -- if nil then no pattern match
err_type = 'value'; -- so value error
end
return external_link_id({link = handler.link, label = handler.label, q = handler.q,
prefix=handler.prefix,id=id,separator=handler.separator,
encode=handler.encode, access=handler.access}) .. err_cat;
local matched;
local 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=handler.access});
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_month, good; if is_set(inactive_year) then tableif 4 < inactive:len() then -- inactive date has more than just a year (could be anything) local lang_obj = mw.insertgetContentLanguage(); -- get a language object for this wiki good, inactive_month = pcall ( zlang_obj.error_categoriesformatDate, lang_obj, 'F', "Pages with DOIs inactive since " .. inactive_year );-- try to get the month name from the inactive date if not good then inactive_month = nil; -- something went wrong so make sure this is unset end end
else
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 elseif is_set(inactive_year) then table.insert( z.error_categories, 'Pages with DOIs inactive as of ' .. inactive_year); else table.insert( z.error_categories, 'Pages with inactive DOIs'); -- when inactive doesn't contain a recognizable date end inactive = " (" .. cfg.messages['inactive'] .. " " ' ' .. inactive .. "')" ';
end
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 '')
if nil == id:match("^10%.[^%s–]-/[^%s–]-[^%.,]$") then 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( 'bad_doi' );
end
local handler = cfg.id_handlers['HDL'];
local 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})
local handler = cfg.id_handlers['ASIN'];
return external_link_id({link=handler.link,
label=handler.label, q = handler.q, prefix=handler.prefix .. domain .. "/dp/",
id=id, encode=handler.encode, separator = handler.separator}) .. err_cat;
end
end
text = external_link_id({link = handler.link, label = handler.label, q = handler.q,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode})
end
return external_link_id({link = handler.link, label = handler.label, q = handler.q,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat;
end
end
return external_link_id({link = handler.link, label = handler.label, q = handler.q,
prefix=handler.prefix,id=lccn,separator=handler.separator, encode=handler.encode}) .. err_cat;
end
end
return external_link_id({link = handler.link, label = handler.label, q = handler.q,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat;
end
--[[--------------------------< O C L C >----------------------------------------------------------------------
Validate and format an oclc id. https://www.oclc.org/batchload/controlnumber.en.html {{dead link}}archived at: https://web.archive.org/web/20161228233804/https://www.oclc.org/batchload/controlnumber.en.html
]]
end
local text = external_link_id({link=handler.link, label=handler.label, q = handler.q,
prefix=handler.prefix, id=id, separator=handler.separator, encode=handler.encode}) .. err_msg;
if not is_set (ident) then -- if malformed return an error
return external_link_id({link=handler.link, label=handler.label, q = handler.q,
prefix=handler.prefix .. 'OL',
id=id, separator=handler.separator, encode = handler.encode,
if ( code == "A" ) then
return external_link_id({link=handler.link, label=handler.label, q = handler.q,
prefix=handler.prefix .. 'authors/OL',
id=id, separator=handler.separator, encode = handler.encode,
if ( code == "M" ) then
return external_link_id({link=handler.link, label=handler.label, q = handler.q,
prefix=handler.prefix .. 'books/OL',
id=id, separator=handler.separator, encode = handler.encode,
if ( code == "W" ) then
return external_link_id({link=handler.link, label=handler.label, q = handler.q,
prefix=handler.prefix .. 'works/OL',
id=id, separator=handler.separator, encode = handler.encode,
local function pmc(id, embargo)
local test_limit = 65000007000000; -- update this value as PMCs approach
local handler = cfg.id_handlers['PMC'];
local err_cat = ''; -- presume that PMC is valid
});
else
text = external_link_id({link = handler.link, label = handler.label, q = handler.q, -- 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}) .. err_cat;
end
end
return external_link_id({link = handler.link, label = handler.label, q = handler.q,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat;
end
end
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=handler.access}) .. err_cat;
local handler = cfg.id_handlers['USENETID'];
local text = external_link_id({link = handler.link, label = handler.label, q = handler.q,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode})
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
]]
local function zbl (id)
local handler = cfg.id_handlers['ZBL'];
local err_cat = '';
end
return external_link_id({link = handler.link, label = handler.label, q = handler.q,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat;
end
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.
access-level values must match the case used in cfg.keywords['id-access'] (lowercase unless there is some special reason for something else)
]]
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); -- name of identifier's access-level parameter
if is_set(access_param) then
local access_level = args[access_param]; -- get the assigned value if there is one if is_set(access_level) then if not in_array (access_level:lower(), cfg.keywords['id-access']) then-- exact match required
table.insert( z.message_tail, { set_error( 'invalid_param_val', {access_param, access_level}, true ) } );
access_level = nil; -- invalid so unset
end
if not is_set(id_list[k]) then -- identifer access-level must have a matching identifier table.insert( z.message_tail, { set_error( 'param_access_requires_param', {k_lowerk:lower()}, true ) } ); end if is_set(access_level) then access_level = access_level:lower-- param name is uppercase in cfg.id_handlers (k);lowercase for error message
end
id_accesses_list[k] = access_level;
end
--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
]]
return {