Module:Cs1 documentation support: Difference between revisions

m 1 revision imported: Templates and CSS files
m 1 revision imported: template update
 
(2 intermediate revisions by 2 users not shown)
Line 187: Line 187:
local lang = (frame.args.lang and '' ~= frame.args.lang) and frame.args.lang or mw.getContentLanguage():getCode()
local lang = (frame.args.lang and '' ~= frame.args.lang) and frame.args.lang or mw.getContentLanguage():getCode()
local source_list = mw.language.fetchLanguageNames(lang, 'all');
local source_list = mw.language.fetchLanguageNames(lang, 'all');
local override = cfg.lang_code_remap;
local override = cfg.lang_tag_remap;
local code_1_list={};
local code_1_list={};
local code_2_list={};
local code_2_list={};
Line 259: Line 259:
local function script_lang_lister (frame)
local function script_lang_lister (frame)
local lang_code_src = cfg.script_lang_codes ; -- get list of allowed script language codes
local lang_code_src = cfg.script_lang_codes ; -- get list of allowed script language codes
local override = cfg.lang_code_remap;
local override = cfg.lang_tag_remap;
local this_wiki_lang = mw.language.getContentLanguage().code; -- get this wiki's language
local this_wiki_lang = mw.language.getContentLanguage().code; -- get this wiki's language


Line 695: Line 695:
local lang_list_t = mw.language.fetchLanguageNames ('en', 'all');
local lang_list_t = mw.language.fetchLanguageNames ('en', 'all');
   
   
local function script_cat_lister (script_lang_codes_t, lang_code_remap_t, cats_list_t)
local function script_cat_lister (script_lang_codes_t, lang_tag_remap_t, cats_list_t)
for _, lang_code in ipairs (script_lang_codes_t) do
for _, lang_code in ipairs (script_lang_codes_t) do
local lang_name = lang_code_remap_t[lang_code] or lang_list_t[lang_code]; -- use remap table to get Bengali instead of Bangla and the like; else use standard MediaWiki names
local lang_name = lang_tag_remap_t[lang_code] or lang_list_t[lang_code]; -- use remap table to get Bengali instead of Bangla and the like; else use standard MediaWiki names
local cat = 'CS1 uses ' .. lang_name .. '-language script (' .. lang_code .. ')'; -- build a category name
local cat = 'CS1 uses ' .. lang_name .. '-language script (' .. lang_code .. ')'; -- build a category name
cats_list_t[cat] = 1; -- and save it
cats_list_t[cat] = 1; -- and save it
Line 778: Line 778:
end
end


script_cat_lister (cfg.script_lang_codes, cfg.lang_code_remap, list_live_cats); -- get live module's foriegn language script cats
script_cat_lister (cfg.script_lang_codes, cfg.lang_tag_remap, list_live_cats); -- get live module's foriegn language script cats


if sandbox then -- if ~/sandbox module exists and |sandbox= not set to 'no'
if sandbox then -- if ~/sandbox module exists and |sandbox= not set to 'no'
Line 786: Line 786:
end
end


