Module:Citation/CS1/Configuration/sandbox: Difference between revisions

no edit summary
m (1 revision imported: Templates and CSS files)
imported>Trappist the monk
No edit summary
 
Line 1: Line 1:
--[[
--[[
History of changes since last sync: 2022-07-01
History of changes since last sync: 2023-01-14


2022-07-09: i18n change for uncategorized namespaces; see Help_talk:Citation_Style_1#i18n_uncategorized_namespace_list
2023-02-20: maint cat for temp bibcodes; see Help_talk:Citation_Style_1#New_maintenance_category%3A_Category%3ACS1_maint%3A_bibcode
2022-07-10: add script tag pa;
2023-02-21: detect |archive-date= / |archive-url= timestamp mismatch; see Help_talk:Citation_Style_1#Error_or_Maint_message_if_archive_date_doesn't_match_url
2022-08-03: add 'allmusic' to 'generic_names' list; see Help_talk:Citation_Style_1/Archive_85#allmusic
2023-03-14: cleanup archive error messaging; see Help_talk:Citation_Style_1#Possible_invalid_edits_to_live_CS1_module
2022-09-22: add support for |article_number= in journal and conference cites; see Help_talk:Citation_Style_1/Archive_85#article_numbers
2023-03-16: i18n; autofill datenames['local_digits']; see Help_talk:Citation_Style_1#i18n_date_handling
2022-09-25: create list of single-letter second-level TLDs from main module; add 'foundation'; see Help_talk:Citation_Style_1#CS1_flagging_seemingly_fine_url_as_valid
2023-03-17: add mni script lang tag;
2022-10-09: update emoji list; see Help_talk:Citation_Style_1#Reconsider_throwing_an_error_on_ZWJ_sequences?
2022-10-23: add 'Reuters', 'Business', 'CNN', 'Inc' and 'Inc.' to 'generic_names' list; see Help_talk:Citation_Style_1#Reuters_and_Business_as_generic_last_names
2022-10-30: add script tag tt;


]]
]]


local lang_obj = mw.language.getContentLanguage(); -- make a language object for the local language; used here for languages and dates  
local lang_obj = mw.language.getContentLanguage(); -- make a language object for the local language; used here for languages and dates  
--[[--------------------------< S E T T I N G S >--------------------------------------------------------------
boolean settings used to control various things.  these setting located here to make them easy to find
]]
-- these settings local to this module only
local local_digits_from_mediawiki = false; -- for i18n; when true, module fills date_names['local_digits'] from MediaWiki; manual fill required else; always false at en.wiki
local local_date_names_from_mediawiki = false; -- for i18n; when true, module fills date_names['local']['long'] and date_names['local']['short'] from MediaWiki;
-- manual translation required else; ; always false at en.wiki
-- these settings exported to other modules
local use_identifier_redirects = true; -- when true use redirect name for identifier label links; always true at en.wiki
local local_lang_cat_enable = false; -- when true categorizes pages where |language=<local wiki's language>; always false at en.wiki
local date_name_auto_xlate_enable = false; -- when true translates English month-names to the local-wiki's language month names; always false at en.wiki
local date_digit_auto_xlate_enable = false; -- when true translates Western date digit to the local-wiki's language digits (date_names['local_digits']); always false at en.wiki


