Module:Citation/CS1: Difference between revisions

Synch from sandbox;
m (1 revision imported: cite web)
(Synch from sandbox;)
Line 22:
--[[--------------------------< P A G E S C O P E V A R I A B L E S >--------------------------------------
 
delare variables here that have page-wide scope that are not brought in from other modules; thatare created here
and used here
 
]]
 
local Preview_mode = falseadded_deprecated_cat; -- boolean flag indicatingso that we are rendering athe previewcategory pageis (Showadded previewonly button)once
local added_prop_cats = {}; -- list of property categories that have been added to z.properties_cats
local added_vanc_errs; -- boolean flag so we only emit one Vancouver error / category
 
local Frame; -- holds the module's frame table
 
 
--[[--------------------------< F I R S T _ S E T >------------------------------------------------------------
Line 52 ⟶ 58:
 
Adds a category to z.properties_cats using names from the configuration file with additional text if any.
 
added_prop_cats is a table declared in page scope variables above
 
]]
 
local added_prop_cats = {} -- list of property categories that have been added to z.properties_cats
local function add_prop_cat (key, arguments)
if not added_prop_cats [key] then
Line 67 ⟶ 74:
Adds a single Vancouver system error message to the template's output regardless of how many error actually exist.
To prevent duplication, added_vanc_errs is nil until an error message is emitted.
 
added_vanc_errs is a boolean declared in page scope variables above
 
]]
 
local added_vanc_errs; -- flag so we only emit one Vancouver error / category
local function add_vanc_error (source)
if not added_vanc_errs then
Line 407 ⟶ 415:
offending parameter name to the error message. Only one error message is emitted regardless of the number of deprecated
parameters in the citation.
 
added_deprecated_cat is a boolean declared in page scope variables above
 
]]
 
local page_in_deprecated_cat; -- sticky flag so that the category is added only once
local function deprecated_parameter(name)
if not page_in_deprecated_catadded_deprecated_cat then
page_in_deprecated_catadded_deprecated_cat = true; -- note that we've added this category
table.insert( z.message_tail, { set_error( 'deprecated_params', {name}, true ) } ); -- add error message
end
Line 425 ⟶ 434:
" 'Kerned title with leading and trailing single quote marks' " (in real life the kerning isn't as wide as this example)
Double single quotes (italic or bold wikimarkup) are not kerned.
 
Replaces unicode quotemarks with typewriter quote marks regardless of the need for kerning.
 
Call this function for chapter titles, for website titles, etc; not for book titles.
Line 433 ⟶ 444:
local cap='';
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 887 ⟶ 901:
to use an external editor to maintain this code.
 
\195\128-\195\150 – À-Ö (U+00C0–U+00D6 – C0 controls)
\195\152-\195\182 – Ø-ö (U+00D8-U+00F6 – C0 controls)
\195\184-\198\191 – ø-ƿ (U+00F8-U+01BF – C0 controls, Latin extended A & B)
\199\132-\201\143 – DŽ-ɏ% (U+01C4-U+024F – Latin extended B)
 
]]
Line 966 ⟶ 980:
end
-- for word in mw.ustring.gmatch(first, "[^%s%.%-]+") do -- names separated by spaces, hyphens, or periods
-- table.insert(initials, mw.ustring.sub(word,1,1)) -- Vancouver format does not include full stops.
-- i = i + 1; -- bump the counter
-- if 2 <= i then break; end -- only two initials allowed in Vancouver system; if 2, quit
-- end
return table.concat(initials) -- Vancouver format does not include spaces.
end
Line 1,477 ⟶ 1,486:
end
 
--[[--------------------------< G E T _ V _ N A M E _ T A B L E >----------------------------------------------
 
split apart a |vautthors= 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 parnetheses were included in the
rendered citation and in the metadata.
 
|vauthors=Jones AB, White EB, ((Black, Brown, and Co.))
 
This code is experimental and may not be retained.
 
]]
local function get_v_name_table (vparam, output_table)
local name_table = mw.text.split(vparam, "%s*,%s*"); -- names are separated by commas
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 parens
local name = name_table[i];
i=i+1; -- bump indexer to next segment
while name_table[i] do
name = name .. ', ' .. name_table[i]; -- concatenate with previous segments
if name_table[i]:match ('^.*%)%)$') then -- if this table member has the closing doubled parens
break; -- and done reassembling so
end
i=i+1; -- bump indexer
end
table.insert (output_table, name); -- and add corporate name to the output table
else
table.insert (output_table, name_table[i]); -- add this name
end
i = i+1;
end
return output_table;
end
 