script_cat_lister (sb_cfg.script_lang_codes, sb_cfg.lang_code_remap, list_sbox_cats); -- get sandbox module's foriegn language script cats
script_cat_lister (sb_cfg.script_lang_codes, sb_cfg.lang_tag_remap, list_sbox_cats); -- get sandbox module's foriegn language script cats
end
end
else
else
Line 984: Line 984:
Each subsequence table holds:
Each subsequence table holds:
[1] documentation page where the TemplateData json is stored ({{cite book}} is the oddball)
[1] documentation page where the TemplateData json is stored ({{cite book}} is the oddball)
[2] key to 'preprint_arguments' and unique_arguments' tables in Module:Citation/CS1/Whitelist; these keys
[2] key to 'preprint_arguments_t' and unique_arguments_t' tables in Module:Citation/CS1/Whitelist; these keys
dictate which of the basic or limited arguments and numbered arguments tables will be used to validate
dictate which of the basic or limited arguments and numbered arguments tables will be used to validate
the content of the TemplateData
the content of the TemplateData
Line 996: Line 996:
citebiorxiv = {'Template:Cite bioRxiv/doc', 'biorxiv'}, -- preprint arguments
citebiorxiv = {'Template:Cite bioRxiv/doc', 'biorxiv'}, -- preprint arguments
citebook = {'Template:Cite book/TemplateData'},
citebook = {'Template:Cite book/TemplateData'},
citeciteseerx = {'Template:Cite citeseerx/doc', 'citeseerx'}, -- no template data; preprint uses limited arguments
citeciteseerx = {'Template:Cite CiteSeerX/doc', 'citeseerx'}, -- no template data; preprint uses limited arguments
citeconference = {'Template:Cite conference/doc', 'conference'}, -- unique arguments
citeconference = {'Template:Cite conference/doc', 'conference'}, -- unique arguments
citedocument = {'Template:Cite document/doc', 'document'}, -- special case; uses whitelist.document_parameters_t
citeencyclopedia = {'Template:Cite encyclopedia/doc'},
citeencyclopedia = {'Template:Cite encyclopedia/doc'},
citeepisode = {'Template:Cite episode/doc', 'episode'}, -- unique arguments
citeepisode = {'Template:Cite episode/doc', 'episode'}, -- unique arguments
Line 1,005: Line 1,006:
citemailinglist = {'Template:Cite mailing list/doc', 'mailinglist'}, -- unique arguments -- no template data
citemailinglist = {'Template:Cite mailing list/doc', 'mailinglist'}, -- unique arguments -- no template data
citemap = {'Template:Cite map/TemplateData', 'map'}, -- unique arguments
citemap = {'Template:Cite map/TemplateData', 'map'}, -- unique arguments
citemedrxiv = {'Template:Cite medRxiv/doc', 'medrxiv'}, -- preprint arguments
citenews = {'Template:Cite news/doc'},
citenews = {'Template:Cite news/doc'},
citenewsgroup = {'Template:Cite newsgroup/doc', 'newsgroup'}, -- unique arguments
citenewsgroup = {'Template:Cite newsgroup/doc', 'newsgroup'}, -- unique arguments
Line 1,013: Line 1,015:
citesign = {'Template:Cite sign/doc'},
citesign = {'Template:Cite sign/doc'},
citespeech = {'Template:Cite speech/doc', 'speech'}, -- unique arguments -- no template data
citespeech = {'Template:Cite speech/doc', 'speech'}, -- unique arguments -- no template data
citessrn = {'Template:Cite ssrn/doc', 'ssrn'}, -- preprint arguments -- no template data
citessrn = {'Template:Cite SSRN/doc', 'ssrn'}, -- preprint arguments -- no template data
citetechreport = {'Template:Cite techreport/doc'},
citetechreport = {'Template:Cite tech report/doc'},
citethesis = {'Template:Cite thesis/doc', 'thesis'}, -- unique arguments
citethesis = {'Template:Cite thesis/doc', 'thesis'}, -- unique arguments
citeweb = {'Template:Cite web/doc'},
citeweb = {'Template:Cite web/doc'},
Line 1,058: Line 1,060:
json = json:match ('<[Tt]emplate[Dd]ata>(.-)</[Tt]emplate[Dd]ata>'); -- remove everything exept the content of the TemplatData tags
json = json:match ('<[Tt]emplate[Dd]ata>(.-)</[Tt]emplate[Dd]ata>'); -- remove everything exept the content of the TemplatData tags
return json and mw.text.jsonDecode (json); -- decode the json string and return as a table; nil if not found
return json and mw.text.jsonDecode (json); -- decode the json string and return as a table; nil if not found
end
--[[--------------------------< V A L I D A T E _ D O C U M E N T _ P A R A M >--------------------------------
looks for <param> (can be the canonical parameter name or can be an alias) in whitelist.document_parameters_t.
When found, returns true; nil else
<param> is the parameter's name as listed in the TemplateData
]]
local function validate_document_param (param)
if true == whitelist.document_parameters_t[param] then
return true;
end
end
end


Line 1,071: Line 1,089:


local function validate_basic_param (param)
local function validate_basic_param (param)
if true == whitelist.basic_arguments[param] or true == whitelist.numbered_arguments[param] then
if true == whitelist.common_parameters_t[param] then
return true;
return true;
end
end
Line 1,079: Line 1,097:
--[[--------------------------< V A L I D A T E _ P R E P R I N T _ P A R A M >--------------------------------
--[[--------------------------< V A L I D A T E _ P R E P R I N T _ P A R A M >--------------------------------


looks for <param> (can be the canonical parameter name or can be an alias) in whitelist.preprint_arguments{} or
looks for <param> (can be the canonical parameter name or can be an alias) in whitelist.preprint_arguments_t{} or
whitelist.limited_basic_arguments{} or whitelist.limited_numbered_arguments{}.  When found, returns true; nil else
whitelist.limited_basic_arguments{} or whitelist.limited_numbered_arguments{}.  When found, returns true; nil else


<param> is the parameter's name as listed in the TemplateData
<param> is the parameter's name as listed in the TemplateData
<key> is key neccessary to look in the appropriate subtable of whitelist.preprint_arguments{}
<key> is key neccessary to look in the appropriate subtable of whitelist.preprint_arguments_t{}


]]
]]


