Content deleted Content added
sync from live; |
No edit summary |
||
Line 1:
require('Module:No globals');
local data = mw.loadData ('Module:Footnotes/anchor id list/data');
local anchor_id_list = {};
--local redirect_patterns_anchor = {
-- '{{%s*[Aa]nchor',
-- '{{%s*[Aa]nchor for redirect',
-- '{{%s*[Aa]nchors',
-- '{{%s*[Aa]nchro',
-- '{{%s*[Aa]ncor',
--local redirect_patterns_harvc = {
local redirect_patterns_sfn_whitelist = {
'{{%s*[Ss]fn whitelist',
'{{%s*[Hh]arv whitelist',
}
--local redirect_patterns_vcite = {
---- '{{%s*[Cc]it ', -- disabled 'cit journal & cit paper' redirect to vcite journal but 'cit book', 'cit new', 'cit web' are cs1 redirects
local redirects_citation = {
['citation'] = true,
Line 37 ⟶ 38:
['isotomos'] = true,
}
--local redirects_harvc = {
local redirects_patent = {
['cite patent'] = true,
Line 121 ⟶ 122:
}
local Article_content;
local template_list = {};
--[[--------------------------< A R T I C L E _ C O N T E N T _ G E T >----------------------------------------
Line 403 ⟶ 406:
local function template_name_get (template)
local template_name = template:match ('{{%s*([^#][^#/|]+)'); -- get template name; ignore subpages ~/new, ~/sandbox; parser functions, magic words don't count as templates
if not template_name then
return nil; -- could not get template name from (possibly corrupt) template; extraneous opening { mid template can cause this;
Line 565 ⟶ 570:
return nil; -- anchor id expicitly suppressed
else
anchor_id = ref; -- |ref=<text> may match an anchor id override value in {{harv}} template |ref= parameter
Line 633 ⟶ 637:
end
end
end
--[[--------------------------< T E M P L A T E _ L I S T _ A D D >--------------------------------------------
makes a list of templates use in the article.
]]
local Lang_obj = mw.language.getContentLanguage();
local function template_list_add (template)
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)
list_add (template, template_list); -- add to list with (unused) tally
end
--mw.logObject (template_list, 'template_list')
-- return template_list;
end
Line 655 ⟶ 680:
local template; -- place to hold the template that we found
local template_name;
local anchor_id; -- place to hold an anchor id as it is extracted / decoded
for template in Article_content:gmatch ('{%b{}}') do
template_name = template_name_get (template);
template_list_add (template); -- add this template's name to the list
if data.known_templates_cs12 [template_name] then
anchor_id = anchor_id_make (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}}
anchor_id = sfnref_get (ref); -- returns content of {{sfnref}} or {{harvid}}; nil else
list_add (anchor_id, anchor_id_list, true);
local params = {};
template_params_get (template, params); -- build a table of template parameters and their values
if not anchor_id and params['harvid'] then
anchor_id = 'CITEREF' .. params['
end
list_add (anchor_id, anchor_id_list, true);
end
elseif data.known_templates_harvc [template_name] then
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 729 ⟶ 723:
elseif template:match ('|%s*id%s*=%s*(%b{})') then
anchor_id = 'Reference-' .. sfnref_get (ref);
elseif template:match ('|%s*id%s*=([^|}]+)') then
anchor_id = 'Reference-' .. template:match ('|%s*id%s*=([^|}]+)'); -- plain-text
Line 741 ⟶ 736:
list_add (anchor_id, anchor_id_list, true);
end
elseif data.known_templates_anchor [template_name] then
anchor_id_make_anchor (template, anchor_id_list); -- extract anchor ids from this template if any
end
end
mw.logObject (anchor_id_list, 'anchor_id_list')
mw.logObject (template_list, 'template_list')
return anchor_id_list;
end
Line 771 ⟶ 754:
]]
--[[
local Lang_obj = mw.language.getContentLanguage();
Line 794 ⟶ 777:
return template_list;
end
]]
--[[--------------------------< A R T I C L E _ L O C A L _ W H I T E L I S T _ M A K E >----------------------
Line 846 ⟶ 829:
anchor_id_list = anchor_id_list_make(), -- table of anchor ids available in this article
article_whitelist = article_local_whitelist_make(), -- table of anchor ids with false-positive error message to be suppressed
template_list = template_list, -- table of templates used in this article
}
|