Module:Citation/CS1/Identifiers: Difference between revisions

m 1 revision imported: Importing CS1
m 1 revision imported: Fix for LUA errors
 
(2 intermediate revisions by 2 users not shown)
Line 25: Line 25:
as an aid to internationalizing identifier-label wikilinks, gets identifier article names from Wikidata.
as an aid to internationalizing identifier-label wikilinks, gets identifier article names from Wikidata.


returns :<lang code>:<article title> when <q> has an <article title> for <lang code>; nil else
returns w:<lang code>:<article title> when <q> has an <article title> for <lang code>; nil else. 'w:<lang code>'
ensures that sister project (like wiktionary) will link to the <lang code>.wikipedia article.


for identifiers that do not have q, returns nil
for identifiers that do not have <q>, returns nil


for wikis that do not have mw.wikibase installed, returns nil
for wikis that do not have mw.wikibase installed, returns nil
Line 44: Line 45:


if wd_article then
if wd_article then
wd_article = table.concat ({':', this_wiki_code, ':', wd_article}); -- interwiki-style link without brackets if taken from WD; leading colon required
wd_article = table.concat ({'w:', this_wiki_code, ':', wd_article}); -- interwiki-style link without brackets if taken from WD; leading 'w:' required
end
end


Line 51: Line 52:




--[[--------------------------< L I N K _ L A B E L _ M A K E >------------------------------------------------
--[[--------------------------< L A B E L _ L I N K _ M A K E >------------------------------------------------


common function to create identifier link label from handler table or from Wikidata
common function to create a link for an identifier label from handler table or from Wikidata


returns the first available of
returns the first available of:
1. redirect from local wiki's handler table (if enabled)
1. redirect from local wiki's handler table (if enabled)
2. Wikidata (if there is a Wikidata entry for this identifier in the local wiki's language)
2. Wikidata sitelink to the local language wikipedia article (if there is a Wikidata entry for this identifier in the local language)
3. label specified in the local wiki's handler table
3. link to wikipedia article specified in the local wiki's handler table
]]
]]


local function link_label_make (handler)
local function label_link_make (handler)
local wd_article;
local wd_article;
Line 99: Line 100:


return table.concat ({
return table.concat ({
make_wikilink (link_label_make (options), options.label), -- redirect, Wikidata link, or locally specified link (in that order)
make_wikilink (label_link_make (options), options.label), -- redirect, Wikidata link, or locally specified link (in that order)
options.separator or '&nbsp;',
options.separator or '&nbsp;',
ext_link
ext_link
Line 121: Line 122:
return table.concat (
return table.concat (
{
{
make_wikilink (link_label_make (options), options.label), -- wiki-link the identifier label
make_wikilink (label_link_make (options), options.label), -- wiki-link the identifier label
options.separator or '&nbsp;', -- add the separator
options.separator or '&nbsp;', -- add the separator
make_wikilink (
make_wikilink (
Line 291: Line 292:
return lccn;
return lccn;
end
end




Line 381: Line 382:
else
else
set_message ('err_class_ignored');
set_message ('err_class_ignored');
end
else -- class not set
if id:match ('^%d+') and options.CitationClass == 'arxiv' then -- new (post 2007) format; {{cite arxiv}} only
set_message ('maint_missing_class'); -- add maint cat
end
end
end
end
Line 710: Line 715:
]]
]]


local function isbn (options)
local function isbn (options_t)
local isbn_str = options.id;
local isbn_str = options_t.id;
local ignore_invalid = options.accept;
local ignore_invalid = options_t.accept;
local handler = options.handler;
local handler = options_t.handler;
local year = options_t.Year; -- when set, valid anchor_year; may have a disambiguator which must be removed


local function return_result (check, err_type) -- local function to handle the various returns
local function return_result (check, err_type) -- local function to handle the various returns
Line 722: Line 728:
else -- here when not ignoring
else -- here when not ignoring
if not check then -- and there is an error
if not check then -- and there is an error
options.coins_list_t['ISBN'] = nil; -- when error, unset so not included in COinS
options_t.coins_list_t['ISBN'] = nil; -- when error, unset so not included in COinS
set_message ('err_bad_isbn', err_type); -- set an error message
set_message ('err_bad_isbn', err_type); -- set an error message
return ISBN; -- return id text
return ISBN; -- return id text
Line 728: Line 734:
end
end
return ISBN; -- return id text
return ISBN; -- return id text
end
if year and not ignore_invalid then --
year = year:match ('%d%d%d%d?'); -- strip disambiguator if present
if year and (1965 > tonumber(year)) then -- <year> will be nil here when |year=n.d. or |year=nd
set_message ('err_invalid_isbn_date'); -- set an error message
return internal_link_id ({link = handler.link, label = handler.label, redirect = handler.redirect,
prefix = handler.prefix, id = isbn_str, separator = handler.separator});
end
end
end


Line 860: Line 875:
text = table.concat ( -- because no place to link to yet
text = table.concat ( -- because no place to link to yet
{
{
make_wikilink (link_label_make (handler), handler.label),
make_wikilink (label_link_make (handler), handler.label),
handler.separator,
handler.separator,
id_copy
id_copy
Line 1,058: Line 1,073:


local patterns = {
local patterns = {
'%d%d%d%d%d%d%d%d$', -- simple 8-digit identifier; these should be relatively rare
'^%d%d%d%d%d%d%d%d$', -- simple 8-digit identifier; these should be relatively rare
'^10%.1101/(20%d%d)%.(%d%d)%.(%d%d)%.%d%d%d%d%d%d%d%dv%d+$', -- y.m.d. date + 8-digit identifier + version (2020-01-01 and later)
'^10%.1101/(20%d%d)%.(%d%d)%.(%d%d)%.%d%d%d%d%d%d%d%dv%d+$', -- y.m.d. date + 8-digit identifier + version (2020-01-01 and later)
'^10%.1101/(20%d%d)%.(%d%d)%.(%d%d)%.%d%d%d%d%d%d%d%d$', -- y.m.d. date + 8-digit identifier (2020-01-01 and later)
'^10%.1101/(20%d%d)%.(%d%d)%.(%d%d)%.%d%d%d%d%d%d%d%d$', -- y.m.d. date + 8-digit identifier (2020-01-01 and later)
Line 1,279: Line 1,294:
text = table.concat ( -- still embargoed so no external link
text = table.concat ( -- still embargoed so no external link
{
{
make_wikilink (link_label_make (handler), handler.label),
make_wikilink (label_link_make (handler), handler.label),
handler.separator,
handler.separator,
id,
id,