Content deleted Content added
other debugging |
|||
(19 intermediate revisions by 2 users not shown) | |||
Line 2:
local data = mw.loadData ('Module:Footnotes/anchor id list/data');
local whitelist = mw.loadData ('Module:Footnotes/whitelist/sandbox');
local Lang_obj = mw.language.getContentLanguage(); -- used by
local redirects_date = {
Line 92:
['Citation-attribution'] = true,
}
local global_article_content = nil
local global_template_list = nil
local global_article_whitelist = nil
▲local anchor_id_list = {}; -- exported tables
local template_list = {};▼
local article_whitelist = {};▼
Line 108:
local function article_content_get ()
if global_article_content then return global_article_content end
end▼
end
global_article_content = article_content
return article_content
end
Line 373 ⟶ 374:
end
--[[--------------------------< T E M P L A T E _
if passed a module invocation, return the name of the template represented. Otherwise return the input.
{{#invoke:cite|foo|...}} or {{#invoke:cite bar||...}} will return "cite foo" and "cite bar", respectively.
]]▼
local function template_name_from_module (template, template_name)
if template_name and template_name:match ('^#invoke%s*:') then -- handle directly-invoked citation modules
template_name = template_name:match ('^#invoke%s*:%s*(.+)'); -- get module name
local func_name = template:match ('^{{[^|}]+%|%s*([^/|}]*)'); -- get function name
if template_name and func_name then -- valid module invocation
return template_name:gsub ('%s+$', '') .. ' ' .. func_name; -- ensure exactly one trailing whitespace between module and function name
▲ end;
return nil -- could not get module and function name
end;▼
return template_name
end▼
--[[--------------------------< T E M P L A T E _ N A M E _ G E T >--------------------------------------------
Line 386 ⟶ 406:
local template_name = template:match ('^{{%s*([^/|}]+)'); -- get template name; ignore subpages ~/new, ~/sandbox; parser functions
template_name = template_name_from_module (template, template_name); -- if passed a module invocation, return the name of the template represented
if not template_name or template_name:match ('^#') then -- parser functions, magic words don't count as templates
return nil; -- could not get template name from (possibly corrupt) template; extraneous opening { mid template can cause this;
Line 521 ⟶ 543:
date_default = wrap_data[vol][2]; -- get the default date
end
if 'harv' == ref or not ref then -- |ref=harv specified or |ref= missing or empty
anchor_id = names_get (params, aliases_contributor) or -- get contributor, author, or editor names
Line 550 ⟶ 573:
return anchor_id; -- anchor_id text; nil else
end
Line 689 ⟶ 709:
list_add (anchor_id, anchor_id_list, true); -- add anchor ID to the list
end
▲ end
▲end
▲--[[--------------------------< T E M P L A T E _ L I S T _ A D D >--------------------------------------------
▲]]
list_add (template, template_list); -- add to list with (unused) tally▼
end
end
Line 725 ⟶ 729:
local function anchor_id_list_make ()
article_content_get (); -- attempt to get this article's content▼
if
return ''; -- no point in continuing
end
Line 736 ⟶ 743:
local find_pattern = '%f[{]{{[^{]';
local tstart, tend =
while tstart do
template =
if not template then
break; -- template is nil for some reason (last template missing closing }} for example) so declare ourselves done
end
template_name = template_name_get (template); -- get first char uppercase trimmed template name; ignore subpages ~/new, ~/sandbox
▲ list_add (
if data.known_templates_cs12 [template_name] then
anchor_id = anchor_id_make_cs12 (template); -- extract an anchor id from this template
list_add (anchor_id, anchor_id_list, true)
elseif data.known_templates_vcite [template_name] then
local ref = template:match ('|%s*ref%s*=%s*(%b{})'); -- first look for |ref={{sfnref}} or |ref={{harvid}} because we will strip templates from the vcite template
if ref then -- |ref={{template}}
Line 772 ⟶ 775:
elseif data.known_templates_harvc [template_name] then
anchor_id = anchor_id_make_harvc (template); -- extract an anchor id from this template
list_add (anchor_id, anchor_id_list, true);
elseif data.known_templates_wikicite [template_name] then
local ref = template:match ('|%s*ref%s*=%s*(%b{})'); -- first look for |ref={{sfnref}} or |ref={{harvid}}
Line 802 ⟶ 803:
elseif data.known_templates_anchor [template_name] then
anchor_id_make_anchor (template, anchor_id_list); -- extract anchor ids from this template if any
elseif data.known_templates_sfn_whitelist [template_name] then
template = template:gsub ('^{{[^|]+|', ''):gsub ('}}$', '', 1); -- remove outer {{ and }} and template name
template = mw.text.trim (template, '%s|'); -- trim leading trailing white space and pipes
Line 819 ⟶ 818:
elseif template_name and whitelist.wrapper_templates[template_name] then
anchor_id = anchor_id_make_wrapper (template); -- extract an anchor id from this template if possible
list_add (anchor_id, anchor_id_list, true);
Line 825 ⟶ 823:
elseif template_name and template_name:match ('^Cit[ea]') then -- not known, not known wrapper; last gasp, try as cs1-like
anchor_id = anchor_id_make_cs12 (template); -- extract an anchor id from this template if possible
list_add (anchor_id, anchor_id_list, true);
end
tstart, tend =
end
mw.logObject (anchor_id_list, 'anchor_id_list');
Line 838 ⟶ 834:
mw.logObject (article_whitelist, 'article_whitelist');
▲ return anchor_id_list;
global_anchor_id_list = anchor_id_list
global_template_list = template_list
global_article_whitelist = article_whitelist
end
Line 850 ⟶ 849:
local function citeref_patterns_make()
if not
local citeref_patterns = {}
local template_patterns = whitelist.wrapper_template_patterns
for _, p in ipairs(template_patterns) do
for _, t in ipairs(p[1]) do -- loop through list of template wrappers
if
for _, pat in ipairs(p[2]) do
table.insert(citeref_patterns, pat)
Line 871 ⟶ 870:
]]
-- First create global_anchor_id_list, global_template_list, global_article_whitelist
anchor_id_list_make()
-- Then stuff them (and derived tables) into return table
return {
anchor_id_list =
article_whitelist =
template_list =
citeref_patterns = citeref_patterns_make() or
}
|