--[[--------------------------< U N C A T E G O R I Z E D _ N A M E S P A C E S >------------------------------
--[[--------------------------< U N C A T E G O R I Z E D _ N A M E S P A C E S >------------------------------
Line 48: Line 63:
['archived-dead'] = 'Archived from $1 on $2',
['archived-dead'] = 'Archived from $1 on $2',
['archived-live'] = '$1 from the original on $2',
['archived-live'] = '$1 from the original on $2',
['archived-missing'] = 'Archived from the original$1 on $2',
['archived-unfit'] = 'Archived from the original on ',
['archived-unfit'] = 'Archived from the original on ',
['archived'] = 'Archived',
['archived'] = 'Archived',
Line 631: Line 645:
date_names[invert_t[2]][i] = name; -- invert to get [i] = 'name' for conversions from ymd
date_names[invert_t[2]][i] = name; -- invert to get [i] = 'name' for conversions from ymd
end
end
end
if local_digits_from_mediawiki then -- if fetching local digits from MediaWiki is enabled
local digits_t = {};
for i=0, 9 do -- loop 10x and
digits_t [lang_obj:formatNum (i)] = tostring (i); -- format the loop indexer as local lang table index and assign loop indexer (a string) as the value
end
date_names['local_digits'] = digits_t;
end
end


Line 652: Line 674:
'{{ *([Mm]DY) *[|}]', -- 0
'{{ *([Mm]DY) *[|}]', -- 0
}
}
local title_object = mw.title.getCurrentTitle();
local content = title_object:getContent() or ''; -- get the content of the article or ''; new pages edited w/ve do not have 'content' until saved; ve does not preview; phab:T221625


local function get_date_format ()
local function get_date_format ()
local title_object = mw.title.getCurrentTitle();
if title_object.namespace == 10 then -- not in template space so that unused templates appear in unused-template-reports;  
if title_object.namespace == 10 then -- not in template space so that unused templates appear in unused-template-reports;  
return nil; -- auto-formatting does not work in Template space so don't set global_df
return nil; -- auto-formatting does not work in Template space so don't set global_df
end
end
local content = title_object:getContent() or ''; -- get the content of the article or ''; new pages edited w/ve do not have 'content' until saved; ve does not preview; phab:T221625
for _, pattern in ipairs (df_template_patterns) do -- loop through the patterns looking for {{Use dmy dates}} or {{Use mdy dates}} or any of their redirects
for _, pattern in ipairs (df_template_patterns) do -- loop through the patterns looking for {{Use dmy dates}} or {{Use mdy dates}} or any of their redirects
local start, _, match = content:find(pattern); -- match is the three letters indicating desired date format
local start, _, match = content:find(pattern); -- match is the three letters indicating desired date format
if match then
if match then
content = content:match ('%b{}', start); -- get the whole template
local use_dates_template = content:match ('%b{}', start); -- get the whole template
if content:match ('| *cs1%-dates *= *[lsy][sy]?') then -- look for |cs1-dates=publication date length access-/archive-date length
if use_dates_template:match ('| *cs1%-dates *= *[lsy][sy]?') then -- look for |cs1-dates=publication date length access-/archive-date length
return match:lower() .. '-' .. content:match ('| *cs1%-dates *= *([lsy][sy]?)');
return match:lower() .. '-' .. use_dates_template:match ('| *cs1%-dates *= *([lsy][sy]?)');
else
else
return match:lower() .. '-all'; -- no |cs1-dates= k/v pair; return value appropriate for use in |df=
return match:lower() .. '-all'; -- no |cs1-dates= k/v pair; return value appropriate for use in |df=
Line 672: Line 695:
end
end


local global_df;
local global_df; -- TODO: add this to <global_cs1_config_t>?




Line 862: Line 885:
['id-access'] = make_keywords_list ({keywords.free}),
['id-access'] = make_keywords_list ({keywords.free}),
}
}
--[[--------------------------< C S 1 _ C O N F I G _ G E T >--------------------------------------------------
fetch and validate values from {{cs1 config}} template to fill <global_cs1_config_t>
no error messages; when errors are detected, the parameter value from {{cs1 config}} is blanked.
Supports all parameters and aliases associated with the metaparameters: DisplayAuthors, DisplayContributors,
DisplayEditors, DisplayInterviewers, DisplayTranslators, NameListStyle, and Mode.  The DisplayWhatever metaparameters
accept numeric values only (|display-authors=etal and the like is not supported).
]]
local global_cs1_config_t = {}; -- TODO: add value returned from get_date_format() to this table?
local function get_cs1_config ()
if title_object.namespace == 10 then -- not in template space so that unused templates appear in unused-template-reports;
return nil; -- auto-formatting does not work in Template space so don't set global_df
end
local start = content:find('{{ *[Cc]s1 config *[|}]'); -- <start> is offset into <content> when {{cs1 config}} found; nil else
if start then
local cs1_config_template = content:match ('%b{}', start); -- get the whole template
if not cs1_config_template then
return nil;
end
local params_t = mw.text.split (cs1_config_template:gsub ('[{}]', ''), '%s*|%s*'); -- remove '{{' and '}}'; make a sequence of parameter/value pairs (split on the pipe)
table.remove (params_t, 1); -- remove the template name because it isn't a parameter/value pair
local config_meta_params_t = {'DisplayAuthors', 'DisplayContributors', 'DisplayEditors', 'DisplayInterviewers', 'DisplayTranslators', 'NameListStyle', 'Mode'};
local meta_param_map_t = {}; -- list of accepted parameter names usable in {{cs1 config}} goes here
for _, meta_param in ipairs (config_meta_params_t) do -- for i18n using <config_meta_params_t>, map template parameter names to their metaparameter equivalents
if 'table' == type (aliases[meta_param]) then -- if <meta_param> is a sequence,
for _, param in ipairs (aliases[meta_param]) do -- extract its contents
meta_param_map_t[param] = meta_param; -- and add to <meta_param_map_t>
end
else
meta_param_map_t[aliases[meta_param]] = meta_param; -- not a sequence so just add the parameter to <meta_param_map_t>
end
end
local keywords_t = {}; -- map valid keywords to their associate metaparameter; reverse form of <keyword_lists[key] for these metaparameters
for _, metaparam_t in ipairs ({{'NameListStyle', 'name-list-style'}, {'Mode', 'mode'}}) do -- only these metaparameter / keywords_lists key pairs
for _, keyword in ipairs (keywords_lists[metaparam_t[2]]) do -- spin through the list of keywords
keywords_t[keyword] = metaparam_t[1]; -- add [keyword] = metaparameter to the map
end
end
for _, param in ipairs (params_t) do -- spin through the {{cs1 config}} parameters and fill <global_cs1_config_t>
local k, v = param:match ('([^=]-)%s*=%s*(.+)'); -- <k> is the parameter name; <v> is parameter's assigned value
if k then
if k:find ('^display') then -- if <k> is one of the |display-<namelist>= parameters
if v:match ('%d+') then -- the assigned value must be digits; doesn't accept 'etal'
global_cs1_config_t[meta_param_map_t[k]]=v; -- add the display param and its value to globals table
end
else
if keywords_t[v] == meta_param_map_t[k] then -- keywords_t[v] returns nil or the metaparam name; these must be the same
global_cs1_config_t[meta_param_map_t[k]]=v; -- add the parameter and its value to globals table
end
end
end
end
end
end
get_cs1_config (); -- fill <global_cs1_config_t>