local function validate_preprint_param (param, key)
local function validate_preprint_param (param, key)
if true == whitelist.preprint_arguments[key][param] or  
if true == whitelist.preprint_arguments_t[key][param] or
true == whitelist.limited_basic_arguments[param] or
true == whitelist.limited_parameters_t[param] then
true == whitelist.limited_numbered_arguments[param] then
-- true == whitelist.limited_basic_arguments_t[param] or
-- true == whitelist.limited_numbered_arguments_t[param] then
return true;
return true;
end
end
Line 1,098: Line 1,117:
--[[--------------------------< V A L I D A T E _ U N I Q U E _ P A R A M >------------------------------------
--[[--------------------------< V A L I D A T E _ U N I Q U E _ P A R A M >------------------------------------


looks for <param> (can be the canonical parameter name or can be an alias) in whitelist.unique_arguments{} or
looks for <param> (can be the canonical parameter name or can be an alias) in whitelist.unique_arguments_t{} or
whitelist.basic_arguments{} or whitelist.numbered_arguments{}.  When found, returns true; nil else
whitelist.basic_arguments{} or whitelist.numbered_arguments{}.  When found, returns true; nil else


<param> is the parameter's name as listed in the TemplateData
<param> is the parameter's name as listed in the TemplateData
<key> is key neccessary to look in the appropriate subtable of whitelist.unique_arguments{}
<key> is key neccessary to look in the appropriate subtable of whitelist.unique_arguments_t{}


]]
]]


local function validate_unique_param (param, key, cfg_aliases_t)
local function validate_unique_param (param, key, cfg_aliases_t)
if true == whitelist.unique_arguments[key][param] or true == validate_basic_param (param) then
if true == whitelist.unique_arguments_t[key][param] or true == validate_basic_param (param) then
return true;
return true;
end
end
Line 1,133: Line 1,152:


local function param_error_msg (param)
local function param_error_msg (param)
return '<code style="color: inherit; background: inherit; border: none; padding: inherit">|' .. param .. '=</code> is not a valid parameter';
return '<span style="font-family:"monospace">|' .. param .. '=</span> is not a valid parameter';
end
 
 
--[[--------------------------< D U P _ A L I A S _ E R R O R_ M S G >-----------------------------------------
 
 
]]
 
local function dup_alias_error_msg (param, alias)
return '<span style="font-family:"monospace">|' .. param .. '=</span> has duplicate aliases: <span font-family:"monospace";>|' .. alias .. '=</span>';
end
 
 
--[[--------------------------< D U P _ A L I A S E S _ C H E C K >--------------------------------------------
 
create an associative array of <param> aliases. if <alias> already present in <aliases_t> add an error message
to <out>
 
]]
 
local function dup_aliases_check (param, alias, aliases_t, out_t)
if not aliases_t[alias] then
aliases_t[alias] = true;
else
table.insert (out_t, dup_alias_error_msg (param, alias));
end
end
end


Line 1,190: Line 1,235:
local function template_data_validate (frame)
local function template_data_validate (frame)
local args_t = getArgs (frame);
local args_t = getArgs (frame);
 
if not args_t[1] then
if not args_t[1] then
return '<span style="color:#d33">Error: cs1|2 template name required</span>';
return '<span style="color:#d33">Error: cs1|2 template name required</span>';
Line 1,203: Line 1,248:


local cfg_aliases_t = cfg_aliasts_t_make ();
local cfg_aliases_t = cfg_aliasts_t_make ();


local template_t = templates_t[template_idx];
local template_t = templates_t[template_idx];
Line 1,215: Line 1,259:
else
else
for param, param_t in pairs (json_t['params']) do
for param, param_t in pairs (json_t['params']) do
local param_i = param:gsub ('%d+', '#'); -- in case an enumerated parameter, convert the enumerate digits to a single '#' character
local param_i; -- this will be the parameter name that gets validated
if param:find ('[Ss]2[Cc][Ii][Dd]') then -- |s2cid*= parameters are not enumerated ...
param_i = param; -- ... so don't convert the '2' to '#'
else
param_i = param:gsub ('%d+', '#'); -- for enumerated parameters, convert the enumerator digits to a single '#' character; all others unmolested
end
 
