Jump to content

Module:Citation/CS1: Difference between revisions

interim fix to kern_quotes(); see discussion;
m (1 revision imported: CITATION NEEDED)
(interim fix to kern_quotes(); see discussion;)
Line 12:
local z ={}; -- tables in Module:Citation/CS1/Utilities
 
local extract_ids, extract_id_access_levels, build_id_list, is_embargoed; -- functions in Module:Citation/CS1/Identifiers
 
local make_coins_title, get_coins_pages, COinS; -- functions in Module:Citation/CS1/COinS
Line 407:
end
if is_set (access) then -- access level (subscription, registration, limited)
base_url = table.concat({ "[", URL, " ", safe_for_url( label ), "]" });
local label_head = '';
local label_tail;
if is_set(access) then -- access level (free, paywalled, ...)
local markup = ''; -- can't start a span inside italic markup and end it outside the italic markup
base_url = substitute(cfg.presentation[access], base_url);
 
label = safe_for_url (label); -- replace square brackets and newlines (is this necessary? already done above?)
if label:match ("(.*)%s+(.+)('''?)$") then -- for italicized titles (cite book, etc)
label_head, label_tail, markup = label:match ("(.*)%s+(.+)('''?)$"); -- split the label at the right-most space; separate the markup
elseif label:match ("(.*)%s+(.+)$") then -- for upright titles (journal, news, magazine, etc)
label_head, label_tail = label:match ("(.*)%s+(.+)$"); -- split the label at the right-most space; no markup
elseif label:match ("(.+)('''?)$") then -- single word label with markup
label_tail, markup = label:match ("(.+)('''?)$"); -- save label text as label tail; separate the markup
else
label_tail = label;
end
 
base_url = table.concat (
{
'<span class="plainlinks">[', -- opening css
URL, -- the url
' ', -- the required space
label_head, -- all but the last word of the label
' <span class="nowrap">', -- nowrap css for the last word and the signal icon
label_tail, -- last (or only) word of the label inside the span
'<span style="padding-left:0.15em">', -- signal spacing css
cfg.presentation[access], -- the appropriate icon
'</span></span>', -- close signal spacing and nowrap spans
markup, -- insert italic markup if any
']</span>' -- close the plain links span
});
else
base_url = table.concat({ "[", URL, " ", safe_for_url( label ), "]" }); -- no signal markup
end
Line 452 ⟶ 480:
local cap2='';
-- TODO: move this elswhere so that all title-holding elements get these quote marks replaced?
-- str= mw.ustring.gsub (str, '[“”]', '\"'); -- replace “” (U+201C & U+201D) with " (typewriter double quote mark)
-- str= mw.ustring.gsub (str, '[‘’]', '\''); -- replace ‘’ (U+2018 & U+2019) with ' (typewriter single quote mark)
cap, cap2 = str:match ("^([\"\'])([^\'].+)"); -- match leading double or single quote but not double single quotes
Line 704 ⟶ 732:
 
--[[--------------------------< V A L I D A T E >--------------------------------------------------------------
 
Looks for a parameter's name in the whitelist.
Looks for a parameter's name in one of several whitelists.
 
Parameters in the whitelist can have three values:
Line 713 ⟶ 742:
]]
 
--local function validate( name )
local function validate( name, cite_class )
local name = tostring( name );
local state = whitelist.basic_arguments[ name ];
if in_array (cite_class, {'arxiv', 'biorxiv', 'citeseerx'}) then -- limited parameter sets allowed for these templates
-- Normal arguments
state = whitelist.limited_basic_arguments[ name ];
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
deprecated_parameter (name); -- parameter is deprecated but still supported
return true;
end
 
if 'arxiv' == cite_class then -- basic parameters unique to these templates
state = whitelist.arxiv_basic_arguments[name];
end
if 'biorxiv' == cite_class then
state = whitelist.biorxiv_basic_arguments[name];
end
if 'citeseerx' == cite_class then
state = whitelist.citeseerx_basic_arguments[name];
end
 
