「モジュール:Citation/CS1」の版間の差分

sync from sandbox;
(1版 をインポートしました)
bsd>Trappist the monk
(sync from sandbox;)
1行目: 1行目:
 
require('strict');
require('Module:No globals');


--[[--------------------------< F O R W A R D  D E C L A R A T I O N S >--------------------------------------
--[[--------------------------< F O R W A R D  D E C L A R A T I O N S >--------------------------------------
11行目: 10行目:


local utilities; -- functions in Module:Citation/CS1/Utilities
local utilities; -- functions in Module:Citation/CS1/Utilities
local z ={}; -- table of tables in Module:Citation/CS1/Utilities
local z = {}; -- table of tables in Module:Citation/CS1/Utilities


local identifiers; -- functions and tables in Module:Citation/CS1/Identifiers
local identifiers; -- functions and tables in Module:Citation/CS1/Identifiers
19行目: 18行目:




--[[--------------------------< P A G E  S C O P E  V A R I A B L E S >--------------------------------------
--[[------------------< P A G E  S C O P E  V A R I A B L E S >---------------


declare variables here that have page-wide scope that are not brought in from other modules; that are created here and used here
declare variables here that have page-wide scope that are not brought in from
other modules; that are created here and used here


]]
]]
27行目: 27行目:
local added_deprecated_cat; -- Boolean flag so that the category is added only once
local added_deprecated_cat; -- Boolean flag so that the category is added only once
local added_vanc_errs; -- Boolean flag so we only emit one Vancouver error / category
local added_vanc_errs; -- Boolean flag so we only emit one Vancouver error / category
 
local added_generic_name_errs; -- Boolean flag so we only emit one generic name error / category and stop testing names once an error is encountered
local Frame; -- holds the module's frame table
local Frame; -- holds the module's frame table
local is_preview_mode; -- true when article is in preview mode; false when using 'Preview page with this template' (previewing the module)
local is_sandbox; -- true when using sandbox modules to render citation




62行目: 64行目:
]]
]]


local function add_vanc_error (source)
local function add_vanc_error (source, position)
if not added_vanc_errs then
if added_vanc_errs then return end
added_vanc_errs = true; -- note that we've added this category
table.insert( z.message_tail, { utilities.set_message ( 'err_vancouver', {source}, true ) } );
added_vanc_errs = true; -- note that we've added this category
end
utilities.set_message ('err_vancouver', {source, position});
end
end


152行目: 154行目:
end
end


for _, d in ipairs ({'cash', 'company', 'today', 'org'}) do -- look for single letter second level domain names for these top level domains
for _, d in ipairs (cfg.single_letter_2nd_lvl_domains_t) do -- look for single letter second level domain names for these top level domains
if domain:match ('%f[%w][%w]%.' .. d) then
if domain:match ('%f[%w][%w]%.' .. d) then
return true
return true
263行目: 265行目:


local function link_title_ok (link, lorig, title, torig)
local function link_title_ok (link, lorig, title, torig)
local orig;
local orig;
if utilities.is_set (link) then -- don't bother if <param>-link doesn't have a value
if utilities.is_set (link) then -- don't bother if <param>-link doesn't have a value
if not link_param_ok (link) then -- check |<param>-link= markup
if not link_param_ok (link) then -- check |<param>-link= markup
280行目: 282行目:
if utilities.is_set (orig) then
if utilities.is_set (orig) then
link = ''; -- unset
link = ''; -- unset
table.insert( z.message_tail, { utilities.set_message ( 'err_bad_paramlink', orig)}); -- URL or wikilink in |title= with |title-link=;
utilities.set_message ('err_bad_paramlink', orig); -- URL or wikilink in |title= with |title-link=;
end
end
355行目: 357行目:
]]
]]


local function check_for_url (parameter_list)
local function check_for_url (parameter_list, error_list)
local error_message = '';
for k, v in pairs (parameter_list) do -- for each parameter in the list
for k, v in pairs (parameter_list) do -- for each parameter in the list
if is_parameter_ext_wikilink (v) then -- look at the value; if there is a URL add an error message
if is_parameter_ext_wikilink (v) then -- look at the value; if there is a URL add an error message
if utilities.is_set(error_message) then -- once we've added the first portion of the error message ...
table.insert (error_list, utilities.wrap_style ('parameter', k));
error_message = error_message .. ", "; -- ... add a comma space separator
end
error_message = error_message .. "&#124;" .. k .. "="; -- add the failed parameter
end
end
end
if utilities.is_set (error_message) then -- done looping, if there is an error message, display it
table.insert( z.message_tail, { utilities.set_message ( 'err_param_has_ext_link', {error_message}, true ) } );
end
end
end
end
379行目: 374行目:
local function safe_for_url( str )
local function safe_for_url( str )
if str:match( "%[%[.-%]%]" ) ~= nil then  
if str:match( "%[%[.-%]%]" ) ~= nil then  
table.insert( z.message_tail, { utilities.set_message ( 'err_wikilink_in_url', {}, true ) } );
utilities.set_message ('err_wikilink_in_url', {});
end
end
395行目: 390行目:
]]
]]


local function external_link( URL, label, source, access)
local function external_link (URL, label, source, access)
local error_str = "";
local err_msg = '';
local domain;
local domain;
local path;
local path;
local base_url;
local base_url;


if not utilities.is_set ( label ) then
if not utilities.is_set (label) then
label = URL;
label = URL;
if utilities.is_set ( source ) then
if utilities.is_set (source) then
error_str = utilities.set_message ( 'err_bare_url_missing_title', { utilities.wrap_style ('parameter', source) }, false, " " );
utilities.set_message ('err_bare_url_missing_title', {utilities.wrap_style ('parameter', source)});
else
else
error( cfg.messages["bare_url_no_origin"] );
error (cfg.messages["bare_url_no_origin"]); -- programmer error; valid parameter name does not have matching meta-parameter
end
end
end
end
if not check_url( URL ) then
if not check_url (URL) then
error_str = utilities.set_message ( 'err_bad_url', {utilities.wrap_style ('parameter', source)}, false, " " ) .. error_str;
utilities.set_message ('err_bad_url', {utilities.wrap_style ('parameter', source)});
end
end
domain, path = URL:match ('^([/%.%-%+:%a%d]+)([/%?#].*)$'); -- split the URL into scheme plus domain and path
domain, path = URL:match ('^([/%.%-%+:%a%d]+)([/%?#].*)$'); -- split the URL into scheme plus domain and path
if path then -- if there is a path portion
if path then -- if there is a path portion
path = path:gsub ('[%[%]]', {['['] = '%5b', [']'] = '%5d'}); -- replace '[' and ']' with their percent-encoded values
path = path:gsub ('[%[%]]', {['['] = '%5b', [']'] = '%5d'}); -- replace '[' and ']' with their percent-encoded values
URL = table.concat ({domain, path}); -- and reassemble
URL = table.concat ({domain, path}); -- and reassemble
end
end


base_url = table.concat({ "[", URL, " ", safe_for_url (label), "]" }); -- assemble a wiki-markup URL
base_url = table.concat ({ "[", URL, " ", safe_for_url (label), "]" }); -- assemble a wiki-markup URL


if utilities.is_set (access) then -- access level (subscription, registration, limited)
if utilities.is_set (access) then -- access level (subscription, registration, limited)
base_url = utilities.substitute (cfg.presentation['ext-link-access-signal'], {cfg.presentation[access].class, cfg.presentation[access].title, base_url}); -- add the appropriate icon
base_url = utilities.substitute (cfg.presentation['ext-link-access-signal'], {cfg.presentation[access].class, cfg.presentation[access].title, base_url}); -- add the appropriate icon
end
end
 
return table.concat ({base_url, error_str});
return base_url;
end
end


442行目: 437行目:
if not added_deprecated_cat then
if not added_deprecated_cat then
added_deprecated_cat = true; -- note that we've added this category
added_deprecated_cat = true; -- note that we've added this category
table.insert( z.message_tail, { utilities.set_message ( 'err_deprecated_params', {name}, true ) } ); -- add error message
utilities.set_message ('err_deprecated_params', {name}); -- add error message
end
end
end
end
466行目: 461行目:
local function kern_quotes (str)
local function kern_quotes (str)
local cap = '';
local cap = '';
local cap2 = '';
local wl_type, label, link;
local wl_type, label, link;


473行目: 467行目:
if 1 == wl_type then -- [[D]] simple wikilink with or without quote marks
if 1 == wl_type then -- [[D]] simple wikilink with or without quote marks
if mw.ustring.match (str, '%[%[[\"“”\'‘’].+[\"“”\'‘’]%]%]') then -- leading and trailing quote marks
if mw.ustring.match (str, '%[%[[\"“”\'‘’].+[\"“”\'‘’]%]%]') then -- leading and trailing quote marks
str = utilities.substitute (cfg.presentation['kern-wl-both'], str);
str = utilities.substitute (cfg.presentation['kern-left'], str);
str = utilities.substitute (cfg.presentation['kern-right'], str);
elseif mw.ustring.match (str, '%[%[[\"“”\'‘’].+%]%]') then -- leading quote marks
elseif mw.ustring.match (str, '%[%[[\"“”\'‘’].+%]%]') then -- leading quote marks
str = utilities.substitute (cfg.presentation['kern-wl-left'], str);
str = utilities.substitute (cfg.presentation['kern-left'], str);
elseif mw.ustring.match (str, '%[%[.+[\"“”\'‘’]%]%]') then -- trailing quote marks
elseif mw.ustring.match (str, '%[%[.+[\"“”\'‘’]%]%]') then -- trailing quote marks
str = utilities.substitute (cfg.presentation['kern-wl-right'], str);
str = utilities.substitute (cfg.presentation['kern-right'], str);
end
end


484行目: 479行目:
label = mw.ustring.gsub (label, '[‘’]', '\''); -- replace ‘’ (U+2018 & U+2019) with ' (typewriter single quote mark)
label = mw.ustring.gsub (label, '[‘’]', '\''); -- replace ‘’ (U+2018 & U+2019) with ' (typewriter single quote mark)


cap, cap2 = mw.ustring.match (label, "^([\"\'])([^\'].+)"); -- match leading double or single quote but not doubled single quotes (italic markup)
cap = mw.ustring.match (label, "^([\"\'][^\'].+)"); -- match leading double or single quote but not doubled single quotes (italic markup)
if utilities.is_set (cap) then
if utilities.is_set (cap) then
label = utilities.substitute (cfg.presentation['kern-left'], {cap, cap2});
label = utilities.substitute (cfg.presentation['kern-left'], cap);
end
end
cap, cap2 = mw.ustring.match (label, "^(.+[^\'])([\"\'])$") -- match trailing double or single quote but not doubled single quotes (italic markup)
cap = mw.ustring.match (label, "^(.+[^\'][\"\'])$") -- match trailing double or single quote but not doubled single quotes (italic markup)
if utilities.is_set (cap) then
if utilities.is_set (cap) then
label = utilities.substitute (cfg.presentation['kern-right'], {cap, cap2});
label = utilities.substitute (cfg.presentation['kern-right'], cap);
end
end
534行目: 529行目:
lang = script_value:match('^(%l%l%l?)%s*:%s*%S.*'); -- get the language prefix or nil if there is no script
lang = script_value:match('^(%l%l%l?)%s*:%s*%S.*'); -- get the language prefix or nil if there is no script
if not utilities.is_set (lang) then
if not utilities.is_set (lang) then
table.insert( z.message_tail, { utilities.set_message ( 'err_script_parameter', {script_param, 'missing title part'}, true ) } ); -- prefix without 'title'; add error message
utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['missing title part']}); -- prefix without 'title'; add error message
return ''; -- script_value was just the prefix so return empty string
return ''; -- script_value was just the prefix so return empty string
end
end
-- if we get this far we have prefix and script
-- if we get this far we have prefix and script
name = cfg.lang_code_remap[lang] or mw.language.fetchLanguageName( lang, cfg.this_wiki_code ); -- get language name so that we can use it to categorize
name = cfg.lang_code_remap[lang] or mw.language.fetchLanguageName( lang, cfg.this_wiki_code ); -- get language name so that we can use it to categorize
if utilities.is_set (name) then -- is prefix a proper ISO 639-1 language code?
if utilities.is_set (name) then -- is prefix a proper ISO 639-1 language code?
script_value = script_value:gsub ('^%l+%s*:%s*', ''); -- strip prefix from script
script_value = script_value:gsub ('^%l+%s*:%s*', ''); -- strip prefix from script
-- is prefix one of these language codes?
-- is prefix one of these language codes?
if utilities.in_array (lang, cfg.script_lang_codes) then
if utilities.in_array (lang, cfg.script_lang_codes) then
utilities.add_prop_cat ('script_with_name', {name, lang})
utilities.add_prop_cat ('script', {name, lang})
else
else
table.insert( z.message_tail, { utilities.set_message ( 'err_script_parameter', {script_param, 'unknown language code'}, true ) } ); -- unknown script-language; add error message
utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['unknown language code']}); -- unknown script-language; add error message
end
end
lang = ' lang="' .. lang .. '" '; -- convert prefix into a lang attribute
lang = ' lang="' .. lang .. '" '; -- convert prefix into a lang attribute
else
else
table.insert( z.message_tail, { utilities.set_message ( 'err_script_parameter', {script_param, 'invalid language code'}, true ) } ); -- invalid language code; add error message
utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['invalid language code']}); -- invalid language code; add error message
lang = ''; -- invalid so set lang to empty string
lang = ''; -- invalid so set lang to empty string
end
end
else
else
table.insert( z.message_tail, { utilities.set_message ( 'err_script_parameter', {script_param, 'missing prefix'}, true ) } ); -- no language code prefix; add error message
utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['missing prefix']}); -- no language code prefix; add error message
end
end
script_value = utilities.substitute (cfg.presentation['bdi'], {lang, script_value}); -- isolate in case script is RTL
script_value = utilities.substitute (cfg.presentation['bdi'], {lang, script_value}); -- isolate in case script is RTL
563行目: 558行目:
--[[--------------------------< S C R I P T _ C O N C A T E N A T E >------------------------------------------
--[[--------------------------< S C R I P T _ C O N C A T E N A T E >------------------------------------------


Initially for |title= and |script-title=, this function concatenates those two parameter values after the script value has been  
Initially for |title= and |script-title=, this function concatenates those two parameter values after the script
wrapped in <bdi> tags.
value has been wrapped in <bdi> tags.
 
]]
]]


600行目: 596行目:




