Module:Harvc: Difference between revisions

Content deleted Content added
use require('strict') instead of require('Module:No globals')
replace target_check() with call to target_check() in Module:Footnotes, which has full wrapper/whitelist functionality
 
(2 intermediate revisions by 2 users not shown)
Line 1:
require('strict')
local anchor_id_list = mw.loadData ('Module:Footnotes/anchor_id_list').anchor_id_list;
 
local code_open_tag = '<code class="cs1-code">'; -- cs1-code class defined in Module:Citation/CS1/styles.css
Line 12 ⟶ 11:
--[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------
 
check to see if target of harvc exists in the page somewhere. Uses the target check mechanism from Module:Footnotes
look for anchor_id (CITEREF name-list and year or text from |ref=) in anchor_id_list
 
setting |ignore-errors=yes in {{harvc}} will override this check
the 'no target' error may be suppressed with |ignore-err=yes when target cannot be found because target is inside
a template that wraps another template; 'multiple targets' error may not be suppressed
 
]]
 
local function target_check (anchor_id, ignore)
local whitelist_check = require('Module:Footnotes').target_check
local number = anchor_id_list[anchor_id]; -- nil when anchor_id not in list; else a number
local args = {ignore=ignore, template='Harvc', show=true}
local msg;
return whitelist_check(anchor_id, args)
local category;
 
if not number then
if ignore then
return ''; -- if ignore is true then no message, no category
end
msg = 'no target: ' .. anchor_id; -- anchor_id not found in this article
category = '[[Category:Harv and Sfn no-target errors]]';
elseif 1 < number then
msg = 'multiple targets (' .. number .. '×): ' .. anchor_id; -- more than one anchor_id in this article
category = '[[Category:Harv and Sfn multiple-target errors]]';
end
 
category = 0 == mw.title.getCurrentTitle().namespace and category or ''; -- only categorize in article space
 
--use this version to show error messages
return msg and ' <span class="error harv-error" style="display: inline; font-size:100%">Harvc error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
--use this version to hide error messages
-- return msg and ' <span class="error harv-error" style="display: none; font-size:100%">Harvc error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
end
 
Line 46 ⟶ 26:
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
 
Whether variable is set or not. A varablevariable is set when it is not nil and not empty.
 
]]
Line 212 ⟶ 192:
count = #args.last; -- set count to display all of the authors
end
 
while i <= count do
if is_set (contributors) then
Line 329 ⟶ 309:
table.insert (result, args.ps);
table.insert (result, args.err_msg);
if not is_set(args.err_msg) then
table.insert (result, target_err_msg);
end
table.insert (result, '</span>');
 
Line 394 ⟶ 376:
i = i + 1 -- bump the index
end
end
 
if 0 == #args.last then -- |last= is required
args.err_msg = args.err_msg .. ' no authors in contributor list.';
end