Modul:Sandbox/trappist the monk/parameter match test
Utseende
Moduldokumentasjon
[opprett]
--[[--------------------------< P A R A M E T E R M A T C H T E S T >--------------------------------------
this module is a hack intended to be run from the debug console. The module assembles and then compares lists
of cs1|2 parameters extracted from the cs1|2 whitelist module and from the cs1|2 configuration module. In general,
these lists should match.
the module returns one of five tables via mw.dumpObject(). In the debug console type:
=p.aliases – returns the list of parameters and their associated meta parameter from the ~/Configuration module
=p.aliases_dups – returns a list of parameters that appear in more than one meta parameter (not necessarily a bad thing depending on the version of the cs1|2 module suite)
=p.whitelist – returns the list of parameters from the ~/Whitelist module
=p.alias_params_not_in_whitelist – returns a list of parameters found in the ~/Configuration module but not found in the ~/Whitelist module
=p.wh_params_not_in_aliases – returns a list of parameters found in the ~/Whitelist module but not found in the ~/Configuration module
Module:Sandbox/trappist_the_monk/parameter_match_test
]]
require('Module:No globals');
local lang_code = mw.language.getContentLanguage():getCode(); -- so that this can be used at multiple wikis
local modules = {
da = {whitelist = 'Modul:Citation/CS1/Whitelist', configuration = 'Modul:Citation/CS1/Configuration'},
en = {whitelist = 'Module:Citation/CS1/Whitelist', configuration = 'Module:Citation/CS1/Configuration'},
es = {whitelist = 'Módulo:Citas/Whitelist', configuration = 'Módulo:Citas/Configuración'},
it = {whitelist = 'Modulo:Citazione/Whitelist', configuration = 'Modulo:Citazione/Configurazione'},
nb = {whitelist = 'Modul:Citation/CS1/Whitelist', configuration = 'Modul:Citation/CS1/Configuration'}, -- language code different from interwiki code for no.wiki
tr = {whitelist = 'Modül:Kaynak/KB1/Beyazliste', configuration = 'Modül:Kaynak/KB1/Yapılandırma'},
}
local whitelist_m = mw.loadData (modules[lang_code].whitelist);
local whitelist_t = {}; -- a master list of all whitelist parameters
local simple_sections = {
'basic_arguments',
'numbered_arguments',
'limited_basic_arguments',
'limited_numbered_arguments',
'arxiv_basic_arguments',
'biorxiv_basic_arguments',
'citeseerx_basic_arguments'
}
local special_sections = {'preprint_arguments', 'unique_arguments'};
local configuration_m = mw.loadData (modules[lang_code].configuration);
local aliases_t = {}; -- a master k/v table of all parameter aliases
local aliases_dups_t = {}; -- a sequence table of parameter aliases that are used in multiple metaparameters
local wh_params_not_in_aliases_t = {}; -- a sequence table of whitelist parameters not found in the master aliases list
local alias_params_not_in_whitelist_t = {}; -- a sequence table of alias list parameters not found in the master whitelist
for _, section in ipairs (simple_sections) do
if whitelist_m[section] then -- not all simple sections used in every cs1|2 implementation
for k, _ in pairs (whitelist_m[section]) do -- for each of the whitelist tables that do not have subtables
whitelist_t[k] = section; -- save the parameter name with section name (just because and all = true is boring)
end
end
end
if whitelist_m[special_sections[1]] or whitelist_m[special_sections[1]] then -- not all implementations of cs1|2 have these sections
for _, section in ipairs (special_sections) do
for k1, v1_t in pairs (whitelist_m[section]) do
for k, v in pairs (whitelist_m[section][k1]) do
whitelist_t[k] = section .. '[' .. k1.. ']'; -- save the parameter name with section name (just because and all = true is boring)
end
end
end
end
for meta, params_t in pairs (configuration_m.aliases) do -- build a list of all parameters in the ~/Configuration aliases table
if 'table' == type (params_t) then -- when only one parameter assigned to <meta>(parameter) it is type string
for _, param in ipairs (params_t) do -- loop through the sequence table of parameters associated with <meta>
if aliases_t[param] then -- if already in <aliases_t>
table.insert (aliases_dups_t, table.concat ({'\'', param, '\' in: \'', meta, '\' duplicated in: \'', aliases_t[param], '\''})); -- make a note
else
aliases_t[param] = meta; -- add this <param> with its associated <meta> to <aliases_t>
end
if param:find ('#', 1, true) then -- if this is an enumerated parameter
param = param:gsub ('#', ''); -- make a parameter without enumeration
if aliases_t[param] then -- if already in <aliases_t>
if meta ~= aliases_t[param] then
table.insert (aliases_dups_t, table.concat ({'\'', param, '\', in: \'', meta, '\' duplicated in: \'', aliases_t[param], '\' (enumneration)'})); -- make a note
end
else
aliases_t[param] = meta; -- add this <param> with its associated <meta> to <aliases_t>
end
end
end
else -- here when <params_t> is a string
if aliases_t[params_t] then -- if already in <aliases_t>
table.insert (aliases_dups_t, table.concat ({'\'', params_t, '\' in: \'', meta, '\' duplicated in: \'', aliases_t[params_t], '\''})); -- make a note
else
aliases_t[params_t] = meta; -- add this <param> with its associated <meta> to <aliases_t>
end
end
end
for k, v_t in pairs (configuration_m.id_handlers) do
for k, param in ipairs (v_t.parameters) do
if aliases_t[param] then -- if already in <aliases_t>
table.insert (aliases_dups_t, table.concat ({param, ' in: id_handlers.', k, ' duplicated in: ', aliases_t[param]})); -- make a note
else
aliases_t[param] = 'id_handlers.' .. k; -- add this <param> with its associated id_hamdler to <aliases_t>
end
end
local param = v_t.custom_access;
if param and aliases_t[param] then -- if already in <aliases_t>
table.insert (aliases_dups_t, table.concat ({param, ' in: id_handlers.', k, ' duplicated in: ', aliases_t[param]})); -- make a note
elseif param then
aliases_t[param] = 'id_handlers.' .. k; -- add this <param> with its associated id_hamdler to <aliases_t>
end
end
for wl_param, _ in pairs (whitelist_t) do
if not aliases_t[wl_param] then
table.insert (wh_params_not_in_aliases_t, wl_param);
end
end
for alias, _ in pairs (aliases_t) do
if not whitelist_t[alias] then
table.insert (alias_params_not_in_whitelist_t, alias);
end
end
table.sort (wh_params_not_in_aliases_t); -- sort so the lists are more pretty-like
table.sort (alias_params_not_in_whitelist_t);
table.sort (aliases_dups_t);
table.insert (wh_params_not_in_aliases_t, 1, '~/Whitelist parameters not found in ~/Configuration aliases list:'); -- insert a header describing this list
table.insert (alias_params_not_in_whitelist_t, 1, '~/Configuration alias parameters not found in ~/Whitelist:');
table.insert (aliases_dups_t, 1, 'parameters found in multiple ~/Configuration metaparameters:');
local aliases = mw.dumpObject (aliases_t);
local aliases_dups = table.concat (aliases_dups_t, '\n\t'); -- mw.dumpObject (aliases_dups_t);
local wh_params_not_in_aliases = table.concat (wh_params_not_in_aliases_t, '\n\t');
local whitelist = mw.dumpObject (whitelist_t);
local alias_params_not_in_whitelist = table.concat (alias_params_not_in_whitelist_t, '\n\t');
return {
aliases = aliases,
aliases_dups = aliases_dups,
whitelist = whitelist,
alias_params_not_in_whitelist = alias_params_not_in_whitelist,
wh_params_not_in_aliases = wh_params_not_in_aliases,
}