--[[--------------------------< P A R S E _ V A U T H O R S _ V E D I T O R S >--------------------------------
Line 1,504 ⟶ 1,548:
add_vanc_error ('wikilink');
end
v_name_table = mw.text.splitget_v_name_table (vparam, "%s*,%s*"v_name_table) ; -- names are separated by commas
 
for i, v_name in ipairs(v_name_table) do
Line 1,544 ⟶ 1,588:
end
else
if not corporate then
is_good_vanc_name (last, '');
is_good_vanc_name (last, '');
end
end
-- this from extract_names ()
link = select_one( args, cfg.aliases[list_name .. '-Link'], 'redundant_parameters', i );
Line 1,555 ⟶ 1,599:
return names, etal; -- all done, return our list of names
end
 
 
--[[--------------------------< S E L E C T _ A U T H O R _ E D I T O R _ S O U R C E >------------------------
Line 1,576 ⟶ 1,621:
local function select_author_editor_source (vxxxxors, xxxxors, args, list_name)
local lastfirst = false;
if select_one( args, cfg.aliases[list_name .. '-Last'], 'none', 1 ) or -- do this twice incase we have a first 1|first1= without a |last1=; this ...
select_one( args, cfg.aliases[list_name .. '-LastFirst'], 'none', 21 ) thenor -- ... also catches the case where |first= is used with |vauthors=
select_one( args, cfg.aliases[list_name .. '-Last'], 'none', 2 ) or
select_one( args, cfg.aliases[list_name .. '-First'], 'none', 2 ) then
lastfirst=true;
end
Line 1,661 ⟶ 1,708:
end
end
 
local vol = '';
Line 1,668 ⟶ 1,715:
vol = substitute (cfg.messages['j-vol'], {sepc, volume});
else
vol = wrap_stylesubstitute (cfg.presentation['vol-bold'], {sepc, hyphen_to_dash(volume)});
end
end
Line 1,676 ⟶ 1,723:
return vol;
end
 
 
 
 
 
 
Line 1,699 ⟶ 1,742:
end
]]
 
 
--[[-------------------------< F O R M A T _ P A G E S _ S H E E T S >-----------------------------------------
Line 1,795 ⟶ 1,839:
 
if url:match('//web%.archive%.org/save/') then -- if a save command url, we don't want to allow saving of the target page
err_msg = 'save command';
table.insert( z.message_tail, { set_error( 'archive_url', {'save command'}, true ) } ); -- add error message
url = url:gsub ('(//web%.archive%.org)/save/', '%1/*/', 1); -- for preview mode: modify ArchiveURL
if Preview_mode then
else
return url:gsub ('(//web%.archive%.org)/save/', '%1/*/', 1), date; -- preview mode: modify and return ArchiveURL and ArchiveDate
path, timestamp, flag = url:match('//web%.archive%.org/([^%d]*)(%d+)([^/]*)/'); -- split out some of the url parts for evaluation
if not is_set(timestamp) or 14 ~= timestamp:len() then -- path and flag optional, must have 14-digit timestamp here
err_msg = 'timestamp';
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)
end
elseif is_set(path) and 'web/' ~= path then -- older archive urls do not have the extra 'web/' path element
err_msg = 'path';
elseif is_set (flag) and not is_set (path) then -- flag not allowed with the old form url (without the 'web/' path element)
err_msg = 'flag';
elseif is_set (flag) and not flag:match ('%a%a_') then -- flag if present must be two alpha characters and underscore (requires 'web/' path element)
err_msg = 'flag';
else
return ''url, ''date; -- return empty strings for archiveURL and ArchiveDate
end
end
-- if here, something not right so
 
table.insert( z.message_tail, { set_error( 'archive_url', {err_msg}, true ) } ); -- add error message and
-- if url:match('//web%.archive%.org/web/%*/') or url:match('//web%.archive%.org/%*/') then -- wildcard with or without 'web/' path element
if is_set (Frame:preprocess('{{REVISIONID}}')) then
-- table.insert( z.message_tail, { set_error( 'archive_url', {'wildcard'}, true ) } ); -- add error message and
-- return '', ''; -- return empty strings for archiveURL and ArchiveDate
-- end
path, timestamp, flag = url:match('//web%.archive%.org/([^%d]*)(%d+)([^/]*)/'); -- split out some of the url parts for evaluation
if not is_set(timestamp) or 14 ~= timestamp:len() then -- path and flag optional, must have 14-digit timestamp here
err_msg = 'timestamp';
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)
end
elseif is_set(path) and 'web/' ~= path then -- older archive urls do not have the extra 'web/' path element
err_msg = 'path';
elseif is_set (flag) and not is_set (path) then -- flag not allowed with the old form url (without the 'web/' path element)
err_msg = 'flag';
elseif is_set (flag) and not flag:match ('%a%a_') then -- flag if present must be two alpha characters and underscore (requires 'web/' path element)
err_msg = 'flag';
else
return url, date; -- return archiveURL and ArchiveDate
end
-- if here something not right so
table.insert( z.message_tail, { set_error( 'archive_url', {err_msg}, true ) } ); -- add error message and
if Preview_mode then
return url, date; -- preview mode so return archiveURL and ArchiveDate
else
return '', ''; -- return empty strings for archiveURL and ArchiveDate
end
end
Line 1,890 ⟶ 1,925:
elseif 3 == selected then
Authors = A['Authors']; -- use content of |authors=
if 'authors' == A:ORIGIN('Authors') then -- but add a maint cat if the parameter is |authors=
add_maint_cat ('authors'); -- because use of this parameter is discouraged; what to do about the aliases is a TODO:
end
end
if is_set (Collaboration) then
Line 1,912 ⟶ 1,950:
elseif 3 == selected then
Editors = A['Editors']; -- use content of |editors=
add_maint_cat ('editors'); -- but add a maint cat because use of this parameter is discouraged
end
end
Line 2,178 ⟶ 2,217:
-- Special case for cite techreport.
if (config.CitationClass == "techreport") then -- special case for cite techreport
if is_set(A['Number']) then -- cite techreport uses 'number', which other citations alias to 'issue'
if not is_set(ID) then -- can we use ID for the "number"?
ID = A['Number']; -- yes, use it
else -- ID has a value so emit error message
table.insert( z.message_tail, { set_error('redundant_parameters', {wrap_style ('parameter', 'id') .. ' and ' .. wrap_style ('parameter', 'number')}, true )});
Line 2,187 ⟶ 2,226:
end
 
-- special case for cite interview -- TODO: make cite interveiw not need special cases
if (config.CitationClass == "interview") then
if is_set(Program) then
Line 2,209 ⟶ 2,248:
if is_set(Others) then
if is_set(TitleType) then
Others = ' 'substitute (cfg.. TitleType .. messages[' with interview-type'], ..{TitleType, Others});
TitleType = '';
else
Others = ' 'substitute (cfg.. messages['Interview with interview' ..], Others;)
end
else
Others = cfg.title_types ['(Interview)interview'];
end
end
Line 2,342 ⟶ 2,381:
end
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
ID_list['ASIN'], ID_list['BIBCODE'], ID_list['DOI'], ID_list['ISBN'], ID_list['ISSN'], -- TODO: find a better way to do this
ID_list['JFM'], ID_list['JSTOR'], ID_list['LCCN'], ID_list['MR'], ID_list['OCLC'], ID_list['OL'],
ID_list['OSTI'], ID_list['PMC'], ID_list['PMID'], ID_list['RFC'], ID_list['SSRN'], ID_list['USENETID'], ID_list['ZBL']},27) then
table.insert( z.message_tail, { set_error( 'arxiv_params_not_supported', {}, true ) } ); -- add error message
 
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 = '';
Line 2,362 ⟶ 2,402:
TitleType = set_titletype (config.CitationClass, TitleType);
if is_set(Degree) and "Thesis" == TitleType then -- special case for cite thesis
TitleType = Degree .. "' ' .. cfg.title_types ['thesis"']:lower();
end
end
Line 2,370 ⟶ 2,410:
end
 