if true == state then return true; end -- valid actively supported parameter
if false == state then
deprecated_parameter (name); -- parameter is deprecated but still supported
return true;
end
-- limited enumerated parameters list
name = name:gsub( "%d+", "#" ); -- replace digit(s) with # (last25 becomes last#)
state = whitelist.limited_numbered_arguments[ name ];
if true == state then return true; end -- valid actively supported parameter
if false == state then
deprecated_parameter (name); -- parameter is deprecated but still supported
return true;
end
 
return false; -- not supported because not found or name is set to nil
end -- end limited parameter-set templates
state = whitelist.basic_arguments[ name ]; -- all other templates; all normal parameters allowed
if true == state then return true; end -- valid actively supported parameter
if false == state then
deprecated_parameter (name); -- parameter is deprecated but still supported
return true;
end
-- all enumerated parameters allowed
name = name:gsub( "%d+", "#" ); -- replace digit(s) with # (last25 becomes last#
-- Arguments with numbers in them
name = name:gsub( "%d+", "#" ); -- replace digit(s) with # (last25 becomes last#
state = whitelist.numbered_arguments[ name ];
 
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
deprecated_parameter (name); -- parameter is deprecated but still supported
return true;
end
return false; -- Notnot supported because not found or name is set to nil
end
 
Line 953 ⟶ 1,019:
 
if name then -- if first is initials with or without suffix
if 3 > name:mw.ustring.len (name) then -- if one or two initials
if suffix then -- if there is a suffix
if is_suffix (suffix) then -- is it legitimate?
Line 1,138 ⟶ 1,204:
return name, etal; --
end
 
 
--[[--------------------------< N A M E _ H A S _ E D _ M A R K U P >------------------------------------------
 
Evaluates the content of author and editor parameters for extranious 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.
 
]]
 
