Module:Footnotes/anchor id list: Difference between revisions

m 1 revision imported
fix fascicle logic
Line 97: Line 97:
local template_list = {};
local template_list = {};
local article_whitelist = {};
local article_whitelist = {};
local template_list_done = false




Line 500: Line 501:
template_params_get (template, params); -- build a table of template parameters and their values
template_params_get (template, params); -- build a table of template parameters and their values


if whitelist.wrapper_templates[template_name][1] then -- is this wrapper a simple-default wrapper?
    local wrap_data = whitelist.wrapper_templates[template_name]
name_default = whitelist.wrapper_templates[template_name][1]; -- get the default names
 
date_default = whitelist.wrapper_templates[template_name][2]; -- get the default date
if wrap_data[1] then                                 -- is this wrapper a simple-default wrapper?
name_default = wrap_data[1];                                 -- get the default names
date_default = wrap_data[2];                                 -- get the default date
else
else
vol = params['volume'] or 'default';
vol = params['volume'] or 'default';
if not whitelist.wrapper_templates[template_name][vol] then -- make sure this volume exists
        local fascicle = params['fascicle']                                    -- some templates use "fascicle" to mean "subvolume"
        if fascicle then
            local subvol = vol..'/'..fascicle                                  -- if fascicle is used, subvolume = "vol/fascicle"
            if wrap_data[subvol] then                                          -- if subvolume exists, use it, otherwise fall back to volume
                vol = subvol
            end
        end                         
if not wrap_data[vol] then                                 -- make sure this volume exists
vol = 'default'; -- doesn't exist, use default volume
vol = 'default'; -- doesn't exist, use default volume
end
end
name_default = whitelist.wrapper_templates[template_name][vol][1]; -- get the default names
name_default = wrap_data[vol][1];                                 -- get the default names
date_default = whitelist.wrapper_templates[template_name][vol][2]; -- get the default date
date_default = wrap_data[vol][2];                                 -- get the default date
end
end


Line 798: Line 808:
end
end
end
end
 
elseif template_name and whitelist.wrapper_templates[template_name] then
    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
anchor_id = anchor_id_make_wrapper (template); -- extract an anchor id from this template if possible
list_add (anchor_id, anchor_id_list, true);
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
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
anchor_id = anchor_id_make_cs12 (template); -- extract an anchor id from this template if possible
Line 810: Line 821:
tstart, tend = Article_content:find (find_pattern, tend); -- search for another template; begin at end of last search
tstart, tend = Article_content:find (find_pattern, tend); -- search for another template; begin at end of last search
end
end
    template_list_done = true


mw.logObject (anchor_id_list, 'anchor_id_list');
mw.logObject (anchor_id_list, 'anchor_id_list');
Line 816: Line 828:


return anchor_id_list;
return anchor_id_list;
end
--[[--------------------------< C I T E R E F _ P A T T E R N S _ M A K E >--------------------------------------------
Scans template_list to look for wrapper templates that generate citerefs that require Lua patterns.
This scan is only done once per page load, to save time
]]
local function citeref_patterns_make()
    if not template_list_done then error("Template list not yet created") end
    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 template_list[t] then                                          -- if wrapper is found in article, record corresponding patterns
                for _, pat in ipairs(p[2]) do
                    table.insert(citeref_patterns, pat)
                end
                break
            end
        end
    end
mw.logObject(citeref_patterns,'citeref_patterns')
    return citeref_patterns
end
end


Line 826: Line 864:
article_whitelist = article_whitelist, -- table of anchor ids with false-positive error message to be suppressed
article_whitelist = article_whitelist, -- table of anchor ids with false-positive error message to be suppressed
template_list = template_list, -- table of templates used in this article
template_list = template_list, -- table of templates used in this article
    citeref_patterns = citeref_patterns_make()                                  -- table of Lua patterns to search for citeref from wrappers
}
}