--[[--------------------------< W I K I S O U R C E _ U R L _ M A K E >----------------------------------------
--[[----------------< W I K I S O U R C E _ U R L _ M A K E >-------------------


Makes a Wikisource URL from Wikisource interwiki-link.  Returns the URL and appropriate label; nil else.
Makes a Wikisource URL from Wikisource interwiki-link.  Returns the URL and appropriate
label; nil else.


str is the value assigned to |chapter= (or aliases) or |title= or |title-link=
str is the value assigned to |chapter= (or aliases) or |title= or |title-link=
643行目: 640行目:
end
end
end
end
 
if ws_url then
if ws_url then
ws_url = mw.uri.encode (ws_url, 'WIKI'); -- make a usable URL
ws_url = mw.uri.encode (ws_url, 'WIKI'); -- make a usable URL
ws_url = ws_url:gsub ('%%23', '#'); -- undo percent encoding of fragment marker
ws_url = ws_url:gsub ('%%23', '#'); -- undo percent-encoding of fragment marker
end
end


653行目: 650行目:




--[[--------------------------< F O R M A T _ P E R I O D I C A L >--------------------------------------------
--[[----------------< F O R M A T _ P E R I O D I C A L >-----------------------


Format the three periodical parameters: |script-<periodical>=, |<periodical>=, and |trans-<periodical>= into a single Periodical meta-
Format the three periodical parameters: |script-<periodical>=, |<periodical>=,
parameter.
and |trans-<periodical>= into a single Periodical meta-parameter.


]]
]]


local function format_periodical (script_periodical, script_periodical_source, periodical, trans_periodical)
local function format_periodical (script_periodical, script_periodical_source, periodical, trans_periodical)
local periodical_error = '';


if not utilities.is_set (periodical) then
if not utilities.is_set (periodical) then
677行目: 673行目:
else -- here when trans-periodical without periodical or script-periodical
else -- here when trans-periodical without periodical or script-periodical
periodical = trans_periodical;
periodical = trans_periodical;
periodical_error = ' ' .. utilities.set_message ('err_trans_missing_title', {'periodical'});
utilities.set_message ('err_trans_missing_title', {'periodical'});
end
end
end
end


return periodical .. periodical_error;
return periodical;
end
end




--[[--------------------------< F O R M A T _ C H A P T E R _ T I T L E >--------------------------------------
--[[------------------< F O R M A T _ C H A P T E R _ T I T L E >---------------


Format the four chapter parameters: |script-chapter=, |chapter=, |trans-chapter=, and |chapter-url= into a single chapter meta-
Format the four chapter parameters: |script-chapter=, |chapter=, |trans-chapter=,
parameter (chapter_url_source used for error messages).
and |chapter-url= into a single chapter meta- parameter (chapter_url_source used
for error messages).


]]
]]


local function format_chapter_title (script_chapter, script_chapter_source, chapter, chapter_source, trans_chapter, trans_chapter_source, chapter_url, chapter_url_source, no_quotes, access)
local function format_chapter_title (script_chapter, script_chapter_source, chapter, chapter_source, trans_chapter, trans_chapter_source, chapter_url, chapter_url_source, no_quotes, access)
local chapter_error = '';
local ws_url, ws_label, L = wikisource_url_make (chapter); -- make a wikisource URL and label from a wikisource interwiki link
local ws_url, ws_label, L = wikisource_url_make (chapter); -- make a wikisource URL and label from a wikisource interwiki link
if ws_url then
if ws_url then
ws_label = ws_label:gsub ('_', ''); -- replace underscore separaters with space characters
ws_label = ws_label:gsub ('_', ' '); -- replace underscore separators with space characters
chapter = ws_label;
chapter = ws_label;
end
end
726行目: 721行目:
chapter = trans_chapter;
chapter = trans_chapter;
chapter_source = trans_chapter_source:match ('trans%-?(.+)'); -- when no chapter, get matching name from trans-<param>
chapter_source = trans_chapter_source:match ('trans%-?(.+)'); -- when no chapter, get matching name from trans-<param>
chapter_error = ' ' .. utilities.set_message ('err_trans_missing_title', {chapter_source});
utilities.set_message ('err_trans_missing_title', {chapter_source});
end
end
end
end


return chapter .. chapter_error;
return chapter;
end
end




--[[--------------------------< H A S _ I N V I S I B L E _ C H A R S >----------------------------------------
--[[----------------< H A S _ I N V I S I B L E _ C H A R S >-------------------


This function searches a parameter's value for non-printable or invisible characters. The search stops at the
This function searches a parameter's value for non-printable or invisible characters.
first match.
The search stops at the first match.


This function will detect the visible replacement character when it is part of the Wikisource.
This function will detect the visible replacement character when it is part of the Wikisource.


Detects but ignores nowiki and math stripmarkers.  Also detects other named stripmarkers (gallery, math, pre, ref)
Detects but ignores nowiki and math stripmarkers.  Also detects other named stripmarkers
and identifies them with a slightly different error message. See also coins_cleanup().
(gallery, math, pre, ref) and identifies them with a slightly different error message.
See also coins_cleanup().


Output of this function is an error message that identifies the character or the Unicode group, or the stripmarker
Output of this function is an error message that identifies the character or the
that was detected along with its position (or, for multi-byte characters, the position of its first byte) in the
Unicode group, or the stripmarker that was detected along with its position (or,
parameter value.
for multi-byte characters, the position of its first byte) in the parameter value.


]]
]]
752行目: 748行目:
local function has_invisible_chars (param, v)
local function has_invisible_chars (param, v)
local position = ''; -- position of invisible char or starting position of stripmarker
local position = ''; -- position of invisible char or starting position of stripmarker
local dummy; -- end of matching string; not used but required to hold end position when a capture is returned
local capture; -- used by stripmarker detection to hold name of the stripmarker
local capture; -- used by stripmarker detection to hold name of the stripmarker
local i = 1;
local stripmarker; -- boolean set true when a stripmarker is found
local stripmarker, apostrophe;
 
capture = string.match (v, '[%w%p ]*'); -- test for values that are simple ASCII text and bypass other tests if true
capture = string.match (v, '[%w%p ]*'); -- test for values that are simple ASCII text and bypass other tests if true
if capture == v then -- if same there are no Unicode characters
if capture == v then -- if same there are no Unicode characters
762行目: 756行目:
end
end


while cfg.invisible_chars[i] do
for _, invisible_char in ipairs (cfg.invisible_chars) do
local char = cfg.invisible_chars[i][1] -- the character or group name
local char_name = invisible_char[1]; -- the character or group name
local pattern = cfg.invisible_chars[i][2] -- the pattern used to find it
local pattern = invisible_char[2]; -- the pattern used to find it
position, dummy, capture = mw.ustring.find (v, pattern) -- see if the parameter value contains characters that match the pattern
position, _, capture = mw.ustring.find (v, pattern); -- see if the parameter value contains characters that match the pattern
if position and (char == 'zero width joiner') then -- if we found a zero-width joiner character
if position and (cfg.invisible_defs.zwj == capture) then -- if we found a zero-width joiner character
if mw.ustring.find (v, cfg.indic_script) then -- it's ok if one of the Indic scripts
if mw.ustring.find (v, cfg.indic_script) then -- it's ok if one of the Indic scripts
position = nil; -- unset position
elseif cfg.emoji_t[mw.ustring.codepoint (v, position+1)] then -- is zwj followed by a character listed in emoji{}?
position = nil; -- unset position
position = nil; -- unset position
end
end
777行目: 773行目:
('templatestyles' == capture and utilities.in_array (param, {'id', 'quote'})) then -- templatestyles stripmarker allowed in these parameters
('templatestyles' == capture and utilities.in_array (param, {'id', 'quote'})) then -- templatestyles stripmarker allowed in these parameters
stripmarker = true; -- set a flag
stripmarker = true; -- set a flag
elseif true == stripmarker and 'delete' == char then -- because stripmakers begin and end with the delete char, assume that we've found one end of a stripmarker
elseif true == stripmarker and cfg.invisible_defs.del == capture then -- because stripmakers begin and end with the delete char, assume that we've found one end of a stripmarker
position = nil; -- unset
position = nil; -- unset
else
else
local err_msg;
local err_msg;
if capture then
if capture and not (cfg.invisible_defs.del == capture or cfg.invisible_defs.zwj == capture) then
err_msg = capture .. ' ' .. char;
err_msg = capture .. ' ' .. char_name;
else
else
err_msg = char .. ' ' .. 'character';
err_msg = char_name .. ' ' .. 'character';
end
end


table.insert( z.message_tail, { utilities.set_message ( 'err_invisible_char', {err_msg, utilities.wrap_style ('parameter', param), position}, true ) } ); -- add error message
utilities.set_message ('err_invisible_char', {err_msg, utilities.wrap_style ('parameter', param), position}); -- add error message
return; -- and done with this parameter
return; -- and done with this parameter
end
end
end
end
i = i+1; -- bump our index
end
end
end
end




--[[--------------------------< A R G U M E N T _ W R A P P E R >----------------------------------------------
--[[-------------------< A R G U M E N T _ W R A P P E R >----------------------


Argument wrapper.  This function provides support for argument mapping defined in the configuration file so that
Argument wrapper.  This function provides support for argument mapping defined
multiple names can be transparently aliased to single internal variable.
in the configuration file so that multiple names can be transparently aliased to
single internal variable.


]]
]]
808行目: 804行目:
return setmetatable({
return setmetatable({
ORIGIN = function ( self, k )
ORIGIN = function ( self, k )
local dummy = self[k]; --force the variable to be loaded.
local dummy = self[k]; -- force the variable to be loaded.
return origin[k];
return origin[k];
end
end
823行目: 819行目:
v, origin[k] = utilities.select_one ( args, list, 'err_redundant_parameters' );
v, origin[k] = utilities.select_one ( args, list, 'err_redundant_parameters' );
if origin[k] == nil then
if origin[k] == nil then
origin[k] = ''; -- Empty string, not nil
origin[k] = ''; -- Empty string, not nil
end
end
elseif list ~= nil then
elseif list ~= nil then
846行目: 842行目:




--[[--------------------------< N O W R A P _ D A T E >--------------------------------------------------------
--[[--------------------------< N O W R A P _ D A T E >-------------------------


When date is YYYY-MM-DD format wrap in nowrap span: <span ...>YYYY-MM-DD</span>. When date is DD MMMM YYYY or is
When date is YYYY-MM-DD format wrap in nowrap span: <span ...>YYYY-MM-DD</span>.
MMMM DD, YYYY then wrap in nowrap span: <span ...>DD MMMM</span> YYYY or <span ...>MMMM DD,</span> YYYY
When date is DD MMMM YYYY or is MMMM DD, YYYY then wrap in nowrap span:
<span ...>DD MMMM</span> YYYY or <span ...>MMMM DD,</span> YYYY


DOES NOT yet support MMMM YYYY or any of the date ranges.
DOES NOT yet support MMMM YYYY or any of the date ranges.
871行目: 868行目:




--[[--------------------------< S E T _ T I T L E T Y P E >----------------------------------------------------
--[[--------------------------< S E T _ T I T L E T Y P E >---------------------


This function sets default title types (equivalent to the citation including |type=<default value>) for those templates that have defaults.
This function sets default title types (equivalent to the citation including
Also handles the special case where it is desirable to omit the title type from the rendered citation (|type=none).
|type=<default value>) for those templates that have defaults. Also handles the
special case where it is desirable to omit the title type from the rendered citation
(|type=none).


]]
]]
890行目: 889行目:




--[[--------------------------< H Y P H E N _ T O _ D A S H >--------------------------------------------------
--[[--------------------------< S A F E _ J O I N >-----------------------------
 
Converts a hyphen to a dash under certain conditions.  The hyphen must separate like items; unlike items are
returned unmodified.  These forms are modified:
letter - letter (A - B)
digit - digit (4-5)
digit separator digit - digit separator digit (4.1-4.5 or 4-1-4-5)
letterdigit - letterdigit (A1-A5) (an optional separator between letter and digit is supported – a.1-a.5 or a-1-a-5)
digitletter - digitletter (5a - 5d) (an optional separator between letter and digit is supported – 5.a-5.d or 5-a-5-d)
 
any other forms are returned unmodified.
 
str may be a comma- or semicolon-separated list
 
]]
 
local function hyphen_to_dash( str )
if not utilities.is_set (str) then
return str;
end
 
local accept; -- Boolean
str, accept = utilities.has_accept_as_written (str); -- remove accept-this-as-written markup when it wraps all of str
if accept then
return str; -- when markup removed, nothing to do, we're done
end
 
str = str:gsub ('&[nm]dash;', {['&ndash;'] = '–', ['&mdash;'] = '—'}); -- replace &mdash; and &ndash; entities with their characters; semicolon mucks up the text.split
str = str:gsub ('&#45;', '-'); -- replace HTML numeric entity with hyphen character
str = str:gsub ('&nbsp;', ' '); -- replace &nbsp; entity with generic keyboard space character
local out = {};
local list = mw.text.split (str, '%s*[,;]%s*'); -- split str at comma or semicolon separators if there are any
 
for _, item in ipairs (list) do -- for each item in the list
if mw.ustring.match (item, '^%w*[%.%-]?%w+%s*[%-–—]%s*%w*[%.%-]?%w+$') then -- if a hyphenated range or has endash or emdash separators
if item:match ('^%a+[%.%-]?%d+%s*%-%s*%a+[%.%-]?%d+$') or -- letterdigit hyphen letterdigit (optional separator between letter and digit)
item:match ('^%d+[%.%-]?%a+%s*%-%s*%d+[%.%-]?%a+$') or -- digitletter hyphen digitletter (optional separator between digit and letter)
item:match ('^%d+[%.%-]%d+%s*%-%s*%d+[%.%-]%d+$') or -- digit separator digit hyphen digit separator digit
item:match ('^%d+%s*%-%s*%d+$') or -- digit hyphen digit
item:match ('^%a+%s*%-%s*%a+$') then -- letter hyphen letter
item = item:gsub ('(%w*[%.%-]?%w+)%s*%-%s*(%w*[%.%-]?%w+)', '%1–%2'); -- replace hyphen, remove extraneous space characters
else
item = mw.ustring.gsub (item, '%s*[–—]%s*', '–'); -- for endash or emdash separated ranges, replace em with en, remove extraneous whitespace
end
end
item = utilities.has_accept_as_written (item); -- remove accept-this-as-written markup when it wraps all of str
table.insert (out, item); -- add the (possibly modified) item to the output table
end
 
return table.concat (out, ', '); -- concatenate the output table into a comma separated string
end
 
 
--[[--------------------------< S A F E _ J O I N >------------------------------------------------------------


Joins a sequence of strings together while checking for duplicate separation characters.
Joins a sequence of strings together while checking for duplicate separation characters.
983行目: 928行目:
trim = false;
trim = false;
end_chr = f.sub(str, -1, -1); -- get the last character of the output string
end_chr = f.sub(str, -1, -1); -- get the last character of the output string
-- str = str .. "<HERE(enchr=" .. end_chr .. ")" -- debug stuff?
-- str = str .. "<HERE(enchr=" .. end_chr .. ")" -- debug stuff?
if end_chr == duplicate_char then -- if same as separator
if end_chr == duplicate_char then -- if same as separator
str = f.sub(str, 1, -2); -- remove it
str = f.sub(str, 1, -2); -- remove it
elseif end_chr == "'" then -- if it might be wiki-markup
elseif end_chr == "'" then -- if it might be wiki-markup
if f.sub(str, -3, -1) == duplicate_char .. "''" then -- if last three chars of str are sepc''  
if f.sub(str, -3, -1) == duplicate_char .. "''" then -- if last three chars of str are sepc''  
str = f.sub(str, 1, -4) .. "''"; -- remove them and add back ''
str = f.sub(str, 1, -4) .. "''"; -- remove them and add back ''
elseif  f.sub(str, -5, -1) == duplicate_char .. "]]''" then -- if last five chars of str are sepc]]''  
elseif  f.sub(str, -5, -1) == duplicate_char .. "]]''" then -- if last five chars of str are sepc]]''  
995行目: 940行目:
end
end
elseif end_chr == "]" then -- if it might be wiki-markup
elseif end_chr == "]" then -- if it might be wiki-markup
if f.sub(str, -3, -1) == duplicate_char .. "]]" then -- if last three chars of str are sepc]] wikilink  
if f.sub(str, -3, -1) == duplicate_char .. "]]" then -- if last three chars of str are sepc]] wikilink  
trim = true;
trim = true;
elseif f.sub(str, -3, -1) == duplicate_char .. '"]' then -- if last three chars of str are sepc"] quoted external link  
elseif f.sub(str, -3, -1) == duplicate_char .. '"]' then -- if last three chars of str are sepc"] quoted external link  
trim = true;
trim = true;
elseif  f.sub(str, -2, -1) == duplicate_char .. "]" then -- if last two chars of str are sepc] external link
elseif  f.sub(str, -2, -1) == duplicate_char .. "]" then -- if last two chars of str are sepc] external link
trim = true;
trim = true;
elseif f.sub(str, -4, -1) == duplicate_char .. "'']" then -- normal case when |url=something & |title=Title.
elseif f.sub(str, -4, -1) == duplicate_char .. "'']" then -- normal case when |url=something & |title=Title.
1,006行目: 951行目:
elseif end_chr == " " then -- if last char of output string is a space
elseif end_chr == " " then -- if last char of output string is a space
if f.sub(str, -2, -1) == duplicate_char .. " " then -- if last two chars of str are <sepc><space>
if f.sub(str, -2, -1) == duplicate_char .. " " then -- if last two chars of str are <sepc><space>
str = f.sub(str, 1, -3); -- remove them both
str = f.sub(str, 1, -3); -- remove them both
end
end
end
end
1,021行目: 966行目:
end
end
end
end
str = str .. value; --add it to the output string
str = str .. value; -- add it to the output string
end
end
end
end
1,028行目: 973行目:




--[[--------------------------< I S _ S U F F I X >------------------------------------------------------------
--[[--------------------------< I S _ S U F F I X >-----------------------------


returns true is suffix is properly formed Jr, Sr, or ordinal in the range 1–9. Puncutation not allowed.
returns true if suffix is properly formed Jr, Sr, or ordinal in the range 1–9.
Puncutation not allowed.


]]
]]
1,042行目: 988行目:




--[[--------------------------< I S _ G O O D _ V A N C _ N A M E >--------------------------------------------
--[[--------------------< I S _ G O O D _ V A N C _ N A M E >-------------------


For Vancouver style, author/editor names are supposed to be rendered in Latin (read ASCII) characters.  When a name
For Vancouver style, author/editor names are supposed to be rendered in Latin
uses characters that contain diacritical marks, those characters are to converted to the corresponding Latin character.
(read ASCII) characters.  When a name uses characters that contain diacritical
When a name is written using a non-Latin alphabet or logogram, that name is to be transliterated into Latin characters.
marks, those characters are to be converted to the corresponding Latin
These things are not currently possible in this module so are left to the editor to do.
character. When a name is written using a non-Latin alphabet or logogram, that
name is to be transliterated into Latin characters. The module doesn't do this
so editors may/must.


This test allows |first= and |last= names to contain any of the letters defined in the four Unicode Latin character sets
This test allows |first= and |last= names to contain any of the letters defined
in the four Unicode Latin character sets
[http://www.unicode.org/charts/PDF/U0000.pdf C0 Controls and Basic Latin] 0041–005A, 0061–007A
[http://www.unicode.org/charts/PDF/U0000.pdf C0 Controls and Basic Latin] 0041–005A, 0061–007A
[http://www.unicode.org/charts/PDF/U0080.pdf C1 Controls and Latin-1 Supplement] 00C0–00D6, 00D8–00F6, 00F8–00FF
[http://www.unicode.org/charts/PDF/U0080.pdf C1 Controls and Latin-1 Supplement] 00C0–00D6, 00D8–00F6, 00F8–00FF
1,055行目: 1,004行目:
[http://www.unicode.org/charts/PDF/U0180.pdf Latin Extended-B] 0180–01BF, 01C4–024F
[http://www.unicode.org/charts/PDF/U0180.pdf Latin Extended-B] 0180–01BF, 01C4–024F


|lastn= also allowed to contain hyphens, spaces, and apostrophes. (http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35029/)
|lastn= also allowed to contain hyphens, spaces, and apostrophes.
(http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35029/)
|firstn= also allowed to contain hyphens, spaces, apostrophes, and periods
|firstn= also allowed to contain hyphens, spaces, apostrophes, and periods


This original test:
This original test:
if nil == mw.ustring.find (last, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%']*$") or nil == mw.ustring.find (first, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%'%.]+[2-6%a]*$") then
if nil == mw.ustring.find (last, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%']*$")
was written outside of the code editor and pasted here because the code editor gets confused between character insertion point and cursor position.
or nil == mw.ustring.find (first, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%'%.]+[2-6%a]*$") then
The test has been rewritten to use decimal character escape sequence for the individual bytes of the Unicode characters so that it is not necessary
was written outside of the code editor and pasted here because the code editor
to use an external editor to maintain this code.
gets confused between character insertion point and cursor position. The test has
been rewritten to use decimal character escape sequence for the individual bytes
of the Unicode characters so that it is not necessary to use an external editor
to maintain this code.


\195\128-\195\150 – À-Ö (U+00C0–U+00D6 – C0 controls)
\195\128-\195\150 – À-Ö (U+00C0–U+00D6 – C0 controls)
1,071行目: 1,024行目:
]]
]]


local function is_good_vanc_name (last, first, suffix)
local function is_good_vanc_name (last, first, suffix, position)
if not suffix then
if not suffix then
if first:find ('[,%s]') then -- when there is a space or comma, might be first name/initials + generational suffix
if first:find ('[,%s]') then -- when there is a space or comma, might be first name/initials + generational suffix
1,080行目: 1,033行目:
if utilities.is_set (suffix) then
if utilities.is_set (suffix) then
if not is_suffix (suffix) then
if not is_suffix (suffix) then
add_vanc_error (cfg.err_msg_supl.suffix);
add_vanc_error (cfg.err_msg_supl.suffix, position);
return false; -- not a name with an appropriate suffix
return false; -- not a name with an appropriate suffix
end
end
1,086行目: 1,039行目:
if nil == mw.ustring.find (last, "^[A-Za-z\195\128-\195\150\195\152-\195\182\195\184-\198\191\199\132-\201\143%-%s%']*$") or
if nil == mw.ustring.find (last, "^[A-Za-z\195\128-\195\150\195\152-\195\182\195\184-\198\191\199\132-\201\143%-%s%']*$") or
nil == mw.ustring.find (first, "^[A-Za-z\195\128-\195\150\195\152-\195\182\195\184-\198\191\199\132-\201\143%-%s%'%.]*$") then
nil == mw.ustring.find (first, "^[A-Za-z\195\128-\195\150\195\152-\195\182\195\184-\198\191\199\132-\201\143%-%s%'%.]*$") then
add_vanc_error (cfg.err_msg_supl['non-Latin char']);
add_vanc_error (cfg.err_msg_supl['non-Latin char'], position);
return false; -- not a string of Latin characters; Vancouver requires Romanization
return false; -- not a string of Latin characters; Vancouver requires Romanization
end;
end;
1,097行目: 1,050行目:
Attempts to convert names to initials in support of |name-list-style=vanc.   
Attempts to convert names to initials in support of |name-list-style=vanc.   


Names in |firstn= may be separated by spaces or hyphens, or for initials, a period. See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35062/.
Names in |firstn= may be separated by spaces or hyphens, or for initials, a period.
See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35062/.


Vancouver style requires family rank designations (Jr, II, III, etc.) to be rendered as Jr, 2nd, 3rd, etc.  See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35085/.
Vancouver style requires family rank designations (Jr, II, III, etc.) to be rendered
This code only accepts and understands generational suffix in the Vancouver format because Roman numerals look like, and can be mistaken for, initials.
as Jr, 2nd, 3rd, etc.  See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35085/.
This code only accepts and understands generational suffix in the Vancouver format
because Roman numerals look like, and can be mistaken for, initials.


This function uses ustring functions because firstname initials may be any of the Unicode Latin characters accepted by is_good_vanc_name ().
This function uses ustring functions because firstname initials may be any of the
Unicode Latin characters accepted by is_good_vanc_name ().


]]
]]


local function reduce_to_initials(first)
local function reduce_to_initials(first, position)
local name, suffix = mw.ustring.match(first, "^(%u+) ([%dJS][%drndth]+)$");
local name, suffix = mw.ustring.match(first, "^(%u+) ([%dJS][%drndth]+)$");


1,119行目: 1,076行目:
return first; -- one or two initials and a valid suffix so nothing to do
return first; -- one or two initials and a valid suffix so nothing to do
else
else
add_vanc_error (cfg.err_msg_supl.suffix); -- one or two initials with invalid suffix so error message
add_vanc_error (cfg.err_msg_supl.suffix, position); -- one or two initials with invalid suffix so error message
return first; -- and return first unmolested
return first; -- and return first unmolested
end
end
1,142行目: 1,099行目:
end
end
if 3 > i then
if 3 > i then
table.insert (initials, mw.ustring.sub(names[i], 1, 1)); -- insert the initial at end of initials table
table.insert (initials, mw.ustring.sub(names[i], 1, 1)); -- insert the initial at end of initials table
end
end
i = i+1; -- bump the counter
i = i + 1; -- bump the counter
end
end
1,151行目: 1,108行目:




--[[--------------------------< L I S T _ P E O P L E >-------------------------------------------------------
--[[--------------------------< I N T E R W I K I _ P R E F I X E N _ G E T >----------------------------------


Formats a list of people (e.g. authors, contributors, editors, interviewers, translators)  
extract interwiki prefixen from <value>.  Returns two one or two values:
false – no prefixen
nil – prefix exists but not recognized
project prefix, language prefix – when value has either of:
:<project>:<language>:<article>
:<language>:<project>:<article>
project prefix, nil – when <value> has only a known single-letter prefix
nil, language prefix – when <value> has only a known language prefix
 
accepts single-letter project prefixen: 'd' (wikidata), 's' (wikisource), and 'w' (wikipedia) prefixes; at this
writing, the other single-letter prefixen (b (wikibook), c (commons), m (meta), n (wikinews), q (wikiquote), and
v (wikiversity)) are not supported.
 
]]
 
local function interwiki_prefixen_get (value, is_link)
if not value:find (':%l+:') then -- if no prefix
return false; -- abandon; boolean here to distinguish from nil fail returns later
end
 
local prefix_patterns_linked_t = { -- sequence of valid interwiki and inter project prefixen
'^%[%[:([dsw]):(%l%l+):', -- wikilinked; project and language prefixes
'^%[%[:(%l%l+):([dsw]):', -- wikilinked; language and project prefixes
'^%[%[:([dsw]):', -- wikilinked; project prefix
'^%[%[:(%l%l+):', -- wikilinked; language prefix
}
local prefix_patterns_unlinked_t = { -- sequence of valid interwiki and inter project prefixen
'^:([dsw]):(%l%l+):', -- project and language prefixes
'^:(%l%l+):([dsw]):', -- language and project prefixes
'^:([dsw]):', -- project prefix
'^:(%l%l+):', -- language prefix
}
local cap1, cap2;
for _, pattern in ipairs ((is_link and prefix_patterns_linked_t) or prefix_patterns_unlinked_t) do
cap1, cap2 = value:match (pattern);
if cap1 then
break; -- found a match so stop looking
end
end
if cap1 and cap2 then -- when both then :project:language: or :language:project: (both forms allowed)
if 1 == #cap1 then -- length == 1 then :project:language:
if cfg.inter_wiki_map[cap2] then -- is language prefix in the interwiki map?
return cap1, cap2; -- return interwiki project and interwiki language
end
else -- here when :language:project:
if cfg.inter_wiki_map[cap1] then -- is language prefix in the interwiki map?
return cap2, cap1; -- return interwiki project and interwiki language
end
end
return nil; -- unknown interwiki language
elseif not (cap1 or cap2) then -- both are nil?
return nil; -- we got something that looks like a project prefix but isn't; return fail
elseif 1 == #cap1 then -- here when one capture
return cap1, nil; -- length is 1 so return project, nil language
else -- here when one capture and its length it more than 1
if cfg.inter_wiki_map[cap1] then -- is language prefix in the interwiki map?
return nil, cap1; -- return nil project, language
end
end
end
 
 
--[[--------------------------< L I S T _ P E O P L E >--------------------------
 
Formats a list of people (authors, contributors, editors, interviewers, translators)  


names in the list will be linked when
names in the list will be linked when
|<name>-link= has a value
|<name>-link= has a value
|<name>-mask- does NOT have a value; masked names are presumed to have been rendered previously so should have been linked there
|<name>-mask- does NOT have a value; masked names are presumed to have been
rendered previously so should have been linked there


when |<name>-mask=0, the associated name is not rendered
when |<name>-mask=0, the associated name is not rendered
1,168行目: 1,193行目:
local format = control.format;
local format = control.format;
local maximum = control.maximum;
local maximum = control.maximum;
local lastauthoramp = control.lastauthoramp; -- TODO: delete after deprecation
local name_list = {};
local name_list = {};


1,174行目: 1,198行目:
sep = cfg.presentation['sep_nl_vanc']; -- name-list separator between names is a comma
sep = cfg.presentation['sep_nl_vanc']; -- name-list separator between names is a comma
namesep = cfg.presentation['sep_name_vanc']; -- last/first separator is a space
namesep = cfg.presentation['sep_name_vanc']; -- last/first separator is a space
lastauthoramp = nil; -- TODO: delete after deprecation -- unset because isn't used by Vancouver style
else
else
sep = cfg.presentation['sep_nl']; -- name-list separator between names is a semicolon
sep = cfg.presentation['sep_nl']; -- name-list separator between names is a semicolon
1,197行目: 1,220行目:
local n = tonumber (mask); -- convert to a number if it can be converted; nil else
local n = tonumber (mask); -- convert to a number if it can be converted; nil else
if n then
if n then
one = 0 ~= n and string.rep("&mdash;",n) or nil; -- make a string of (n > 0) mdashes, nil else, to replace name
one = 0 ~= n and string.rep("&mdash;", n) or nil; -- make a string of (n > 0) mdashes, nil else, to replace name
person.link = nil; -- don't create link to name if name is replaces with mdash string or has been set nil
person.link = nil; -- don't create link to name if name is replaces with mdash string or has been set nil
else
else
1,209行目: 1,232行目:
if ("vanc" == format) then -- if Vancouver format
if ("vanc" == format) then -- if Vancouver format
one = one:gsub ('%.', ''); -- remove periods from surnames (http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35029/)
one = one:gsub ('%.', ''); -- remove periods from surnames (http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35029/)
if not person.corporate and is_good_vanc_name (one, first) then -- and name is all Latin characters; corporate authors not tested
if not person.corporate and is_good_vanc_name (one, first, nil, i) then -- and name is all Latin characters; corporate authors not tested
first = reduce_to_initials (first); -- attempt to convert first name(s) to initials
first = reduce_to_initials (first, i); -- attempt to convert first name(s) to initials
end
end
end
end
1,219行目: 1,242行目:
one = utilities.make_wikilink (person.link, one); -- link author/editor
one = utilities.make_wikilink (person.link, one); -- link author/editor
end
end
if one then -- if <one> has a value (name, mdash replacement, or mask text replacement)
if one then -- if <one> has a value (name, mdash replacement, or mask text replacement)
local proj, tag = interwiki_prefixen_get (one, true); -- get the interwiki prefixen if present
if 'w' == proj and ('Wikipedia' == mw.site.namespaces.Project['name']) then
proj = nil; -- for stuff like :w:de:<article>, :w is unnecessary TODO: maint cat?
end
if proj then
proj = ({['d'] = 'Wikidata', ['s'] = 'Wikisource', ['w'] = 'Wikipedia'})[proj]; -- :w (wikipedia) for linking from a non-wikipedia project
if proj then
one = one .. utilities.wrap_style ('interproj', proj); -- add resized leading space, brackets, static text, language name
tag = nil; -- unset; don't do both project and language
end
end
if tag == cfg.this_wiki_code then
tag = nil; -- stuff like :en:<article> at en.wiki is pointless TODO: maint cat?
end
if tag then
local lang = cfg.lang_code_remap[tag] or cfg.mw_languages_by_tag_t[tag];
if lang then -- error messaging done in extract_names() where we know parameter names
one = one .. utilities.wrap_style ('interwiki', lang); -- add resized leading space, brackets, static text, language name
end
end
table.insert (name_list, one); -- add it to the list of names
table.insert (name_list, one); -- add it to the list of names
table.insert (name_list, sep_one); -- add the proper name-list separator
table.insert (name_list, sep_one); -- add the proper name-list separator
1,229行目: 1,275行目:
if 0 < count then  
if 0 < count then  
if 1 < count and not etal then
if 1 < count and not etal then
if 'amp' == format or utilities.is_set (lastauthoramp) then -- TODO: delete lastauthoramp after deprecation
if 'amp' == format then
name_list[#name_list-2] = " & "; -- replace last separator with ampersand text
name_list[#name_list-2] = " & "; -- replace last separator with ampersand text
elseif 'and' == format then
elseif 'and' == format then
1,251行目: 1,297行目:




--[[--------------------------< A N C H O R _ I D >------------------------------------------------------------
--[[--------------------< M A K E _ C I T E R E F _ I D >-----------------------


Generates a CITEREF anchor ID if we have at least one name or a date.  Otherwise returns an empty string.
Generates a CITEREF anchor ID if we have at least one name or a date.  Otherwise
returns an empty string.


namelist is one of the contributor-, author-, or editor-name lists chosen in that order.  year is Year or anchor_year.
namelist is one of the contributor-, author-, or editor-name lists chosen in that
order.  year is Year or anchor_year.


]]
]]


local function anchor_id (namelist, year)
local function make_citeref_id (namelist, year)
local names={}; -- a table for the one to four names and year
local names={}; -- a table for the one to four names and year
for i,v in ipairs (namelist) do -- loop through the list and take up to the first four last names
for i,v in ipairs (namelist) do -- loop through the list and take up to the first four last names
names[i] = v.last  
names[i] = v.last
if i == 4 then break end -- if four then done
if i == 4 then break end -- if four then done
end
end
table.insert (names, year); -- add the year at the end
table.insert (names, year); -- add the year at the end
local id = table.concat(names); -- concatenate names and year for CITEREF id
local id = table.concat(names); -- concatenate names and year for CITEREF id
if utilities.is_set (id) then -- if concatenation is not an empty string
if utilities.is_set (id) then -- if concatenation is not an empty string
return "CITEREF" .. id; -- add the CITEREF portion
return "CITEREF" .. id; -- add the CITEREF portion
else
else
return ''; -- return an empty string; no reason to include CITEREF id in this citation
return ''; -- return an empty string; no reason to include CITEREF id in this citation
end
end
end
end




--[[--------------------------< N A M E _ H A S _ E T A L >----------------------------------------------------
--[[--------------------------< C I T E _ C L A S S _A T T R I B U T E _M A K E >------------------------------


Evaluates the content of name parameters (author, editor, etc.) for variations on the theme of et al.  If found,
construct <cite> tag class attribute for this citation.
the et al. is removed, a flag is set to true and the function returns the modified name and the flag.


This function never sets the flag to false but returns it's previous state because it may have been set by
<cite_class> – config.CitationClass from calling template
previous passes through this function or by the associated |display-<names>=etal parameter
<mode> – value from |mode= parameter


]]
]]


local function name_has_etal (name, etal, nocat, param)
local function cite_class_attribute_make (cite_class, mode)
local class_t = {};
table.insert (class_t, 'citation'); -- required for blue highlight
if 'citation' ~= cite_class then
table.insert (class_t, cite_class); -- identify this template for user css
table.insert (class_t, utilities.is_set (mode) and mode or 'cs1'); -- identify the citation style for user css or javascript
else
table.insert (class_t, utilities.is_set (mode) and mode or 'cs2'); -- identify the citation style for user css or javascript
end
for _, prop_key in ipairs (z.prop_keys_t) do
table.insert (class_t, prop_key); -- identify various properties for user css or javascript
end
 
return table.concat (class_t, ' '); -- make a big string and done
end


if utilities.is_set (name) then -- name can be nil in which case just return
 
local patterns = cfg.et_al_patterns; --get patterns from configuration
--[[---------------------< N A M E _ H A S _ E T A L >--------------------------
 
Evaluates the content of name parameters (author, editor, etc.) for variations on
the theme of et al.  If found, the et al. is removed, a flag is set to true and
the function returns the modified name and the flag.
 
This function never sets the flag to false but returns its previous state because
it may have been set by previous passes through this function or by the associated
|display-<names>=etal parameter
 
]]
 
local function name_has_etal (name, etal, nocat, param)
 
if utilities.is_set (name) then -- name can be nil in which case just return
local patterns = cfg.et_al_patterns; -- get patterns from configuration
for _, pattern in ipairs (patterns) do -- loop through all of the patterns
for _, pattern in ipairs (patterns) do -- loop through all of the patterns
if name:match (pattern) then -- if this 'et al' pattern is found in name
if name:match (pattern) then -- if this 'et al' pattern is found in name
1,295行目: 1,371行目:
etal = true; -- set flag (may have been set previously here or by |display-<names>=etal)
etal = true; -- set flag (may have been set previously here or by |display-<names>=etal)
if not nocat then -- no categorization for |vauthors=
if not nocat then -- no categorization for |vauthors=
table.insert( z.message_tail, {utilities.set_message ('err_etal', {param})}); -- and set an error if not added
utilities.set_message ('err_etal', {param}); -- and set an error if not added
end
end
end
end
1,305行目: 1,381行目:




--[[--------------------------< N A M E _ I S _ N U M E R I C >------------------------------------------------
--[[---------------------< N A M E _ I S _ N U M E R I C >----------------------


Add maint cat when name parameter value does not contain letters.  Does not catch mixed alphanumeric names so
Add maint cat when name parameter value does not contain letters.  Does not catch
|last=A. Green (1922-1987) does not get caught in the current version of this test but |first=(1888) is caught.
mixed alphanumeric names so |last=A. Green (1922-1987) does not get caught in the
current version of this test but |first=(1888) is caught.


returns nothing
returns nothing
1,323行目: 1,400行目:




--[[--------------------------< N A M E _ H A S _ E D _ M A R K U P >------------------------------------------
--[[-----------------< N A M E _ H A S _ M U L T _ N A M E S >------------------
 
Evaluates the content of author and editor parameters for extraneous editor annotations: ed, ed., eds, (Ed.), etc.
These annotation do not belong in author parameters and are redundant in editor parameters.  If found, the function
adds the editor markup maintenance category.
 
returns nothing
 
]]
 
local function name_has_ed_markup (name, list_name)
local patterns = cfg.editor_markup_patterns; -- get patterns from configuration
 
if utilities.is_set (name) then
for _, pattern in ipairs (patterns) do -- spin through patterns table and
if name:match (pattern) then
utilities.set_message ('maint_extra_text_names', cfg.special_case_translation [list_name]); -- add a maint cat for this template
break;
end
end
end
end
 
 
--[[--------------------------< N A M E _ H A S _ M U L T _ N A M E S >----------------------------------------


Evaluates the content of last/surname (authors etc.) parameters for multiple names. Multiple names are indicated
Evaluates the content of last/surname (authors etc.) parameters for multiple names.
if there is more than one comma or any semicolons. If found, the function adds the multiple name maintenance category.
Multiple names are indicated if there is more than one comma or any "unescaped"
semicolons. Escaped semicolons are ones used as part of selected HTML entities.
If the condition is met, the function adds the multiple name maintenance category.


returns nothing
returns nothing
1,357行目: 1,412行目:


local function name_has_mult_names (name, list_name)
local function name_has_mult_names (name, list_name)
local _, commas, semicolons;
local _, commas, semicolons, nbsps;
if utilities.is_set (name) then
if utilities.is_set (name) then
_, commas = name:gsub (',', ''); -- count the number of commas
_, commas = name:gsub (',', ''); -- count the number of commas
_, semicolons = name:gsub (';', ''); -- count the number of semicolons
_, semicolons = name:gsub (';', ''); -- count the number of semicolons
-- nbsps probably should be its own separate count rather than merged in
-- some way with semicolons because Lua patterns do not support the
-- grouping operator that regex does, which means there is no way to add
-- more entities to escape except by adding more counts with the new
-- entities
_, nbsps = name:gsub ('&nbsp;',''); -- count nbsps
if 1 < commas or 0 < semicolons then
-- There is exactly 1 semicolon per &nbsp; entity, so subtract nbsps
-- from semicolons to 'escape' them. If additional entities are added,
-- they also can be subtracted.
if 1 < commas or 0 < (semicolons - nbsps) then
utilities.set_message ('maint_mult_names', cfg.special_case_translation [list_name]); -- add a maint message
utilities.set_message ('maint_mult_names', cfg.special_case_translation [list_name]); -- add a maint message
end
end
1,369行目: 1,433行目:




--[[--------------------------< N A M E _ C H E C K S >--------------------------------------------------------
--[=[-------------------------< I S _ G E N E R I C >----------------------------------------------------------


This function calls various name checking functions used to validate the content of the various name-holding
Compares values assigned to various parameters according to the string provided as <item> in the function call.
parameters.
<item> can have on of two values:
'generic_names' – for name-holding parameters: |last=, |first=, |editor-last=, etc
'generic_titles' – for |title=


]]
There are two types of generic tests.  The 'accept' tests look for a pattern that should not be rejected by the
'reject' test.  For example,
|author=[[John Smith (author)|Smith, John]]
would be rejected by the 'author' reject test.  But piped wikilinks with 'author' disambiguation should not be
rejected so the 'accept' test prevents that from happening.  Accept tests are always performed before reject
tests.


local function name_checks (last, first, list_name)
Each of the 'accept' and 'reject' sequence tables hold tables for en.wiki (['en']) and local.wiki (['local'])
local accept_name;
that each can hold a test sequence table  The sequence table holds, at index [1], a test pattern, and, at index
[2], a boolean control value.  The control value tells string.find() or mw.ustring.find() to do plain-text search (true)
or a pattern search (false).  The intent of all this complexity is to make these searches as fast as possible so
that we don't run out of processing time on very large articles.


if utilities.is_set (last) then
Returns
last, accept_name = utilities.has_accept_as_written (last); -- remove accept-this-as-written markup when it wraps all of <last>
true when a reject test finds the pattern or string
false when an accept test finds the pattern or string
if not accept_name then -- <last> not wrapped in accept-as-written markup
nil else
name_has_mult_names (last, list_name); -- check for multiple names in the parameter (last only)
name_has_ed_markup (last, list_name); -- check for extraneous 'editor' annotation
name_is_numeric (last, list_name); -- check for names that are compsed of digits and punctuation
end
end


if utilities.is_set (first) then
]=]
first, accept_name = utilities.has_accept_as_written (first); -- remove accept-this-as-written markup when it wraps all of <first>
 
local function is_generic (item, value, wiki)
local test_val;
local str_lower = { -- use string.lower() for en.wiki (['en']) and use mw.ustring.lower() or local.wiki (['local'])
['en'] = string.lower,
['local'] = mw.ustring.lower,
}
local str_find = { -- use string.find() for en.wiki (['en']) and use mw.ustring.find() or local.wiki (['local'])
['en'] = string.find,
['local'] = mw.ustring.find,
}
 
local function test (val, test_t, wiki) -- local function to do the testing; <wiki> selects lower() and find() functions
val = test_t[2] and str_lower[wiki](value) or val; -- when <test_t[2]> set to 'true', plaintext search using lowercase value
return str_find[wiki] (val, test_t[1], 1, test_t[2]); -- return nil when not found or matched
end
local test_types_t = {'accept', 'reject'}; -- test accept patterns first, then reject patterns
local wikis_t = {'en', 'local'}; -- do tests for each of these keys; en.wiki first, local.wiki second


if not accept_name then -- <first> not wrapped in accept-as-written markup
for _, test_type in ipairs (test_types_t) do -- for each test type
name_has_ed_markup (first, list_name); -- check for extraneous 'editor' annotation
for _, generic_value in pairs (cfg.special_case_translation[item][test_type]) do -- spin through the list of generic value fragments to accept or reject
name_is_numeric (first, list_name); -- check for names that are compsed of digits and punctuation
for _, wiki in ipairs (wikis_t) do
if generic_value[wiki] then
if test (value, generic_value[wiki], wiki) then -- go do the test
return ('reject' == test_type); -- param value rejected, return true; false else
end
end
end
end
end
end
end
end


return last, first; -- done
end


--[[--------------------------< N A M E _ I S _ G E N E R I C >------------------------------------------------
calls is_generic() to determine if <name> is a 'generic name' listed in cfg.generic_names; <name_alias> is the
parameter name used in error messaging
]]


--[[--------------------------< E X T R A C T _ N A M E S >----------------------------------------------------
local function name_is_generic (name, name_alias)
Gets name list from the input arguments
if not added_generic_name_errs  and is_generic ('generic_names', name) then
utilities.set_message ('err_generic_name', name_alias); -- set an error message
added_generic_name_errs = true;
end
end


Searches through args in sequential order to find |lastn= and |firstn= parameters (or their aliases), and their matching link and mask parameters.
Stops searching when both |lastn= and |firstn= are not found in args after two sequential attempts: found |last1=, |last2=, and |last3= but doesn't
find |last4= and |last5= then the search is done.


This function emits an error message when there is a |firstn= without a matching |lastn=.  When there are 'holes' in the list of last names, |last1= and |last3=
--[[--------------------------< N A M E _ C H E C K S >--------------------------------------------------------
are present but |last2= is missing, an error message is emitted. |lastn= is not required to have a matching |firstn=.


When an author or editor parameter contains some form of 'et al.', the 'et al.' is stripped from the parameter and a flag (etal) returned
This function calls various name checking functions used to validate the content of the various name-holding parameters.
that will cause list_people() to add the static 'et al.' text from Module:Citation/CS1/Configuration.  This keeps 'et al.' out of the  
template's metadata.  When this occurs, the page is added to a maintenance category.


]]
]]


local function extract_names(args, list_name)
local function name_checks (last, first, list_name, last_alias, first_alias)
local names = {}; -- table of names
local accept_name;
local last; -- individual name components
local first;
local link;
local mask;
local i = 1; -- loop counter/indexer
local n = 1; -- output table indexer
local count = 0; -- used to count the number of times we haven't found a |last= (or alias for authors, |editor-last or alias for editors)
local etal = false; -- return value set to true when we find some form of et al. in an author parameter


local last_alias, first_alias, link_alias; -- selected parameter aliases used in error messaging
if utilities.is_set (last) then
while true do
last, accept_name = utilities.has_accept_as_written (last); -- remove accept-this-as-written markup when it wraps all of <last>
last, last_alias = utilities.select_one ( args, cfg.aliases[list_name .. '-Last'], 'err_redundant_parameters', i ); -- search through args for name components beginning at 1
 
first, first_alias = utilities.select_one ( args, cfg.aliases[list_name .. '-First'], 'err_redundant_parameters', i );
if not accept_name then -- <last> not wrapped in accept-as-written markup
link, link_alias = utilities.select_one ( args, cfg.aliases[list_name .. '-Link'], 'err_redundant_parameters', i );
name_has_mult_names (last, list_name); -- check for multiple names in the parameter (last only)
mask = utilities.select_one ( args, cfg.aliases[list_name .. '-Mask'], 'err_redundant_parameters', i );
name_is_numeric (last, list_name); -- check for names that are composed of digits and punctuation
name_is_generic (last, last_alias); -- check for names found in the generic names list
end
end


last, etal = name_has_etal (last, etal, false, last_alias); -- find and remove variations on et al.
if utilities.is_set (first) then
first, etal = name_has_etal (first, etal, false, first_alias); -- find and remove variations on et al.
first, accept_name = utilities.has_accept_as_written (first); -- remove accept-this-as-written markup when it wraps all of <first>
last, first = name_checks (last, first, list_name); -- multiple names, extraneous annotation, etc. checks
if first and not last then -- if there is a firstn without a matching lastn
local alias = first_alias:find ('given', 1, true) and 'given' or 'first'; -- get first or given form of the alias
table.insert (z.message_tail, { utilities.set_message ( 'err_first_missing_last', {
first_alias, -- param name of alias missing its mate
first_alias:gsub (alias, {['first'] = 'last', ['given'] = 'surname'}), -- make param name appropriate to the alias form
}, true ) } ); -- add this error message
elseif not first and not last then -- if both firstn and lastn aren't found, are we done?
count = count + 1; -- number of times we haven't found last and first
if 2 <= count then -- two missing names and we give up
break; -- normal exit or there is a two-name hole in the list; can't tell which
end
else -- we have last with or without a first
local result;
link = link_title_ok (link, link_alias, last, last_alias); -- check for improper wiki-markup
if first then
link = link_title_ok (link, link_alias, first, first_alias); -- check for improper wiki-markup
end


names[n] = {last = last, first = first, link = link, mask = mask, corporate = false}; -- add this name to our names list (corporate for |vauthors= only)
if not accept_name then -- <first> not wrapped in accept-as-written markup
n = n + 1; -- point to next location in the names table
name_is_numeric (first, list_name); -- check for names that are composed of digits and punctuation
if 1 == count then -- if the previous name was missing
name_is_generic (first, first_alias); -- check for names found in the generic names list
table.insert( z.message_tail, { utilities.set_message ( 'err_missing_name', {list_name:match ("(%w+)List"):lower(), i - 1}, true ) } ); -- add this error message
end
end
local wl_type, D = utilities.is_wikilink (first);
count = 0; -- reset the counter, we're looking for two consecutive missing names
if 0 ~= wl_type then
first = D;
utilities.set_message ('err_bad_paramlink', first_alias);
end
end
i = i + 1; -- point to next args location
end
end
 
return names, etal; -- all done, return our list of names and the etal flag
return last, first; -- done
end
end




--[[--------------------------< G E T _ I S O 6 3 9 _ C O D E >------------------------------------------------
--[[----------------------< E X T R A C T _ N A M E S >-------------------------


Validates language names provided in |language= parameter if not an ISO639-1 or 639-2 code.
Gets name list from the input arguments


Returns the language name and associated two- or three-character code. Because case of the source may be incorrect
Searches through args in sequential order to find |lastn= and |firstn= parameters
or different from the case that WikiMedia uses, the name comparisons are done in lower case and when a match is
(or their aliases), and their matching link and mask parameters. Stops searching
found, the Wikimedia version (assumed to be correct) is returned along with the code.  When there is no match, we
when both |lastn= and |firstn= are not found in args after two sequential attempts:
return the original language name string.
found |last1=, |last2=, and |last3= but doesn't find |last4= and |last5= then the
search is done.


mw.language.fetchLanguageNames(<local wiki language>, 'all') returns a list of languages that in some cases may include
This function emits an error message when there is a |firstn= without a matching
extensions. For example, code 'cbk-zam' and its associated name 'Chavacano de Zamboanga' (MediaWiki does not support
|lastn=. When there are 'holes' in the list of last names, |last1= and |last3=
code 'cbk' or name 'Chavacano'. Most (all?) of these languages are not used a 'language' codes per se, rather they
are present but |last2= is missing, an error message is emitted. |lastn= is not
are used as sub-domain names: cbk-zam.wikipedia.org.  A list of language names and codes supported by fetchLanguageNames()
required to have a matching |firstn=.
can be found at Template:Citation Style documentation/language/doc


Names that are included in the list will be found if that name is provided in the |language= parameter.  For example,
When an author or editor parameter contains some form of 'et al.', the 'et al.'
if |language=Chavacano de Zamboanga, that name will be found with the associated code 'cbk-zam'.  When names are found
is stripped from the parameter and a flag (etal) returned that will cause list_people()
and the associated code is not two or three characters, this function returns only the WikiMedia language name.
to add the static 'et al.' text from Module:Citation/CS1/ConfigurationThis keeps
 
'et al.' out of the template's metadata. When this occurs, an error is emitted.
Some language names have multiple entries under different codes:
Aromanian has code rup and code roa-rup
When this occurs, this function returns the language name and the 2- or 3-character code
 
Adapted from code taken from Module:Check ISO 639-1.


]]
]]


local function get_iso639_code (lang, this_wiki_code)
local function extract_names(args, list_name)
if cfg.lang_name_remap[lang:lower()] then -- if there is a remapped name (because MediaWiki uses something that we don't think is correct)
local names = {}; -- table of names
return cfg.lang_name_remap[lang:lower()][1], cfg.lang_name_remap[lang:lower()][2]; -- for this language 'name', return a possibly new name and appropriate code
local last; -- individual name components
end
local first;
local link;
local mask;
local i = 1; -- loop counter/indexer
local n = 1; -- output table indexer
local count = 0; -- used to count the number of times we haven't found a |last= (or alias for authors, |editor-last or alias for editors)
local etal = false; -- return value set to true when we find some form of et al. in an author parameter


local ietf_code; -- because some languages have both IETF-like codes and ISO 639-like codes
local last_alias, first_alias, link_alias; -- selected parameter aliases used in error messaging
local ietf_name;
while true do
last, last_alias = utilities.select_one ( args, cfg.aliases[list_name .. '-Last'], 'err_redundant_parameters', i ); -- search through args for name components beginning at 1
first, first_alias = utilities.select_one ( args, cfg.aliases[list_name .. '-First'], 'err_redundant_parameters', i );
link, link_alias = utilities.select_one ( args, cfg.aliases[list_name .. '-Link'], 'err_redundant_parameters', i );
mask = utilities.select_one ( args, cfg.aliases[list_name .. '-Mask'], 'err_redundant_parameters', i );
local langlc = mw.ustring.lower (lang); -- lower-case version for comparisons
if last then -- error check |lastn= alias for unknown interwiki link prefix; done here because this is where we have the parameter name
 
local project, language = interwiki_prefixen_get (last, true); -- true because we expect interwiki links in |lastn= to be wikilinked
for code, name in pairs (cfg.languages) do -- scan the list to see if we can find our language
if nil == project and nil == language then -- when both are nil
if langlc == mw.ustring.lower (name) then
utilities.set_message ('err_bad_paramlink', last_alias); -- not known, emit an error message -- TODO: err_bad_interwiki?
if 2 == #code or 3 == #code then -- two- or three-character codes only; IETF extensions not supported
last = utilities.remove_wiki_link (last); -- remove wikilink markup; show display value only
return name, code; -- so return the name and the code
end
end
if link then -- error check |linkn= alias for unknown interwiki link prefix
local project, language = interwiki_prefixen_get (link, false); -- false because wiki links in |author-linkn= is an error
if nil == project and nil == language then -- when both are nil
utilities.set_message ('err_bad_paramlink', link_alias); -- not known, emit an error message -- TODO: err_bad_interwiki?
link = nil; -- unset so we don't link
link_alias = nil;
end
end
ietf_code = code; -- remember that we found an IETF-like code and save its name
ietf_name = name; -- but keep looking for a 2- or 3-char code
end
end
end
-- didn't find name with 2- or 3-char code; if IETF-like code found return
last, etal = name_has_etal (last, etal, false, last_alias); -- find and remove variations on et al.
return ietf_code and ietf_name or lang; -- associated name; return original language text else
first, etal = name_has_etal (first, etal, false, first_alias); -- find and remove variations on et al.
end
last, first = name_checks (last, first, list_name, last_alias, first_alias); -- multiple names, extraneous annotation, etc. checks


if first and not last then -- if there is a firstn without a matching lastn
local alias = first_alias:find ('given', 1, true) and 'given' or 'first'; -- get first or given form of the alias
utilities.set_message ('err_first_missing_last', {
first_alias, -- param name of alias missing its mate
first_alias:gsub (alias, {['first'] = 'last', ['given'] = 'surname'}), -- make param name appropriate to the alias form
}); -- add this error message
elseif not first and not last then -- if both firstn and lastn aren't found, are we done?
count = count + 1; -- number of times we haven't found last and first
if 2 <= count then -- two missing names and we give up
break; -- normal exit or there is a two-name hole in the list; can't tell which
end
else -- we have last with or without a first
local result;
link = link_title_ok (link, link_alias, last, last_alias); -- check for improper wiki-markup


--[[--------------------------< L A N G U A G E _ P A R A M E T E R >------------------------------------------
if first then
 
link = link_title_ok (link, link_alias, first, first_alias); -- check for improper wiki-markup
Gets language name from a provided two- or three-character ISO 639 code.  If a code is recognized by MediaWiki,
end
use the returned name; if not, then use the value that was provided with the language parameter.
 
 
names[n] = {last = last, first = first, link = link, mask = mask, corporate = false}; -- add this name to our names list (corporate for |vauthors= only)
When |language= contains a recognized language (either code or name), the page is assigned to the category for
n = n + 1; -- point to next location in the names table
that code: Category:Norwegian-language sources (no).  For valid three-character code languages, the page is assigned
if 1 == count then -- if the previous name was missing
to the single category for '639-2' codes: Category:CS1 ISO 639-2 language sources.
utilities.set_message ('err_missing_name', {list_name:match ("(%w+)List"):lower(), i - 1}); -- add this error message
 
end
Languages that are the same as the local wiki are not categorized.  MediaWiki does not recognize three-character
count = 0; -- reset the counter, we're looking for two consecutive missing names
equivalents of two-character codes: code 'ar' is recognized but code 'ara' is not.
end
 
i = i + 1; -- point to next args location
This function supports multiple languages in the form |language=nb, French, th where the language names or codes are
end
separated from each other by commas with optional space characters.
return names, etal; -- all done, return our list of names and the etal flag
end


]]


local function language_parameter (lang)
--[[--------------------------< N A M E _ T A G _ G E T >------------------------------------------------------
local code; -- the two- or three-character language code
local name; -- the language name
local language_list = {}; -- table of language names to be rendered
local names_table = {}; -- table made from the value assigned to |language=


local this_wiki_name = mw.language.fetchLanguageName (cfg.this_wiki_code, cfg.this_wiki_code); -- get this wiki's language name
attempt to decode |language=<lang_param> and return language name and matching tag; nil else.


names_table = mw.text.split (lang, '%s*,%s*'); -- names should be a comma separated list
This function looks for:
<lang_param> as a tag in cfg.lang_code_remap{}
<lang_param> as a name in cfg.lang_name_remap{}
<lang_param> as a name in cfg.mw_languages_by_name_t
<lang_param> as a tag in cfg.mw_languages_by_tag_t
when those fail, presume that <lang_param> is an IETF-like tag that MediaWiki does not recognize.  Strip all
script, region, variant, whatever subtags from <lang_param> to leave just a two or three character language tag
and look for the new <lang_param> in cfg.mw_languages_by_tag_t{}


for _, lang in ipairs (names_table) do -- reuse lang
on success, returns name (in properly capitalized form) and matching tag (in lowercase); on failure returns nil
name = cfg.lang_code_remap[lang:lower()]; -- first see if this is a code that is not supported by MediaWiki but is in remap


if name then -- there was a remapped code so
]]
if not lang:match ('^%a%a%a?%-x%-%a+$') then -- if not a private IETF tag
lang = lang:gsub ('^(%a%a%a?)%-.*', '%1'); -- strip IETF tags from code
end
else
lang = lang:gsub ('^(%a%a%a?)%-.*', '%1'); -- strip any IETF-like tags from code
if 2 == lang:len() or 3 == lang:len() then -- if two-or three-character code
name = mw.language.fetchLanguageName (lang:lower(), cfg.this_wiki_code); -- get language name if |language= is a proper code
end
end


if utilities.is_set (name) then -- if |language= specified a valid code
local function name_tag_get (lang_param)
code = lang:lower(); -- save it
local lang_param_lc = mw.ustring.lower (lang_param); -- use lowercase as an index into the various tables
else
local name;
name, code = get_iso639_code (lang, cfg.this_wiki_code); -- attempt to get code from name (assign name here so that we are sure of proper capitalization)
local tag;
end
if utilities.is_set (code) then -- only 2- or 3-character codes
name = cfg.lang_code_remap[code] or name; -- override wikimedia when they misuse language codes/names


if cfg.this_wiki_code ~= code then -- when the language is not the same as this wiki's language
name = cfg.lang_code_remap[lang_param_lc]; -- assume <lang_param_lc> is a tag; attempt to get remapped language name
if 2 == code:len() then -- and is a two-character code
if name then -- when <name>, <lang_param> is a tag for a remapped language name
utilities.add_prop_cat ('foreign_lang_source' .. code, {name, code}); -- categorize it; code appended to allow for multiple language categorization
return name, lang_param_lc; -- so return <name> from remap and <lang_param_lc>
else -- or is a recognized language (but has a three-character code)
end
utilities.add_prop_cat ('foreign_lang_source_2' .. code, {code}); -- categorize it differently TODO: support multiple three-character code categories per cs1|2 template
 
end
tag = lang_param_lc:match ('^(%a%a%a?)%-.*'); -- still assuming that <lang_param_lc> is a tag; strip script, region, variant subtags
name = cfg.lang_code_remap[tag]; -- attempt to get remapped language name with language subtag only
if name then -- when <name>, <tag> is a tag for a remapped language name
return name, tag; -- so return <name> from remap and <tag>
end
 
if cfg.lang_name_remap[lang_param_lc] then -- not a tag, assume <lang_param_lc> is a name; attempt to get remapped language tag
return cfg.lang_name_remap[lang_param_lc][1], cfg.lang_name_remap[lang_param_lc][2]; -- for this <lang_param_lc>, return a (possibly) new name and appropriate tag
end
 
tag = cfg.mw_languages_by_name_t[lang_param_lc]; -- assume that <lang_param_lc> is a language name; attempt to get its matching tag
if tag then
return cfg.mw_languages_by_tag_t[tag], tag; -- <lang_param_lc> is a name so return the name from the table and <tag>
end
 
name = cfg.mw_languages_by_tag_t[lang_param_lc]; -- assume that <lang_param_lc> is a tag; attempt to get its matching language name
if name then
return name, lang_param_lc; -- <lang_param_lc> is a tag so return it and <name>
end
tag = lang_param_lc:match ('^(%a%a%a?)%-.*'); -- is <lang_param_lc> an IETF-like tag that MediaWiki doesn't recognize? <tag> gets the language subtag; nil else
 
if tag then
name = cfg.mw_languages_by_tag_t[tag]; -- attempt to get a language name using the shortened <tag>
if name then
return name, tag; -- <lang_param_lc> is an unrecognized IETF-like tag so return <name> and language subtag
end
end
end
 
 
--[[-------------------< L A N G U A G E _ P A R A M E T E R >------------------
 
Gets language name from a provided two- or three-character ISO 639 code.  If a code
is recognized by MediaWiki, use the returned name; if not, then use the value that
was provided with the language parameter.
 
When |language= contains a recognized language (either code or name), the page is
assigned to the category for that code: Category:Norwegian-language sources (no).
For valid three-character code languages, the page is assigned to the single category
for '639-2' codes: Category:CS1 ISO 639-2 language sources.
 
Languages that are the same as the local wiki are not categorized.  MediaWiki does
not recognize three-character equivalents of two-character codes: code 'ar' is
recognized but code 'ara' is not.
 
This function supports multiple languages in the form |language=nb, French, th
where the language names or codes are separated from each other by commas with
optional space characters.
 
]]
 
local function language_parameter (lang)
local tag; -- some form of IETF-like language tag; language subtag with optional region, sript, vatiant, etc subtags
local lang_subtag; -- ve populates |language= with mostly unecessary region subtags the MediaWiki does not recognize; this is the base language subtag
local name; -- the language name
local language_list = {}; -- table of language names to be rendered
local names_t = {}; -- table made from the value assigned to |language=
 
local this_wiki_name = mw.language.fetchLanguageName (cfg.this_wiki_code, cfg.this_wiki_code); -- get this wiki's language name
 
names_t = mw.text.split (lang, '%s*,%s*'); -- names should be a comma separated list
 
for _, lang in ipairs (names_t) do -- reuse lang here because we don't yet know if lang is a language name or a language tag
name, tag = name_tag_get (lang); -- attempt to get name/tag pair for <lang>; <name> has proper capitalization; <tag> is lowercase
 
if utilities.is_set (tag) then
lang_subtag = tag:gsub ('^(%a%a%a?)%-.*', '%1'); -- for categorization, strip any IETF-like tags from language tag
 
if cfg.this_wiki_code ~= lang_subtag then -- when the language is not the same as this wiki's language
if 2 == lang_subtag:len() then -- and is a two-character tag
utilities.add_prop_cat ('foreign-lang-source', {name, tag}, lang_subtag); -- categorize it; tag appended to allow for multiple language categorization
else -- or is a recognized language (but has a three-character tag)
utilities.add_prop_cat ('foreign-lang-source-2', {lang_subtag}, lang_subtag); -- categorize it differently TODO: support multiple three-character tag categories per cs1|2 template?
end
elseif cfg.local_lang_cat_enable then -- when the language and this wiki's language are the same and categorization is enabled
elseif cfg.local_lang_cat_enable then -- when the language and this wiki's language are the same and categorization is enabled
utilities.add_prop_cat ('local_lang_source', {name, code}); -- categorize it
utilities.add_prop_cat ('local-lang-source', {name, lang_subtag}); -- categorize it
end
end
else
else
name = lang; -- return whatever <lang> has so that we show something
utilities.set_message ('maint_unknown_lang'); -- add maint category if not already added
utilities.set_message ('maint_unknown_lang'); -- add maint category if not already added
end
end
1,591行目: 1,757行目:
   
   
name = utilities.make_sep_list (#language_list, language_list);
name = utilities.make_sep_list (#language_list, language_list);
 
if (1 == #language_list) and (lang_subtag == cfg.this_wiki_code) then -- when only one language, find lang name in this wiki lang name; for |language=en-us, 'English' in 'American English'
if this_wiki_name == name then
return ''; -- if one language and that language is this wiki's return an empty string (no annotation)
return ''; -- if one language and that language is this wiki's return an empty string (no annotation)
end
end
1,602行目: 1,767行目:




--[[--------------------------< S E T _ C S 1 _ S T Y L E >----------------------------------------------------
--[[-----------------------< S E T _ C S _ S T Y L E >--------------------------


Set style settings for CS1 citation templates. Returns separator and postscript settings
Gets the default CS style configuration for the given mode.
At en.wiki, for cs1:
Returns default separator and either postscript as passed in or the default.
ps gets: '.'
In CS1, the default postscript and separator are '.'.
sep gets: '.'
In CS2, the default postscript is the empty string and the default separator is ','.


]]
]]


local function set_cs1_style (ps)
local function set_cs_style (postscript, mode)
if not utilities.is_set (ps) then -- unless explicitly set to something
if utilities.is_set(postscript) then
ps = cfg.presentation['ps_cs1']; -- terminate the rendered citation
-- emit a maintenance message if user postscript is the default cs1 postscript
-- we catch the opposite case for cs2 in set_style
if mode == 'cs1' and postscript == cfg.presentation['ps_' .. mode] then
utilities.set_message ('maint_postscript');
end
else
postscript = cfg.presentation['ps_' .. mode];
end
end
return cfg.presentation['sep_cs1'], ps; -- element separator
return cfg.presentation['sep_' .. mode], postscript;
end
end




--[[--------------------------< S E T _ C S 2 _ S T Y L E >----------------------------------------------------
--[[--------------------------< S E T _ S T Y L E >-----------------------------


Set style settings for CS2 citation templates. Returns separator, postscript, ref settings
Sets the separator and postscript styles. Checks the |mode= first and the
At en.wiki, for cs2:
#invoke CitationClass second. Removes the postscript if postscript == none.
ps gets: '' (empty string - no terminal punctuation)
sep gets: ','


]]
]]


local function set_cs2_style (ps, ref)
local function set_style (mode, postscript, cite_class)
if not utilities.is_set (ps) then -- if |postscript= has not been set, set cs2 default
ps = cfg.presentation['ps_cs2']; -- terminate the rendered citation
end
if not utilities.is_set (ref) then -- if |ref= is not set
ref = "harv"; -- set default |ref=harv
end
return cfg.presentation['sep_cs2'], ps, ref; -- element separator
end
 
 
--[[--------------------------< G E T _ S E T T I N G S _ F R O M _ C I T E _ C L A S S >----------------------
 
When |mode= is not set or when its value is invalid, use config.CitationClass and parameter values to establish
rendered style.
 
]]
 
local function get_settings_from_cite_class (ps, ref, cite_class)
local sep;
local sep;
if (cite_class == "citation") then -- for citation templates (CS2)
if 'cs2' == mode then
sep, ps, ref = set_cs2_style (ps, ref);
sep, postscript = set_cs_style (postscript, 'cs2');
else -- not a citation template so CS1
elseif 'cs1' == mode then
sep, ps = set_cs1_style (ps);
sep, postscript = set_cs_style (postscript, 'cs1');
elseif 'citation' == cite_class then
sep, postscript = set_cs_style (postscript, 'cs2');
else
sep, postscript = set_cs_style (postscript, 'cs1');
end
end


return sep, ps, ref -- return them all
if cfg.keywords_xlate[postscript:lower()] == 'none' then
end
-- emit a maintenance message if user postscript is the default cs2 postscript
 
-- we catch the opposite case for cs1 in set_cs_style
 
if 'cs2' == mode or 'citation' == cite_class then
--[[--------------------------< S E T _ S T Y L E >------------------------------------------------------------
utilities.set_message ('maint_postscript');
 
end
Establish basic style settings to be used when rendering the citation.  Uses |mode= if set and valid or uses
postscript = '';
config.CitationClass from the template's #invoke: to establish style.
 
]]
 
local function set_style (mode, ps, ref, cite_class)
local sep;
if 'cs2' == mode then -- if this template is to be rendered in CS2 (citation) style
sep, ps, ref = set_cs2_style (ps, ref);
elseif 'cs1' == mode then -- if this template is to be rendered in CS1 (cite xxx) style
sep, ps = set_cs1_style (ps);
else -- anything but cs1 or cs2
sep, ps, ref = get_settings_from_cite_class (ps, ref, cite_class); -- get settings based on the template's CitationClass
end
 
if cfg.keywords_xlate[ps:lower()] == 'none' then -- if assigned value is 'none' then
ps = ''; -- set to empty string
end
end
return sep, ps, ref
return sep, postscript
end
end




--[=[-------------------------< I S _ P D F >------------------------------------------------------------------
--[=[-------------------------< I S _ P D F >-----------------------------------


Determines if a URL has the file extension that is one of the PDF file extensions used by [[MediaWiki:Common.css]] when
Determines if a URL has the file extension that is one of the PDF file extensions
applying the PDF icon to external links.
used by [[MediaWiki:Common.css]] when applying the PDF icon to external links.


returns true if file extension is one of the recognized extensions, else false
returns true if file extension is one of the recognized extensions, else false
1,699行目: 1,838行目:




--[[--------------------------< S T Y L E _ F O R M A T >------------------------------------------------------
--[[--------------------------< S T Y L E _ F O R M A T >-----------------------


Applies CSS style to |format=, |chapter-format=, etc.  Also emits an error message if the format parameter does
Applies CSS style to |format=, |chapter-format=, etc.  Also emits an error message
not have a matching URL parameter.  If the format parameter is not set and the URL contains a file extension that
if the format parameter does not have a matching URL parameter.  If the format parameter
is recognized as a PDF document by MediaWiki's commons.css, this code will set the format parameter to (PDF) with
is not set and the URL contains a file extension that is recognized as a PDF document
by MediaWiki's commons.css, this code will set the format parameter to (PDF) with
the appropriate styling.
the appropriate styling.


1,712行目: 1,852行目:
format = utilities.wrap_style ('format', format); -- add leading space, parentheses, resize
format = utilities.wrap_style ('format', format); -- add leading space, parentheses, resize
if not utilities.is_set (url) then
if not utilities.is_set (url) then
format = format .. ' ' .. utilities.set_message ( 'err_format_missing_url', {fmt_param, url_param} ); -- add an error message
utilities.set_message ('err_format_missing_url', {fmt_param, url_param}); -- add an error message
end
end
elseif is_pdf (url) then -- format is not set so if URL is a PDF file then
elseif is_pdf (url) then -- format is not set so if URL is a PDF file then
1,723行目: 1,863行目:




--[[--------------------------< G E T _ D I S P L A Y _ N A M E S >--------------------------------------------
--[[---------------------< G E T _ D I S P L A Y _ N A M E S >------------------


Returns a number that defines the number of names displayed for author and editor name lists and a Boolean flag
Returns a number that defines the number of names displayed for author and editor
to indicate when et al. should be appended to the name list.
name lists and a Boolean flag to indicate when et al. should be appended to the name list.


When the value assigned to |display-xxxxors= is a number greater than or equal to zero, return the number and
When the value assigned to |display-xxxxors= is a number greater than or equal to zero,
the previous state of the 'etal' flag (false by default but may have been set to true if the name list contains
return the number and the previous state of the 'etal' flag (false by default
some variant of the text 'et al.').
but may have been set to true if the name list contains some variant of the text 'et al.').


When the value assigned to |display-xxxxors= is the keyword 'etal', return a number that is one greater than the
When the value assigned to |display-xxxxors= is the keyword 'etal', return a number
number of authors in the list and set the 'etal' flag true. This will cause the list_people() to display all of
that is one greater than the number of authors in the list and set the 'etal' flag true.
the names in the name list followed by 'et al.'
This will cause the list_people() to display all of the names in the name list followed by 'et al.'


In all other cases, returns nil and the previous state of the 'etal' flag.
In all other cases, returns nil and the previous state of the 'etal' flag.
1,746行目: 1,886行目:
]]
]]


local function get_display_names (max, count, list_name, etal)
local function get_display_names (max, count, list_name, etal, param)
if utilities.is_set (max) then
if utilities.is_set (max) then
if 'etal' == max:lower():gsub("[ '%.]", '') then -- the :gsub() portion makes 'etal' from a variety of 'et al.' spellings and stylings
if 'etal' == max:lower():gsub("[ '%.]", '') then -- the :gsub() portion makes 'etal' from a variety of 'et al.' spellings and stylings
1,754行目: 1,894行目:
max = tonumber (max); -- make it a number
max = tonumber (max); -- make it a number
if max >= count then -- if |display-xxxxors= value greater than or equal to number of authors/editors
if max >= count then -- if |display-xxxxors= value greater than or equal to number of authors/editors
table.insert( z.message_tail, {utilities.set_message ('err_disp_name', {cfg.special_case_translation [list_name], max}, true)}); -- add error message
utilities.set_message ('err_disp_name', {param, max}); -- add error message
max = nil;
max = nil;
end
end
else -- not a valid keyword or number
else -- not a valid keyword or number
table.insert( z.message_tail, {utilities.set_message ('err_disp_name', {cfg.special_case_translation [list_name], max}, true)}); -- add error message
utilities.set_message ('err_disp_name', {param, max}); -- add error message
max = nil; -- unset; as if |display-xxxxors= had not been set
max = nil; -- unset; as if |display-xxxxors= had not been set
end
end
1,767行目: 1,907行目:




--[[--------------------------< E X T R A _ T E X T _ I N _ P A G E _ C H E C K >------------------------------
--[[----------< E X T R A _ T E X T _ I N _ P A G E _ C H E C K >---------------


Adds page to Category:CS1 maint: extra text if |page= or |pages= has what appears to be some form of p. or pp.  
Adds error if |page=, |pages=, |quote-page=, |quote-pages= has what appears to be
abbreviation in the first characters of the parameter content.
some form of p. or pp. abbreviation in the first characters of the parameter content.


check Page and Pages for extraneous p, p., pp, and pp. at start of parameter value:
check page for extraneous p, p., pp, pp., pg, pg. at start of parameter value:
good pattern: '^P[^%.P%l]' matches when |page(s)= begins PX or P# but not Px where x and X are letters and # is a dgiit
good pattern: '^P[^%.P%l]' matches when page begins PX or P# but not Px
bad pattern: '^[Pp][Pp]' matches matches when |page(s)= begins pp or pP or Pp or PP
      where x and X are letters and # is a digit
bad pattern: '^[Pp][PpGg]' matches when page begins pp, pP, Pp, PP, pg, pG, Pg, PG


]]
]]


local function extra_text_in_page_check (page)
local function extra_text_in_page_check (val, name)
local good_pattern = '^P[^%.Pp]'; -- ok to begin with uppercase P: P7 (pg 7 of section P) but not p123 (page 123) TODO: add Gg for PG or Pg?
if not val:match (cfg.vol_iss_pg_patterns.good_ppattern) then
local bad_pattern = '^[Pp]?[Pp]%.?[ %d]';
for _, pattern in ipairs (cfg.vol_iss_pg_patterns.bad_ppatterns) do -- spin through the selected sequence table of patterns
 
if val:match (pattern) then -- when a match, error so
if not page:match (good_pattern) and (page:match (bad_pattern) or  page:match ('^[Pp]ages?')) then
utilities.set_message ('err_extra_text_pages', name); -- add error message
utilities.set_message ('maint_extra_text'); -- add maint cat;
return; -- and done
end
end
end
end
end
end




--[=[-------------------------< G E T _ V _ N A M E _ T A B L E >----------------------------------------------
--[[--------------------------< E X T R A _ T E X T _ I N _ V O L _ I S S _ C H E C K >------------------------


split apart a |vauthors= or |veditors= parameter.  This function allows for corporate names, wrapped in doubled
Adds error if |volume= or |issue= has what appears to be some form of redundant 'type' indicator.
parentheses to also have commas; in the old version of the code, the doubled parentheses were included in the
rendered citation and in the metadata. Individual author names may be wikilinked


|vauthors=Jones AB, [[E. B. White|White EB]], ((Black, Brown, and Co.))
For |volume=:
'V.', or 'Vol.' (with or without the dot) abbreviations or 'Volume' in the first characters of the parameter
content (all case insensitive). 'V' and 'v' (without the dot) are presumed to be roman numerals so
are allowed.


]=]
For |issue=:
 
'No.', 'I.', 'Iss.' (with or without the dot) abbreviations, or 'Issue' in the first characters of the
local function get_v_name_table (vparam, output_table, output_link_table)
parameter content (all case insensitive).
local name_table = mw.text.split(vparam, "%s*,%s*"); -- names are separated by commas
local wl_type, label, link; -- wl_type not used here; just a place holder
local i = 1;
Single character values ('v', 'i', 'n') allowed when not followed by separator character ('.', ':', '=', or
whitespace character) – param values are trimmed of whitespace by MediaWiki before delivered to the module.
while name_table[i] do
<val> is |volume= or |issue= parameter value
<name> is |volume= or |issue= parameter name for error message
<selector> is 'v' for |volume=, 'i' for |issue=
 
sets error message on failure; returns nothing
 
]]
 
local function extra_text_in_vol_iss_check (val, name, selector)
if not utilities.is_set (val) then
return;
end
local patterns = 'v' == selector and cfg.vol_iss_pg_patterns.vpatterns or cfg.vol_iss_pg_patterns.ipatterns;
 
local handler = 'v' == selector and 'err_extra_text_volume' or 'err_extra_text_issue';
val = val:lower(); -- force parameter value to lower case
for _, pattern in ipairs (patterns) do -- spin through the selected sequence table of patterns
if val:match (pattern) then -- when a match, error so
utilities.set_message (handler, name); -- add error message
return; -- and done
end
end
end
 
 
--[=[-------------------------< G E T _ V _ N A M E _ T A B L E >----------------------------------------------
 
split apart a |vauthors= or |veditors= parameter.  This function allows for corporate names, wrapped in doubled
parentheses to also have commas; in the old version of the code, the doubled parentheses were included in the
rendered citation and in the metadata.  Individual author names may be wikilinked
 
|vauthors=Jones AB, [[E. B. White|White EB]], ((Black, Brown, and Co.))
 
]=]
 
local function get_v_name_table (vparam, output_table, output_link_table)
local name_table = mw.text.split(vparam, "%s*,%s*"); -- names are separated by commas
local wl_type, label, link; -- wl_type not used here; just a placeholder
local i = 1;
while name_table[i] do
if name_table[i]:match ('^%(%(.*[^%)][^%)]$') then -- first segment of corporate with one or more commas; this segment has the opening doubled parentheses
if name_table[i]:match ('^%(%(.*[^%)][^%)]$') then -- first segment of corporate with one or more commas; this segment has the opening doubled parentheses
local name = name_table[i];
local name = name_table[i];
i = i + 1; -- bump indexer to next segment
i = i + 1; -- bump indexer to next segment
while name_table[i] do
while name_table[i] do
name = name .. ', ' .. name_table[i]; -- concatenate with previous segments
name = name .. ', ' .. name_table[i]; -- concatenate with previous segments
1,863行目: 2,048行目:
v_name, accept_name = utilities.has_accept_as_written (v_name); -- remove accept-this-as-written markup when it wraps all of <v_name>
v_name, accept_name = utilities.has_accept_as_written (v_name); -- remove accept-this-as-written markup when it wraps all of <v_name>


-- if v_name:match ('^%(%(.+%)%)$') then -- corporate authors are wrapped in doubled parentheses to suppress vanc formatting and error detection
-- last = v_name:match ('^%(%((.+)%)%)$') -- remove doubled parentheses
if accept_name then
if accept_name then
last = v_name;
last = v_name;
1,870行目: 2,053行目:
elseif string.find(v_name, "%s") then
elseif string.find(v_name, "%s") then
if v_name:find('[;%.]') then -- look for commonly occurring punctuation characters;  
if v_name:find('[;%.]') then -- look for commonly occurring punctuation characters;  
add_vanc_error (cfg.err_msg_supl.punctuation);
add_vanc_error (cfg.err_msg_supl.punctuation, i);
end
end
local lastfirstTable = {}
local lastfirstTable = {}
1,884行目: 2,067行目:
first = ''; -- unset
first = ''; -- unset
last = v_name; -- last empty because something wrong with first
last = v_name; -- last empty because something wrong with first
add_vanc_error (cfg.err_msg_supl.name);
add_vanc_error (cfg.err_msg_supl.name, i);
end
end
if mw.ustring.match (last, '%a+%s+%u+%s+%a+') then
if mw.ustring.match (last, '%a+%s+%u+%s+%a+') then
add_vanc_error (cfg.err_msg_supl['missing comma']); -- matches last II last; the case when a comma is missing
add_vanc_error (cfg.err_msg_supl['missing comma'], i); -- matches last II last; the case when a comma is missing
end
end
if mw.ustring.match (v_name, ' %u %u$') then -- this test is in the wrong place TODO: move or replace with a more appropriate test
if mw.ustring.match (v_name, ' %u %u$') then -- this test is in the wrong place TODO: move or replace with a more appropriate test
add_vanc_error (cfg.err_msg_supl.name); -- matches a space between two initials
add_vanc_error (cfg.err_msg_supl.initials, i); -- matches a space between two initials
end
end
else
else
1,898行目: 2,081行目:
if utilities.is_set (first) then
if utilities.is_set (first) then
if not mw.ustring.match (first, "^%u?%u$") then -- first shall contain one or two upper-case letters, nothing else
if not mw.ustring.match (first, "^%u?%u$") then -- first shall contain one or two upper-case letters, nothing else
add_vanc_error (cfg.err_msg_supl.initials); -- too many initials; mixed case initials (which may be ok Romanization); hyphenated initials
add_vanc_error (cfg.err_msg_supl.initials, i); -- too many initials; mixed case initials (which may be ok Romanization); hyphenated initials
end
end
is_good_vanc_name (last, first, suffix); -- check first and last before restoring the suffix which may have a non-Latin digit
is_good_vanc_name (last, first, suffix, i); -- check first and last before restoring the suffix which may have a non-Latin digit
if utilities.is_set (suffix) then
if utilities.is_set (suffix) then
first = first .. ' ' .. suffix; -- if there was a suffix concatenate with the initials
first = first .. ' ' .. suffix; -- if there was a suffix concatenate with the initials
1,907行目: 2,090行目:
else
else
if not corporate then
if not corporate then
is_good_vanc_name (last, '');
is_good_vanc_name (last, '', nil, i);
end
end
end
end
1,922行目: 2,105行目:


Select one of |authors=, |authorn= / |lastn / firstn=, or |vauthors= as the source of the author name list or
Select one of |authors=, |authorn= / |lastn / firstn=, or |vauthors= as the source of the author name list or
select one of |editors=, |editorn= / editor-lastn= / |editor-firstn= or |veditors= as the source of the editor name list.
select one of |editorn= / editor-lastn= / |editor-firstn= or |veditors= as the source of the editor name list.


Only one of these appropriate three will be used.  The hierarchy is: |authorn= (and aliases) highest and |authors= lowest and
Only one of these appropriate three will be used.  The hierarchy is: |authorn= (and aliases) highest and |authors= lowest;
similarly, |editorn= (and aliases) highest and |editors= lowest
|editorn= (and aliases) highest and |veditors= lowest (support for |editors= withdrawn)


When looking for |authorn= / |editorn= parameters, test |xxxxor1= and |xxxxor2= (and all of their aliases); stops after the second
When looking for |authorn= / |editorn= parameters, test |xxxxor1= and |xxxxor2= (and all of their aliases); stops after the second
1,933行目: 2,116行目:
Emits an error message when more than one xxxxor name source is provided.
Emits an error message when more than one xxxxor name source is provided.


In this function, vxxxxors = vauthors or veditors; xxxxors = authors or editors as appropriate.
In this function, vxxxxors = vauthors or veditors; xxxxors = authors as appropriate.


]]
]]
1,955行目: 2,138行目:
err_name = 'editor';
err_name = 'editor';
end
end
table.insert( z.message_tail, { utilities.set_message ( 'err_redundant_parameters',
utilities.set_message ('err_redundant_parameters', err_name .. '-name-list parameters'); -- add error message
{err_name .. '-name-list parameters'}, true ) } ); -- add error message
end
end


1,973行目: 2,155行目:
of the list of allowed values returns the translated value; else, emits an error message and returns the value
of the list of allowed values returns the translated value; else, emits an error message and returns the value
specified by ret_val.
specified by ret_val.
TODO: explain <invert>


]]
]]


local function is_valid_parameter_value (value, name, possible, ret_val)
local function is_valid_parameter_value (value, name, possible, ret_val, invert)
if not utilities.is_set (value) then
if not utilities.is_set (value) then
return ret_val; -- an empty parameter is ok
return ret_val; -- an empty parameter is ok
elseif utilities.in_array (value, possible) then
end
 
if (not invert and utilities.in_array (value, possible)) then -- normal; <value> is in <possible> table
return cfg.keywords_xlate[value]; -- return translation of parameter keyword
return cfg.keywords_xlate[value]; -- return translation of parameter keyword
elseif invert and not utilities.in_array (value, possible) then -- invert; <value> is not in <possible> table
return value; -- return <value> as it is
else
else
table.insert( z.message_tail, { utilities.set_message ( 'err_invalid_param_val', {name, value}, true ) } ); -- not an allowed value so add error message
utilities.set_message ('err_invalid_param_val', {name, value}); -- not an allowed value so add error message
return ret_val;
return ret_val;
end
end
2,008行目: 2,196行目:




--[[-------------------------< F O R M A T _ V O L U M E _ I S S U E >----------------------------------------
--[[-------------------------< F O R M A T _ V O L U M E _ I S S U E >-----------------------------------------


returns the concatenation of the formatted volume and issue parameters as a single string; or formatted volume
returns the concatenation of the formatted volume and issue (or journal article number) parameters as a single
or formatted issue, or an empty string if neither are set.
string; or formatted volume or formatted issue, or an empty string if neither are set.


]]
]]
local function format_volume_issue (volume, issue, cite_class, origin, sepc, lower)
local function format_volume_issue (volume, issue, article, cite_class, origin, sepc, lower)
if not utilities.is_set (volume) and not utilities.is_set (issue) then
if not utilities.is_set (volume) and not utilities.is_set (issue) and not utilities.is_set (article) then
return '';
return '';
end
end
-- same condition as in format_pages_sheets()
local is_journal = 'journal' == cite_class or (utilities.in_array (cite_class, {'citation', 'map', 'interview'}) and 'journal' == origin);
local is_numeric_vol = volume and (volume:match ('^[MDCLXVI]+$') or volume:match ('^%d+$')); -- is only uppercase roman numerals or only digits?
local is_long_vol = volume and (4 < mw.ustring.len(volume)); -- is |volume= value longer than 4 characters?
if 'magazine' == cite_class or (utilities.in_array (cite_class, {'citation', 'map'}) and 'magazine' == origin) then
if volume and (not is_numeric_vol and is_long_vol) then -- when not all digits or Roman numerals, is |volume= longer than 4 characters?
if utilities.is_set (volume) and utilities.is_set (issue) then
utilities.add_prop_cat ('long-vol'); -- yes, add properties cat
return wrap_msg ('vol-no', {sepc, volume, issue}, lower);
elseif utilities.is_set (volume) then
return wrap_msg ('vol', {sepc, volume}, lower);
else
return wrap_msg ('issue', {sepc, issue}, lower);
end
end
end


if 'podcast' == cite_class and utilities.is_set (issue) then
if is_journal then -- journal-style formatting
local vol = '';
 
if utilities.is_set (volume) then
if is_numeric_vol then -- |volume= value all digits or all uppercase Roman numerals?
vol = utilities.substitute (cfg.presentation['vol-bold'], {sepc, volume}); -- render in bold face
elseif is_long_vol then -- not all digits or Roman numerals; longer than 4 characters?
vol = utilities.substitute (cfg.messages['j-vol'], {sepc, utilities.hyphen_to_dash (volume)}); -- not bold
else -- four or fewer characters
vol = utilities.substitute (cfg.presentation['vol-bold'], {sepc, utilities.hyphen_to_dash (volume)}); -- bold
end
end
vol = vol .. (utilities.is_set (issue) and utilities.substitute (cfg.messages['j-issue'], issue) or '')
vol = vol .. (utilities.is_set (article) and utilities.substitute (cfg.messages['j-article-num'], article) or '')
return vol;
end
if 'podcast' == cite_class and utilities.is_set (issue) then
return wrap_msg ('issue', {sepc, issue}, lower);
return wrap_msg ('issue', {sepc, issue}, lower);
end
end
 
local vol = ''; -- here for all cites except magazine
if 'conference' == cite_class and utilities.is_set (article) then -- |article-number= supported only in journal and conference cites
if utilities.is_set (volume) and utilities.is_set (article) then -- both volume and article number
if utilities.is_set (volume) then
return wrap_msg ('vol-art', {sepc, utilities.hyphen_to_dash (volume), article}, lower);
if volume:match ('^[MDCLXVI]+$') or volume:match ('^%d+$') then -- volume value is all digits or all uppercase Roman numerals
elseif utilities.is_set (article) then -- article number alone; when volume alone, handled below
vol = utilities.substitute (cfg.presentation['vol-bold'], {sepc, hyphen_to_dash(volume)}); -- render in bold face
return wrap_msg ('art', {sepc, article}, lower);
elseif (4 < mw.ustring.len(volume)) then -- not all digits or Roman numerals and longer than 4 characters
vol = utilities.substitute (cfg.messages['j-vol'], {sepc, volume}); -- not bold
utilities.add_prop_cat ('long_vol');
else -- four or less characters
vol = utilities.substitute (cfg.presentation['vol-bold'], {sepc, hyphen_to_dash(volume)}); -- bold
end
end
end
end
if utilities.is_set (issue) then
 
return vol .. utilities.substitute (cfg.messages['j-issue'], issue);
-- all other types of citation
if utilities.is_set (volume) and utilities.is_set (issue) then
return wrap_msg ('vol-no', {sepc, utilities.hyphen_to_dash (volume), issue}, lower);
elseif utilities.is_set (volume) then
return wrap_msg ('vol', {sepc, utilities.hyphen_to_dash (volume)}, lower);
else
return wrap_msg ('issue', {sepc, issue}, lower);
end
end
return vol;
end
end


2,111行目: 2,316行目:


If any of these are interwiki links to Wikisource, returns the label portion of the interwiki-link as plain text
If any of these are interwiki links to Wikisource, returns the label portion of the interwiki-link as plain text
for use in COinS.  This COinS thing is done because here we convert an interwiki-link to and external link and
for use in COinS.  This COinS thing is done because here we convert an interwiki-link to an external link and
add an icon span around that; get_coins_pages() doesn't know about the span.  TODO: should it?   
add an icon span around that; get_coins_pages() doesn't know about the span.  TODO: should it?   


2,121行目: 2,326行目:
]]
]]


local function insource_loc_get (page, pages, at)
local function insource_loc_get (page, page_orig, pages, pages_orig, at)
local ws_url, ws_label, coins_pages, L; -- for Wikisource interwiki-links; TODO: this corrupts page metadata (span remains in place after cleanup; fix there?)
local ws_url, ws_label, coins_pages, L; -- for Wikisource interwiki-links; TODO: this corrupts page metadata (span remains in place after cleanup; fix there?)


2,129行目: 2,334行目:
at = '';
at = '';
end
end
extra_text_in_page_check (page); -- add this page to maint cat if |page= value begins with what looks like p. or pp.
extra_text_in_page_check (page, page_orig); -- emit error message when |page= value begins with what looks like p., pp., etc.


ws_url, ws_label, L = wikisource_url_make (page); -- make ws URL from |page= interwiki link; link portion L becomes tooltip label
ws_url, ws_label, L = wikisource_url_make (page); -- make ws URL from |page= interwiki link; link portion L becomes tooltip label
2,141行目: 2,346行目:
at = ''; -- unset
at = ''; -- unset
end
end
extra_text_in_page_check (pages); -- add this page to maint cat if |pages= value begins with what looks like p. or pp.
extra_text_in_page_check (pages, pages_orig); -- emit error message when |page= value begins with what looks like p., pp., etc.


ws_url, ws_label, L = wikisource_url_make (pages); -- make ws URL from |pages= interwiki link; link portion L becomes tooltip label
ws_url, ws_label, L = wikisource_url_make (pages); -- make ws URL from |pages= interwiki link; link portion L becomes tooltip label
2,159行目: 2,364行目:
return page, pages, at, coins_pages;
return page, pages, at, coins_pages;
end
--[[--------------------------< I S _ U N I Q U E _ A R C H I V E _ U R L >------------------------------------
add error message when |archive-url= value is same as |url= or chapter-url= (or alias...) value
]]
local function is_unique_archive_url (archive, url, c_url, source, date)
if utilities.is_set (archive) then
if archive == url or archive == c_url then
utilities.set_message ('err_bad_url', {utilities.wrap_style ('parameter', source)}); -- add error message
return '', ''; -- unset |archive-url= and |archive-date= because same as |url= or |chapter-url=
end
end
return archive, date;
end
end


2,210行目: 2,432行目:
else
else
path, timestamp, flag = url:match('//web%.archive%.org/([^%d]*)(%d+)([^/]*)/'); -- split out some of the URL parts for evaluation
path, timestamp, flag = url:match('//web%.archive%.org/([^%d]*)(%d+)([^/]*)/'); -- split out some of the URL parts for evaluation
if not path then -- malformed in some way; pattern did not match
if not utilities.is_set (timestamp) or 14 ~= timestamp:len() then -- path and flag optional, must have 14-digit timestamp here
err_msg = cfg.err_msg_supl.timestamp;
elseif 14 ~= timestamp:len() then -- path and flag optional, must have 14-digit timestamp here
err_msg = cfg.err_msg_supl.timestamp;
err_msg = cfg.err_msg_supl.timestamp;
if '*' ~= flag then
if '*' ~= flag then
url=url:gsub ('(//web%.archive%.org/[^%d]*%d?%d?%d?%d?%d?%d?)[^/]*', '%1*', 1) -- for preview, modify ts to be yearmo* max (0-6 digits plus splat)
local replacement = timestamp:match ('^%d%d%d%d%d%d') or timestamp:match ('^%d%d%d%d'); -- get the first 6 (YYYYMM) or first 4 digits (YYYY)
if replacement then -- nil if there aren't at least 4 digits (year)
replacement = replacement .. string.rep ('0', 14 - replacement:len()); -- year or yearmo (4 or 6 digits) zero-fill to make 14-digit timestamp
url=url:gsub ('(//web%.archive%.org/[^%d]*)%d[^/]*', '%1' .. replacement .. '*', 1) -- for preview, modify ts to 14 digits plus splat for calendar display
end
end
end
elseif utilities.is_set (path) and 'web/' ~= path then -- older archive URLs do not have the extra 'web/' path element
elseif utilities.is_set (path) and 'web/' ~= path then -- older archive URLs do not have the extra 'web/' path element
2,227行目: 2,454行目:
end
end
-- if here, something not right so
-- if here, something not right so
table.insert( z.message_tail, { utilities.set_message ( 'err_archive_url', {err_msg}, true ) } ); -- add error message and
utilities.set_message ('err_archive_url', {err_msg}); -- add error message and
if utilities.is_set (Frame:preprocess('{{REVISIONID}}')) then
 
if is_preview_mode then
return url, date; -- preview mode so return ArchiveURL and ArchiveDate
else
return '', ''; -- return empty strings for ArchiveURL and ArchiveDate
return '', ''; -- return empty strings for ArchiveURL and ArchiveDate
else
return url, date; -- preview mode so return ArchiveURL and ArchiveDate
end
end
end
end
2,258行目: 2,486行目:




--[[--------------------------< I S _ G E N E R I C _ T I T L E >----------------------------------------------
--[[--------------------------< I S _ A R C H I V E D _ C O P Y >----------------------------------------------


compares |title= value against list of known generic title patterns.  Returns true when pattern matches; nil else
compares |title= to 'Archived copy' (placeholder added by bots that can't find proper title); if matches, return true; nil else
 
the k/v pairs in 'generic_titles' each contain two tables, one for English and one for another 'local' language
Each of those tables contain another table that holds the string or pattern (whole title or title fragment) in
index [1].  index [2] is a Boolean that tells string.find() or mw.ustring.find() to do plain-text search (true)
or a pattern search (false).  The intent of all this complexity is to make these searches as fast as possible so
that we don't run out of processing time on very large articles.


]]
]]


local function is_generic_title (title)
local function is_archived_copy (title)
title = mw.ustring.lower(title); -- switch title to lower case
title = mw.ustring.lower(title); -- switch title to lower case
for _, generic_title in ipairs (cfg.special_case_translation['generic_titles']) do --spin through the list of known generic title fragments
if title:find (cfg.special_case_translation.archived_copy.en) then -- if title is 'Archived copy'
if title:find (generic_title['en'][1], 1, generic_title['en'][2]) then
return true;
return true; -- found English generic title so done
elseif cfg.special_case_translation.archived_copy['local'] then
elseif generic_title['local'] then -- to keep work load down, generic_title['local'] should be nil except when there is a local version of the generic title
if mw.ustring.find (title, generic_title['local'][1], 1, generic_title['local'][2]) then -- mw.ustring() because might not be Latin script
return true; -- found local generic title so done
end
end
end
end
 
 
--[[--------------------------< I S _ A R C H I V E D _ C O P Y >----------------------------------------------
 
compares |title= to 'Archived copy' (place holder added by bots that can't find proper title); if matches, return true; nil else
 
]]
 
local function is_archived_copy (title)
title = mw.ustring.lower(title); -- switch title to lower case
if title:find (cfg.special_case_translation.archived_copy.en) then -- if title is 'Archived copy'
return true;
elseif cfg.special_case_translation.archived_copy['local'] then
if mw.ustring.find (title, cfg.special_case_translation.archived_copy['local']) then -- mw.ustring() because might not be Latin script
if mw.ustring.find (title, cfg.special_case_translation.archived_copy['local']) then -- mw.ustring() because might not be Latin script
return true;
return true;
2,308行目: 2,510行目:
]]
]]


local function citation0( config, args)
local function citation0( config, args )
--[[  
--[[  
Load Input Parameters
Load Input Parameters
2,318行目: 2,520行目:
-- Pick out the relevant fields from the arguments.  Different citation templates
-- Pick out the relevant fields from the arguments.  Different citation templates
-- define different field names for the same underlying things.
-- define different field names for the same underlying things.
local Mode = is_valid_parameter_value (A['Mode'], A:ORIGIN('Mode'), cfg.keywords_lists['mode'], '');


local author_etal;
local author_etal;
local a = {}; -- authors list from |lastn= / |firstn= pairs or |vauthors=
local a = {}; -- authors list from |lastn= / |firstn= pairs or |vauthors=
local Authors;
local Authors;
local NameListStyle = is_valid_parameter_value (A['NameListStyle'], A:ORIGIN('NameListStyle'), cfg.keywords_lists['name-list-style'], '');
local NameListStyle = is_valid_parameter_value (A['NameListStyle'], A:ORIGIN('NameListStyle'), cfg.keywords_lists['name-list-style'], '');
local Collaboration = A['Collaboration'];
local Collaboration = A['Collaboration'];
2,333行目: 2,532行目:
a, author_etal = extract_names (args, 'AuthorList'); -- fetch author list from |authorn= / |lastn= / |firstn=, |author-linkn=, and |author-maskn=
a, author_etal = extract_names (args, 'AuthorList'); -- fetch author list from |authorn= / |lastn= / |firstn=, |author-linkn=, and |author-maskn=
elseif 2 == selected then
elseif 2 == selected then
NameListStyle = 'vanc'; -- override whatever |name-list-style= might be
NameListStyle = 'vanc'; -- override whatever |name-list-style= might be
a, author_etal = parse_vauthors_veditors (args, args.vauthors, 'AuthorList'); -- fetch author list from |vauthors=, |author-linkn=, and |author-maskn=
a, author_etal = parse_vauthors_veditors (args, args.vauthors, 'AuthorList'); -- fetch author list from |vauthors=, |author-linkn=, and |author-maskn=
elseif 3 == selected then
elseif 3 == selected then
2,345行目: 2,544行目:
end
end
end
end
local Others = A['Others'];


local editor_etal;
local editor_etal;
local e = {}; -- editors list from |editor-lastn= / |editor-firstn= pairs or |veditors=
local e = {}; -- editors list from |editor-lastn= / |editor-firstn= pairs or |veditors=
local Editors;


do -- to limit scope of selected
do -- to limit scope of selected
local selected = select_author_editor_source (A['Veditors'], A['Editors'], args, 'EditorList');
local selected = select_author_editor_source (A['Veditors'], nil, args, 'EditorList'); -- support for |editors= withdrawn
if 1 == selected then
if 1 == selected then
e, editor_etal = extract_names (args, 'EditorList'); -- fetch editor list from |editorn= / |editor-lastn= / |editor-firstn=, |editor-linkn=, and |editor-maskn=
e, editor_etal = extract_names (args, 'EditorList'); -- fetch editor list from |editorn= / |editor-lastn= / |editor-firstn=, |editor-linkn=, and |editor-maskn=
elseif 2 == selected then
elseif 2 == selected then
NameListStyle = 'vanc'; -- override whatever |name-list-style= might be
NameListStyle = 'vanc'; -- override whatever |name-list-style= might be
e, editor_etal = parse_vauthors_veditors (args, args.veditors, 'EditorList'); -- fetch editor list from |veditors=, |editor-linkn=, and |editor-maskn=
e, editor_etal = parse_vauthors_veditors (args, args.veditors, 'EditorList'); -- fetch editor list from |veditors=, |editor-linkn=, and |editor-maskn=
elseif 3 == selected then
Editors = A['Editors']; -- use content of |editors=
end
end
end
end
 
local translator_etal;
local t = {}; -- translators list from |translator-lastn= / translator-firstn= pairs
local Translators; -- assembled translators name list
t = extract_names (args, 'TranslatorList'); -- fetch translator list from |translatorn= / |translator-lastn=, -firstn=, -linkn=, -maskn=
 
local interviewer_etal;
local interviewers_list = {};
local Interviewers; -- used later
interviewers_list = extract_names (args, 'InterviewerList'); -- process preferred interviewers parameters
 
local contributor_etal;
local c = {}; -- contributors list from |contributor-lastn= / contributor-firstn= pairs
local Contributors; -- assembled contributors name list
 
local Chapter = A['Chapter']; -- done here so that we have access to |contribution= from |chapter= aliases
local Chapter = A['Chapter']; -- done here so that we have access to |contribution= from |chapter= aliases
local Chapter_origin = A:ORIGIN ('Chapter');
local Chapter_origin = A:ORIGIN ('Chapter');
local Contribution; -- because contribution is required for contributor(s)
local Contribution; -- because contribution is required for contributor(s)
if 'contribution' == A:ORIGIN ('Chapter') then
if 'contribution' == Chapter_origin then
Contribution = A['Chapter']; -- get the name of the contribution
Contribution = Chapter; -- get the name of the contribution
end
end
 
local c = {}; -- contributors list from |contributor-lastn= / contributor-firstn= pairs
if utilities.in_array (config.CitationClass, {"book", "citation"}) and not utilities.is_set (A['Periodical']) then -- |contributor= and |contribution= only supported in book cites
if utilities.in_array (config.CitationClass, {"book", "citation"}) and not utilities.is_set (A['Periodical']) then -- |contributor= and |contribution= only supported in book cites
c = extract_names (args, 'ContributorList'); -- fetch contributor list from |contributorn= / |contributor-lastn=, -firstn=, -linkn=, -maskn=
c = extract_names (args, 'ContributorList'); -- fetch contributor list from |contributorn= / |contributor-lastn=, -firstn=, -linkn=, -maskn=
2,390行目: 2,571行目:
if 0 < #c then
if 0 < #c then
if not utilities.is_set (Contribution) then -- |contributor= requires |contribution=
if not utilities.is_set (Contribution) then -- |contributor= requires |contribution=
table.insert( z.message_tail, { utilities.set_message ( 'err_contributor_missing_required_param', 'contribution')}); -- add missing contribution error message
utilities.set_message ('err_contributor_missing_required_param', 'contribution'); -- add missing contribution error message
c = {}; -- blank the contributors' table; it is used as a flag later
c = {}; -- blank the contributors' table; it is used as a flag later
end
end
if 0 == #a then -- |contributor= requires |author=
if 0 == #a then -- |contributor= requires |author=
table.insert( z.message_tail, { utilities.set_message ( 'err_contributor_missing_required_param', 'author')}); -- add missing author error message
utilities.set_message ('err_contributor_missing_required_param', 'author'); -- add missing author error message
c = {}; -- blank the contributors' table; it is used as a flag later
c = {}; -- blank the contributors' table; it is used as a flag later
end
end
2,400行目: 2,581行目:
else -- if not a book cite
else -- if not a book cite
if utilities.select_one (args, cfg.aliases['ContributorList-Last'], 'err_redundant_parameters', 1 ) then -- are there contributor name list parameters?
if utilities.select_one (args, cfg.aliases['ContributorList-Last'], 'err_redundant_parameters', 1 ) then -- are there contributor name list parameters?
table.insert( z.message_tail, { utilities.set_message ( 'err_contributor_ignored')}); -- add contributor ignored error message
utilities.set_message ('err_contributor_ignored'); -- add contributor ignored error message
end
end
Contribution = nil; -- unset
Contribution = nil; -- unset
end
end


if utilities.is_set (Others) then
local Title = A['Title'];
if 0 == #a and 0 == #e then -- add maint cat when |others= has value and used without |author=, |editor=
utilities.set_message ('maint_others');
end
end
 
local Year = A['Year'];
local PublicationDate = A['PublicationDate'];
local OrigDate = A['OrigDate'];
local Date = A['Date'];
local LayDate = A['LayDate'];
------------------------------------------------- Get title data
local Title = A['Title'];
local ScriptTitle = A['ScriptTitle'];
local BookTitle = A['BookTitle'];
local Conference = A['Conference'];
local TransTitle = A['TransTitle'];
local TransTitle_origin = A:ORIGIN ('TransTitle');
local TitleNote = A['TitleNote'];
local TitleLink = A['TitleLink'];
local TitleLink = A['TitleLink'];


local auto_select = ''; -- default is auto
local auto_select = ''; -- default is auto
local accept_link;
local accept_link;
TitleLink, accept_link = utilities.has_accept_as_written(TitleLink, true); -- test for accept-this-as-written markup
TitleLink, accept_link = utilities.has_accept_as_written (TitleLink, true); -- test for accept-this-as-written markup
if (not accept_link) and utilities.in_array (TitleLink, {'none', 'pmc', 'doi'}) then -- check for special keywords
if (not accept_link) and utilities.in_array (TitleLink, {'none', 'pmc', 'doi'}) then -- check for special keywords
auto_select = TitleLink; -- remember selection for later
auto_select = TitleLink; -- remember selection for later
TitleLink = ''; -- treat as if |title-link= would have been empty
TitleLink = ''; -- treat as if |title-link= would have been empty
end
end


2,437行目: 2,600行目:


local Section = ''; -- {{cite map}} only; preset to empty string for concatenation if not used
local Section = ''; -- {{cite map}} only; preset to empty string for concatenation if not used
if 'map' == config.CitationClass and 'section' == A:ORIGIN ('Chapter') then
if 'map' == config.CitationClass and 'section' == Chapter_origin then
Section = A['Chapter']; -- get |section= from |chapter= alias list; |chapter= and the other aliases not supported in {{cite map}}
Section = A['Chapter']; -- get |section= from |chapter= alias list; |chapter= and the other aliases not supported in {{cite map}}
Chapter = ''; -- unset for now; will be reset later from |map= if present
Chapter = ''; -- unset for now; will be reset later from |map= if present
end
 
local Periodical = A['Periodical'];
local Periodical_origin = '';
if utilities.is_set (Periodical) then
Periodical_origin = A:ORIGIN('Periodical'); -- get the name of the periodical parameter
local i;
Periodical, i = utilities.strip_apostrophe_markup (Periodical); -- strip apostrophe markup so that metadata isn't contaminated
if i then -- non-zero when markup was stripped so emit an error message
utilities.set_message ('err_apostrophe_markup', {Periodical_origin});
end
end
end


local ScriptChapter = A['ScriptChapter'];
if 'mailinglist' == config.CitationClass then -- special case for {{cite mailing list}}
local ScriptChapter_origin = A:ORIGIN ('ScriptChapter');
if utilities.is_set (Periodical) and utilities.is_set (A ['MailingList']) then -- both set emit an error TODO: make a function for this and similar?
local ChapterLink -- = A['ChapterLink']; -- deprecated as a parameter but still used internally by cite episode
utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', Periodical_origin) .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', 'mailinglist')});
local TransChapter = A['TransChapter'];
end
local TransChapter_origin = A:ORIGIN ('TransChapter');
local TitleType = A['TitleType'];
local Degree = A['Degree'];
local Docket = A['Docket'];
local ArchiveFormat = A['ArchiveFormat'];


local ArchiveDate;
Periodical = A ['MailingList']; -- error or no, set Periodical to |mailinglist= value because this template is {{cite mailing list}}
local ArchiveURL;
 
ArchiveURL, ArchiveDate = archive_url_check (A['ArchiveURL'], A['ArchiveDate'])
local UrlStatus = is_valid_parameter_value (A['UrlStatus'], A:ORIGIN('UrlStatus'), cfg.keywords_lists['url-status'], '');
 
local URL = A['URL']
local URL_origin = A:ORIGIN('URL'); -- get name of parameter that holds URL
local ChapterURL = A['ChapterURL'];
local ChapterURL_origin = A:ORIGIN('ChapterURL'); -- get name of parameter that holds ChapterURL
local ConferenceFormat = A['ConferenceFormat'];
local ConferenceURL = A['ConferenceURL'];
local ConferenceURL_origin = A:ORIGIN('ConferenceURL'); -- get name of parameter that holds ConferenceURL
 
local Periodical = A['Periodical'];
local Periodical_origin = '';
if utilities.is_set (Periodical) then
Periodical_origin = A:ORIGIN('Periodical'); -- get the name of the periodical parameter
local i;
Periodical, i = utilities.strip_apostrophe_markup (Periodical); -- strip apostrophe markup so that metadata isn't contaminated
if i then -- non-zero when markup was stripped so emit an error message
table.insert( z.message_tail, {utilities.set_message ('err_apostrophe_markup', {Periodical_origin}, true)});
end
end
 
if 'mailinglist' == config.CitationClass then -- special case for {{cite mailing list}}
if utilities.is_set (Periodical) and utilities.is_set (A ['MailingList']) then -- both set emit an error
table.insert( z.message_tail, {utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', Periodical_origin) .. ' and ' .. utilities.wrap_style ('parameter', 'mailinglist')}, true )});
end
 
Periodical = A ['MailingList']; -- error or no, set Periodical to |mailinglist= value because this template is {{cite mailing list}}
Periodical_origin = A:ORIGIN('MailingList');
Periodical_origin = A:ORIGIN('MailingList');
end
end


local ScriptPeriodical = A['ScriptPeriodical'];
local ScriptPeriodical = A['ScriptPeriodical'];
local ScriptPeriodical_origin = A:ORIGIN('ScriptPeriodical');


-- web and news not tested for now because of  
-- web and news not tested for now because of  
2,496行目: 2,633行目:
local p = {['journal'] = 'journal', ['magazine'] = 'magazine'}; -- for error message
local p = {['journal'] = 'journal', ['magazine'] = 'magazine'}; -- for error message
if p[config.CitationClass]  then
if p[config.CitationClass]  then
table.insert( z.message_tail, {utilities.set_message ('err_missing_periodical', {config.CitationClass, p[config.CitationClass]}, true)});
utilities.set_message ('err_missing_periodical', {config.CitationClass, p[config.CitationClass]});
end
end
end
end
local TransPeriodical =  A['TransPeriodical'];
local TransPeriodical_origin =  A:ORIGIN ('TransPeriodical');
local Series = A['Series'];
local Volume;
local Volume;
local Issue;
local ScriptPeriodical_origin = A:ORIGIN('ScriptPeriodical');
local Page;
if 'citation' == config.CitationClass then
local Pages;
local At;
 
if 'citation' == config.CitationClass then
if utilities.is_set (Periodical) then
if utilities.is_set (Periodical) then
if not utilities.in_array (Periodical_origin, {'website', 'mailinglist'}) then -- {{citation}} does not render volume for these 'periodicals'
if not utilities.in_array (Periodical_origin, cfg.citation_no_volume_t) then -- {{citation}} does not render |volume= when these parameters are used
Volume = A['Volume']; -- but does for all other 'periodicals'
Volume = A['Volume']; -- but does for all other 'periodicals'
end
end
2,526行目: 2,654行目:
Volume = A['Volume'];
Volume = A['Volume'];
end
end
extra_text_in_vol_iss_check (Volume, A:ORIGIN ('Volume'), 'v');


local Issue;
if 'citation' == config.CitationClass then
if 'citation' == config.CitationClass then
if utilities.is_set (Periodical) and utilities.in_array (Periodical_origin, {'journal', 'magazine', 'newspaper', 'periodical', 'work'}) or -- {{citation}} renders issue for these 'periodicals'
if utilities.is_set (Periodical) and utilities.in_array (Periodical_origin, cfg.citation_issue_t) then -- {{citation}} may render |issue= when these parameters are used
utilities.is_set (ScriptPeriodical) and utilities.in_array (ScriptPeriodical_origin, {'script-journal', 'script-magazine', 'script-newspaper', 'script-periodical', 'script-work'}) then -- and these 'script-periodicals'
Issue = utilities.hyphen_to_dash (A['Issue']);
Issue = hyphen_to_dash (A['Issue']);
end
end
elseif utilities.in_array (config.CitationClass, cfg.templates_using_issue) then -- conference & map books do not support issue; {{citation}} listed here because included in settings table
elseif utilities.in_array (config.CitationClass, cfg.templates_using_issue) then -- conference & map books do not support issue; {{citation}} listed here because included in settings table
if not (utilities.in_array (config.CitationClass, {'conference', 'map', 'citation'}) and not (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical))) then
if not (utilities.in_array (config.CitationClass, {'conference', 'map', 'citation'}) and not (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical))) then
Issue = hyphen_to_dash (A['Issue']);
Issue = utilities.hyphen_to_dash (A['Issue']);
end
end
end
end
local ArticleNumber;


local Position = '';
if utilities.in_array (config.CitationClass, {'journal', 'conference'}) or ('citation' == config.CitationClass and utilities.is_set (Periodical) and 'journal' == Periodical_origin) then
if not utilities.in_array (config.CitationClass, cfg.templates_not_using_page) then
ArticleNumber = A['ArticleNumber'];
end
 
extra_text_in_vol_iss_check (Issue, A:ORIGIN ('Issue'), 'i');
 
local Page;
local Pages;
local At;
local QuotePage;
local QuotePages;
if not utilities.in_array (config.CitationClass, cfg.templates_not_using_page) then -- TODO: rewrite to emit ignored parameter error message?
Page = A['Page'];
Page = A['Page'];
Pages = hyphen_to_dash (A['Pages']);
Pages = utilities.hyphen_to_dash (A['Pages']);
At = A['At'];
At = A['At'];
QuotePage = A['QuotePage'];
QuotePages = utilities.hyphen_to_dash (A['QuotePages']);
end
end


2,555行目: 2,698行目:
PublisherName, i = utilities.strip_apostrophe_markup (PublisherName); -- strip apostrophe markup so that metadata isn't contaminated; publisher is never italicized
PublisherName, i = utilities.strip_apostrophe_markup (PublisherName); -- strip apostrophe markup so that metadata isn't contaminated; publisher is never italicized
if i then -- non-zero when markup was stripped so emit an error message
if i then -- non-zero when markup was stripped so emit an error message
table.insert( z.message_tail, {utilities.set_message ('err_apostrophe_markup', {PublisherName_origin}, true)});
utilities.set_message ('err_apostrophe_markup', {PublisherName_origin});
end
end
end
end
2,564行目: 2,707行目:
if 'newsgroup' == config.CitationClass then
if 'newsgroup' == config.CitationClass then
if utilities.is_set (PublisherName) then -- general use parameter |publisher= not allowed in cite newsgroup
if utilities.is_set (PublisherName) then -- general use parameter |publisher= not allowed in cite newsgroup
local error_text, error_state = utilities.set_message ('err_parameter_ignored', {PublisherName_origin}, true);
utilities.set_message ('err_parameter_ignored', {PublisherName_origin});
if utilities.is_set (error_text) then
table.insert( z.message_tail, {error_text, error_state} );
end
end
end


2,573行目: 2,713行目:
end
end


local URL = A['URL']; -- TODO: better way to do this for URL, ChapterURL, and MapURL?
local UrlAccess = is_valid_parameter_value (A['UrlAccess'], A:ORIGIN('UrlAccess'), cfg.keywords_lists['url-access'], nil);
local UrlAccess = is_valid_parameter_value (A['UrlAccess'], A:ORIGIN('UrlAccess'), cfg.keywords_lists['url-access'], nil);
if not utilities.is_set (URL) and utilities.is_set (UrlAccess) then
UrlAccess = nil;
if not utilities.is_set (URL) and utilities.is_set (UrlAccess) then
table.insert( z.message_tail, { utilities.set_message ( 'err_param_access_requires_param', {'url'}, true ) } );
UrlAccess = nil;
end
utilities.set_message ('err_param_access_requires_param', 'url');
end
local ChapterURL = A['ChapterURL'];
local ChapterUrlAccess = is_valid_parameter_value (A['ChapterUrlAccess'], A:ORIGIN('ChapterUrlAccess'), cfg.keywords_lists['url-access'], nil);
local ChapterUrlAccess = is_valid_parameter_value (A['ChapterUrlAccess'], A:ORIGIN('ChapterUrlAccess'), cfg.keywords_lists['url-access'], nil);
if not utilities.is_set (ChapterURL) and utilities.is_set (ChapterUrlAccess) then
if not utilities.is_set (ChapterURL) and utilities.is_set (ChapterUrlAccess) then
ChapterUrlAccess = nil;
ChapterUrlAccess = nil;
table.insert( z.message_tail, { utilities.set_message ( 'err_param_access_requires_param', {A:ORIGIN('ChapterUrlAccess'):gsub ('%-access', '')}, true ) } );
utilities.set_message ('err_param_access_requires_param', {A:ORIGIN('ChapterUrlAccess'):gsub ('%-access', '')});
end
end


2,588行目: 2,731行目:
if not utilities.is_set (A['MapURL']) and utilities.is_set (MapUrlAccess) then
if not utilities.is_set (A['MapURL']) and utilities.is_set (MapUrlAccess) then
MapUrlAccess = nil;
MapUrlAccess = nil;
table.insert( z.message_tail, { utilities.set_message ( 'err_param_access_requires_param', {'map-url'}, true ) } );
utilities.set_message ('err_param_access_requires_param', {'map-url'});
end
end


local Via = A['Via'];
local this_page = mw.title.getCurrentTitle(); -- also used for COinS and for language
local AccessDate = A['AccessDate'];
local no_tracking_cats = is_valid_parameter_value (A['NoTracking'], A:ORIGIN('NoTracking'), cfg.keywords_lists['yes_true_y'], nil);
local Agency = A['Agency'];


local Language = A['Language'];
-- check this page to see if it is in one of the namespaces that cs1 is not supposed to add to the error categories
local Format = A['Format'];
if not utilities.is_set (no_tracking_cats) then -- ignore if we are already not going to categorize this page
local ChapterFormat = A['ChapterFormat'];
if cfg.uncategorized_namespaces[this_page.namespace] then -- is this page's namespace id one of the uncategorized namespace ids?
local DoiBroken = A['DoiBroken'];
no_tracking_cats = "true"; -- set no_tracking_cats
local ID = A['ID'];
end
local ASINTLD = A['ASINTLD'];
for _, v in ipairs (cfg.uncategorized_subpages) do -- cycle through page name patterns
local IgnoreISBN = is_valid_parameter_value (A['IgnoreISBN'], A:ORIGIN('IgnoreISBN'), cfg.keywords_lists['yes_true_y'], nil);
if this_page.text:match (v) then -- test page name against each pattern
local Embargo = A['Embargo'];
no_tracking_cats = "true"; -- set no_tracking_cats
local Class = A['Class']; -- arxiv class identifier
 
local Quote = A['Quote'];
local QuotePage = A['QuotePage'];
local QuotePages = A['QuotePages'];
local ScriptQuote = A['ScriptQuote'];
local TransQuote = A['TransQuote'];
 
local LayFormat = A['LayFormat'];
local LayURL = A['LayURL'];
local LaySource = A['LaySource'];
local Transcript = A['Transcript'];
local TranscriptFormat = A['TranscriptFormat'];
local TranscriptURL = A['TranscriptURL']
local TranscriptURL_origin = A:ORIGIN('TranscriptURL'); -- get name of parameter that holds TranscriptURL
 
local LastAuthorAmp = is_valid_parameter_value (A['LastAuthorAmp'], A:ORIGIN('LastAuthorAmp'), cfg.keywords_lists['yes_true_y'], nil);
 
local no_tracking_cats = is_valid_parameter_value (A['NoTracking'], A:ORIGIN('NoTracking'), cfg.keywords_lists['yes_true_y'], nil);
if 'nocat' == A:ORIGIN('NoTracking') then
utilities.set_message ('maint_nocat'); -- this one so that we get the message; see main categorization at end of citation0()
end
--local variables that are not cs1 parameters
local use_lowercase; -- controls capitalization of certain static text
local this_page = mw.title.getCurrentTitle(); -- also used for COinS and for language
local anchor_year; -- used in the CITEREF identifier
local COinS_date = {}; -- holds date info extracted from |date= for the COinS metadata by Module:Date verification
 
local DF = is_valid_parameter_value (A['DF'], A:ORIGIN('DF'), cfg.keywords_lists['df'], '');
if not utilities.is_set (DF) then
DF = cfg.global_df; -- local |df= if present overrides global df set by {{use xxx date}} template
end
 
local sepc; -- separator between citation elements for CS1 a period, for CS2, a comma
local PostScript;
local Ref = A['Ref'];
if 'harv' == Ref then
utilities.set_message ('maint_ref_harv'); -- add maint cat to identify templates that have this now-extraneous param value
elseif not utilities.is_set (Ref) then
Ref = 'harv'; -- set as default when not set externally
end
sepc, PostScript, Ref = set_style (Mode:lower(), A['PostScript'], Ref, config.CitationClass);
use_lowercase = ( sepc == ',' ); -- used to control capitalization for certain static text
 
-- check this page to see if it is in one of the namespaces that cs1 is not supposed to add to the error categories
if not utilities.is_set (no_tracking_cats) then -- ignore if we are already not going to categorize this page
if utilities.in_array (this_page.nsText, cfg.uncategorized_namespaces) then
no_tracking_cats = "true"; -- set no_tracking_cats
end
for _, v in ipairs (cfg.uncategorized_subpages) do -- cycle through page name patterns
if this_page.text:match (v) then -- test page name against each pattern
no_tracking_cats = "true"; -- set no_tracking_cats
break; -- bail out if one is found
break; -- bail out if one is found
end
end
2,666行目: 2,754行目:
local coins_pages;
local coins_pages;
Page, Pages, At, coins_pages = insource_loc_get (Page, Pages, At);
Page, Pages, At, coins_pages = insource_loc_get (Page, A:ORIGIN('Page'), Pages, A:ORIGIN('Pages'), At);


local NoPP = is_valid_parameter_value (A['NoPP'], A:ORIGIN('NoPP'), cfg.keywords_lists['yes_true_y'], nil);
local NoPP = is_valid_parameter_value (A['NoPP'], A:ORIGIN('NoPP'), cfg.keywords_lists['yes_true_y'], nil);


if utilities.is_set (PublicationPlace) and utilities.is_set (Place) then -- both |publication-place= and |place= (|location=) allowed if different
if utilities.is_set (PublicationPlace) and utilities.is_set (Place) then -- both |publication-place= and |place= (|location=) allowed if different
utilities.add_prop_cat ('location test'); -- add property cat to evaluate how often PublicationPlace and Place are used together
utilities.add_prop_cat ('location-test'); -- add property cat to evaluate how often PublicationPlace and Place are used together
if PublicationPlace == Place then
if PublicationPlace == Place then
Place = ''; -- unset; don't need both if they are the same
Place = ''; -- unset; don't need both if they are the same
2,681行目: 2,769行目:
if PublicationPlace == Place then Place = ''; end -- don't need both if they are the same
if PublicationPlace == Place then Place = ''; end -- don't need both if they are the same
--[[
local URL_origin = A:ORIGIN('URL'); -- get name of parameter that holds URL
local ChapterURL_origin = A:ORIGIN('ChapterURL'); -- get name of parameter that holds ChapterURL
local ScriptChapter = A['ScriptChapter'];
local ScriptChapter_origin = A:ORIGIN ('ScriptChapter');
local Format = A['Format'];
local ChapterFormat = A['ChapterFormat'];
local TransChapter = A['TransChapter'];
local TransChapter_origin = A:ORIGIN ('TransChapter');
local TransTitle = A['TransTitle'];
local ScriptTitle = A['ScriptTitle'];
--[[
Parameter remapping for cite encyclopedia:
Parameter remapping for cite encyclopedia:
When the citation has these parameters:
When the citation has these parameters:
2,698行目: 2,797行目:
if utilities.is_set (Encyclopedia) then -- emit error message when Encyclopedia set but template is other than {{cite encyclopedia}} or {{citation}}
if utilities.is_set (Encyclopedia) then -- emit error message when Encyclopedia set but template is other than {{cite encyclopedia}} or {{citation}}
if 'encyclopaedia' ~= config.CitationClass and 'citation' ~= config.CitationClass then
if 'encyclopaedia' ~= config.CitationClass and 'citation' ~= config.CitationClass then
table.insert (z.message_tail, {utilities.set_message ('err_parameter_ignored', {A:ORIGIN ('Encyclopedia')}, true)});
utilities.set_message ('err_parameter_ignored', {A:ORIGIN ('Encyclopedia')});
Encyclopedia = nil; -- unset because not supported by this template
Encyclopedia = nil; -- unset because not supported by this template
end
end
2,704行目: 2,803行目:


if ('encyclopaedia' == config.CitationClass) or ('citation' == config.CitationClass and utilities.is_set (Encyclopedia)) then
if ('encyclopaedia' == config.CitationClass) or ('citation' == config.CitationClass and utilities.is_set (Encyclopedia)) then
if utilities.is_set (Periodical) and utilities.is_set (Encyclopedia) then -- when both set emit an error
if utilities.is_set (Periodical) and utilities.is_set (Encyclopedia) then -- when both set emit an error TODO: make a function for this and similar?
table.insert (z.message_tail, {utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', A:ORIGIN ('Encyclopedia')) .. ' and ' .. utilities.wrap_style ('parameter', Periodical_origin)}, true )});
utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', A:ORIGIN ('Encyclopedia')) .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', Periodical_origin)});
end
end


2,721行目: 2,820行目:
TransChapter = TransTitle;
TransChapter = TransTitle;
ChapterURL = URL;
ChapterURL = URL;
ChapterURL_origin = A:ORIGIN('URL')
ChapterURL_origin = URL_origin;


ChapterUrlAccess = UrlAccess;
ChapterUrlAccess = UrlAccess;
2,737行目: 2,836行目:
ScriptTitle = '';
ScriptTitle = '';
end
end
elseif utilities.is_set (Chapter) then -- |title= not set
elseif utilities.is_set (Chapter) or utilities.is_set (ScriptChapter) then -- |title= not set
Title = Periodical; -- |encyclopedia= set and |article= set so map |encyclopedia= to |title=
Title = Periodical; -- |encyclopedia= set and |article= set so map |encyclopedia= to |title=
Periodical = ''; -- redundant so unset
Periodical = ''; -- redundant so unset
2,745行目: 2,844行目:


-- special case for cite techreport.
-- special case for cite techreport.
local ID = A['ID'];
if (config.CitationClass == "techreport") then -- special case for cite techreport
if (config.CitationClass == "techreport") then -- special case for cite techreport
if utilities.is_set (A['Number']) then -- cite techreport uses 'number', which other citations alias to 'issue'
if utilities.is_set (A['Number']) then -- cite techreport uses 'number', which other citations alias to 'issue'
2,750行目: 2,850行目:
ID = A['Number']; -- yes, use it
ID = A['Number']; -- yes, use it
else -- ID has a value so emit error message
else -- ID has a value so emit error message
table.insert( z.message_tail, { utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', 'id') .. ' and ' .. utilities.wrap_style ('parameter', 'number')}, true )});
utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', 'id') .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', 'number')});
end
end
end
end
2,756行目: 2,856行目:


-- Account for the oddity that is {{cite conference}}, before generation of COinS data.
-- Account for the oddity that is {{cite conference}}, before generation of COinS data.
local ChapterLink -- = A['ChapterLink']; -- deprecated as a parameter but still used internally by cite episode
local Conference = A['Conference'];
local BookTitle = A['BookTitle'];
local TransTitle_origin = A:ORIGIN ('TransTitle');
if 'conference' == config.CitationClass then
if 'conference' == config.CitationClass then
if utilities.is_set (BookTitle) then
if utilities.is_set (BookTitle) then
2,777行目: 2,881行目:
Conference = ''; -- not cite conference or cite speech so make sure this is empty string
Conference = ''; -- not cite conference or cite speech so make sure this is empty string
end
end
 
-- CS1/2 mode
local Mode = is_valid_parameter_value (A['Mode'], A:ORIGIN('Mode'), cfg.keywords_lists['mode'], '');
-- separator character and postscript
local sepc, PostScript = set_style (Mode:lower(), A['PostScript'], config.CitationClass);
-- controls capitalization of certain static text
local use_lowercase = ( sepc == ',' );
-- cite map oddities
-- cite map oddities
local Cartography = "";
local Cartography = "";
2,784行目: 2,895行目:
local Sheets = A['Sheets'] or '';
local Sheets = A['Sheets'] or '';
if config.CitationClass == "map" then
if config.CitationClass == "map" then
if utilities.is_set (Chapter) then
if utilities.is_set (Chapter) then --TODO: make a function for this and similar?
table.insert( z.message_tail, { utilities.set_message ( 'err_redundant_parameters', {utilities.wrap_style ('parameter', 'map') .. ' and ' .. utilities.wrap_style ('parameter', Chapter_origin)}, true ) } ); -- add error message
utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', 'map') .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', Chapter_origin)}); -- add error message
end
end
Chapter = A['Map'];
Chapter = A['Map'];
2,809行目: 2,920行目:


-- Account for the oddities that are {{cite episode}} and {{cite serial}}, before generation of COinS data.
-- Account for the oddities that are {{cite episode}} and {{cite serial}}, before generation of COinS data.
local Series = A['Series'];
if 'episode' == config.CitationClass or 'serial' == config.CitationClass then
if 'episode' == config.CitationClass or 'serial' == config.CitationClass then
local SeriesLink = A['SeriesLink'];
local SeriesLink = A['SeriesLink'];
2,826行目: 2,938行目:
local SeriesNumber = A['SeriesNumber'];
local SeriesNumber = A['SeriesNumber'];


if utilities.is_set (Season) and utilities.is_set (SeriesNumber) then -- these are mutually exclusive so if both are set
if utilities.is_set (Season) and utilities.is_set (SeriesNumber) then -- these are mutually exclusive so if both are set TODO: make a function for this and similar?
table.insert( z.message_tail, { utilities.set_message ( 'err_redundant_parameters', {utilities.wrap_style ('parameter', 'season') .. ' and ' .. utilities.wrap_style ('parameter', 'seriesno')}, true ) } ); -- add error message
utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', 'season') .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', 'seriesno')}); -- add error message
SeriesNumber = ''; -- unset; prefer |season= over |seriesno=
SeriesNumber = ''; -- unset; prefer |season= over |seriesno=
end
end
2,843行目: 2,955行目:
ChapterURL = URL;
ChapterURL = URL;
ChapterUrlAccess = UrlAccess;
ChapterUrlAccess = UrlAccess;
ChapterURL_origin = A:ORIGIN('URL');
ChapterURL_origin = URL_origin;
ChapterFormat = Format;
 
Title = Series; -- promote series to title
Title = Series; -- promote series to title
TitleLink = SeriesLink;
TitleLink = SeriesLink;
2,857行目: 2,970行目:
TransTitle = '';
TransTitle = '';
ScriptTitle = '';
ScriptTitle = '';
Format = '';
else -- now oddities that are cite serial
else -- now oddities that are cite serial
2,870行目: 2,984行目:


-- handle type parameter for those CS1 citations that have default values
-- handle type parameter for those CS1 citations that have default values
if utilities.in_array (config.CitationClass, {"AV-media-notes", "interview", "mailinglist", "map", "podcast", "pressrelease", "report", "techreport", "thesis"}) then
local TitleType = A['TitleType'];
local Degree = A['Degree'];
if utilities.in_array (config.CitationClass, {'AV-media-notes', 'interview', 'mailinglist', 'map', 'podcast', 'pressrelease', 'report', 'speech', 'techreport', 'thesis'}) then
TitleType = set_titletype (config.CitationClass, TitleType);
TitleType = set_titletype (config.CitationClass, TitleType);
if utilities.is_set (Degree) and "Thesis" == TitleType then -- special case for cite thesis
if utilities.is_set (Degree) and "Thesis" == TitleType then -- special case for cite thesis
2,883行目: 2,999行目:


-- legacy: promote PublicationDate to Date if neither Date nor Year are set.
-- legacy: promote PublicationDate to Date if neither Date nor Year are set.
local Date = A['Date'];
  local Date_origin; -- to hold the name of parameter promoted to Date; required for date error messaging
  local Date_origin; -- to hold the name of parameter promoted to Date; required for date error messaging
local PublicationDate = A['PublicationDate'];
local Year = A['Year'];


if not utilities.is_set (Date) then
if not utilities.is_set (Date) then
2,907行目: 3,026行目:
Date validation supporting code is in Module:Citation/CS1/Date_validation
Date validation supporting code is in Module:Citation/CS1/Date_validation
]]
]]
do -- create defined block to contain local variables error_message, date_parameters_list, mismatch
 
local error_message = '';
local DF = is_valid_parameter_value (A['DF'], A:ORIGIN('DF'), cfg.keywords_lists['df'], '');
-- AirDate has been promoted to Date so not necessary to check it
if not utilities.is_set (DF) then
DF = cfg.global_df; -- local |df= if present overrides global df set by {{use xxx date}} template
end
 
local ArchiveURL;
local ArchiveDate;
local ArchiveFormat = A['ArchiveFormat'];
 
ArchiveURL, ArchiveDate = archive_url_check (A['ArchiveURL'], A['ArchiveDate'])
ArchiveFormat = style_format (ArchiveFormat, ArchiveURL, 'archive-format', 'archive-url');
ArchiveURL, ArchiveDate = is_unique_archive_url (ArchiveURL, URL, ChapterURL, A:ORIGIN('ArchiveURL'), ArchiveDate); -- add error message when URL or ChapterURL == ArchiveURL
 
local AccessDate = A['AccessDate'];
local LayDate = A['LayDate'];
local COinS_date = {}; -- holds date info extracted from |date= for the COinS metadata by Module:Date verification
local DoiBroken = A['DoiBroken'];
local Embargo = A['Embargo'];
local anchor_year; -- used in the CITEREF identifier
do -- create defined block to contain local variables error_message, date_parameters_list, mismatch
local error_message = '';
-- AirDate has been promoted to Date so not necessary to check it
local date_parameters_list = {
local date_parameters_list = {
['access-date'] = {val = AccessDate, name = A:ORIGIN ('AccessDate')},
['access-date'] = {val = AccessDate, name = A:ORIGIN ('AccessDate')},
2,926行目: 3,067行目:
-- start temporary Julian / Gregorian calendar uncertainty categorization
-- start temporary Julian / Gregorian calendar uncertainty categorization
if COinS_date.inter_cal_cat then
if COinS_date.inter_cal_cat then
utilities.add_prop_cat ('jul_greg_uncertainty');
utilities.add_prop_cat ('jul-greg-uncertainty');
end
end
-- end temporary Julian / Gregorian calendar uncertainty categorization
-- end temporary Julian / Gregorian calendar uncertainty categorization


if utilities.is_set (Year) and utilities.is_set (Date) then -- both |date= and |year= not normally needed;  
if utilities.is_set (Year) and utilities.is_set (Date) then -- both |date= and |year= not normally needed;  
local mismatch = validation.year_date_check (Year, Date);
validation.year_date_check (Year, A:ORIGIN ('Year'), Date, A:ORIGIN ('Date'), error_list);
if 0 == mismatch then -- |year= does not match a year-value in |date=
table.insert (error_list, '<code class="cs1-code">&#124;year= / &#124;date= mismatch</code>');
elseif 1 == mismatch then -- |year= matches year-value in |date=
utilities.set_message ('maint_date_year'); -- add a maint cat
end
end
end
2,951行目: 3,087行目:
end
end
-- for those wikis that can and want to have English date names translated to the local language,
-- for those wikis that can and want to have English date names translated to the local language; not supported at en.wiki
-- uncomment the next three lines.  Not supported by en.wiki (for obvious reasons)
if cfg.date_name_auto_xlate_enable and validation.date_name_xlate (date_parameters_list, cfg.date_digit_auto_xlate_enable ) then
-- set validation.date_name_xlate() second argument to true to translate English digits to local digits (will translate ymd dates)
utilities.set_message ('maint_date_auto_xlated'); -- add maint cat
-- if validation.date_name_xlate (date_parameters_list, false) then
modified = true;
-- modified = true;
end
-- end


if modified then -- if the date_parameters_list values were modified
if modified then -- if the date_parameters_list values were modified
2,967行目: 3,102行目:
end
end
else
else
table.insert (z.message_tail, {utilities.set_message ('err_bad_date', {utilities.make_sep_list (#error_list, error_list)}, true)}); -- add this error message
utilities.set_message ('err_bad_date', {utilities.make_sep_list (#error_list, error_list)}); -- add this error message
end
end
end -- end of do
end -- end of do


local ID_list_coins = identifiers.extract_ids (args); -- gets identifiers and their values from args; this list used for COinS and source for build_id_list()
local ID_list = {}; -- sequence table of rendered identifiers
if utilities.is_set (DoiBroken) and not ID_list_coins['DOI'] then
local ID_list_coins = {}; -- table of identifiers and their values from args; key is same as cfg.id_handlers's key
table.insert (z.message_tail, {utilities.set_message ('err_doibroken_missing_doi', A:ORIGIN('DoiBroken'))});
local Class = A['Class']; -- arxiv class identifier
end
local ID_access_levels = identifiers.extract_id_access_levels (args, ID_list_coins);
local ID_list = identifiers.build_id_list (ID_list_coins, {IdAccessLevels = ID_access_levels, DoiBroken = DoiBroken, ASINTLD = ASINTLD, IgnoreISBN = IgnoreISBN, Embargo = Embargo, Class = Class}); -- render identifiers
local ID_support = {
{A['ASINTLD'], 'ASIN', 'err_asintld_missing_asin', A:ORIGIN ('ASINTLD')},
{DoiBroken, 'DOI', 'err_doibroken_missing_doi', A:ORIGIN ('DoiBroken')},
{Embargo, 'PMC', 'err_embargo_missing_pmc', A:ORIGIN ('Embargo')},
}
ID_list, ID_list_coins = identifiers.identifier_lists_get (args, {DoiBroken = DoiBroken, ASINTLD = A['ASINTLD'], Embargo = Embargo, Class = Class}, ID_support);
-- Account for the oddities that are {{cite arxiv}}, {{cite biorxiv}}, {{cite citeseerx}}, {{cite ssrn}}, before generation of COinS data.
-- Account for the oddities that are {{cite arxiv}}, {{cite biorxiv}}, {{cite citeseerx}}, {{cite ssrn}}, before generation of COinS data.
if utilities.in_array (config.CitationClass, whitelist.preprint_template_list) then
if utilities.in_array (config.CitationClass, whitelist.preprint_template_list) then -- |arxiv= or |eprint= required for cite arxiv; |biorxiv=, |citeseerx=, |ssrn= required for their templates
if not utilities.is_set (ID_list_coins[config.CitationClass:upper()]) then -- |arxiv= or |eprint= required for cite arxiv; |biorxiv= & |citeseerx= required for their templates
if not (args[cfg.id_handlers[config.CitationClass:upper()].parameters[1]] or -- can't use ID_list_coins k/v table here because invalid parameters omitted
table.insert (z.message_tail, {utilities.set_message ('err_' .. config.CitationClass .. '_missing', {}, true)}); -- add error message
args[cfg.id_handlers[config.CitationClass:upper()].parameters[2]]) then -- which causes unexpected parameter missing error message
utilities.set_message ('err_' .. config.CitationClass .. '_missing'); -- add error message
end
end


2,990行目: 3,131行目:


if config.CitationClass == "journal" and not utilities.is_set (URL) and not utilities.is_set (TitleLink) and not utilities.in_array (cfg.keywords_xlate[Title], {'off', 'none'}) then -- TODO: remove 'none' once existing citations have been switched to 'off', so 'none' can be used as token for "no title" instead
if config.CitationClass == "journal" and not utilities.is_set (URL) and not utilities.is_set (TitleLink) and not utilities.in_array (cfg.keywords_xlate[Title], {'off', 'none'}) then -- TODO: remove 'none' once existing citations have been switched to 'off', so 'none' can be used as token for "no title" instead
    if 'none' ~= cfg.keywords_xlate[auto_select] then -- if auto-linking not disabled
if 'none' ~= cfg.keywords_xlate[auto_select] then -- if auto-linking not disabled
  if identifiers.auto_link_urls[auto_select] then -- manual selection
  if identifiers.auto_link_urls[auto_select] then -- manual selection
URL = identifiers.auto_link_urls[auto_select]; -- set URL to be the same as identifier's external link
URL = identifiers.auto_link_urls[auto_select]; -- set URL to be the same as identifier's external link
  URL_origin = cfg.id_handlers[auto_select:upper()].parameters[1]; -- set URL_origin to parameter name for use in error message if citation is missing a |title=
  URL_origin = cfg.id_handlers[auto_select:upper()].parameters[1]; -- set URL_origin to parameter name for use in error message if citation is missing a |title=
elseif identifiers.auto_link_urls['pmc'] then -- auto-select PMC
elseif identifiers.auto_link_urls['pmc'] then -- auto-select PMC
URL = identifiers.auto_link_urls['pmc']; -- set URL to be the same as the PMC external link if not embargoed
URL = identifiers.auto_link_urls['pmc']; -- set URL to be the same as the PMC external link if not embargoed
URL_origin = cfg.id_handlers['PMC'].parameters[1]; -- set URL_origin to parameter name for use in error message if citation is missing a |title=
URL_origin = cfg.id_handlers['PMC'].parameters[1]; -- set URL_origin to parameter name for use in error message if citation is missing a |title=
elseif identifiers.auto_link_urls['doi'] then -- auto-select DOI
elseif identifiers.auto_link_urls['doi'] then -- auto-select DOI
URL = identifiers.auto_link_urls['doi'];
URL = identifiers.auto_link_urls['doi'];
URL_origin = cfg.id_handlers['DOI'].parameters[1];
URL_origin = cfg.id_handlers['DOI'].parameters[1];
3,003行目: 3,144行目:
  end
  end


if utilities.is_set (URL) and utilities.is_set (AccessDate) then -- access date requires |url=; identifier-created URL is not |url=
if utilities.is_set (URL) then -- set when using an identifier-created URL
table.insert( z.message_tail, { utilities.set_message ( 'err_accessdate_missing_url', {}, true ) } ); -- add an error message
if utilities.is_set (AccessDate) then -- |access-date= requires |url=; identifier-created URL is not |url=
AccessDate = ''; -- unset
utilities.set_message ('err_accessdate_missing_url'); -- add an error message
AccessDate = ''; -- unset
end
 
if utilities.is_set (ArchiveURL) then -- |archive-url= requires |url=; identifier-created URL is not |url=
utilities.set_message ('err_archive_missing_url'); -- add an error message
ArchiveURL = ''; -- unset
end
end
end
end
end
3,012行目: 3,160行目:
-- Test if citation has no title
-- Test if citation has no title
if not utilities.is_set (Title) and not utilities.is_set (TransTitle) and not utilities.is_set (ScriptTitle) then -- has special case for cite episode
if not utilities.is_set (Title) and not utilities.is_set (TransTitle) and not utilities.is_set (ScriptTitle) then -- has special case for cite episode
table.insert( z.message_tail, { utilities.set_message ( 'err_citation_missing_title', {'episode' == config.CitationClass and 'series' or 'title'}, true ) } );
utilities.set_message ('err_citation_missing_title', {'episode' == config.CitationClass and 'series' or 'title'});
end
end


3,022行目: 3,170行目:
utilities.set_message ('maint_untitled'); -- add maint cat
utilities.set_message ('maint_untitled'); -- add maint cat
end
end
check_for_url ({ -- add error message when any of these parameters hold a URL
['title']=Title,
[A:ORIGIN('Chapter')]=Chapter,
[Periodical_origin] = Periodical,
[PublisherName_origin] = PublisherName
});


-- COinS metadata (see <http://ocoins.info/>) for automated parsing of citation information.
-- COinS metadata (see <http://ocoins.info/>) for automated parsing of citation information.
3,047行目: 3,188行目:
coins_author = c; -- use that instead
coins_author = c; -- use that instead
end
end
 
-- this is the function call to COinS()
-- this is the function call to COinS()
local OCinSoutput = metadata.COinS({
local OCinSoutput = metadata.COinS({
['Periodical'] = utilities.strip_apostrophe_markup (Periodical), -- no markup in the metadata
['Periodical'] = utilities.strip_apostrophe_markup (Periodical), -- no markup in the metadata
['Encyclopedia'] = Encyclopedia, -- just a flag; content ignored by ~/COinS
['Encyclopedia'] = Encyclopedia, -- just a flag; content ignored by ~/COinS
['Chapter'] = metadata.make_coins_title (coins_chapter, ScriptChapter), -- Chapter and ScriptChapter stripped of bold / italic wiki-markup
['Chapter'] = metadata.make_coins_title (coins_chapter, ScriptChapter), -- Chapter and ScriptChapter stripped of bold / italic / accept-as-written markup
['Degree'] = Degree; -- cite thesis only
['Degree'] = Degree; -- cite thesis only
['Title'] = metadata.make_coins_title (coins_title, ScriptTitle), -- Title and ScriptTitle stripped of bold / italic wiki-markup
['Title'] = metadata.make_coins_title (coins_title, ScriptTitle), -- Title and ScriptTitle stripped of bold / italic / accept-as-written markup
['PublicationPlace'] = PublicationPlace,
['PublicationPlace'] = PublicationPlace,
['Date'] = COinS_date.rftdate, -- COinS_date has correctly formatted date if Date is valid;
['Date'] = COinS_date.rftdate, -- COinS_date has correctly formatted date if Date is valid;
3,063行目: 3,204行目:
['Volume'] = Volume,
['Volume'] = Volume,
['Issue'] = Issue,
['Issue'] = Issue,
['Pages'] = coins_pages or metadata.get_coins_pages (first_set ({Sheet, Sheets, Page, Pages, At}, 5)), -- pages stripped of external links
['ArticleNumber'] = ArticleNumber,
['Pages'] = coins_pages or metadata.get_coins_pages (first_set ({Sheet, Sheets, Page, Pages, At, QuotePage, QuotePages}, 7)), -- pages stripped of external links
['Edition'] = Edition,
['Edition'] = Edition,
['PublisherName'] = PublisherName or Newsgroup, -- any apostrophe markup already removed from PublisherName
['PublisherName'] = PublisherName or Newsgroup, -- any apostrophe markup already removed from PublisherName
3,082行目: 3,224行目:
end
end


-- Now perform various field substitutions.
local Editors;
-- We also add leading spaces and surrounding markup and punctuation to the
-- various parts of the citation, but only when they are non-nil.
local EditorCount; -- used only for choosing {ed.) or (eds.) annotation at end of editor name-list
local EditorCount; -- used only for choosing {ed.) or (eds.) annotation at end of editor name-list
local Contributors; -- assembled contributors name list
local contributor_etal;
local Translators; -- assembled translators name list
local translator_etal;
local t = {}; -- translators list from |translator-lastn= / translator-firstn= pairs
t = extract_names (args, 'TranslatorList'); -- fetch translator list from |translatorn= / |translator-lastn=, -firstn=, -linkn=, -maskn=
local Interviewers;
local interviewers_list = {};
interviewers_list = extract_names (args, 'InterviewerList'); -- process preferred interviewers parameters
local interviewer_etal;
-- Now perform various field substitutions.
-- We also add leading spaces and surrounding markup and punctuation to the
-- various parts of the citation, but only when they are non-nil.
do
do
local last_first_list;
local last_first_list;
local control = {  
local control = {  
format = NameListStyle, -- empty string or 'vanc'
format = NameListStyle, -- empty string or 'vanc'
maximum = nil, -- as if display-authors or display-editors not set
maximum = nil, -- as if display-authors or display-editors not set
lastauthoramp = LastAuthorAmp,
mode = Mode
mode = Mode
};
};


do -- do editor name list first because the now unsupported coauthors used to modify control table
do -- do editor name list first because the now unsupported coauthors used to modify control table
control.maximum , editor_etal = get_display_names (A['DisplayEditors'], #e, 'editors', editor_etal);
control.maximum , editor_etal = get_display_names (A['DisplayEditors'], #e, 'editors', editor_etal, A:ORIGIN ('DisplayEditors'));
last_first_list, EditorCount = list_people(control, e, editor_etal);
Editors, EditorCount = list_people (control, e, editor_etal);
 
if utilities.is_set (Editors) then
Editors, editor_etal = name_has_etal (Editors, editor_etal, false, 'editors'); -- find and remove variations on et al.
if editor_etal then
Editors = Editors .. ' ' .. cfg.messages['et al']; -- add et al. to editors parameter beause |display-editors=etal
end
EditorCount = 2; -- we don't know but assume |editors= is multiple names; spoof to display (eds.) annotation
else
Editors = last_first_list; -- either an author name list or an empty string
end


if 1 == EditorCount and (true == editor_etal or 1 < #e) then -- only one editor displayed but includes etal then  
if 1 == EditorCount and (true == editor_etal or 1 < #e) then -- only one editor displayed but includes etal then  
3,114行目: 3,257行目:
end
end
do -- now do interviewers
do -- now do interviewers
control.maximum , interviewer_etal = get_display_names (A['DisplayInterviewers'], #interviewers_list, 'interviewers', interviewer_etal);
control.maximum, interviewer_etal = get_display_names (A['DisplayInterviewers'], #interviewers_list, 'interviewers', interviewer_etal, A:ORIGIN ('DisplayInterviewers'));
Interviewers = list_people (control, interviewers_list, interviewer_etal);
Interviewers = list_people (control, interviewers_list, interviewer_etal);
end
end
do -- now do translators
do -- now do translators
control.maximum , translator_etal = get_display_names (A['DisplayTranslators'], #t, 'translators', translator_etal);
control.maximum, translator_etal = get_display_names (A['DisplayTranslators'], #t, 'translators', translator_etal, A:ORIGIN ('DisplayTranslators'));
Translators = list_people (control, t, translator_etal);
Translators = list_people (control, t, translator_etal);
end
end
do -- now do contributors
do -- now do contributors
control.maximum , contributor_etal = get_display_names (A['DisplayContributors'], #c, 'contributors', contributor_etal);
control.maximum, contributor_etal = get_display_names (A['DisplayContributors'], #c, 'contributors', contributor_etal, A:ORIGIN ('DisplayContributors'));
Contributors = list_people (control, c, contributor_etal);
Contributors = list_people (control, c, contributor_etal);
end
end
do -- now do authors
do -- now do authors
control.maximum , author_etal = get_display_names (A['DisplayAuthors'], #a, 'authors', author_etal);
control.maximum, author_etal = get_display_names (A['DisplayAuthors'], #a, 'authors', author_etal, A:ORIGIN ('DisplayAuthors'));


last_first_list = list_people(control, a, author_etal);
last_first_list = list_people (control, a, author_etal);


if utilities.is_set (Authors) then
if utilities.is_set (Authors) then
3,146行目: 3,289行目:
end
end


-- apply |[xx-]format= styling; at the end, these parameters hold correctly styled format annotation,
local ConferenceFormat = A['ConferenceFormat'];
-- an error message if the associated URL is not set, or an empty string for concatenation
local ConferenceURL = A['ConferenceURL'];
ArchiveFormat = style_format (ArchiveFormat, ArchiveURL, 'archive-format', 'archive-url');
ConferenceFormat = style_format (ConferenceFormat, ConferenceURL, 'conference-format', 'conference-url');
ConferenceFormat = style_format (ConferenceFormat, ConferenceURL, 'conference-format', 'conference-url');
Format = style_format (Format, URL, 'format', 'url');
Format = style_format (Format, URL, 'format', 'url');
LayFormat = style_format (LayFormat, LayURL, 'lay-format', 'lay-url');
TranscriptFormat = style_format (TranscriptFormat, TranscriptURL, 'transcript-format', 'transcripturl');


-- special case for chapter format so no error message or cat when chapter not supported
-- special case for chapter format so no error message or cat when chapter not supported
3,163行目: 3,303行目:
if utilities.in_array (config.CitationClass, {"web", "podcast", "mailinglist"}) or -- |url= required for cite web, cite podcast, and cite mailinglist
if utilities.in_array (config.CitationClass, {"web", "podcast", "mailinglist"}) or -- |url= required for cite web, cite podcast, and cite mailinglist
('citation' == config.CitationClass and ('website' == Periodical_origin or 'script-website' == ScriptPeriodical_origin)) then -- and required for {{citation}} with |website= or |script-website=
('citation' == config.CitationClass and ('website' == Periodical_origin or 'script-website' == ScriptPeriodical_origin)) then -- and required for {{citation}} with |website= or |script-website=
table.insert( z.message_tail, { utilities.set_message ( 'err_cite_web_url', {}, true ) } );
utilities.set_message ('err_cite_web_url');
end
end
-- do we have |accessdate= without either |url= or |chapter-url=?
-- do we have |accessdate= without either |url= or |chapter-url=?
if utilities.is_set (AccessDate) and not utilities.is_set (ChapterURL) then -- ChapterURL may be set when URL is not set;
if utilities.is_set (AccessDate) and not utilities.is_set (ChapterURL) then -- ChapterURL may be set when URL is not set;
table.insert( z.message_tail, { utilities.set_message ( 'err_accessdate_missing_url', {}, true ) } );
utilities.set_message ('err_accessdate_missing_url');
AccessDate = '';
AccessDate = '';
end
end
end
end


local OriginalURL, OriginalURL_origin, OriginalFormat, OriginalAccess;
local UrlStatus = is_valid_parameter_value (A['UrlStatus'], A:ORIGIN('UrlStatus'), cfg.keywords_lists['url-status'], '');
local OriginalURL
local OriginalURL_origin
local OriginalFormat
local OriginalAccess;
UrlStatus = UrlStatus:lower(); -- used later when assembling archived text
UrlStatus = UrlStatus:lower(); -- used later when assembling archived text
if utilities.is_set ( ArchiveURL ) then
if utilities.is_set ( ArchiveURL ) then
3,199行目: 3,343行目:
UrlAccess = nil; -- restricted access levels do not make sense for archived URLs
UrlAccess = nil; -- restricted access levels do not make sense for archived URLs
end
end
  end
end
elseif utilities.is_set (UrlStatus) then -- if |url-status= is set when |archive-url= is not set
  utilities.set_message ('maint_url_status'); -- add maint cat
end
end


3,218行目: 3,364行目:


if utilities.is_set (chap_param) then -- if we found one
if utilities.is_set (chap_param) then -- if we found one
table.insert( z.message_tail, { utilities.set_message ( 'err_chapter_ignored', {chap_param}, true ) } ); -- add error message
utilities.set_message ('err_chapter_ignored', {chap_param}); -- add error message
Chapter = ''; -- and set them to empty string to be safe with concatenation
Chapter = ''; -- and set them to empty string to be safe with concatenation
TransChapter = '';
TransChapter = '';
3,258行目: 3,404行目:
end
end


if not accept_title then -- <Title> not wrapped in accept-as-written markup
if not accept_title then -- <Title> not wrapped in accept-as-written markup
if '...' == Title:sub (-3) then -- if ellipsis is the last three characters of |title=
if '...' == Title:sub (-3) then -- if ellipsis is the last three characters of |title=
Title = Title:gsub ('(%.%.%.)%.+$', '%1'); -- limit the number of dots to three
Title = Title:gsub ('(%.%.%.)%.+$', '%1'); -- limit the number of dots to three
3,270行目: 3,416行目:
end
end


if is_generic_title (Title) then
if is_generic ('generic_titles', Title) then
table.insert (z.message_tail, {utilities.set_message ( 'err_generic_title', {}, true ) } ); -- set an error message
utilities.set_message ('err_generic_title'); -- set an error message
end
end
end
end
3,282行目: 3,428行目:
Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped
Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped
TransTitle = utilities.wrap_style ('trans-quoted-title', TransTitle );
TransTitle = utilities.wrap_style ('trans-quoted-title', TransTitle );
elseif plain_title or ('report' == config.CitationClass) then -- no styling for cite report and descriptive titles (otherwise same as above)
elseif plain_title or ('report' == config.CitationClass) then -- no styling for cite report and descriptive titles (otherwise same as above)
Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped
Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped
TransTitle = utilities.wrap_style ('trans-quoted-title', TransTitle ); -- for cite report, use this form for trans-title
TransTitle = utilities.wrap_style ('trans-quoted-title', TransTitle ); -- for cite report, use this form for trans-title
else
else
Title = utilities.wrap_style ('italic-title', Title);
Title = utilities.wrap_style ('italic-title', Title);
3,291行目: 3,437行目:
end
end


local TransError = "";
if utilities.is_set (TransTitle) then
if utilities.is_set (TransTitle) then
if utilities.is_set (Title) then
if utilities.is_set (Title) then
TransTitle = " " .. TransTitle;
TransTitle = " " .. TransTitle;
else
else
TransError = " " .. utilities.set_message ( 'err_trans_missing_title', {'title'} );
utilities.set_message ('err_trans_missing_title', {'title'});
end
end
end
end
3,302行目: 3,447行目:
if utilities.is_set (Title) then -- TODO: is this the right place to be making Wikisource URLs?
if utilities.is_set (Title) then -- TODO: is this the right place to be making Wikisource URLs?
if utilities.is_set (TitleLink) and utilities.is_set (URL) then
if utilities.is_set (TitleLink) and utilities.is_set (URL) then
table.insert( z.message_tail, { utilities.set_message ( 'err_wikilink_in_url', {}, true ) } ); -- set an error message because we can't have both
utilities.set_message ('err_wikilink_in_url'); -- set an error message because we can't have both
TitleLink = ''; -- unset
TitleLink = ''; -- unset
end
end
if not utilities.is_set (TitleLink) and utilities.is_set (URL) then
if not utilities.is_set (TitleLink) and utilities.is_set (URL) then
Title = external_link (URL, Title, URL_origin, UrlAccess) .. TransTitle .. TransError .. Format;
Title = external_link (URL, Title, URL_origin, UrlAccess) .. TransTitle .. Format;
URL = ''; -- unset these because no longer needed
URL = ''; -- unset these because no longer needed
Format = "";
Format = "";
3,316行目: 3,461行目:
Title = external_link (ws_url, Title .. '&nbsp;', 'ws link in title-link'); -- space char after Title to move icon away from italic text; TODO: a better way to do this?
Title = external_link (ws_url, Title .. '&nbsp;', 'ws link in title-link'); -- space char after Title to move icon away from italic text; TODO: a better way to do this?
Title = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], TitleLink, Title});
Title = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], TitleLink, Title});
Title = Title .. TransTitle .. TransError;
Title = Title .. TransTitle;
else
else
Title = utilities.make_wikilink (TitleLink, Title) .. TransTitle .. TransError;
Title = utilities.make_wikilink (TitleLink, Title) .. TransTitle;
end
end
else
else
local ws_url, ws_label, L; -- Title has italic or quote markup by the time we get here which causes is_wikilink() to return 0 (not a wikilink)
local ws_url, ws_label, L; -- Title has italic or quote markup by the time we get here which causes is_wikilink() to return 0 (not a wikilink)
ws_url, ws_label, L = wikisource_url_make (Title:gsub('[\'"](.-)[\'"]', '%1')); -- make ws URL from |title= interwiki link (strip italic or quote markup); link portion L becomes tooltip label
ws_url, ws_label, L = wikisource_url_make (Title:gsub('^[\'"]*(.-)[\'"]*$', '%1')); -- make ws URL from |title= interwiki link (strip italic or quote markup); link portion L becomes tooltip label
if ws_url then
if ws_url then
Title = Title:gsub ('%b[]', ws_label); -- replace interwiki link with ws_label to retain markup
Title = Title:gsub ('%b[]', ws_label); -- replace interwiki link with ws_label to retain markup
Title = external_link (ws_url, Title .. '&nbsp;', 'ws link in title'); -- space char after Title to move icon away from italic text; TODO: a better way to do this?
Title = external_link (ws_url, Title .. '&nbsp;', 'ws link in title'); -- space char after Title to move icon away from italic text; TODO: a better way to do this?
Title = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, Title});
Title = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, Title});
Title = Title .. TransTitle .. TransError;
Title = Title .. TransTitle;
else
else
Title = Title .. TransTitle .. TransError;
Title = Title .. TransTitle;
end
end
end
end
else
else
Title = TransTitle .. TransError;
Title = TransTitle;
end
end


3,340行目: 3,485行目:
end
end


local ConferenceURL_origin = A:ORIGIN('ConferenceURL'); -- get name of parameter that holds ConferenceURL
if utilities.is_set (Conference) then
if utilities.is_set (Conference) then
if utilities.is_set (ConferenceURL) then
if utilities.is_set (ConferenceURL) then
3,349行目: 3,495行目:
end
end


local Position = '';
if not utilities.is_set (Position) then
if not utilities.is_set (Position) then
local Minutes = A['Minutes'];
local Minutes = A['Minutes'];
3,354行目: 3,501行目:


if utilities.is_set (Minutes) then
if utilities.is_set (Minutes) then
if utilities.is_set (Time) then
if utilities.is_set (Time) then --TODO: make a function for this and similar?
table.insert( z.message_tail, { utilities.set_message ( 'err_redundant_parameters', {utilities.wrap_style ('parameter', 'minutes') .. ' and ' .. utilities.wrap_style ('parameter', 'time')}, true ) } );
utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', 'minutes') .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', 'time')});
end
end
Position = " " .. Minutes .. " " .. cfg.messages['minutes'];
Position = " " .. Minutes .. " " .. cfg.messages['minutes'];
3,395行目: 3,542行目:
end
end


if utilities.is_set (Language) then
local Others = A['Others'];
Language = language_parameter (Language); -- format, categories, name from ISO639-1, etc.
if utilities.is_set (Others) and 0 == #a and 0 == #e then -- add maint cat when |others= has value and used without |author=, |editor=
else
if config.CitationClass == "AV-media-notes"
Language=""; -- language not specified so make sure this is an empty string;
or config.CitationClass == "audio-visual" then -- special maint for AV/M which has a lot of 'false' positives right now
--[[ TODO: need to extract the wrap_msg from language_parameter
utilities.set_message ('maint_others_avm')
so that we can solve parentheses bunching problem with Format/Language/TitleType
else
]]
utilities.set_message ('maint_others');
end
end
end
Others = utilities.is_set (Others) and (sepc .. " " .. Others) or "";
Others = utilities.is_set (Others) and (sepc .. " " .. Others) or "";
3,413行目: 3,560行目:
end
end
local TitleNote = A['TitleNote'];
TitleNote = utilities.is_set (TitleNote) and (sepc .. " " .. TitleNote) or "";
TitleNote = utilities.is_set (TitleNote) and (sepc .. " " .. TitleNote) or "";
if utilities.is_set (Edition) then
if utilities.is_set (Edition) then
if Edition:match ('%f[%a][Ee]d%.?$') or Edition:match ('%f[%a][Ee]dition$') then
if Edition:match ('%f[%a][Ee]d%n?%.?$') or Edition:match ('%f[%a][Ee]dition$') then -- Ed, ed, Ed., ed., Edn, edn, Edn., edn.
utilities.set_message ('maint_extra_text', 'edition'); -- add maint cat
utilities.set_message ('err_extra_text_edition'); -- add error message
end
end
Edition = " " .. wrap_msg ('edition', Edition);
Edition = " " .. wrap_msg ('edition', Edition);
3,424行目: 3,572行目:


Series = utilities.is_set (Series) and wrap_msg ('series', {sepc, Series}) or ""; -- not the same as SeriesNum
Series = utilities.is_set (Series) and wrap_msg ('series', {sepc, Series}) or ""; -- not the same as SeriesNum
OrigDate = utilities.is_set (OrigDate) and wrap_msg ('origdate', OrigDate) or '';
local Agency = A['Agency'];
Agency = utilities.is_set (Agency) and wrap_msg ('agency', {sepc, Agency}) or "";
Agency = utilities.is_set (Agency) and wrap_msg ('agency', {sepc, Agency}) or "";
Volume = format_volume_issue (Volume, Issue, config.CitationClass, Periodical_origin, sepc, use_lowercase);
Volume = format_volume_issue (Volume, Issue, ArticleNumber, config.CitationClass, Periodical_origin, sepc, use_lowercase);
 
------------------------------------ totally unrelated data
Via = utilities.is_set (Via) and  wrap_msg ('via', Via) or '';


if utilities.is_set (AccessDate) then
if utilities.is_set (AccessDate) then
3,442行目: 3,587行目:
if utilities.is_set (ID) then ID = sepc .. " " .. ID; end
if utilities.is_set (ID) then ID = sepc .. " " .. ID; end
local Docket = A['Docket'];
   if "thesis" == config.CitationClass and utilities.is_set (Docket) then
   if "thesis" == config.CitationClass and utilities.is_set (Docket) then
ID = sepc .. " Docket " .. Docket .. ID;
ID = sepc .. " Docket " .. Docket .. ID;
3,453行目: 3,600行目:
end
end


local Quote = A['Quote'];
local TransQuote = A['TransQuote'];
local ScriptQuote = A['ScriptQuote'];
if utilities.is_set (Quote) or utilities.is_set (TransQuote) or utilities.is_set (ScriptQuote) then
if utilities.is_set (Quote) or utilities.is_set (TransQuote) or utilities.is_set (ScriptQuote) then


3,460行目: 3,610行目:
end
end
end
end
 
Quote = utilities.wrap_style ('quoted-text', Quote ); -- wrap in <q>...</q> tags
Quote = kern_quotes (Quote); -- kern if needed
Quote = utilities.wrap_style ('quoted-text', Quote ); -- wrap in <q>...</q> tags
if utilities.is_set (ScriptQuote) then
if utilities.is_set (ScriptQuote) then
Quote = script_concatenate (Quote, ScriptQuote, 'script-quote'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after quote is wrapped
Quote = script_concatenate (Quote, ScriptQuote, 'script-quote'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after quote is wrapped
end
end


3,477行目: 3,628行目:
local quote_prefix = '';
local quote_prefix = '';
if utilities.is_set (QuotePage) then
if utilities.is_set (QuotePage) then
extra_text_in_page_check (QuotePage, 'quote-page'); -- add to maint cat if |quote-page= value begins with what looks like p., pp., etc.
if not NoPP then
if not NoPP then
quote_prefix = utilities.substitute (cfg.messages['p-prefix'], {sepc, QuotePage}), '', '', '';
quote_prefix = utilities.substitute (cfg.messages['p-prefix'], {sepc, QuotePage}), '', '', '';
3,483行目: 3,635行目:
end
end
elseif utilities.is_set (QuotePages) then
elseif utilities.is_set (QuotePages) then
extra_text_in_page_check (QuotePages, 'quote-pages'); -- add to maint cat if |quote-pages= value begins with what looks like p., pp., etc.
if tonumber(QuotePages) ~= nil and not NoPP then -- if only digits, assume single page
if tonumber(QuotePages) ~= nil and not NoPP then -- if only digits, assume single page
quote_prefix = utilities.substitute (cfg.messages['p-prefix'], {sepc, QuotePages}), '', '';
quote_prefix = utilities.substitute (cfg.messages['p-prefix'], {sepc, QuotePages}), '', '';
3,500行目: 3,653行目:
end
end
local Archived
-- We check length of PostScript here because it will have been nuked by
-- the quote parameters. We'd otherwise emit a message even if there wasn't
-- a displayed postscript.
-- TODO: Should the max size (1) be configurable?
-- TODO: Should we check a specific pattern?
if utilities.is_set(PostScript) and mw.ustring.len(PostScript) > 1 then
utilities.set_message ('maint_postscript')
end
local Archived;
if utilities.is_set (ArchiveURL) then
if utilities.is_set (ArchiveURL) then
local arch_text;
local arch_text;
if not utilities.is_set (ArchiveDate) then
if not utilities.is_set (ArchiveDate) then
ArchiveDate = utilities.set_message ('err_archive_missing_date');
utilities.set_message ('err_archive_missing_date');
ArchiveDate = ''; -- empty string for concatenation
end
end
if "live" == UrlStatus then
if "live" == UrlStatus then
arch_text = cfg.messages['archived'];
arch_text = cfg.messages['archived'];
if sepc ~= "." then arch_text = arch_text:lower() end
if sepc ~= "." then arch_text = arch_text:lower() end
Archived = sepc .. " " .. utilities.substitute ( cfg.messages['archived-live'],
if utilities.is_set (ArchiveDate) then
{ external_link( ArchiveURL, arch_text, A:ORIGIN('ArchiveURL'), nil ) .. ArchiveFormat, ArchiveDate } );
Archived = sepc .. ' ' .. utilities.substitute ( cfg.messages['archived-live'],
{external_link( ArchiveURL, arch_text, A:ORIGIN('ArchiveURL'), nil) .. ArchiveFormat, ArchiveDate } );
else
Archived = '';
end
if not utilities.is_set (OriginalURL) then
if not utilities.is_set (OriginalURL) then
Archived = Archived .. " " .. utilities.set_message ('err_archive_missing_url');  
utilities.set_message ('err_archive_missing_url');
Archived = ''; -- empty string for concatenation
end
end
elseif utilities.is_set (OriginalURL) then -- UrlStatus is empty, 'dead', 'unfit', 'usurped', 'bot: unknown'
elseif utilities.is_set (OriginalURL) then -- UrlStatus is empty, 'dead', 'unfit', 'usurped', 'bot: unknown'
3,518行目: 3,686行目:
arch_text = cfg.messages['archived-unfit'];
arch_text = cfg.messages['archived-unfit'];
if sepc ~= "." then arch_text = arch_text:lower() end
if sepc ~= "." then arch_text = arch_text:lower() end
Archived = sepc .. " " .. arch_text .. ArchiveDate; -- format already styled
Archived = sepc .. ' ' .. arch_text .. ArchiveDate; -- format already styled
if 'bot: unknown' == UrlStatus then
if 'bot: unknown' == UrlStatus then
utilities.set_message ('maint_bot_unknown'); -- and add a category if not already added
utilities.set_message ('maint_bot_unknown'); -- and add a category if not already added
3,527行目: 3,695行目:
arch_text = cfg.messages['archived-dead'];
arch_text = cfg.messages['archived-dead'];
if sepc ~= "." then arch_text = arch_text:lower() end
if sepc ~= "." then arch_text = arch_text:lower() end
Archived = sepc .. " " .. utilities.substitute ( arch_text,
if utilities.is_set (ArchiveDate) then
{ external_link( OriginalURL, cfg.messages['original'], OriginalURL_origin, OriginalAccess ) .. OriginalFormat, ArchiveDate } ); -- format already styled
Archived = sepc .. " " .. utilities.substitute ( arch_text,
{ external_link( OriginalURL, cfg.messages['original'], OriginalURL_origin, OriginalAccess ) .. OriginalFormat, ArchiveDate } ); -- format already styled
else
Archived = ''; -- unset for concatenation
end
end
end
else -- OriginalUrl not set
else -- OriginalUrl not set
arch_text = cfg.messages['archived-missing'];
arch_text = cfg.messages['archived-missing'];
if sepc ~= "." then arch_text = arch_text:lower() end
if sepc ~= "." then arch_text = arch_text:lower() end
Archived = sepc .. " " .. utilities.substitute ( arch_text,
utilities.set_message ('err_archive_missing_url');
{ utilities.set_message ('err_archive_missing_url'), ArchiveDate } );
Archived = ''; -- empty string for concatenation
end
end
elseif utilities.is_set (ArchiveFormat) then
elseif utilities.is_set (ArchiveFormat) then
Archived = ArchiveFormat; -- if set and ArchiveURL not set ArchiveFormat has error message
Archived = ArchiveFormat; -- if set and ArchiveURL not set ArchiveFormat has error message
else
else
Archived = ""
Archived = '';
end
end
local Lay = '';
local Lay = '';
local LaySource = A['LaySource'];
local LayURL = A['LayURL'];
local LayFormat = A['LayFormat'];
LayFormat = style_format (LayFormat, LayURL, 'lay-format', 'lay-url');
if utilities.is_set (LayURL) then
if utilities.is_set (LayURL) then
if utilities.is_set (LayDate) then LayDate = " (" .. LayDate .. ")" end
if utilities.is_set (LayDate) then LayDate = " (" .. LayDate .. ")" end
3,559行目: 3,735行目:
end
end


local TranscriptURL = A['TranscriptURL']
local TranscriptFormat = A['TranscriptFormat'];
TranscriptFormat = style_format (TranscriptFormat, TranscriptURL, 'transcript-format', 'transcripturl');
local Transcript = A['Transcript'];
local TranscriptURL_origin = A:ORIGIN('TranscriptURL'); -- get name of parameter that holds TranscriptURL
if utilities.is_set (Transcript) then
if utilities.is_set (Transcript) then
if utilities.is_set (TranscriptURL) then
if utilities.is_set (TranscriptURL) then
3,584行目: 3,765行目:
end
end
local TransPeriodical =  A['TransPeriodical'];
local TransPeriodical_origin =  A:ORIGIN ('TransPeriodical');
-- Several of the above rely upon detecting this as nil, so do it last.
-- Several of the above rely upon detecting this as nil, so do it last.
if (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical) or utilities.is_set (TransPeriodical)) then
if (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical) or utilities.is_set (TransPeriodical)) then
3,591行目: 3,774行目:
Periodical = format_periodical (ScriptPeriodical, ScriptPeriodical_origin, Periodical, TransPeriodical, TransPeriodical_origin);
Periodical = format_periodical (ScriptPeriodical, ScriptPeriodical_origin, Periodical, TransPeriodical, TransPeriodical_origin);
end
end
end
local Language = A['Language'];
if utilities.is_set (Language) then
Language = language_parameter (Language); -- format, categories, name from ISO639-1, etc.
else
Language=''; -- language not specified so make sure this is an empty string;
--[[ TODO: need to extract the wrap_msg from language_parameter
so that we can solve parentheses bunching problem with Format/Language/TitleType
]]
end
end


3,598行目: 3,791行目:
]]
]]
if "speech" == config.CitationClass then -- cite speech only
if "speech" == config.CitationClass then -- cite speech only
TitleNote = " (Speech)"; -- annotate the citation
TitleNote = TitleType; -- move TitleType to TitleNote so that it renders ahead of |event=
TitleType = ''; -- and unset
 
if utilities.is_set (Periodical) then -- if Periodical, perhaps because of an included |website= or |journal= parameter  
if utilities.is_set (Periodical) then -- if Periodical, perhaps because of an included |website= or |journal= parameter  
if utilities.is_set (Conference) then -- and if |event= is set
if utilities.is_set (Conference) then -- and if |event= is set
3,614行目: 3,809行目:
if utilities.in_array (config.CitationClass, {"journal", "citation"}) and utilities.is_set (Periodical) then
if utilities.in_array (config.CitationClass, {"journal", "citation"}) and utilities.is_set (Periodical) then
if not (utilities.is_set (Authors) or utilities.is_set (Editors)) then
Others = Others:gsub ('^' .. sepc .. ' ', ''); -- when no authors and no editors, strip leading sepc and space
end
if utilities.is_set (Others) then Others = safe_join ({Others, sepc .. " "}, sepc) end -- add terminal punctuation & space; check for dup sepc; TODO why do we need to do this here?
if utilities.is_set (Others) then Others = safe_join ({Others, sepc .. " "}, sepc) end -- add terminal punctuation & space; check for dup sepc; TODO why do we need to do this here?
tcommon = safe_join( {Others, Title, TitleNote, Conference, Periodical, Format, TitleType, Series, Language, Edition, Publisher, Agency, Volume}, sepc );
tcommon = safe_join( {Others, Title, TitleNote, Conference, Periodical, Format, TitleType, Series, Language, Edition, Publisher, Agency, Volume}, sepc );
3,647行目: 3,845行目:
end
end
local Via = A['Via'];
Via = utilities.is_set (Via) and  wrap_msg ('via', Via) or '';
local idcommon;
local idcommon;
if 'audio-visual' == config.CitationClass or 'episode' == config.CitationClass then -- special case for cite AV media & cite episode position transcript
if 'audio-visual' == config.CitationClass or 'episode' == config.CitationClass then -- special case for cite AV media & cite episode position transcript
3,657行目: 3,857行目:
local pgtext = Position .. Sheet .. Sheets .. Page .. Pages .. At;
local pgtext = Position .. Sheet .. Sheets .. Page .. Pages .. At;


local OrigDate = A['OrigDate'];
OrigDate = utilities.is_set (OrigDate) and wrap_msg ('origdate', OrigDate) or '';
if utilities.is_set (Date) then
if utilities.is_set (Date) then
if utilities.is_set (Authors) or utilities.is_set (Editors) then -- date follows authors or editors when authors not set
if utilities.is_set (Authors) or utilities.is_set (Editors) then -- date follows authors or editors when authors not set
3,705行目: 3,907行目:
if utilities.is_set (Date) then
if utilities.is_set (Date) then
if EditorCount <= 1 then
if EditorCount <= 1 then
Editors = Editors .. ", " .. cfg.messages['editor'];
Editors = Editors .. cfg.presentation['sep_name'] .. cfg.messages['editor'];
else
else
Editors = Editors .. ", " .. cfg.messages['editors'];
Editors = Editors .. cfg.presentation['sep_name'] .. cfg.messages['editors'];
end
end
else
else
3,726行目: 3,928行目:
if utilities.is_set (PostScript) and PostScript ~= sepc then
if utilities.is_set (PostScript) and PostScript ~= sepc then
text = safe_join( {text, sepc}, sepc ); --Deals with italics, spaces, etc.
text = safe_join( {text, sepc}, sepc ); -- Deals with italics, spaces, etc.
text = text:sub(1, -sepc:len() - 1);
text = text:sub(1, -sepc:len() - 1);
end
end
3,732行目: 3,934行目:
text = safe_join( {text, PostScript}, sepc );
text = safe_join( {text, PostScript}, sepc );


-- Now enclose the whole thing in a <cite/> element
-- Now enclose the whole thing in a <cite> element
local options = {};
local options_t = {};
options_t.class = cite_class_attribute_make (config.CitationClass, Mode);
if utilities.is_set (config.CitationClass) and config.CitationClass ~= "citation" then
 
options.class = string.format ('%s %s %s', 'citation', config.CitationClass, utilities.is_set (Mode) and Mode or 'cs1'); -- class=citation required for blue highlight when used with |ref=
local Ref = is_valid_parameter_value (A['Ref'], A:ORIGIN('Ref'), cfg.keywords_lists['ref'], nil, true); -- nil when |ref=harv; A['Ref'] else
else
 
options.class = string.format ('%s %s', 'citation', utilities.is_set (Mode) and Mode or 'cs2');
if 'none' ~= cfg.keywords_xlate[(Ref and Ref:lower()) or ''] then
end
local namelist_t = {}; -- holds selected contributor, author, editor name list
local year = first_set ({Year, anchor_year}, 2); -- Year first for legacy citations and for YMD dates that require disambiguation
if utilities.is_set (Ref) and 'none' ~= cfg.keywords_xlate[Ref:lower()] then
local id = Ref
if ('harv' == Ref ) then
local namelist = {}; -- holds selected contributor, author, editor name list
local year = first_set ({Year, anchor_year}, 2); -- Year first for legacy citations and for YMD dates that require disambiguation


if #c > 0 then -- if there is a contributor list
if #c > 0 then -- if there is a contributor list
namelist = c; -- select it
namelist_t = c; -- select it
elseif #a > 0 then -- or an author list
elseif #a > 0 then -- or an author list
namelist = a;
namelist_t = a;
elseif #e > 0 then -- or an editor list
elseif #e > 0 then -- or an editor list
namelist = e;
namelist_t = e;
end
end
if #namelist > 0 then -- if there are names in namelist
local citeref_id;
id = anchor_id (namelist, year); -- go make the CITEREF anchor
if #namelist_t > 0 then -- if there are names in namelist_t
else
citeref_id = make_citeref_id (namelist_t, year); -- go make the CITEREF anchor
id = ''; -- unset
if mw.uri.anchorEncode (citeref_id) == ((Ref and mw.uri.anchorEncode (Ref)) or '') then -- Ref may already be encoded (by {{sfnref}}) so citeref_id must be encoded before comparison
utilities.set_message ('maint_ref_duplicates_default');
end
end
else
citeref_id = ''; -- unset
end
end
options.id = id;
options_t.id = Ref or citeref_id;
end
end
 
if string.len(text:gsub("<span[^>/]*>(.-)</span>", "%1"):gsub("%b<>", "")) <= 2 then -- remove <span> tags and other HTML-like markup; then get length of what remains
if string.len (text:gsub('%b<>', '')) <= 2 then -- remove html and html-like tags; then get length of what remains;
z.error_categories = {};
z.error_cats_t = {}; -- blank the categories list
text = utilities.set_message ('err_empty_citation');
z.error_msgs_t = {}; -- blank the error messages list
z.message_tail = {};
OCinSoutput = nil; -- blank the metadata string
text = ''; -- blank the the citation
utilities.set_message ('err_empty_citation'); -- set empty citation message and category
end
end
local render = {}; -- here we collect the final bits for concatenation into the rendered citation
local render_t = {}; -- here we collect the final bits for concatenation into the rendered citation


if utilities.is_set (options.id) then -- here we wrap the rendered citation in <cite ...>...</cite> tags
if utilities.is_set (options_t.id) then -- here we wrap the rendered citation in <cite ...>...</cite> tags
table.insert (render, utilities.substitute (cfg.presentation['cite-id'], {mw.uri.anchorEncode(options.id), mw.text.nowiki(options.class), text})); -- when |ref= is set
table.insert (render_t, utilities.substitute (cfg.presentation['cite-id'], {mw.uri.anchorEncode(options_t.id), mw.text.nowiki(options_t.class), text})); -- when |ref= is set or when there is a namelist
else
else
table.insert (render, utilities.substitute (cfg.presentation['cite'], {mw.text.nowiki(options.class), text})); -- all other cases
table.insert (render_t, utilities.substitute (cfg.presentation['cite'], {mw.text.nowiki(options_t.class), text})); -- when |ref=none or when namelist_t empty and |ref= is missing or is empty
end
end


table.insert (render, utilities.substitute (cfg.presentation['ocins'], {OCinSoutput})); -- append metadata to the citation
if OCinSoutput then -- blanked when citation is 'empty' so don't bother to add boilerplate metadata span
table.insert (render_t, utilities.substitute (cfg.presentation['ocins'], OCinSoutput)); -- format and append metadata to the citation
end


if 0 ~= #z.message_tail then
local template_name = ('citation' == config.CitationClass) and 'citation' or 'cite ' .. (cfg.citation_class_map_t[config.CitationClass] or config.CitationClass);
table.insert (render, ' ');
local template_link = '[[Template:' .. template_name .. '|' .. template_name .. ']]';
for i,v in ipairs( z.message_tail ) do
local msg_prefix = '<code class="cs1-code">{{' .. template_link .. '}}</code>: ';
if utilities.is_set (v[1]) then
 
if i == #z.message_tail then
if 0 ~= #z.error_msgs_t then
table.insert (render, utilities.error_comment ( v[1], v[2] ));
mw.addWarning (utilities.substitute (cfg.messages.warning_msg_e, template_link));
else
 
table.insert (render, utilities.error_comment ( v[1] .. "; ", v[2] ));
table.insert (render_t, ' '); -- insert a space between citation and its error messages
end
table.sort (z.error_msgs_t); -- sort the error messages list; sorting includes wrapping <span> and <code> tags; hidden-error sorts ahead of visible-error
 
local hidden = true; -- presume that the only error messages emited by this template are hidden
for _, v in ipairs (z.error_msgs_t) do -- spin through the list of error messages
if v:find ('cs1-visible-error', 1, true) then -- look for the visible error class name
hidden = false; -- found one; so don't hide the error message prefix
break; -- and done because no need to look further
end
end
end
end
z.error_msgs_t[1] = table.concat ({utilities.error_comment (msg_prefix, hidden), z.error_msgs_t[1]}); -- add error message prefix to first error message to prevent extraneous punctuation
table.insert (render_t, table.concat (z.error_msgs_t, '; ')); -- make a big string of error messages and add it to the rendering
end
end


if 0 ~= #z.maintenance_cats then
if 0 ~= #z.maint_cats_t then
local maint_msgs = {}; -- here we collect all of the maint messages
mw.addWarning (utilities.substitute (cfg.messages.warning_msg_m, template_link));
for _, v in ipairs( z.maintenance_cats ) do -- append maintenance categories
 
local maint = {}; -- here we assemble a maintenence message
table.sort (z.maint_cats_t); -- sort the maintenance messages list
table.insert (maint, v); -- maint msg is the category name
 
table.insert (maint, ' ('); -- open the link text
local maint_msgs_t = {}; -- here we collect all of the maint messages
table.insert (maint, utilities.make_wikilink (':Category:' .. v, 'link')); -- add the link
 
table.insert (maint, ')'); -- and close it
if 0 == #z.error_msgs_t then -- if no error messages
table.insert (maint_msgs, table.concat (maint)); -- assemble new maint message and add it to the maint_msgs table
table.insert (maint_msgs_t, msg_prefix); -- insert message prefix in maint message livery
end
for _, v in ipairs( z.maint_cats_t ) do -- append maintenance categories
table.insert (maint_msgs_t, -- assemble new maint message and add it to the maint_msgs_t table
table.concat ({v, ' (', utilities.substitute (cfg.messages[':cat wikilink'], v), ')'})
);
end
end
table.insert (render, utilities.substitute (cfg.presentation['hidden-maint'], table.concat (maint_msgs, ' '))); -- wrap the group of maint message with proper presentation and save
table.insert (render_t, utilities.substitute (cfg.presentation['hidden-maint'], table.concat (maint_msgs_t, ' '))); -- wrap the group of maint messages with proper presentation and save
end
end
 
if not no_tracking_cats then
if not no_tracking_cats then
for _, v in ipairs( z.error_categories ) do
for _, v in ipairs (z.error_cats_t) do -- append error categories
table.insert (render, utilities.make_wikilink ('Category:' .. v));
table.insert (render_t, utilities.substitute (cfg.messages['cat wikilink'], v));
end
end
for _, v in ipairs( z.maintenance_cats ) do -- append maintenance categories
for _, v in ipairs (z.maint_cats_t) do -- append maintenance categories
table.insert (render, utilities.make_wikilink ('Category:' .. v));
table.insert (render_t, utilities.substitute (cfg.messages['cat wikilink'], v));
end
end
for _, v in ipairs( z.properties_cats ) do -- append properties categories
for _, v in ipairs (z.prop_cats_t) do -- append properties categories
table.insert (render, utilities.make_wikilink ('Category:' .. v));
table.insert (render_t, utilities.substitute (cfg.messages['cat wikilink'], v));
end
end
elseif 'nocat' == A:ORIGIN('NoTracking') then -- peculiar special case; can't track nocat without tracking nocat
table.insert (render, utilities.make_wikilink ('Category:CS1 maint: nocat')); -- hand-set this category because it is supposed to be temporary
end
end


return table.concat (render);
return table.concat (render_t); -- make a big string and done
end
end


3,841行目: 4,058行目:
if true == state then return true; end -- valid actively supported parameter
if true == state then return true; end -- valid actively supported parameter
if false == state then
if false == state then
if empty then return nil; end -- deprecated empty parameters are treated as unknowns
if empty then return nil; end -- empty deprecated parameters are treated as unknowns
deprecated_parameter (name); -- parameter is deprecated but still supported
deprecated_parameter (name); -- parameter is deprecated but still supported
return true;
end
if 'tracked' == state then
local base_name = name:gsub ('%d', ''); -- strip enumerators from parameter names that have them to get the base name
utilities.add_prop_cat ('tracked-param', {base_name}, base_name); -- add a properties category; <base_name> modifies <key>
return true;
return true;
end
end
3,900行目: 4,122行目:
if prefix and cfg.inter_wiki_map[prefix:lower()] then -- if prefix is in the map, needs preceding colon so
if prefix and cfg.inter_wiki_map[prefix:lower()] then -- if prefix is in the map, needs preceding colon so
table.insert( z.message_tail, {utilities.set_message ('err_bad_paramlink', parameter)}); -- emit an error message
utilities.set_message ('err_bad_paramlink', parameter); -- emit an error message
_, value, _ = utilities.is_wikilink (value); -- extract label portion from wikilink
_, value, _ = utilities.is_wikilink (value); -- extract label portion from wikilink
end
end
3,927行目: 4,149行目:
capture = value:match ('%s+(%a[%w%-]+)%s*=') or value:match ('^(%a[%w%-]+)%s*='); -- find and categorize parameters with possible missing pipes
capture = value:match ('%s+(%a[%w%-]+)%s*=') or value:match ('^(%a[%w%-]+)%s*='); -- find and categorize parameters with possible missing pipes
if capture and validate (capture) then -- if the capture is a valid parameter name
if capture and validate (capture) then -- if the capture is a valid parameter name
table.insert( z.message_tail, {utilities.set_message ('err_missing_pipe', parameter)});
utilities.set_message ('err_missing_pipe', parameter);
end
end
end
end
3,949行目: 4,171行目:
if value:match ('[,;:]$') then
if value:match ('[,;:]$') then
utilities.set_message ('maint_extra_punct'); -- has extraneous punctuation; add maint cat
end
if value:match ('^=') then -- sometimes an extraneous '=' character appears ...
utilities.set_message ('maint_extra_punct'); -- has extraneous punctuation; add maint cat
utilities.set_message ('maint_extra_punct'); -- has extraneous punctuation; add maint cat
end
end
--[[--------------------------< H A S _ E X T R A N E O U S _ U R L >------------------------------------------
look for extraneous url parameter values; parameters listed in skip table are not checked
]]
local function has_extraneous_url (url_param_t)
local url_error_t = {};
check_for_url (url_param_t, url_error_t); -- extraneous url check
if 0 ~= #url_error_t then -- non-zero when there are errors
table.sort (url_error_t);
utilities.set_message ('err_param_has_ext_link', {utilities.make_sep_list (#url_error_t, url_error_t)}); -- add this error message
end
end
end
end
3,962行目: 4,204行目:
local function citation(frame)
local function citation(frame)
Frame = frame; -- save a copy in case we need to display an error message in preview mode
Frame = frame; -- save a copy in case we need to display an error message in preview mode
local config = {}; -- table to store parameters from the module {{#invoke:}}
for k, v in pairs( frame.args ) do -- get parameters from the {{#invoke}} frame
config[k] = v;
-- args[k] = v; -- crude debug support that allows us to render a citation from module {{#invoke:}}; skips parameter validation; TODO: keep?
end
-- i18n: set the name that your wiki uses to identify sandbox subpages from sandbox template invoke (or can be set here)
local sandbox = ((config.SandboxPath and '' ~= config.SandboxPath) and config.SandboxPath) or '/sandbox'; -- sandbox path from {{#invoke:Citation/CS1/sandbox|citation|SandboxPath=/...}}
is_sandbox = nil ~= string.find (frame:getTitle(), sandbox, 1, true); -- is this invoke the sandbox module?
sandbox = is_sandbox and sandbox or ''; -- use i18n sandbox to load sandbox modules when this module is the sandox; live modules else
local pframe = frame:getParent()
local pframe = frame:getParent()
local styles;
local styles;
if nil ~= string.find (frame:getTitle(), 'sandbox', 1, true) then -- did the {{#invoke:}} use sandbox version?
cfg = mw.loadData ('Module:Citation/CS1/Configuration' .. sandbox); -- load sandbox versions of support modules when {{#invoke:Citation/CS1/sandbox|...}}; live modules else
cfg = mw.loadData ('Module:Citation/CS1/Configuration/sandbox'); -- load sandbox versions of support modules
whitelist = mw.loadData ('Module:Citation/CS1/Whitelist' .. sandbox);
whitelist = mw.loadData ('Module:Citation/CS1/Whitelist/sandbox');
utilities = require ('Module:Citation/CS1/Utilities' .. sandbox);
utilities = require ('Module:Citation/CS1/Utilities/sandbox');
validation = require ('Module:Citation/CS1/Date_validation' .. sandbox);
validation = require ('Module:Citation/CS1/Date_validation/sandbox');
identifiers = require ('Module:Citation/CS1/Identifiers' .. sandbox);
identifiers = require ('Module:Citation/CS1/Identifiers/sandbox');
metadata = require ('Module:Citation/CS1/COinS' .. sandbox);
metadata = require ('Module:Citation/CS1/COinS/sandbox');
styles = 'Module:Citation/CS1' .. sandbox .. '/styles.css';
styles = 'Module:Citation/CS1/sandbox/styles.css';
else -- otherwise
cfg = mw.loadData ('Module:Citation/CS1/Configuration'); -- load live versions of support modules
whitelist = mw.loadData ('Module:Citation/CS1/Whitelist');
utilities = require ('Module:Citation/CS1/Utilities');
validation = require ('Module:Citation/CS1/Date_validation');
identifiers = require ('Module:Citation/CS1/Identifiers');
metadata = require ('Module:Citation/CS1/COinS');
styles = 'Module:Citation/CS1/styles.css';
end


utilities.set_selected_modules (cfg); -- so that functions in Utilities can see the selected cfg tables
utilities.set_selected_modules (cfg); -- so that functions in Utilities can see the selected cfg tables
3,990行目: 4,232行目:


z = utilities.z; -- table of error and category tables in Module:Citation/CS1/Utilities
z = utilities.z; -- table of error and category tables in Module:Citation/CS1/Utilities
is_preview_mode = not utilities.is_set (frame:preprocess ('{{REVISIONID}}'));


local args = {}; -- table where we store all of the template's arguments
local args = {}; -- table where we store all of the template's arguments
local suggestions = {}; -- table where we store suggestions if we need to loadData them
local suggestions = {}; -- table where we store suggestions if we need to loadData them
local error_text, error_state;
local error_text; -- used as a flag
 
local config = {}; -- table to store parameters from the module {{#invoke:}}
for k, v in pairs( frame.args ) do -- get parameters from the {{#invoke}} frame
config[k] = v;
-- args[k] = v; -- crude debug support that allows us to render a citation from module {{#invoke:}}; skips parameter validation; TODO: keep?
end


local capture; -- the single supported capture when matching unknown parameters using patterns
local capture; -- the single supported capture when matching unknown parameters using patterns
4,010行目: 4,248行目:
end
end
if not validate( k, config.CitationClass ) then
if not validate( k, config.CitationClass ) then
error_text = "";
if type (k) ~= 'string' then -- exclude empty numbered parameters
if type( k ) ~= 'string' then
-- exclude empty numbered parameters
if v:match("%S+") ~= nil then
if v:match("%S+") ~= nil then
error_text, error_state = utilities.set_message ( 'err_text_ignored', {v}, true );
error_text = utilities.set_message ('err_text_ignored', {v});
end
end
elseif validate( k:lower(), config.CitationClass ) then  
elseif validate (k:lower(), config.CitationClass) then  
error_text, error_state = utilities.set_message ( 'err_parameter_ignored_suggest', {k, k:lower()}, true ); -- suggest the lowercase version of the parameter
error_text = utilities.set_message ('err_parameter_ignored_suggest', {k, k:lower()}); -- suggest the lowercase version of the parameter
else
else
if nil == suggestions.suggestions then -- if this table is nil then we need to load it
if nil == suggestions.suggestions then -- if this table is nil then we need to load it
if nil ~= string.find (frame:getTitle(), 'sandbox', 1, true) then -- did the {{#invoke:}} use sandbox version?
suggestions = mw.loadData ('Module:Citation/CS1/Suggestions' .. sandbox); --load sandbox version of suggestion module when {{#invoke:Citation/CS1/sandbox|...}}; live module else
suggestions = mw.loadData( 'Module:Citation/CS1/Suggestions/sandbox' ); -- use the sandbox version
else
suggestions = mw.loadData( 'Module:Citation/CS1/Suggestions' ); -- use the live version
end
end
end
for pattern, param in pairs (suggestions.patterns) do -- loop through the patterns to see if we can suggest a proper parameter
for pattern, param in pairs (suggestions.patterns) do -- loop through the patterns to see if we can suggest a proper parameter
4,031行目: 4,263行目:
param = utilities.substitute (param, capture); -- add the capture to the suggested parameter (typically the enumerator)
param = utilities.substitute (param, capture); -- add the capture to the suggested parameter (typically the enumerator)
if validate (param, config.CitationClass) then -- validate the suggestion to make sure that the suggestion is supported by this template (necessary for limited parameter lists)
if validate (param, config.CitationClass) then -- validate the suggestion to make sure that the suggestion is supported by this template (necessary for limited parameter lists)
error_text, error_state = utilities.set_message ('err_parameter_ignored_suggest', {k, param}, true); -- set the suggestion error message
error_text = utilities.set_message ('err_parameter_ignored_suggest', {k, param}); -- set the suggestion error message
else
else
error_text, error_state = utilities.set_message ( 'err_parameter_ignored', {param}, true ); -- suggested param not supported by this template
error_text = utilities.set_message ('err_parameter_ignored', {k}); -- suggested param not supported by this template
v = ''; -- unset
v = ''; -- unset
end
end
end
end
end
end
if not utilities.is_set (error_text) then -- couldn't match with a pattern, is there an expicit suggestion?
if not utilities.is_set (error_text) then -- couldn't match with a pattern, is there an explicit suggestion?
if suggestions.suggestions[ k:lower() ] ~= nil then
if (suggestions.suggestions[ k:lower() ] ~= nil) and validate (suggestions.suggestions[ k:lower() ], config.CitationClass) then
error_text, error_state = utilities.set_message ( 'err_parameter_ignored_suggest', {k, suggestions.suggestions[ k:lower() ]}, true );
utilities.set_message ('err_parameter_ignored_suggest', {k, suggestions.suggestions[ k:lower() ]});
else
else
error_text, error_state = utilities.set_message ( 'err_parameter_ignored', {k}, true );
utilities.set_message ('err_parameter_ignored', {k});
v = ''; -- unset value assigned to unrecognized parameters (this for the limited parameter lists)
v = ''; -- unset value assigned to unrecognized parameters (this for the limited parameter lists)
end
end
end
end
end    
end    
if error_text ~= '' then
table.insert( z.message_tail, {error_text, error_state} );
end
end
end


4,066行目: 4,295行目:


if 0 ~= #empty_unknowns then -- create empty unknown error message
if 0 ~= #empty_unknowns then -- create empty unknown error message
table.insert (z.message_tail, {utilities.set_message ('err_param_unknown_empty', {
utilities.set_message ('err_param_unknown_empty', {
1 == #empty_unknowns and '' or 's',
1 == #empty_unknowns and '' or 's',
utilities.make_sep_list (#empty_unknowns, empty_unknowns)
utilities.make_sep_list (#empty_unknowns, empty_unknowns)
}, true )});
});
end
end
local url_param_t = {};


for k, v in pairs( args ) do
for k, v in pairs( args ) do
4,079行目: 4,310行目:
missing_pipe_check (k, v); -- do we think that there is a parameter that is missing a pipe?
missing_pipe_check (k, v); -- do we think that there is a parameter that is missing a pipe?
args[k] = inter_wiki_check (k, v); -- when language interwiki-linked parameter missing leading colon replace with wiki-link label
args[k] = inter_wiki_check (k, v); -- when language interwiki-linked parameter missing leading colon replace with wiki-link label
if 'string' == type (k) and not cfg.url_skip[k] then -- when parameter k is not positional and not in url skip table
url_param_t[k] = v; -- make a parameter/value list for extraneous url check
end
end
end


return table.concat ({citation0( config, args), frame:extensionTag ('templatestyles', '', {src=styles})});
has_extraneous_url (url_param_t); -- look for url in parameter values where a url does not belong
 
return table.concat ({
frame:extensionTag ('templatestyles', '', {src=styles}),
citation0( config, args)
});
end
end


--[[--------------------------< E X P O R T E D  F U N C T I O N S >------------------------------------------
--[[--------------------------< E X P O R T E D  F U N C T I O N S >------------------------------------------
匿名利用者