Line 1,008: Line 1,101:
local this_wiki_code = lang_obj:getCode(); -- get this wiki's language code
local this_wiki_code = lang_obj:getCode(); -- get this wiki's language code
if string.match (mw.site.server, 'wikidata') then
if string.match (mw.site.server, 'wikidata') then
this_wiki_code = mw.getCurrentFrame():preprocess('{{int:lang}}'); -- on Wikidata so use interface language setting instead
this_wiki_code = mw.getCurrentFrame():callParserFunction('int', {'lang'}); -- on Wikidata so use interface language setting instead
end
end


Line 1,040: Line 1,133:


local script_lang_codes = {
local script_lang_codes = {
'ab', 'am', 'ar', 'be', 'bg', 'bn', 'bo', 'bs', 'dv', 'dz', 'el', 'fa', 'gu',  
'ab', 'am', 'ar', 'be', 'bg', 'bn', 'bo', 'bs', 'dv', 'dz', 'el', 'fa', 'gu', 'he',
'he', 'hi', 'hy', 'ja', 'ka', 'kk', 'km', 'kn', 'ko', 'ku', 'ky', 'lo', 'mk',
'hi', 'hy', 'ja', 'ka', 'kk', 'km', 'kn', 'ko', 'ku', 'ky', 'lo', 'mk', 'ml', 'mn',
'ml', 'mn', 'mr', 'my', 'ne', 'or', 'ota', 'pa', 'ps', 'ru', 'sd', 'si', 'sr',
'mni', 'mr', 'my', 'ne', 'or', 'ota', 'pa', 'ps', 'ru', 'sd', 'si', 'sr', 'syc', 'ta',
'syc', 'ta', 'te', 'tg', 'th', 'ti', 'tt', 'ug', 'uk', 'ur', 'uz', 'yi', 'yue', 'zh'
'te', 'tg', 'th', 'ti', 'tt', 'ug', 'uk', 'ur', 'uz', 'yi', 'yue', 'zh'
};
};