local function name_has_ed_markup (name, list_name)
local _, pattern;
local patterns = { -- these patterns match annotations at end of name
'%f[%(%[][%(%[]%s*[Ee][Dd][Ss]?%.?%s*[%)%]]?$', -- (ed) or (eds): leading '(', case insensitive 'ed', optional 's', '.' and/or ')'
'[,%.%s]%f[e]eds?%.?$', -- ed or eds: without '('or ')'; case sensitive (ED could be initials Ed could be name)
'%f[%(%[][%(%[]%s*[Ee][Dd][Ii][Tt][Oo][Rr][Ss]?%.?%s*[%)%]]?$', -- (editor) or (editors): leading '(', case insensitive, optional '.' and/or ')'
'[,%.%s]%f[Ee][Ee][Dd][Ii][Tt][Oo][Rr][Ss]?%.?$', -- editor or editors: without '('or ')'; case insensitive
-- these patterns match annotations at beginning of name
'^eds?[%.,;]', -- ed. or eds.: lower case only, optional 's', requires '.'
'^[%(%[]%s*[Ee][Dd][Ss]?%.?%s*[%)%]]', -- (ed) or (eds): also sqare brackets, case insensitive, optional 's', '.'
'^[%(%[]?%s*[Ee][Dd][Ii][Tt][Oo][Rr][Ss]?%A', -- (editor or (editors: also sq brackets, case insensitive, optional brackets, 's'
'^[%(%[]?%s*[Ee][Dd][Ii][Tt][Ee][Dd]%A', -- (edited: also sq brackets, case insensitive, optional brackets
 
}
 
if is_set (name) then
for _, pattern in ipairs (patterns) do -- spin through patterns table and
if name:match (pattern) then
add_maint_cat ('extra_text_names', cfg.special_case_translation [list_name]); -- add a maint cat for this template
break;
end
end
end
return name; -- and done
end
 
 
--[[--------------------------< N A M E _ H A S _ M U L T _ N A M E S >----------------------------------------
Line 1,150 ⟶ 1,253:
local count, _;
if is_set (name) then
if_, count = name:matchgsub ('^%(%(.*%)%)$[;,]'), then''); -- ifcount wrappedthe innumber doubledof parentheses, ignoreseparator-like characters
name = name:match ('^%(%((.*)%)%)$'); -- strip parens
if 1 < count then -- param could be |author= or |editor= so one separator character is acceptable
else
add_maint_cat ('mult_names', cfg.special_case_translation [list_name]); -- more than one separator indicates multiple names so add a maint cat for this template
_, count = name:gsub ('[;,]', ''); -- count the number of separator-like characters
if 1 < count then -- param could be |author= or |editor= so one separactor character is acceptable
add_maint_cat ('mult_names', cfg.special_case_translation [list_name]); -- more than one separator indicates multiple names so add a maint cat for this template
end
end
end
return name; -- and done
end
 
 
--[[--------------------------< N A M E _ C H E C K S >--------------------------------------------------------
This function calls various name checking functions used to validate the content of the various name-holding
parameters.
 
]]
 
local function name_checks (last, first, list_name)
if is_set (last) then
if last:match ('^%(%(.*%)%)$') then -- if wrapped in doubled parentheses, accept as written
last = last:match ('^%(%((.*)%)%)$'); -- strip parens
else
last = name_has_mult_names (last, list_name); -- check for multiple names in the parameter (last only)
last = name_has_ed_markup (last, list_name); -- check for extraneous 'editor' annotation
end
end
if is_set (first) then
if first:match ('^%(%(.*%)%)$') then -- if wrapped in doubled parentheses, accept as written
first = first:match ('^%(%((.*)%)%)$'); -- strip parens
else
first = name_has_ed_markup (first, list_name); -- check for extraneous 'editor' annotation
end
end
return last, first; -- done
end
 
 
--[[--------------------------< E X T R A C T _ N A M E S >----------------------------------------------------
Line 1,199 ⟶ 1,325:
last, etal = name_has_etal (last, etal, false); -- find and remove variations on et al.
first, etal = name_has_etal (first, etal, false); -- find and remove variations on et al.
-- last, first= name_has_mult_namesname_checks (last, err_msg_list_namefirst, list_name); -- check for multiple names, inextraneous last andannotation, itsetc aliaseschecks
last = name_has_mult_names (last, list_name); -- check for multiple names in last and its aliases
if first and not last then -- if there is a firstn without a matching lastn
Line 1,247 ⟶ 1,372:
 
local function get_iso639_code (lang, this_wiki_code)
if 'bangla' == lang:lower() then -- special case related to Wikimedia remap of code 'bn' at mw:Extension:CLDR
return 'Bengali', 'bn'; -- make sure rendered version is properly capitalized
end
 
local languages = mw.language.fetchLanguageNames(this_wiki_code, 'all') -- get a list of language names known to Wikimedia
-- ('all' is required for North Ndebele, South Ndebele, and Ojibwa)
Line 1,261 ⟶ 1,390:
return lang; -- not valid language; return language in original case and nil for the code
end
 
 
--[[--------------------------< L A N G U A G E _ P A R A M E T E R >------------------------------------------
Line 1,307 ⟶ 1,437:
if is_set (code) then -- only 2- or 3-character codes
if 'bn' == code then name = 'Bengali' end; -- override wikimedia when code is 'bn'
if this_wiki_code ~= code then -- when the language is not the same as this wiki's language
if 2 == code:len() then -- and is a two-character code
Line 1,714 ⟶ 1,845:
 
local function terminate_name_list (name_list, sepc)
if (string.sub (name_list,-1,-1) == sepc) or (string.sub (name_list,-3,-1) == sepc .. ']]. ') then -- if lastalready name in list ends with sepcproperly charterminated
return name_list; -- just return the name list
elseif (string.sub (name_list,-1,-1) == sepc) or (string.sub (name_list,-3,-1) == sepc .. ']]') then -- if last name in list ends with sepc char
return name_list .. " "; -- don't add another
else
Line 1,884 ⟶ 2,017:
local path, timestamp, flag; -- portions of the archive.or url
if (not url:match('//web%.archive%.org/')) and (not url:match('//liveweb%.archive%.org/')) then -- also deprecated liveweb Wayback machine url
return url, date; -- not an archive.org archive, return ArchiveURL and ArchiveDate
end
Line 1,891 ⟶ 2,024:
err_msg = 'save command';
url = url:gsub ('(//web%.archive%.org)/save/', '%1/*/', 1); -- for preview mode: modify ArchiveURL
elseif url:match('//liveweb%.archive%.org/') then
err_msg = 'liveweb';
else
path, timestamp, flag = url:match('//web%.archive%.org/([^%d]*)(%d+)([^/]*)/'); -- split out some of the url parts for evaluation
Line 1,991 ⟶ 2,126:
end
 
local Coauthors = A['Coauthors'];
local Others = A['Others'];
 
Line 2,015 ⟶ 2,149:
t = extract_names (args, 'TranslatorList'); -- fetch translator list from |translatorn= / |translator-lastn=, -firstn=, -linkn=, -maskn=
 
local interviewers_list = {};
local Interviewers = A['Interviewers']
if is_set (Interviewers) then -- add a maint cat if the |interviewers= is used
add_maint_cat ('interviewers'); -- because use of this parameter is discouraged
else
interviewers_list = extract_names (args, 'InterviewerList'); -- else, process preferred interviewers parameters
end
 
local c = {}; -- contributors list from |contributor-lastn= / contributor-firstn= pairs
local Contributors; -- assembled contributors name list
Line 2,184 ⟶ 2,325:
no_tracking_cats = nil; -- set to empty string
end
 
--these deprecated parameters are used by cite interview
local Callsign = A['Callsign'];
local City = A['City'];
local Program = A['Program'];
 
--local variables that are not cs1 parameters
Line 2,302 ⟶ 2,438:
end
end
end
 
-- special case for cite interview
-- TODO: make cite interview not need any special cases
--[[
Program, Callsign, City deprecated, so avoid using /Configuration
for reassignment, which would allow these parameters' use outside interview
]]
if (config.CitationClass == "interview") then
if is_set(Program) then
if not is_set(Periodical) then
Periodical = Program;
end
end
if is_set(Callsign) then
if not is_set(PublisherName) then
PublisherName = Callsign;
end
end
if is_set(City) then
if not is_set(PublicationPlace) then
PublicationPlace = City;
end
end
end
 
Line 2,441 ⟶ 2,553:
-- end of {{cite episode}} stuff
 
-- Account for the oddities that are {{cite arxiv}}, {{cite biorxiv}}, {{cite citeseerx}}, before generation of COinS data.
do
if 'arxiv' == config.CitationClass then
if in_array (config.CitationClass, {'arxiv', 'biorxiv', 'citeseerx'}) then
if not is_set (ID_list['ARXIV']) then -- |arxiv= or |eprint= required for cite arxiv
if not is_set (ID_list[config.CitationClass:upper()]) then -- |arxiv= or |eprint= required for cite arxiv; |biorxiv= & |citeseerx= required for their templates
table.insert( z.message_tail, { set_error( 'arxiv_missing', {}, true ) } ); -- add error message
table.insert( z.message_tail, { set_error( config.CitationClass .. '_missing', {}, true ) } ); -- add error message
elseif is_set (Series) then -- series is an alias of version
end
ID_list['ARXIV'] = ID_list['ARXIV'] .. Series; -- concatenate version onto the end of the arxiv identifier
Series = ''; -- unset
if 'arxiv' == config.CitationClass then
deprecated_parameter ('version'); -- deprecated parameter but only for cite arxiv
Periodical = 'arXiv'; -- set to arXiv for COinS; after that, must be set to empty string
end
end
if 'biorxiv' == config.CitationClass then
if first_set ({AccessDate, At, Authors, Chapter, Format, Page, Pages, Periodical, PublisherName, URL, -- a crude list of parameters that are not supported by cite arxiv
Periodical = 'bioRxiv'; -- set to bioRxiv for COinS; after that, must be set to empty string
ID_list['ASIN'], ID_list['BIBCODE'], ID_list['DOI'], ID_list['ISBN'], ID_list['ISSN'], -- TODO: find a better way to do this
end
ID_list['JFM'], ID_list['JSTOR'], ID_list['LCCN'], ID_list['MR'], ID_list['OCLC'], ID_list['OL'],
if 'citeseerx' == config.CitationClass then
ID_list['OSTI'], ID_list['PMC'], ID_list['PMID'], ID_list['RFC'], ID_list['SSRN'], ID_list['USENETID'], ID_list['ZBL']},27) then
Periodical = 'CiteSeerX'; -- set to CiteSeerX for COinS; after that, must be set to empty string
table.insert( z.message_tail, { set_error( 'arxiv_params_not_supported', {}, true ) } ); -- add error message
end
 
AccessDate = ''; -- set these to empty string; not supported in cite arXiv
Authors = '';
PublisherName = ''; -- (if the article has been published, use cite journal, or other)
Chapter = '';
URL = '';
Format = '';
Page = ''; Pages = ''; At = '';
end
Periodical = 'arXiv'; -- set to arXiv for COinS; after that, must be set to empty string
end
 
Line 2,625 ⟶ 2,729:
 
-- Account for the oddities that are {{cite arxiv}}, AFTER generation of COinS data.
-- if 'arxiv' == config.CitationClass then -- we have set rft.jtitle in COinS to arXiv, now unset so it isn't displayed
if in_array (config.CitationClass, {'arxiv', 'biorxiv', 'citeseerx'}) then -- we have set rft.jtitle in COinS to arXiv, bioRxiv, or CiteSeerX now unset so it isn't displayed
Periodical = ''; -- periodical not allowed in cite arxiv; if article has been published, use cite journal
Periodical = ''; -- periodical not allowed in these templates; if article has been published, use cite journal
end
 
Line 2,652 ⟶ 2,757:
};
 
do -- do editor name list first because the now unsupported coauthors canused to modify control table
control.maximum , editor_etal = get_display_authors_editors (A['DisplayEditors'], #e, 'editors', editor_etal);
last_first_list, EditorCount = list_people(control, e, editor_etal);
Line 2,670 ⟶ 2,775:
EditorCount = 2; -- spoof to display (eds.) annotation
end
end
do -- now do interviewers
control.maximum = #interviewers_list; -- number of interviewerss
Interviewers = list_people(control, interviewers_list, false); -- et al not currently supported
end
do -- now do translators
Line 2,682 ⟶ 2,791:
control.maximum , author_etal = get_display_authors_editors (A['DisplayAuthors'], #a, 'authors', author_etal);
 
if is_set(Coauthors) then -- if the coauthor field is also used, prevent ampersand and et al. formatting.
control.lastauthoramp = nil;
control.maximum = #a + 1;
end
last_first_list = list_people(control, a, author_etal);
 
Line 2,703 ⟶ 2,807:
end
 
if not is_set(Authors) and is_set(Coauthors) then -- coauthors aren't displayed if one of authors=, authorn=, or lastn= isn't specified
table.insert( z.message_tail, { set_error('coauthors_missing_author', {}, true) } ); -- emit error message
end
end
 
Line 2,717 ⟶ 2,818:
 
-- special case for chapter format so no error message or cat when chapter not supported
if not (in_array(config.CitationClass, {'web', 'news', 'journal', 'magazine', 'pressrelease', 'podcast', 'newsgroup', 'arxiv', 'biorxiv', 'citeseerx'}) or
('citation' == config.CitationClass and is_set (Periodical) and not is_set (Encyclopedia))) then
ChapterFormat = style_format (ChapterFormat, ChapterURL, 'chapter-format', 'chapter-url');
Line 2,760 ⟶ 2,861:
end
 
if in_array(config.CitationClass, {'web','news','journal', 'magazine', 'pressrelease', 'podcast', 'newsgroup', 'arxiv', 'biorxiv', 'citeseerx'}) or -- if any of the 'periodical' cites except encyclopedia
('citation' == config.CitationClass and is_set (Periodical) and not is_set (Encyclopedia)) then
local chap_param;
Line 2,808 ⟶ 2,909:
end
 
if in_array(config.CitationClass, {'web', 'news', 'journal', 'magazine', 'pressrelease', 'podcast', 'newsgroup', 'mailinglist', 'interview', 'arxiv', 'interviewbiorxiv', 'citeseerx'}) or
('citation' == config.CitationClass and is_set (Periodical) and not is_set (Encyclopedia)) or
('map' == config.CitationClass and is_set (Periodical)) then -- special case for cite map when the map is in a periodical treat as an article
Line 2,832 ⟶ 2,933:
end
end
Title = Title .. TransTitle;
if is_set(Title) then
if not is_set(TitleLink) and is_set(URL) then
Title = external_link( URL, Title, URLorigin, UrlAccess ) .. TransTitle .. TransError .. Format;
-- this experiment hidden 2016-04-10; see Help_talk:Citation_Style_1#Recycled_urls
-- local temp_title = external_link( URL, Title, URLorigin ) .. TransError .. Format; -- do this so we get error message even if url is usurped no archive
Line 2,854 ⟶ 2,953:
Format = "";
else
Title = Title .. TransTitle .. TransError;
end
end
Line 3,006 ⟶ 3,105:
 
if is_set(URL) then
URL = " " .. external_link( URL, nil, URLorigin, AccessUrlAccess );
end
 
Line 3,201 ⟶ 3,300:
end
if is_set(Authors) then
if is_set(Coauthors) then
if 'vanc' == NameListFormat then -- separate authors and coauthors with proper name-list-separator
Authors = Authors .. ', ' .. Coauthors;
else
Authors = Authors .. '; ' .. Coauthors;
end
end
if (not is_set (Date)) or ('mla' == Mode) then -- when date is set it's in parentheses; no Authors termination
Authors = terminate_name_list (Authors, sepc); -- when no date, terminate with 0 or 1 sepc and a space
Line 3,236 ⟶ 3,328:
if (sepc ~= '.') then by_text = by_text:lower() end -- lowercase for cs2
Authors = by_text .. Authors; -- author follows title so tweak it here
if is_set (Editors) and is_set (Date) and ('mla' ~= Mode) then -- when Editors make sure that Authors gets terminated
Authors = terminate_name_list (Authors, sepc); -- terminate with 0 or 1 sepc and a space
end
Line 3,357 ⟶ 3,449:
 
if #z.maintenance_cats ~= 0 then
text = text .. '<span class="citation-comment" style="display:none; color:#33aa33; margin-left:0.3em">';
for _, v in ipairs( z.maintenance_cats ) do -- append maintenance categories
text = text .. ' ' .. v .. ' ([[:Category:' .. v ..'|link]])';
end
text = text .. '</span>'; -- maintenance mesages (realy just the names of the categories for now)
end
Line 3,379 ⟶ 3,471:
return text
end
 
 
--[[--------------------------< C S 1 . C I T A T I O N >------------------------------------------------------
Line 3,431 ⟶ 3,524:
z = utilities.z; -- table of error and category tables in Module:Citation/CS1/Utilities
 
extract_ids = identifiers.extract_ids; -- imported functions from Module:Citation/CS1/UtilitiesIdentifiers
build_id_list = identifiers.build_id_list;
is_embargoed = identifiers.is_embargoed;
Line 3,440 ⟶ 3,533:
COinS = metadata.COinS;
 
local args = {}; -- table where we store all of the template's arguments
local args = {};
local suggestions = {}; -- table where we store suggestions if we need to loadData them
local error_text, error_state;
 
local config = {}; -- table to store parameters from the module {{#invoke:}}
for k, v in pairs( frame.args ) do
config[k] = v;
-- args[k] = v; -- debug tool that allows us to render a citation from module {{#invoke:}}
args[k] = v;
end
 
Line 3,453 ⟶ 3,546:
for k, v in pairs( pframe.args ) do
if v ~= '' then
if not validate( k, config.CitationClass ) then
error_text = "";
if type( k ) ~= 'string' then
Line 3,460 ⟶ 3,553:
error_text, error_state = set_error( 'text_ignored', {v}, true );
end
elseif validate( k:lower(), config.CitationClass ) then
error_text, error_state = set_error( 'parameter_ignored_suggest', {k, k:lower()}, true );
else
Line 3,482 ⟶ 3,575:
else
error_text, error_state = set_error( 'parameter_ignored', {k}, true );
v = ''; -- unset value assigned to unrecognized parameters (this for the limited parameter lists)
end
end
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.