Module:Citation/CS1/Identifiers: Difference between revisions
synch from sandbox;
(doi.org is not accepting fully url encoded urls; '/' character must not be encoded;) |
enwiki:Mediawiki>Trappist the monk (synch from sandbox;) |
||
Line 11: | Line 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 ''; | |||
Line 24: | Line 26: | ||
local url_string = options.id; | local url_string = options.id; | ||
local ext_link; | 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 | if options.encode == true or options.encode == nil then | ||
url_string = mw.uri.encode( url_string ); | url_string = mw.uri.encode( url_string ); | ||
end | end | ||
ext_link = mw.ustring.format ('[%s%s%s %s]', options.prefix, url_string, options.suffix or "", mw.text.nowiki(options.id)); | 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 | if is_set(options.access) then | ||
ext_link = substitute (cfg.presentation['access-signal'], { | ext_link = substitute (cfg.presentation['ext-link-access-signal'], {cfg.presentation[options.access].class, cfg.presentation[options.access].title, ext_link}); -- add the free-to-read / paywall lock | ||
end | 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) then | |||
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 ({ | return table.concat ({ | ||
make_wikilink (options.link, options.label), | make_wikilink (wd_article or options.link, options.label), -- wikidata link or locally specified | ||
options.separator or ' ', | options.separator or ' ', | ||
ext_link | ext_link | ||
Line 186: | Line 200: | ||
where: | where: | ||
<archive> is a string of alpha characters - may be hyphenated; no other punctuation | <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 | <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 | <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 | first digit of YY for this form can only 9 and 0 | ||
Line 209: | Line 223: | ||
local handler = cfg.id_handlers['ARXIV']; | local handler = cfg.id_handlers['ARXIV']; | ||
local year, month, version; | local year, month, version; | ||
local err_cat = | local err_cat = false; -- assume no error message | ||
local text; | 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 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 | ||
Line 218: | Line 232: | ||
if ((not (90 < year or 8 > year)) or (1 > month or 12 < month)) or -- if invalid year or invalid month | 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? | ((91 == year and 7 > month) or (7 == year and 3 < month)) then -- if years ok, are starting and ending months ok? | ||
err_cat = | err_cat = true; -- flag for error message | ||
end | 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 | 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]*$"); | year, month = id:match("^(%d%d)([01]%d)%.%d%d%d%d[v%d]*$"); | ||
Line 226: | Line 241: | ||
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) | 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)? | ((7 == year) and (4 > month)) then --or -- when year is 07, is month invalid (before April)? | ||
err_cat = | err_cat = true; -- flag for error message | ||
end | 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 | 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]*$"); | year, month = id:match("^(%d%d)([01]%d)%.%d%d%d%d%d[v%d]*$"); | ||
Line 233: | Line 249: | ||
month = tonumber(month); | 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) | if ((15 > year) or (1 > month or 12 < month)) then -- is year invalid or is month invalid? (doesn't test for future years) | ||
err_cat = true; -- flag for error message | |||
end | end | ||
else | else | ||
err_cat = | err_cat = true; -- not a recognized format; flag for error message | ||
end | end | ||
text = external_link_id({link = handler.link, label = handler.label, | 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; | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, access=handler.access}) .. err_cat; | ||
if is_set (class) then | if is_set (class) then | ||
if id:match ('^%d+') then | |||
text = table.concat ({text, ' [[//arxiv.org/archive/', class, ' ', class, ']]'}); -- external link within square brackets, not wikilink | |||
else | |||
text = table.concat ({text, ' ', set_error ('class_ignored')}); | |||
end | |||
end | end | ||
return text | return text; | ||
end | end | ||
Line 276: | Line 297: | ||
local year; | local year; | ||
local text = external_link_id({link=handler.link, label=handler.label, | 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, | prefix=handler.prefix, id=id, separator=handler.separator, encode=handler.encode, | ||
access=access}); | access=access}); | ||
Line 321: | Line 342: | ||
end | end | ||
return external_link_id({link = handler.link, label = handler.label, | return external_link_id({link = handler.link, label = handler.label, q = handler.q, | ||
prefix=handler.prefix,id=id,separator=handler.separator, | prefix=handler.prefix,id=id,separator=handler.separator, | ||
encode=handler.encode, access=handler.access}) .. err_cat; | encode=handler.encode, access=handler.access}) .. err_cat; | ||
Line 338: | Line 359: | ||
local matched; | local matched; | ||
local text = external_link_id({link=handler.link, label=handler.label, | 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, | prefix=handler.prefix, id=id, separator=handler.separator, encode=handler.encode, | ||
access=handler.access}); | access=handler.access}); | ||
Line 381: | Line 402: | ||
inactive = " (" .. cfg.messages['inactive'] .. " " .. inactive .. ")" | inactive = " (" .. cfg.messages['inactive'] .. " " .. inactive .. ")" | ||
end | end | ||
text = external_link_id({link = handler.link, label = handler.label, | 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 '') | ||
Line 412: | Line 433: | ||
local handler = cfg.id_handlers['HDL']; | local handler = cfg.id_handlers['HDL']; | ||
local text = external_link_id({link = handler.link, label = handler.label, | 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}) | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, access=access}) | ||
Line 492: | Line 513: | ||
local handler = cfg.id_handlers['ASIN']; | local handler = cfg.id_handlers['ASIN']; | ||
return external_link_id({link=handler.link, | return external_link_id({link=handler.link, | ||
label=handler.label, prefix=handler.prefix .. domain .. "/dp/", | label=handler.label, q = handler.q, prefix=handler.prefix .. domain .. "/dp/", | ||
id=id, encode=handler.encode, separator = handler.separator}) .. err_cat; | id=id, encode=handler.encode, separator = handler.separator}) .. err_cat; | ||
end | end | ||
Line 579: | Line 600: | ||
end | end | ||
text = external_link_id({link = handler.link, label = handler.label, | text = external_link_id({link = handler.link, label = handler.label, q = handler.q, | ||
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) | ||
Line 615: | Line 636: | ||
end | end | ||
return external_link_id({link = handler.link, label = handler.label, | 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; | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat; | ||
end | end | ||
Line 672: | Line 693: | ||
end | end | ||
return external_link_id({link = handler.link, label = handler.label, | 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; | prefix=handler.prefix,id=lccn,separator=handler.separator, encode=handler.encode}) .. err_cat; | ||
end | end | ||
Line 704: | Line 725: | ||
end | end | ||
return external_link_id({link = handler.link, label = handler.label, | 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; | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat; | ||
end | end | ||
Line 744: | Line 765: | ||
end | end | ||
local text = external_link_id({link=handler.link, label=handler.label, | 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; | prefix=handler.prefix, id=id, separator=handler.separator, encode=handler.encode}) .. err_msg; | ||
Line 765: | Line 786: | ||
if not is_set (ident) then -- if malformed return an error | if not is_set (ident) then -- if malformed return an error | ||
return external_link_id({link=handler.link, label=handler.label, | return external_link_id({link=handler.link, label=handler.label, q = handler.q, | ||
prefix=handler.prefix .. 'OL', | prefix=handler.prefix .. 'OL', | ||
id=id, separator=handler.separator, encode = handler.encode, | id=id, separator=handler.separator, encode = handler.encode, | ||
Line 774: | Line 795: | ||
if ( code == "A" ) then | if ( code == "A" ) then | ||
return external_link_id({link=handler.link, label=handler.label, | return external_link_id({link=handler.link, label=handler.label, q = handler.q, | ||
prefix=handler.prefix .. 'authors/OL', | prefix=handler.prefix .. 'authors/OL', | ||
id=id, separator=handler.separator, encode = handler.encode, | id=id, separator=handler.separator, encode = handler.encode, | ||
Line 781: | Line 802: | ||
if ( code == "M" ) then | if ( code == "M" ) then | ||
return external_link_id({link=handler.link, label=handler.label, | return external_link_id({link=handler.link, label=handler.label, q = handler.q, | ||
prefix=handler.prefix .. 'books/OL', | prefix=handler.prefix .. 'books/OL', | ||
id=id, separator=handler.separator, encode = handler.encode, | id=id, separator=handler.separator, encode = handler.encode, | ||
Line 788: | Line 809: | ||
if ( code == "W" ) then | if ( code == "W" ) then | ||
return external_link_id({link=handler.link, label=handler.label, | return external_link_id({link=handler.link, label=handler.label, q = handler.q, | ||
prefix=handler.prefix .. 'works/OL', | prefix=handler.prefix .. 'works/OL', | ||
id=id, separator=handler.separator, encode = handler.encode, | id=id, separator=handler.separator, encode = handler.encode, | ||
Line 848: | Line 869: | ||
}); | }); | ||
else | else | ||
text = external_link_id({link = handler.link, label = handler.label, -- no embargo date or embargo has expired, ok to link to article | 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; | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, access=handler.access}) .. err_cat; | ||
end | end | ||
Line 877: | Line 898: | ||
end | end | ||
return external_link_id({link = handler.link, label = handler.label, | 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; | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat; | ||
end | end | ||
Line 910: | Line 931: | ||
end | end | ||
text = external_link_id({link = handler.link, label = handler.label, | 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; | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode, access=handler.access}) .. err_cat; | ||
Line 927: | Line 948: | ||
local handler = cfg.id_handlers['USENETID']; | local handler = cfg.id_handlers['USENETID']; | ||
local text = external_link_id({link = handler.link, label = handler.label, | 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}) | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) | ||
Line 963: | Line 984: | ||
end | end | ||
return external_link_id({link = handler.link, label = handler.label, | 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; | prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat; | ||
end | end |