local param_is_valid; -- boolean true when param is valid; nil else
local param_is_valid; -- boolean true when param is valid; nil else
if template_t[2] then -- if template is a preprint or uses unique parameters
if template_t[2] then -- if template is a preprint or uses unique parameters of 'document' parameters
if whitelist.preprint_arguments[template_t[2]] then -- if a preprint template
if 'document' == template_t[2] then -- if a {{cite document}} template
param_is_valid = validate_document_param (param_i, template_t[2]);
if param_is_valid then
local aliases_t = {}; -- used by dup_aliases_check
if param_t['aliases'] then
for _, alias in ipairs (param_t['aliases']) do
dup_aliases_check (param, alias, aliases_t, out);
local alias_i = alias:gsub ('%d+', '#'); -- in case an enumerated parameter, convert the enumerator digits to a single '#' character
if not validate_document_param (alias_i, template_t[2]) then -- is 'alias' a known parameter?
table.insert (out, alias_error_msg (param, alias)); -- may be known but is not supported
elseif cfg_aliases_t[param_i:gsub ('#', '')] ~= cfg_aliases_t[alias_i:gsub ('#', '')] then -- is 'alias' known to be an alias of 'param'?
table.insert (out, alias_error_msg (param, alias));
end
end
end
else -- here when param not valid preprint param
table.insert (out, param_error_msg (param))
end
elseif whitelist.preprint_arguments_t[template_t[2]] then -- if a preprint template
param_is_valid = validate_preprint_param (param_i, template_t[2]);
param_is_valid = validate_preprint_param (param_i, template_t[2]);
if param_is_valid then
if param_is_valid then
local aliases_t = {}; -- used by dup_aliases_check
if param_t['aliases'] then
if param_t['aliases'] then
for _, alias in ipairs (param_t['aliases']) do
for _, alias in ipairs (param_t['aliases']) do
dup_aliases_check (param, alias, aliases_t, out);
local alias_i = alias:gsub ('%d+', '#'); -- in case an enumerated parameter, convert the enumerator digits to a single '#' character
local alias_i = alias:gsub ('%d+', '#'); -- in case an enumerated parameter, convert the enumerator digits to a single '#' character
if not validate_preprint_param (alias_i, template_t[2]) then -- is 'alias' a known parameter?
if not validate_preprint_param (alias_i, template_t[2]) then -- is 'alias' a known parameter?
Line 1,234: Line 1,304:
table.insert (out, param_error_msg (param))
table.insert (out, param_error_msg (param))
  end
  end
elseif whitelist.unique_arguments[template_t[2]] then -- if a unique parameters template
elseif whitelist.unique_arguments_t[template_t[2]] then -- if a unique parameters template
param_is_valid = validate_unique_param (param_i, template_t[2]);
param_is_valid = validate_unique_param (param_i, template_t[2]);
if param_is_valid then
if param_is_valid then
local aliases_t = {}; -- used by dup_aliases_check
if param_t['aliases'] then
if param_t['aliases'] then
for _, alias in ipairs (param_t['aliases']) do
for _, alias in ipairs (param_t['aliases']) do
dup_aliases_check (param, alias, aliases_t, out);
local alias_i = alias:gsub ('%d+', '#'); -- in case an enumerated parameter, convert the enumerate digits to a single '#' character
local alias_i = alias:gsub ('%d+', '#'); -- in case an enumerated parameter, convert the enumerate digits to a single '#' character
if not validate_unique_param (alias_i, template_t[2]) then -- is 'alias' a known parameter?
if not validate_unique_param (alias_i, template_t[2]) then -- is 'alias' a known parameter?
Line 1,257: Line 1,329:
param_is_valid = validate_basic_param (param_i);
param_is_valid = validate_basic_param (param_i);
if param_is_valid then
if param_is_valid then
local aliases_t = {}; -- used by dup_aliases_check
if param_t['aliases'] then
if param_t['aliases'] then
for _, alias in ipairs (param_t['aliases']) do
for _, alias in ipairs (param_t['aliases']) do
dup_aliases_check (param, alias, aliases_t, out)
local alias_i = alias:gsub ('%d+', '#'); -- in case an enumerated parameter, convert the enumerate digits to a single '#' character
local alias_i = alias:gsub ('%d+', '#'); -- in case an enumerated parameter, convert the enumerate digits to a single '#' character
if not validate_basic_param (alias_i) and not validate_id_alias (param, alias) then -- for isbn13 (while still supported) must not mask the digits
if not validate_basic_param (alias_i) and not validate_id_alias (param, alias) then -- for isbn13 (while still supported) must not mask the digits
  table.insert (out, alias_error_msg (param, alias));
  table.insert (out, alias_error_msg (param, alias));
