Module:Footnotes/anchor id list and Module:Footnotes/anchor id list/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
fix errors when using Visual Editor |
|||
Line 1: | Line 1: | ||
require('strict'); |
require('strict'); |
||
local data = mw.loadData ('Module:Footnotes/anchor id list/data'); |
local data = mw.loadData ('Module:Footnotes/anchor id list/data'); |
||
local whitelist = mw.loadData ('Module:Footnotes/whitelist'); |
local whitelist = mw.loadData ('Module:Footnotes/whitelist/sandbox'); |
||
local Lang_obj = mw.language.getContentLanguage(); -- used by |
local Lang_obj = mw.language.getContentLanguage(); -- used by template_name_get() to uppercase first letter of template name TODO: better way to do that? |
||
local redirects_date = { |
local redirects_date = { |
||
Line 374: | Line 374: | ||
end |
end |
||
⚫ | |||
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. |
|||
⚫ | |||
⚫ | |||
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 |
|||
⚫ | |||
return nil -- could not get module and function name |
|||
⚫ | |||
return template_name |
|||
end |
|||
--[[--------------------------< T E M P L A T E _ N A M E _ G E T >-------------------------------------------- |
--[[--------------------------< T E M P L A T E _ N A M E _ G E T >-------------------------------------------- |
||
Line 387: | Line 406: | ||
local template_name = template:match ('^{{%s*([^/|}]+)'); -- get template name; ignore subpages ~/new, ~/sandbox; parser functions |
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 |
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; |
return nil; -- could not get template name from (possibly corrupt) template; extraneous opening { mid template can cause this; |
||
Line 688: | Line 709: | ||
list_add (anchor_id, anchor_id_list, true); -- add anchor ID to the list |
list_add (anchor_id, anchor_id_list, true); -- add anchor ID to the list |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
makes a list of templates use in the article. |
|||
⚫ | |||
⚫ | |||
local template = template:match ('{{%s*(.-)[|}]'); -- keep the case of the template - this is different from template_name_get() |
|||
if template and not template:match ('^#') then -- found a template or magic word; ignore magic words |
|||
template=mw.text.trim (template); -- trim whitespace |
|||
template = Lang_obj:ucfirst (template); -- first character in template name must be uppercase (same as canonical template name) TODO: better way to do this? |
|||
list_add (template, template_list); -- add to list with (unused) tally |
|||
end |
end |
||
end |
end |
||
Line 745: | Line 750: | ||
break; -- template is nil for some reason (last template missing closing }} for example) so declare ourselves done |
break; -- template is nil for some reason (last template missing closing }} for example) so declare ourselves done |
||
end |
end |
||
template_name = template_name_get (template); -- get first char uppercase trimmed template name; ignore subpages ~/new, ~/sandbox |
template_name = template_name_get (template); -- get first char uppercase trimmed template name; ignore subpages ~/new, ~/sandbox |
||
list_add (template_name, template_list); -- add this template's name to the list |
|||
if data.known_templates_cs12 [template_name] then |
if data.known_templates_cs12 [template_name] then |
||
Line 871: | Line 875: | ||
-- Then stuff them (and derived tables) into return table |
-- Then stuff them (and derived tables) into return table |
||
return { |
return { |
||
anchor_id_list = global_anchor_id_list or {}, |
anchor_id_list = global_anchor_id_list or {}, -- table of anchor ids available in this article |
||
article_whitelist = global_article_whitelist or {}, |
article_whitelist = global_article_whitelist or {}, -- table of anchor ids with false-positive error message to be suppressed |
||
template_list = global_template_list or {}, |
template_list = global_template_list or {}, -- table of templates used in this article |
||
citeref_patterns = citeref_patterns_make() or {} |
citeref_patterns = citeref_patterns_make() or {}, -- table of Lua patterns to search for citeref from wrappers |
||
} |
} |