Line 1,094: Line 1,187:
['taiwanese hokkien'] = {'Taiwanese Hokkien', 'nan-tw'}, -- make room for MediaWiki/IANA/ISO 639 nan: Min Nan Chinese  
['taiwanese hokkien'] = {'Taiwanese Hokkien', 'nan-tw'}, -- make room for MediaWiki/IANA/ISO 639 nan: Min Nan Chinese  
['tosk albanian'] = {'Tosk Albanian', 'als'}, -- MediaWiki replaces 'Tosk Albanian' with 'Alemannisch' so 'Tosk Albanian' cannot be found
['tosk albanian'] = {'Tosk Albanian', 'als'}, -- MediaWiki replaces 'Tosk Albanian' with 'Alemannisch' so 'Tosk Albanian' cannot be found
['valencian'] = {'Valencian', 'ca'}, -- variant of Catalan; categorizes as Catalan
['valencian'] = {'Valencian', 'ca-valencia'}, -- variant of Catalan; categorizes as Valencian
}
}


Line 1,205: Line 1,298:
hidden = false
hidden = false
  },
  },
err_archive_date_missing_url = {
message = '<code class="cs1-code">&#124;archive-date=</code> requires <code class="cs1-code">&#124;archive-url=</code>',
anchor = 'archive_date_missing_url',
category = 'CS1 errors: archive-url',
hidden = false
},
err_archive_date_url_ts_mismatch = {
message = '<code class="cs1-code">&#124;archive-date=</code> / <code class="cs1-code">&#124;archive-url=</code> timestamp mismatch',
anchor = 'archive_date_url_ts_mismatch',
category = 'CS1 errors: archive-url',
hidden = false
},
err_archive_missing_date = {
err_archive_missing_date = {
message = '<code class="cs1-code">&#124;archive-url=</code> requires <code class="cs1-code">&#124;archive-date=</code>',
message = '<code class="cs1-code">&#124;archive-url=</code> requires <code class="cs1-code">&#124;archive-date=</code>',
Line 1,668: Line 1,773:
anchor = 'authors',
anchor = 'authors',
category = 'CS1 maint: uses authors parameter',
category = 'CS1 maint: uses authors parameter',
hidden = true,
},
maint_bibcode = {
message = nil,
anchor = 'bibcode',
category = 'CS1 maint: bibcode',
hidden = true,
hidden = true,
},
},
Line 1,770: Line 1,881:
anchor = 'others_avm',
anchor = 'others_avm',
category = 'CS1 maint: others in cite AV media (notes)',
category = 'CS1 maint: others in cite AV media (notes)',
hidden = true,
},
maint_overridden_setting = {
message = nil,
anchor = 'overridden',
category = 'CS1 maint: overridden setting',
hidden = true,
hidden = true,
},
},
Line 1,868: Line 1,985:
q = 'Q118398',
q = 'Q118398',
label = 'arXiv',
label = 'arXiv',
prefix = '//arxiv.org/abs/', -- protocol-relative tested 2013-09-04
prefix = 'https://arxiv.org/abs/',
encode = false,
encode = false,
COinS = 'info:arxiv',
COinS = 'info:arxiv',
Line 1,880: Line 1,997:
q = 'Q1753278',
q = 'Q1753278',
label = 'ASIN',
label = 'ASIN',
prefix = '//www.amazon.',
prefix = 'https://www.amazon.',
COinS = 'url',
COinS = 'url',
separator = '&nbsp;',
separator = '&nbsp;',
Line 1,903: Line 2,020:
q = 'Q19835482',
q = 'Q19835482',
label = 'bioRxiv',
label = 'bioRxiv',
prefix = '//doi.org/',
prefix = 'https://doi.org/',
COinS = 'pre', -- use prefix value
COinS = 'pre', -- use prefix value
access = 'free', -- free to read
access = 'free', -- free to read
Line 1,915: Line 2,032:
q = 'Q2715061',
q = 'Q2715061',
label = 'CiteSeerX',
label = 'CiteSeerX',
prefix = '//citeseerx.ist.psu.edu/viewdoc/summary?doi=',
prefix = 'https://citeseerx.ist.psu.edu/viewdoc/summary?doi=',
COinS =  'pre', -- use prefix value
COinS =  'pre', -- use prefix value
access = 'free', -- free to read
access = 'free', -- free to read
Line 1,927: Line 2,044:
q = 'Q25670',
q = 'Q25670',
label = 'doi',
label = 'doi',
prefix = '//doi.org/',
prefix = 'https://doi.org/',
COinS = 'info:doi',
COinS = 'info:doi',
separator = ':',
separator = ':',
Line 1,939: Line 2,056:
q = 'Q46339674',
q = 'Q46339674',
label = 'eISSN',
label = 'eISSN',
prefix = '//www.worldcat.org/issn/',
prefix = 'https://www.worldcat.org/issn/',
COinS = 'rft.eissn',
COinS = 'rft.eissn',
encode = false,
encode = false,
Line 1,950: Line 2,067:
q = 'Q3126718',
q = 'Q3126718',
label = 'hdl',
label = 'hdl',
prefix = '//hdl.handle.net/',
prefix = 'https://hdl.handle.net/',
COinS = 'info:hdl',
COinS = 'info:hdl',
separator = ':',
separator = ':',
Line 1,982: Line 2,099:
q = 'Q131276',
q = 'Q131276',
label = 'ISSN',
label = 'ISSN',
prefix = '//www.worldcat.org/issn/',
prefix = 'https://www.worldcat.org/issn/',
COinS = 'rft.issn',
COinS = 'rft.issn',
encode = false,
encode = false,
Line 1,993: Line 2,110:
q = '',
q = '',
label = 'JFM',
label = 'JFM',
prefix = '//zbmath.org/?format=complete&q=an:',
prefix = 'https://zbmath.org/?format=complete&q=an:',
COinS = 'pre', -- use prefix value
COinS = 'pre', -- use prefix value
encode = true,
encode = true,
Line 2,004: Line 2,121:
q = 'Q1420342',
q = 'Q1420342',
label = 'JSTOR',
label = 'JSTOR',
prefix = '//www.jstor.org/stable/', -- protocol-relative tested 2013-09-04
prefix = 'https://www.jstor.org/stable/',
COinS = 'pre', -- use prefix value
COinS = 'pre', -- use prefix value
encode = false,
encode = false,
Line 2,016: Line 2,133:
q = 'Q620946',
q = 'Q620946',
label = 'LCCN',
label = 'LCCN',
prefix = '//lccn.loc.gov/', -- protocol-relative tested 2015-12-28
prefix = 'https://lccn.loc.gov/',
COinS = 'info:lccn',
COinS = 'info:lccn',
encode = false,
encode = false,
Line 2,027: Line 2,144:
q = 'Q211172',
q = 'Q211172',
label = 'MR',
label = 'MR',
prefix = '//www.ams.org/mathscinet-getitem?mr=', -- protocol-relative tested 2013-09-04
prefix = 'https://mathscinet.ams.org/mathscinet-getitem?mr=',
COinS = 'pre', -- use prefix value
COinS = 'pre', -- use prefix value
encode = true,
encode = true,
Line 2,038: Line 2,155:
q = 'Q190593',
q = 'Q190593',
label = 'OCLC',
label = 'OCLC',
prefix = '//www.worldcat.org/oclc/',
prefix = 'https://www.worldcat.org/oclc/',
COinS = 'info:oclcnum',
COinS = 'info:oclcnum',
encode = true,
encode = true,
Line 2,050: Line 2,167:
q = 'Q1201876',
q = 'Q1201876',
label = 'OL',
label = 'OL',
prefix = '//openlibrary.org/',
prefix = 'https://openlibrary.org/',
COinS = 'url',
COinS = 'url',
separator = '&nbsp;',
separator = '&nbsp;',
Line 2,062: Line 2,179:
q = 'Q2015776',
q = 'Q2015776',
label = 'OSTI',
label = 'OSTI',
prefix = '//www.osti.gov/biblio/', -- protocol-relative tested 2018-09-12
prefix = 'https://www.osti.gov/biblio/',
COinS = 'pre', -- use prefix value
COinS = 'pre', -- use prefix value
encode = true,
encode = true,
Line 2,075: Line 2,192:
q = 'Q229883',
q = 'Q229883',
label = 'PMC',
label = 'PMC',
prefix = '//www.ncbi.nlm.nih.gov/pmc/articles/PMC',
prefix = 'https://www.ncbi.nlm.nih.gov/pmc/articles/PMC',
suffix = '',
suffix = '',
COinS = 'pre', -- use prefix value
COinS = 'pre', -- use prefix value
encode = true,
encode = true,
separator = '&nbsp;',
separator = '&nbsp;',
id_limit = 9900000,
id_limit = 10100000,
access = 'free', -- free to read
access = 'free', -- free to read
},
},
Line 2,089: Line 2,206:
q = 'Q2082879',
q = 'Q2082879',
label = 'PMID',
label = 'PMID',
prefix = '//pubmed.ncbi.nlm.nih.gov/',
prefix = 'https://pubmed.ncbi.nlm.nih.gov/',
COinS = 'info:pmid',
COinS = 'info:pmid',
encode = false,
encode = false,
separator = '&nbsp;',
separator = '&nbsp;',
id_limit = 36900000,
id_limit = 37400000,
},
},
['RFC'] = {
['RFC'] = {
Line 2,101: Line 2,218:
q = 'Q212971',
q = 'Q212971',
label = 'RFC',
label = 'RFC',
prefix = '//tools.ietf.org/html/rfc',
prefix = 'https://tools.ietf.org/html/rfc',
COinS = 'pre', -- use prefix value
COinS = 'pre', -- use prefix value
encode = false,
encode = false,
Line 2,123: Line 2,240:
q = 'Q7550801',
q = 'Q7550801',
label = 'SSRN',
label = 'SSRN',
prefix = '//papers.ssrn.com/sol3/papers.cfm?abstract_id=',
prefix = 'https://papers.ssrn.com/sol3/papers.cfm?abstract_id=',
COinS = 'pre', -- use prefix value
COinS = 'pre', -- use prefix value
encode = true,
encode = true,
separator = '&nbsp;',
separator = '&nbsp;',
id_limit = 4300000,
id_limit = 4400000,
custom_access = 'ssrn-access',
custom_access = 'ssrn-access',
},
},
Line 2,140: Line 2,257:
encode = false,
encode = false,
separator = '&nbsp;',
separator = '&nbsp;',
id_limit = 256000000,
id_limit = 258000000,
custom_access = 's2cid-access',
custom_access = 's2cid-access',
},
},
Line 2,160: Line 2,277:
q = 'Q190269',
q = 'Q190269',
label = 'Zbl',
label = 'Zbl',
prefix = '//zbmath.org/?format=complete&q=an:',
prefix = 'https://zbmath.org/?format=complete&q=an:',
COinS = 'pre', -- use prefix value
COinS = 'pre', -- use prefix value
encode = true,
encode = true,
Line 2,172: Line 2,289:


return {
return {
use_identifier_redirects = true, -- when true use redirect name for identifier label links; always true at en.wiki
use_identifier_redirects = use_identifier_redirects, -- booleans defined in the settings at the top of this module
local_lang_cat_enable = false; -- when true categorizes pages where |language=<local wiki's language>; always false at en.wiki
local_lang_cat_enable = local_lang_cat_enable,
date_name_auto_xlate_enable = false; -- when true translates English month-names to the local-wiki's language month names; always false at en.wiki
date_name_auto_xlate_enable = date_name_auto_xlate_enable,
date_digit_auto_xlate_enable = false; -- when true translates Western date digit to the local-wiki's language digits (date_names['local_digits']); always false at en.wiki
date_digit_auto_xlate_enable = date_digit_auto_xlate_enable,
-- tables and variables created when this module is loaded
-- tables and variables created when this module is loaded
global_df = get_date_format (), -- this line can be replaced with "global_df = 'dmy-all'," to have all dates auto translated to dmy format.
global_df = get_date_format (), -- this line can be replaced with "global_df = 'dmy-all'," to have all dates auto translated to dmy format.
global_cs1_config_t = global_cs1_config_t, -- global settings from {{cs1 config}}
punct_skip = build_skip_table (punct_skip, punct_meta_params),
punct_skip = build_skip_table (punct_skip, punct_meta_params),
url_skip = build_skip_table (url_skip, url_meta_params),
url_skip = build_skip_table (url_skip, url_meta_params),