Modulo:Footnotes/anchor id list/pagipadasan: Paggiddiatan a nagbaetan dagiti rebision

Content deleted Content added
Pinabaro manipud iti Module:Footnotes/958422692
Linia 1:
require('Modulo:No globals');
local data = mw.loadData ('Modulo:Footnotes/anchor id list/data');
local whitelist = mw.loadData ('Modulo:Footnotes/whitelist');
local Lang_obj = mw.language.getContentLanguage(); -- used by template_list_add() to uppercase first letter of template name TODO: better way to do that?
 
Line 11 ⟶ 12:
}
local redirects_patent = { -- special case cs1-like templates because uses different parameters for name and date in anchor ID
['citeCite patent'] = true,
['citerefCiteref patent'] = true,
['refRef patent'] = true,
}
local redirects_sfnref = {
Line 86 ⟶ 87:
'<source.->.-</source>', -- deprecated alias of syntaxhighlight tag
}
local template_skip = { -- TODO: necessarytemplates to keepbe this?skipped withfor knownwhatever templatereason; tablesmostly templatesbecause notthey inresemble thosecs1-like tables will be skippedtemplates
['citationCitation-attribution'] = true,
}
local Article_content;
Line 135 ⟶ 136:
while parts[i] and 7 > j do -- loop through what should be just positional parameters for names and year (2-6 four names and a date)
if not parts[i]:find ('=') then -- look for equal sign (named paraneter in a template that doesn't support named parameters)
anchor_id[j] = parts[i]; -- positional parameters are saved
j = j+1; -- bump the anchor_id{} indexer
end
Line 377 ⟶ 378:
 
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 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;
end;
template_name = template_name:gsub ('%s*$', ''); -- trim trailing whitespace; leading whitespace already removed
return Lang_obj:ucfirst (template_name); -- first character in template name must be uppercase (same as canonical template name) TODO: better way to do this?
template_name = template_name:lower(); -- and lowercase only
return template_name;
end
 
Linia 441:
end
return nil; -- no names; no anchor_id
end
 
 
--[[--------------------------< A N C H O R _ I D _ M A K E _ W R A P P E R >----------------------------------
 
for wrapper templates
 
inspect externally visible |ref= to decide what to do:
|ref= - empty or missing: get names and date from whitelist defaults; override defaults from externally visible template parameters
|ref=harv - same as empty or missing
|ref={{SfnRef|name|name|name|name|year}} - assemble an anchor id from {{sfnref}} positional parameters
|ref={{Harvid|name|name|name|name|year}} - assemble an anchor id from {{harvid}} positional parameters
|ref=none - skip; do nothing because an anchor id intentionally suppressed; TODO: keep with a type code of '0'?
|ref=<text> - save param value because may match an anchor id override value in {{harv}} template |ref= parameter or {{harvc}} |id= parameter
 
]]
 
local function anchor_id_make_wrapper (template)
local ref; -- content of |ref=
local template_name; -- name of the template
local anchor_id; -- the assembled anchor id from this template
local date;
local params = {}; -- table of template parameters
template_name = template_name_get (template); -- get first char uppercase trimmed template name; ignore subpages ~/new, ~/sandbox
if not template_name or template_skip[template_name] then
return nil; -- could not extract template name from (possibly corrupted) template (extraneous opening { in the template will cause this)
end
 
date = date_get (template, alias_patterns_date); -- get date; done here because might be in {{date}}
if '' == date then
date = whitelist.wrapper_templates[template_name][2] or ''; -- no externally visible date so get default date
end
 
ref = template:match ('|%s*ref%s*=%s*(%b{})'); -- first look for |ref={{sfnref}} or |ref={{harvid}} because we will strip templates from the wrapper template
if not ref then
if template:match ('|%s*ref%s*=([^|}]+)') then -- |ref={{template}} not found; if there is a |ref= param with an assigned value
ref = template:match ('|%s*ref%s*=([^|}]+)'); -- get the value; whitespace is a 'value'
if ref then -- nil when |ref=|... or when |ref=}} (no spaces between assignment operator and pipe or closing brace)
ref = mw.text.trim (ref); -- something, could be just whitespace, so trim leading / trailing whitespace
if '' == ref then -- trimming a string of whitespace makes an empty string
ref = nil; -- make empty ref same as missing ref
end
end
end
end
 
template_params_get (template, params); -- build a table of template parameters and their values
 
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
names_get (params, aliases_author) or
vnames_get (params, 'vauthors') or -- |vauthors=
names_get (params, aliases_editor) or
vnames_get (params, 'veditors') or -- |veditors=
whitelist.wrapper_templates[template_name][1]; -- default names from whitelist
 
if anchor_id then -- if names were gotten
anchor_id = 'CITEREF' .. anchor_id .. date;
end
 
elseif ref:match ('%b{}') then -- ref holds a template
anchor_id = sfnref_get (ref); -- returns content of {{sfnref}} or {{harvid}}; nil else
 
elseif 'none' == ref then -- |ref=none
return nil; -- anchor id expicitly suppressed
else
anchor_id = ref; -- |ref=<text> may match an anchor id override value in {{harv}} template |ref= parameter
end
return anchor_id; -- anchor_id text; nil else
end
 
Line 465 ⟶ 537:
local params = {}; -- table of template parameters
template_name = template_name_get (template); -- get lowercasefirst char uppercase trimmed template name; ignore subpages ~/new, ~/sandbox
if not template_name or template_skip[template_name] then
return nil; -- could not extract template name from (possibly corrupted) template (extraneous opening { in the template will cause this)
Line 630 ⟶ 702:
local anchor_id; -- place to hold an anchor id as it is extracted / decoded
 
local find_pattern = '%f[{]{{[^{]';
for template in Article_content:gmatch ('{%b{}}') do
local tstart, tend = Article_content:find (find_pattern); -- find the first template; do not find template variables: {{{template var|}}}
template_name = template_name_get (template);
 
while tstart do
template = Article_content:match ('%b{}', tstart); -- get the whole 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
template_list_add (template); -- add this template's name to the list
 
Line 697 ⟶ 776:
end
end
-- whatever it is that gets written for dynamic whitelist goes here
elseif template_name and whitelist.wrapper_templates[template_name:match ('cit[ea]') then -- not known, not know wrapper; last gasp, try as cs1-like
anchor_id = anchor_id_make_wrapper (template); -- extract an anchor id from this template if possible
list_add (anchor_id, anchor_id_list, true);
 
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 = Article_content:find (find_pattern, tend); -- search for another template; begin at end of last search
end