-- legacy: promote concatenation of |month=, and |year= to Date if Date not set; or, promote PublicationDate to Date if neither Date nor Year are set.
if not is_set (Date) then
Date = Year; -- promote Year to Date
Line 2,430 ⟶ 2,470:
table.insert( z.message_tail, { set_error( 'bad_date', {error_message}, true ) } ); -- add this error message
end
 
-- if is_set(error_message) then
-- table.insert( z.message_tail, { set_error( 'bad_date', {error_message}, true ) } ); -- add this error message
-- elseif is_set (DF) then
-- if reformat_dates (date_parameters_list, DF, false) then -- reformat to DF format, use long month names if appropriate
-- AccessDate = date_parameters_list['access-date']; -- overwrite date holding parameters with reformatted values
-- ArchiveDate = date_parameters_list['archive-date'];
-- Date = date_parameters_list['date'];
-- DoiBroken = date_parameters_list['doi-broken-date'];
-- LayDate = date_parameters_list['lay-date'];
-- PublicationDate = date_parameters_list['publication-date'];
-- end
-- end
end -- end of do
 
Line 2,453 ⟶ 2,480:
URL=cfg.id_handlers['PMC'].prefix .. ID_list['PMC']; -- set url to be the same as the PMC external link if not embargoed
URLorigin = cfg.id_handlers['PMC'].parameters[1]; -- set URLorigin to parameter name for use in error message if citation is missing a |title=
if is_set(AccessDate) then -- access date requires |url=; pmc created url is not |url=
table.insert( z.message_tail, { set_error( 'accessdate_missing_url', {}, true ) } );
AccessDate = ''; -- unset
end
 