elseif cfg_aliases_t[param_i:gsub ('#', '')] ~= cfg_aliases_t[alias_i:gsub ('#', '')] then -- is 'alias' known to be an alias of 'param'?
table.insert (out, alias_error_msg (param, alias));
  end
  end
end
end
Line 1,302: Line 1,378:
return table.concat ({
return table.concat ({
'[[Template:' .. args_t[1] .. ']]  uses ',
'[[Template:' .. args_t[1] .. ']]  uses ',
whitelist.preprint_arguments[template_t[2]] and 'preprint and limited parameter sets' or (whitelist.unique_arguments[template_t[2]] and 'unique and standard parameter sets' or 'standard parameter set'),
whitelist.preprint_arguments_t[template_t[2]] and 'preprint and limited parameter sets' or (whitelist.unique_arguments_t[template_t[2]] and 'unique and standard parameter sets' or 'standard parameter set'),
'; TemplateData has errors:\n',
'; TemplateData has errors:\n',
'<div style="color:#d33; font-style: normal">\n', table.concat (out, '\n*'), '</div>'
'<div style="color:#d33; font-style: normal">\n', table.concat (out, '\n*'), '</div>'
Line 1,399: Line 1,475:


local function uncategorized_namespace_lister (frame)
local function uncategorized_namespace_lister (frame)
--TEMP DEVELOPMENT 2022-07-09 -- delete at next module update
local cfg = mw.loadData ('Module:Citation/CS1/Configuration/sandbox'); -- load the SANDBOX configuration module
--END TEMP DEVELOPMENT
local list_t = {};
local list_t = {};
local function compare (a, b) -- local function to sort namespaces numerically by the identifiers
local function compare (a, b) -- local function to sort namespaces numerically by the identifiers
Line 1,426: Line 1,499:
else -- make list of all namespaces and identifiers
else -- make list of all namespaces and identifiers
return table.concat (list_t, '\n'); -- make a big string and done
return table.concat (list_t, '\n'); -- make a big string and done
end
end
--[[--------------------------< S I N G L E _ L T R _ 2 N D _ L V L _ D O M A I N  _ L I S T E R >-------------
for Help:CS1_errors#bad_url, list the supported top level domains that support single-letter 2nd level names
{{#invoke:Module:cs1 documentation support|single_ltr_2nd_lvl_domain_lister}}
]]
local function single_ltr_2nd_lvl_domain_lister ()
local out_t = {}; -- output goes here
for _, tld in ipairs (cfg.single_letter_2nd_lvl_domains_t) do -- fetch each tld
table.insert (out_t, '.' .. tld); -- prefix with a dot and save in out_t{}
end
return table.concat (out_t, ', '); -- make a big string and done
end
--[[--------------------------< C O D E _ N A M E _ P A I R _ E X I S T S >----------------------------------------
Returns language code if pair exists, nil if either code doesn't exist or the name doesn't match.
Intended for use by Template:CS1 language sources/core
args[1] is language code
args[2] is language name
]]
local function code_name_pair_exists(frame)
local wiki_language = mw.getContentLanguage():getCode()
local source_list = mw.language.fetchLanguageNames(wiki_language, 'all');
local code_list = {};
local name_list = {};
local override = cfg.lang_tag_remap;
for code, name in pairs(source_list) do
add_to_list(code_list, name_list, override, code, name);
end
local args = getArgs(frame);
local language_code = args[1]
local language_name = args[2]
-- Check if the language code exists and the corresponding name matches
if code_list[language_code] == language_name then
-- Both code and name are a valid pair
return language_code
else
-- Either code doesn't exist or the name doesn't match
return nil
end
end
end
end
Line 1,439: Line 1,564:
canonical_name_get = canonical_name_get,
canonical_name_get = canonical_name_get,
cat_lister = cat_lister,
cat_lister = cat_lister,
code_name_pair_exists = code_name_pair_exists,
error_cat_page_tally = error_cat_page_tally,
error_cat_page_tally = error_cat_page_tally,
header_make = header_make,
header_make = header_make,
Line 1,449: Line 1,575:
maint_cat_page_tally = maint_cat_page_tally,
maint_cat_page_tally = maint_cat_page_tally,
script_lang_lister = script_lang_lister,
script_lang_lister = script_lang_lister,
single_ltr_2nd_lvl_domain_lister = single_ltr_2nd_lvl_domain_lister,
template_data_validate = template_data_validate,
template_data_validate = template_data_validate,
uncategorized_namespace_lister = uncategorized_namespace_lister,
uncategorized_namespace_lister = uncategorized_namespace_lister,
};
};