en>Trappist the monk |
ja>ネイ |
| 23行目: |
23行目: |
| template = 'harv', -- if template name not provided in {{#invoke:}} use this | | template = 'harv', -- if template name not provided in {{#invoke:}} use this |
| }; | | }; |
|
| |
|
| |
| --[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------
| |
|
| |
| look for anchor_id (CITEREF name-list and year or text from |ref=) in anchor_id_list
| |
|
| |
| 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, args)
| |
| local namespace = mw.title.getCurrentTitle().namespace;
| |
| local anchor_id_list_module = mw.loadData ('Module:Footnotes/anchor_id_list');
| |
| local anchor_id_list = anchor_id_list_module.anchor_id_list;
| |
| local article_whitelist = anchor_id_list_module.article_whitelist;
| |
| local template_list = anchor_id_list_module.template_list;
| |
|
| |
| local whitelist_module = mw.loadData ('Module:Footnotes/whitelist');
| |
| local whitelist = whitelist_module.whitelist;
| |
| local special_patterns = whitelist_module.special_patterns;
| |
| local DNB_special_patterns = whitelist_module.DNB_special_patterns;
| |
| local DNB_template_names = whitelist_module.DNB_template_names;
| |
|
| |
| if 10 == namespace then
| |
| return ''; -- automatic form of |no-tracking=yes; TODO: is this too broad?
| |
| end
| |
|
| |
| local tally = anchor_id_list[anchor_id]; -- nil when anchor_id not in list; else a tally
| |
| local msg;
| |
| local category;
| |
|
| |
| if not tally then
| |
| if args.ignore then
| |
| return ''; -- if ignore is true then no message, no category
| |
| end
| |
|
| |
| if article_whitelist and article_whitelist[anchor_id] then -- if an article-local whitelist and anchor ID is in it
| |
| return ''; -- done
| |
| end
| |
|
| |
| local wl_anchor_id = anchor_id; -- copy to be modified to index into the whitelist
| |
|
| |
| if args.year then -- for anchor IDs created by this template (not in |ref=) that have a date
| |
| if args.year:match ('%d%l$') or -- use the date value to determine if we should remove the disambiguator
| |
| args.year:match ('n%.d%.%l$') or
| |
| args.year:match ('nd%l$') then
| |
| wl_anchor_id = wl_anchor_id:gsub ('%l$', ''); -- remove the disambiguator
| |
| end
| |
| end
| |
|
| |
| local t_tbl = whitelist[wl_anchor_id]; -- get list of templates associated with this anchor ID
| |
|
| |
| if t_tbl then -- when anchor ID not whitelisted t_tbl is nil
| |
| for _, t in ipairs (t_tbl) do -- spin through the list of templates associated with this anchor ID
| |
| if template_list[t] then -- if associated template is found in the list of templates in the article
| |
| return ''; -- anchor ID is whitlisted and article has matching template so no error
| |
| end
| |
| end
| |
| end
| |
|
| |
| for _, pattern in ipairs (special_patterns) do -- spin through the spcial patterns and try to match
| |
| if anchor_id:match (pattern) then
| |
| return '';
| |
| end
| |
| end
| |
|
| |
| for _, dnb_t in ipairs (DNB_template_names or {}) do -- getting desparate now, are there any DNB templates? DNB_template_names may be nil; empty table prevents script error
| |
| if template_list[dnb_t] then -- if the article has this DNB template
| |
| for _, pattern in ipairs (DNB_special_patterns) do -- spin through the DNB-specifiec wildcard patterns
| |
| if anchor_id:match (pattern) then -- and attempt a match
| |
| return ''; -- found a match
| |
| end
| |
| end
| |
| end
| |
| end
| |
|
| |
| msg = 'no target: ' .. anchor_id; -- anchor_id not found
| |
| category = '[[Category:Harv and Sfn no-target errors]]';
| |
|
| |
| elseif 1 < tally then
| |
| msg = 'multiple targets (' .. tally .. '×): ' .. anchor_id; -- more than one anchor_id in this article
| |
| category = 0 == namespace and '[[Category:Harv and Sfn multiple-target errors]]' or ''; -- only categorize in article space
| |
| return '<span class="error harv-error" style="display: inline; font-size:100%"> ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category;
| |
| end
| |
|
| |
| -- category = 0 == namespace and '[[Category:Harv and Sfn template errors]]' or ''; -- only categorize in article space
| |
| category = 0 == 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%"> ' .. args.template .. ' 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%"> ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
| |
|
| |
| end
| |
|
| |
|
|
| |
|
| 210行目: |
115行目: |
| if args.ref ~= '' then | | if args.ref ~= '' then |
| anchor_id = mw.uri.anchorEncode (args.ref); | | anchor_id = mw.uri.anchorEncode (args.ref); |
| err_msg = target_check (anchor_id, args); | | err_msg = ''; |
| result = table.concat ({'[[#', anchor_id, '|', result, ']]'}); | | result = table.concat ({'[[#', anchor_id, '|', result, ']]'}); |
| else | | else |
| anchor_id = mw.uri.anchorEncode (table.concat ({'CITEREF', args.P1, args.P2, args.P3, args.P4, args.P5})); | | anchor_id = mw.uri.anchorEncode (table.concat ({'CITEREF', args.P1, args.P2, args.P3, args.P4, args.P5})); |
| err_msg = target_check (anchor_id, args); | | err_msg = ''; |
| result = table.concat ({'[[#', anchor_id, '|', result, ']]'}); | | result = table.concat ({'[[#', anchor_id, '|', result, ']]'}); |
| end | | end |
| 323行目: |
228行目: |
| args.location = pframe.args.loc or ''; | | args.location = pframe.args.loc or ''; |
| args.ref = pframe.args.ref or pframe.args.Ref or ''; | | args.ref = pframe.args.ref or pframe.args.Ref or ''; |
| | args.refname = pframe.args.refname or ''; |
| args.ignore = ('yes' == pframe.args['ignore-false-positive']) or ('yes' == pframe.args['ignore-err']); | | args.ignore = ('yes' == pframe.args['ignore-false-positive']) or ('yes' == pframe.args['ignore-err']); |
|
| |
|
| 403行目: |
309行目: |
| local result = core (args); -- go make a CITEREF anchor | | local result = core (args); -- go make a CITEREF anchor |
| -- put it all together and then strip redundant spaces | | -- put it all together and then strip redundant spaces |
| local name = table.concat ({'FOOTNOTE', args.P1, args.P2, args.P3, args.P4, args.P5, strip_url (args.page), strip_url (args.pages), strip_url (args.location)}):gsub ('%s+', ' '); | | local name; |
| | |
| | if args.refname == '' then |
| | name = "FOOTNOTE" .. args.P1 .. args.P2 .. args.P3 .. args.P4 .. args.P5 .. args.page .. args.pages .. args.location; |
| | |
| | name = mw.uri.anchorEncode(name); |
| | else |
| | name = "FOOTNOTE" .. args.refname; |
| | end |
|
| |
|
| return frame:extensionTag ({name='ref', args={name=name}, content=result}); | | return frame:extensionTag ({name='ref', args={name=name}, content=result}); |