ಮಾಡ್ಯೂಲ್:Citation/CS1: ಪರಿಷ್ಕರಣೆಗಳ ನಡುವಿನ ವ್ಯತ್ಯಾಸ
Content deleted Content added
No edit summary |
Reverted to revision 765808 by Omshivaprakash (talk): Testing arguments module for Citation/CS1. (TW) |
||
೧೨ ನೇ ಸಾಲು:
local z ={}; -- tables in Module:Citation/CS1/Utilities
local extract_ids, extract_id_access_levels, build_id_list, is_embargoed;
local make_coins_title, get_coins_pages, COinS; -- functions in Module:Citation/CS1/COinS
೪೦೭ ನೇ ಸಾಲು:
end
if is_set (access) then -- access level (subscription, registration, limited)
local label_head = '';
local label_tail;
local markup = ''; -- can't start a span inside italic markup and end it outside the italic markup
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 ೬೮೮ ⟶ ೭೧೬:
-- maybe let through instead of raising an error?
-- v, origin[k] = args[k], k;
end
Line ೭೦೪ ⟶ ೭೩೨:
--[[--------------------------< V A L I D A T E >--------------------------------------------------------------
Looks for a parameter's name in one of several whitelists.
Parameters in the whitelist can have three values:
Line ೭೧೩ ⟶ ೭೪೨:
]]
--local function validate( name )
local function validate( name, cite_class )
local name = tostring( name );
local state
if in_array (cite_class, {'arxiv', 'biorxiv', 'citeseerx'}) then -- limited parameter sets allowed for these templates
state = whitelist.limited_basic_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
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#
state = whitelist.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; --
end
Line ೯೫೩ ⟶ ೧,೦೧೯:
if name then -- if first is initials with or without suffix
if 3 >
if suffix then -- if there is a suffix
if is_suffix (suffix) then -- is it legitimate?
Line ೧,೧೩೮ ⟶ ೧,೨೦೪:
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 ೧,೧೫೦ ⟶ ೧,೨೫೩:
local count, _;
if is_set (name) then
if 1 < count then -- param could be |author= or |editor= so one separator 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
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 ೧,೧೯೯ ⟶ ೧,೩೨೫:
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.
if first and not last then -- if there is a firstn without a matching lastn
Line ೧,೨೪೭ ⟶ ೧,೩೭೨:
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 ೧,೨೬೧ ⟶ ೧,೩೯೦:
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 ೧,೩೦೭ ⟶ ೧,೪೩೭:
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 ೧,೭೧೪ ⟶ ೧,೮೪೫:
local function terminate_name_list (name_list, sepc)
if
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 ೧,೮೮೪ ⟶ ೨,೦೧೭:
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 ೧,೮೯೧ ⟶ ೨,೦೨೪:
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 ೧,೯೯೧ ⟶ ೨,೧೨೬:
end
local Others = A['Others'];
Line ೨,೦೧೫ ⟶ ೨,೧೪೯:
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 ೨,೧೮೪ ⟶ ೨,೩೨೫:
no_tracking_cats = nil; -- set to empty string
end
--local variables that are not cs1 parameters
Line ೨,೩೦೨ ⟶ ೨,೪೩೮:
end
end
end
Line ೨,೪೪೧ ⟶ ೨,೫೫೩:
-- end of {{cite episode}} stuff
-- Account for the oddities that are {{cite arxiv}}, {{cite biorxiv}}, {{cite citeseerx}}, before generation of COinS data.
do
if in_array (config.CitationClass, {'arxiv', 'biorxiv', 'citeseerx'}) then
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( config.CitationClass .. '_missing', {}, true ) } ); -- add error message
end
if 'arxiv' == config.CitationClass then
Periodical = 'arXiv'; -- set to arXiv for COinS; after that, must be set to empty string
end
if 'biorxiv' == config.CitationClass then
Periodical = 'bioRxiv'; -- set to bioRxiv for COinS; after that, must be set to empty string
end
if 'citeseerx' == config.CitationClass then
Periodical = 'CiteSeerX'; -- set to CiteSeerX for COinS; after that, must be set to empty string
end
end
end
Line ೨,೫೦೫ ⟶ ೨,೬೦೯:
['embargo']=Embargo, ['lay-date']=LayDate, ['publication-date']=PublicationDate, ['year']=Year};
if is_set (Year) and is_set (Date) then -- both |date= and |year= not normally needed;
Line ೨,೬೨೫ ⟶ ೨,೭೨೯:
-- Account for the oddities that are {{cite arxiv}}, AFTER generation of COinS data.
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 these templates; if article has been published, use cite journal
end
Line ೨,೬೫೨ ⟶ ೨,೭೫೭:
};
do -- do editor name list first because the now unsupported coauthors
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 ೨,೬೭೦ ⟶ ೨,೭೭೫:
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 ೨,೬೮೨ ⟶ ೨,೭೯೧:
control.maximum , author_etal = get_display_authors_editors (A['DisplayAuthors'], #a, 'authors', author_etal);
last_first_list = list_people(control, a, author_etal);
Line ೨,೭೦೩ ⟶ ೨,೮೦೭:
end
end
Line ೨,೭೧೭ ⟶ ೨,೮೧೮:
-- 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 ೨,೭೬೦ ⟶ ೨,೮೬೧:
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 ೨,೮೦೮ ⟶ ೨,೯೦೯:
end
if in_array(config.CitationClass, {'web', 'news', 'journal', 'magazine', 'pressrelease', 'podcast', 'newsgroup', 'mailinglist', 'interview', 'arxiv', '
('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 ೨,೮೩೨ ⟶ ೨,೯೩೩:
end
end
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 ೨,೮೫೪ ⟶ ೨,೯೫೩:
Format = "";
else
Title = Title .. TransTitle .. TransError;
end
end
Line ೩,೦೦೬ ⟶ ೩,೧೦೫:
if is_set(URL) then
URL = " " .. external_link( URL, nil, URLorigin,
end
Line ೩,೨೦೧ ⟶ ೩,೩೦೦:
end
if is_set(Authors) then
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 ೩,೨೩೬ ⟶ ೩,೩೨೮:
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
Authors = terminate_name_list (Authors, sepc); -- terminate with 0 or 1 sepc and a space
end
Line ೩,೩೫೭ ⟶ ೩,೪೪೯:
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
end
text = text .. '</span>'; -- maintenance mesages (realy just the names of the categories for now)
end
Line ೩,೩೭೯ ⟶ ೩,೪೭೧:
return text
end
--[[--------------------------< C S 1 . C I T A T I O N >------------------------------------------------------
Line ೩,೪೩೧ ⟶ ೩,೫೨೪:
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/
build_id_list = identifiers.build_id_list;
is_embargoed = identifiers.is_embargoed;
Line ೩,೪೪೦ ⟶ ೩,೫೩೩:
COinS = metadata.COinS;
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 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:}}
end
Line ೩,೪೫೩ ⟶ ೩,೫೪೬:
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 ೩,೪೬೦ ⟶ ೩,೫೫೩:
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 ೩,೪೭೦ ⟶ ೩,೫೬೩:
end
end
v = ''; -- unset value assigned to unrecognized parameters (this for the limited parameter lists)
end
end
if error_text ~= '' then
|