Modul:Citation/CS1/Identifiers: Redaktələr arasındakı fərq

Səhifəni ' --[[--------------------------< F O R W A R D D E C L A R A T I O N S >-------------------------------------- ]] local is_set, in_array, set_error, select_one, add_mai...' ilə yarat
 
Redaktənin izahı yoxdur
Sətir 1: Sətir 1:
local identifiers = {};


--[[--------------------------< F O R W A R D  D E C L A R A T I O N S >--------------------------------------
--[[--------------------------< F O R W A R D  D E C L A R A T I O N S >--------------------------------------
Sətir 8: Sətir 11:


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 '';




Sətir 39: Sətir 44:
end
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
if is_set (options.q) then
wd_article = mw.wikibase.getSitelink (options.q, this_wiki_code .. 'wiki'); -- fetch article title from wd
wd_article = mw.wikibase.getEntity (options.q):getSitelink (this_wiki_code .. 'wiki'); -- fetch article title from wd
if wd_article then
if wd_article then
wd_article = table.concat ({':', this_wiki_code, ':', wd_article}); -- make interwiki link if taken from wd; leading colon required
wd_article = table.concat ({':', this_wiki_code, ':', wd_article}); -- make interwiki link if taken from wd; leading colon required
Sətir 61: Sətir 66:


local function internal_link_id(options)
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 (
return table.concat (
Sətir 71: Sətir 75:
{
{
options.prefix,
options.prefix,
id, -- translated to western digits
options.id,
options.suffix or ''
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
mw.text.nowiki (options.id)
); -- nowiki because MediaWiki still has magic links for ISBN and the like; TODO: is it really required?
);
});
});
end
end
Sətir 281: Sətir 285:
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; &. )
6 must be letter, 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
Sətir 299: Sətir 304:
err_type = 'length';
err_type = 'length';
else
else
year = id:match ("^(%d%d%d%d)[%a][%w&%.][%w&%.][%w&%.][%w.]+[%a%.]$") --  
year = id:match ("^(%d%d%d%d)[%a][%a&%.][%a&%.%d][%a&%.%d][%a%d%.]+[%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
Sətir 390: Sətir 395:
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 is_set(inactive_year) then
 
-- table.insert( z.error_categories, "Pages with DOIs inactive since " .. inactive_year );
if is_set (inactive_year) then
-- else
if 4 < inactive:len() then -- inactive date has more than just a year (could be anything)
-- table.insert( z.error_categories, "Pages with inactive DOIs" ); -- when inactive doesn't contain a recognizable year
local lang_obj = mw.getContentLanguage(); -- get a language object for this wiki
-- end
good, inactive_month = pcall (lang_obj.formatDate, lang_obj, 'F', inactive); -- try to get the month name from the inactive date
table.insert( z.error_categories, "Ошибки CS1: прочее|DOI" );
if not good then
inactive = " (" .. cfg.messages['inactive'] .. " " .. inactive .. ")"
inactive_month = nil; -- something went wrong so make sure this is unset
end
end
else
inactive_year = nil; -- |doi-broken= has something but it isn't a date
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
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–]-[^%.,]$") 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
if nil == id:match("^10%.[^%s–]-/[^%s–]-[^%.,]$") then -- 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' );
cat = ' ' .. set_error ('bad_doi');
end
end


Sətir 745: Sətir 733:
--[[--------------------------< O C L C >----------------------------------------------------------------------
--[[--------------------------< O C L C >----------------------------------------------------------------------


Validate and format an oclc id.  https://www.oclc.org/batchload/controlnumber.en.html {{dead link}}
Validate and format an oclc id.  https://www.oclc.org/batchload/controlnumber.en.html
archived at: https://web.archive.org/web/20161228233804/https://www.oclc.org/batchload/controlnumber.en.html


]]
]]
Sətir 849: Sətir 836:


local function pmc(id, embargo)
local function pmc(id, embargo)
local test_limit = 7000000; -- update this value as PMCs approach
local test_limit = 8000000; -- 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
Sətir 899: Sətir 886:


local function pmid(id)
local function pmid(id)
local test_limit = 32000000; -- update this value as PMIDs approach
local test_limit = 33000000; -- update this value as PMIDs approach
local handler = cfg.id_handlers['PMID'];
local handler = cfg.id_handlers['PMID'];
local err_cat = ''; -- presume that PMID is valid
local err_cat = ''; -- presume that PMID is valid
Sətir 976: Sətir 963:


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


]]
]]
Sətir 985: Sətir 968:
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?
id_num = id:match ('^[Zz][Bb][Ll](.*)$'); -- identifier with zbl prefix; extract identifier
add_maint_cat ('zbl'); -- yes, add maint cat
 
elseif not id:match('^%d?%d?%d?%d%.%d%d%d%d%d$') then -- not temporary, is it normal format?
if is_set (id_num) then
err_cat = ' ' .. set_error( 'bad_zbl' ); -- no, set an error message
add_maint_cat ('zbl_format');
else -- plain number without zbl prefix
id_num = id; -- if here id does not have prefix
end
 
if id_num:match('^%d?%d?%d?%d%.%d%d%d%d%d$') then
id = id_num; -- id matches pattern
else
err_cat = ' ' .. set_error( 'bad_zbl' ); -- set an error message
end
end
Sətir 1.049: Sətir 1.041:
if is_set(options.IgnoreISBN) then -- ISBN is invalid; if |ignore-isbn-error= set
if is_set(options.IgnoreISBN) then -- ISBN is invalid; if |ignore-isbn-error= set
add_maint_cat ('ignore_isbn_err'); -- ad a maint category
add_maint_cat ('ignore_isbn_err'); -- ad a maint category
else
ISBN = ISBN .. set_error( 'bad_isbn', {err_type}, false, " ", "" ); -- else display an error message
end
end
elseif is_set(options.IgnoreISBN) then -- ISBN is OK; if |ignore-isbn-error= set
elseif is_set(options.IgnoreISBN) then -- ISBN is OK; if |ignore-isbn-error= set
Sətir 1.119: Sətir 1.113:
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)


]]
]]
Sətir 1.127: Sətir 1.119:
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; -- name of identifier's access-level parameter
local access_param = v.custom_access;
local k_lower = string.lower(k);
if is_set(access_param) then
if is_set(access_param) then
local access_level = args[access_param]; -- get the assigned value if there is one
local access_level = args[access_param];
if is_set (access_level) then
if is_set(access_level) then
if not in_array (access_level, cfg.keywords['id-access']) then -- exact match required
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 ) } );
table.insert( z.message_tail, { set_error( 'invalid_param_val', {access_param, access_level}, true ) } );
access_level = nil; -- invalid so unset
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
end
if not is_set(id_list[k]) then -- identifer access-level must have a matching identifier
if is_set(access_level) then
table.insert( z.message_tail, { set_error( 'param_access_requires_param', {k:lower()}, true ) } ); -- param name is uppercase in cfg.id_handlers (k); lowercase for error message
access_level = access_level:lower();
end
end
id_accesses_list[k] = access_level;
id_accesses_list[k] = access_level;
Sətir 1.166: Sətir 1.162:
end
end


--[[--------------------------< E X P O R T E D  F U N C T I O N S >------------------------------------------
]]


return {
return {