end
end
Line 2,541 ⟶ 2,573:
do
local last_first_list;
-- local maximum;
local control = {
format = NameListFormat, -- empty string or 'vanc'
Line 2,631 ⟶ 2,662:
end
 
local OriginalURL, OriginalURLorigin, OriginalFormat; -- TODO: swap chapter and title here so that archive applies to most specific if both are set?
DeadURL = DeadURL:lower(); -- used later when assembling archived text
if is_set( ArchiveURL ) then
if is_set (ChapterURL) then -- swapped -- URL not set so if chapter-url is set apply archive url to it
OriginalURL = ChapterURL; -- save copy of source chapter's url for archive text
OriginalURLorigin = ChapterURLorigin; -- name of chapter-url parameter for error messages
Line 2,708 ⟶ 2,739:
Title = kern_quotes (Title); -- if necessary, separate title's leading and trailing quote marks from Module provided quote marks
Title = wrap_style ('quoted-title', Title);
Title = script_concatenate (Title, ScriptTitle); -- <bdi> tags, lang atribute, categorization, etc; must be done after title is wrapped
TransTitle= wrap_style ('trans-quoted-title', TransTitle );
Line 2,822 ⟶ 2,852:
if is_set (Translators) then
-- Others = sepc .. ' Translated by ' .. Translators .. Others;
Others = sepc .. ' ' .. wrap_msg ('translated', Translators, use_lowercase) .. Others;
end
Line 2,908 ⟶ 2,937:
local arch_text = cfg.messages['archived-dead'];
if sepc ~= "." then arch_text = arch_text:lower() end
if in_array (DeadURL, {'unfit', 'usurped', 'bot: unknown'}) then
Archived = sepc .. " " .. 'Archived from the original on ' .. ArchiveDate; -- format already styled
if 'bot: unknown' == DeadURL then
add_maint_cat ('bot:_unknown'); -- and add a category if not already added
else
add_maint_cat ('unfit'); -- and add a category if not already added
end
else -- DeadURL is empty, 'yes', 'true', or 'y'
Archived = sepc .. " " .. substitute( arch_text,
Line 2,953 ⟶ 2,987:
 
local Publisher;
if is_set(PeriodicalPublicationDate) andthen
PublicationDate = wrap_msg ('published', PublicationDate);
not in_array(config.CitationClass, {"encyclopaedia","web","pressrelease","podcast"}) then
end
if is_set(PublisherName) then
if is_set(PublicationPlacePublisherName) then
Publisher =if is_set(PublicationPlace) .. ": " .. PublisherName;then
Publisher = sepc .. " " .. PublicationPlace .. ": " .. PublisherName .. PublicationDate;
else
else
Publisher = PublisherName;
Publisher = sepc .. " " .. PublisherName .. PublicationDate;
end
end
elseif is_set(PublicationPlace) then
Publisher= elseif is_set(PublicationPlace;) then
Publisher= sepc .. " " .. PublicationPlace .. PublicationDate;
else
else
Publisher = "";
Publisher = PublicationDate;
end
if is_set(PublicationDate) then
if is_set(Publisher) then
Publisher = Publisher .. ", " .. wrap_msg ('published', PublicationDate);
else
Publisher = PublicationDate;
end
end
if is_set(Publisher) then
Publisher = " (" .. Publisher .. ")";
end
else
if is_set(PublicationDate) then
PublicationDate = " (" .. wrap_msg ('published', PublicationDate) .. ")";
end
if is_set(PublisherName) then
if is_set(PublicationPlace) then
Publisher = sepc .. " " .. PublicationPlace .. ": " .. PublisherName .. PublicationDate;
else
Publisher = sepc .. " " .. PublisherName .. PublicationDate;
end
elseif is_set(PublicationPlace) then
Publisher= sepc .. " " .. PublicationPlace .. PublicationDate;
else
Publisher = PublicationDate;
end
end
Line 3,232 ⟶ 3,241:
 
function cs1.citation(frame)
Frame = frame; -- save a copy incase we need to display an error message in preview mode
local pframe = frame:getParent()
local validation, utilities, identifiers, metadata;
Line 3,283 ⟶ 3,293:
COinS = metadata.COinS;
 
Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id
if is_set (Preview_mode) then -- if there is a value then this is not a preiview
Preview_mode = false;
else
Preview_mode = true; -- no value (nil or empty string) so this is a preview
end
local args = {};
local suggestions = {};
Anonymous user