Module:Harvc: Difference between revisions

Content deleted Content added
support for YYYY–YY;
sync from sandbox; harv link error checking;
Line 1:
require('Module:No globals')
local citerefs = mw.loadData ('Module:Sandbox/trappist_the_monk/harv_link_test').citerefs;
 
local code_open_tag = '<code styleclass="color: inheritcs1-code">'; -- background:cs1-code inherit;class border:defined inherit;in paddingModule: inherit;">';Citation/CS1/styles.css
local lock_icons = { --icon classes are defined in Module:Citation/CS1/styles.css
-- ['free'] = {'cs1-lock-free', 'Freely accessible'}, -- not supported for urls
['registration'] = {'cs1-lock-registration', 'Free registration required'},
['limited'] = {'cs1-lock-limited', 'Free access subject to limited trial, subscription normally required'},
['subscription'] = {'cs1-lock-subscription', 'Paid subscription required'},
}
 
 
--[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------
 
look for citeref (name-list and year) in citerefs
 
the 'no target' error may be suppressed with |ignore-err=yes when target cannot be found because target is inside a template that wraps
a citation template; 'multiple targets' error may not be suppressed
 
]]
 
local function target_check (citeref, ignore)
local number = citerefs[citeref]; -- nil when citeref not in list; else a number
local msg;
local category;
 
if not number then
if ignore then
return ''; -- if ignore is true then no message, no category
end
msg = 'no target: ' .. citeref; -- target not found in this article
elseif 1 < number then
msg = 'multiple targets: ' .. citeref; -- more than one target in this article
end
 
category = 0 == mw.title.getCurrentTitle().namespace and '[[Category:Harv and Sfn template errors]]' or ''; -- only categorize in article space
 
--TODO: use this version until initial testing begins with the live module
-- return msg and ' <span class="error harv-error" style="display: inline; font-size:100%">Harv error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
--TODO: use this version when initial testing begins with the live module
return msg and ' <span class="error harv-error" style="display: none; font-size:100%">Harv error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
 
end
 
 
Line 140 ⟶ 173:
-- form the CITEREF anchor
if is_set (args.id) then
args.id = mw.uri.anchorEncode (args.id)
span_open_tag = '<span id="' .. args.id .. '" class="citation">'; -- for use when contributor name is same as source name
else
span_open_taglocal citeref = '<span id="CITEREF' .. table.concat (args.citeref) .. (is_set (args['anchor-year']) and args['anchor-year'] or args.year) .. '" class="citation">';
citeref = mw.uri.anchorEncode (citeref);
span_open_tag = '<span id="' .. citeref .. '" class="citation">';
end
Line 220 ⟶ 256:
 
--assemble CITEREF wikilink
local name_date;
source = "[[#CITEREF" .. mw.uri.anchorEncode(table.concat ({args.in1, args.in2, args.in3, args.in4, args.year})) .. "|" .. source .. "]]";
local target_err_msg;
if '' ~= args.ref then
name_date = mw.uri.anchorEncode (args.ref)
else
source name_date = "[[#CITEREF" .. mw.uri.anchorEncode(table.concat ({'CITEREF', args.in1, args.in2, args.in3, args.in4, args.year})) .. "|" .. source .. "]]";
end
target_err_msg = target_check (name_date, args.ignore); -- see if there is a target for this name_date
source = '[[#' .. name_date .. "|" .. source .. "]]";
 
--combine contribution with url to make external link
Line 239 ⟶ 285:
end
end
 
 
 
end
 
Line 271 ⟶ 314:
 
-- and put it all together
result = span_open_tag .. contributors .. ' "' .. args.contribution .. '"' .. args.sepc .. in_text .. source .. args.p .. args.ps .. args.err_msg .. target_err_msg .. '</span>' .. args.err_msg;
 
return result;
Line 342 ⟶ 385:
args.pp = pframe.args.pp or '';
args.loc = pframe.args.loc or '';
args.ref = pframe.args.ref or pframe.args.Ref or ''; -- used to match |ref=<text> in cs1|2 source template
args.ignore = 'yes' == pframe.args['ignore-err']; -- suppress false-positive 'no target' errors
 
if 'cs2' == pframe.args.mode then
Line 388 ⟶ 433:
 
return table.concat ({core (args), frame:extensionTag ('templatestyles', '', {src='Module:Citation/CS1/styles.css'})});
-- return table.concat ({core (args), frame:extensionTag ('templatestyles', '', {src=styles})});
end