Module:Citation/CS1: Difference between revisions

Synch from sandbox;
m>Trappist the monk
(Synch from sandbox;)
m>Trappist the monk
(Synch from sandbox;)
Line 41: Line 41:
details of which parameter caused the error message are not provided.  Only one error message is emitted regardless of the number of deprecated parameters in the citation.
details of which parameter caused the error message are not provided.  Only one error message is emitted regardless of the number of deprecated parameters in the citation.
]]
]]
function deprecated_parameter()
function deprecated_parameter(name)
if true ~= Page_in_deprecated_cat then -- if we haven't been here before then set a  
if true ~= Page_in_deprecated_cat then -- if we haven't been here before then set a  
Page_in_deprecated_cat=true; -- sticky flag so that if there are more than one deprecated parameter the category is added only once
Page_in_deprecated_cat=true; -- sticky flag so that if there are more than one deprecated parameter the category is added only once
table.insert( z.message_tail, { seterror( 'deprecated_params', {}, true ) } ); -- add error message
table.insert( z.message_tail, { seterror( 'deprecated_params', {name}, true ) } ); -- add error message
end
end
end
end
Line 288: Line 288:
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
deprecated_parameter (); -- parameter is deprecated but still supported
deprecated_parameter (name); -- parameter is deprecated but still supported
return true;
return true;
end
end
Line 297: Line 297:
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
deprecated_parameter (); -- parameter is deprecated but still supported
deprecated_parameter (name); -- parameter is deprecated but still supported
return true;
return true;
end
end
Line 428: Line 428:
err_cat =  ' ' .. seterror ('bad_asin'); -- asin is not a mix of 10 uppercase alpha and numeric characters
err_cat =  ' ' .. seterror ('bad_asin'); -- asin is not a mix of 10 uppercase alpha and numeric characters
else
else
if id:match("^%d%d%d%d%d%d%d%d%d%d$") then -- if 10-digit numeric
if id:match("^%d%d%d%d%d%d%d%d%d[%dX]$") then -- if 10-digit numeric (or 9 digits with terminal X)
if checkisbn( id ) then -- see if asin value is isbn10
if checkisbn( id ) then -- see if asin value is isbn10
table.insert( z.maintenance_cats, "CS1 maint: ASIN uses ISBN"); -- add to maint category
table.insert( z.maintenance_cats, "CS1 maint: ASIN uses ISBN"); -- add to maint category
Line 451: Line 451:
end
end


--[[
--[[--------------------------< A R X I V >--------------------------------------------------------------------
format and error check arXiv identifier.  There are two valid forms of the identifier:
 
See: http://arxiv.org/help/arxiv_identifier
 
format and error check arXiv identifier.  There are three valid forms of the identifier:
the first form, valid only between date codes 9108 and 0703 is:
the first form, valid only between date codes 9108 and 0703 is:
arXiv:<archive>.<class>/<date code><number><version>
arXiv:<archive>.<class>/<date code><number><version>
Line 463: Line 466:
<version> is a 1 or more digit number preceded with a lowercase v; no spaces (undocumented)
<version> is a 1 or more digit number preceded with a lowercase v; no spaces (undocumented)
the second form, valid from April 2007 is:
the second form, valid from April 2007 through December 2014 is:
arXiv:<date code>.<number><version>
arXiv:<date code>.<number><version>
where:
where:
Line 469: Line 472:
<number> is a four-digit number
<number> is a four-digit number
<version> is a 1 or more digit number preceded with a lowercase v; no spaces
<version> is a 1 or more digit number preceded with a lowercase v; no spaces
the third form, valid from January 2015 is:
arXiv:<date code>.<number><version>
where:
<date code> and <version> are as defined for 0704-1412
<number> is a five-digit number
]]
]]


Line 476: Line 485:
local err_cat = ""
local err_cat = ""
year, month, version = id:match("^%a[%a%.%-]+/([90]%d)([01]%d)%d%d%d([v%d]*)$"); -- test for the 9108-0703 format
if id:match("^%a[%a%.%-]+/[90]%d[01]%d%d%d%d$") or id:match("^%a[%a%.%-]+/[90]%d[01]%d%d%d%dv%d+$") then -- test for the 9108-0703 format w/ & w/o version
if not year then -- arXiv id is not proper 9108-0703 form
year, month = id:match("^%a[%a%.%-]+/([90]%d)([01]%d)%d%d%d[v%d]*$");
year, month, version = id:match("^(%d%d)([01]%d)%.%d%d%d%d([v%d]*)$"); -- test for the 0704- format
year = tonumber(year);
if not year then
month = tonumber(month);
err_cat = ' ' .. seterror( 'bad_arxiv' ); -- arXiv id doesn't match either format
if ((not (90 < year or 8 > year)) or (1 > month or 12 < month)) or -- if invalid year or invalid month
else -- id is the 0704- format
((91 == year and 7 > month) or (7 == year and 3 < month)) then -- if years ok, are starting and ending months ok?
year = tonumber(year);
err_cat = ' ' .. seterror( 'bad_arxiv' ); -- set error message
month = tonumber(month);
end
if ((7 > year) or (1 > month and 12 < month)) or -- is year invalid or is month invalid? (doesn't test for future years)
elseif id:match("^%d%d[01]%d%.%d%d%d%d$") or id:match("^%d%d[01]%d%.%d%d%d%dv%d+$") then -- test for the 0704-1412 w/ & w/o version
((7 == year) and (4 > month)) or -- when year is 07, is month invalid (before April)?
year, month = id:match("^(%d%d)([01]%d)%.%d%d%d%d[v%d]*$");
is_set (version) and nil == version:match("v%d+") then -- is version proper format of single 'v' followed by digits?
year = tonumber(year);
err_cat = ' ' .. seterror( 'bad_arxiv' ); -- set error message
month = tonumber(month);
end
if ((7 > year) or (14 < year) or (1 > month or 12 < month)) or -- is year invalid or is month invalid? (doesn't test for future years)
((7 == year) and (4 > month)) then --or -- when year is 07, is month invalid (before April)?
err_cat = ' ' .. seterror( 'bad_arxiv' ); -- set error message
end
end
else -- id is the 9108-0703 format; are the date values ok
elseif id:match("^%d%d[01]%d%.%d%d%d%d%d$") or id:match("^%d%d[01]%d%.%d%d%d%d%dv%d+$") then -- test for the 1501- format w/ & w/o version
year, month = id:match("^(%d%d)([01]%d)%.%d%d%d%d%d[v%d]*$");
year = tonumber(year);
year = tonumber(year);
month = tonumber(month);
month = tonumber(month);
if ((91 > year and 7 < year) or (1 > month and 12 < month)) or -- if invalid year or invalid month
if ((15 > year) or (1 > month or 12 < month)) then -- is year invalid or is month invalid? (doesn't test for future years)
((91 == year and 8 > month) or (7 == year and 3 < month)) or -- if years ok, are starting and ending months ok?
err_cat = ' ' .. seterror( 'bad_arxiv' ); -- set error message
is_set (version) and nil == version:match("v%d+") then -- is version proper format of single 'v' followed by digits?
err_cat = ' ' .. seterror( 'bad_arxiv' ); -- set error message
end
end
else
err_cat = ' ' .. seterror( 'bad_arxiv' ); -- arXiv id doesn't match any format
end
end


Line 503: Line 515:
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat;
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat;
end
end


--[[
--[[
Line 789: Line 802:




--[[
--[[--------------------------< 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 citations that have defaults.
This function sets default title types (equivalent to the citation including |type=<default value>) for those citations that have defaults.
Also handles the special case where it is desirable to omit the title type from the rendered citation (|type=none).
Also handles the special case where it is desirable to omit the title type from the rendered citation (|type=none).
]]
]]
function set_titletype(cite_class, title_type)
function set_titletype(cite_class, title_type)
Line 803: Line 818:
if "AV-media-notes" == cite_class or "DVD-notes" == cite_class then -- if this citation is cite AV media notes or cite DVD notes
if "AV-media-notes" == cite_class or "DVD-notes" == cite_class then -- if this citation is cite AV media notes or cite DVD notes
return "Media notes"; -- display AV media notes / DVD media notes annotation
return "Media notes"; -- display AV media notes / DVD media notes annotation
elseif "mailinglist" == cite_class then -- if this citation is cite mailing list
return "Mailing list"; -- display mailing list annotation


elseif "podcast" == cite_class then -- if this citation is cite podcast
elseif "podcast" == cite_class then -- if this citation is cite podcast
Line 810: Line 828:
return "Press release"; -- display press release annotation
return "Press release"; -- display press release annotation


elseif "report" == cite_class then -- if this citation is cite report
return "Report"; -- display report annotation
elseif "techreport" == cite_class then -- if this citation is cite techreport
elseif "techreport" == cite_class then -- if this citation is cite techreport
return "Technical report"; -- display techreport annotation
return "Technical report"; -- display techreport annotation
Line 1,009: Line 1,030:
end
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.


TODO: safejoin() has a flaw where it won't remove the duplicate character from a |title= / |url= combination.
This is because by the time we get here, |title=http://somesite.com and |title=Document Title. have been combined:
[http://somesite.com and ''Document Title.'']
so that now, the last character is not sepc but is ] (unless sepc == ']' which breaks the external link)
]]
]]
function safejoin( tbl, duplicate_char )
function safejoin( tbl, duplicate_char )
Line 1,026: Line 1,044:
]]
]]
local str = '';
local str = ''; -- the output string
local comp = '';
local comp = ''; -- what does 'comp' mean?
local end_chr = '';
local end_chr = '';
local trim;
local trim;
Line 1,033: Line 1,051:
if value == nil then value = ''; end
if value == nil then value = ''; end
if str == '' then
if str == '' then -- if output string is empty
str = value;
str = value; -- assign value to it (first time through the loop)
elseif value ~= '' then
elseif value ~= '' then
if value:sub(1,1) == '<' then
if value:sub(1,1) == '<' then -- Special case of values enclosed in spans and other markup.
-- Special case of values enclosed in spans and other markup.
comp = value:gsub( "%b<>", "" ); -- remove html markup (<span>string</span> -> string)
comp = value:gsub( "%b<>", "" );
else
else
comp = value;
comp = value;
end
end
-- typically duplicate_char is sepc
if comp:sub(1,1) == duplicate_char then
if comp:sub(1,1) == duplicate_char then -- is first charactier same as duplicate_char? why test first character?
--  Because individual string segments often (always?) begin with terminal punct for th
--  preceding segment: 'First element' .. 'sepc next element' .. etc?
trim = false;
trim = false;
end_chr = str:sub(-1,-1);
end_chr = str:sub(-1,-1); -- get the last character of the output string
-- str = str .. "<HERE(enchr=" .. end_chr.. ")"
-- str = str .. "<HERE(enchr=" .. end_chr.. ")" -- debug stuff?
if end_chr == duplicate_char then
if end_chr == duplicate_char then -- if same as separator
str = str:sub(1,-2);
str = str:sub(1,-2); -- remove it
elseif end_chr == "'" then
elseif end_chr == "'" then -- if it might be wikimarkup
if str:sub(-3,-1) == duplicate_char .. "''" then
if str:sub(-3,-1) == duplicate_char .. "''" then -- if last three chars of str are sepc''
str = str:sub(1, -4) .. "''";
str = str:sub(1, -4) .. "''"; -- remove them and add back ''
elseif str:sub(-5,-1) == duplicate_char .. "]]''" then
elseif str:sub(-5,-1) == duplicate_char .. "]]''" then -- if last five chars of str are sepc]]''
trim = true;
trim = true; -- why? why do this and next differently from previous?
elseif str:sub(-4,-1) == duplicate_char .. "]''" then
elseif str:sub(-4,-1) == duplicate_char .. "]''" then -- if last four chars of str are sepc]''
trim = true; -- same question
end
elseif end_chr == "]" then -- if it might be wikimarkup
if str:sub(-3,-1) == duplicate_char .. "]]" then -- if last three chars of str are sepc]] wikilink
trim = true;
trim = true;
end
elseif str:sub(-2,-1) == duplicate_char .. "]" then -- if last two chars of str are sepc] external link
elseif end_chr == "]" then
if str:sub(-3,-1) == duplicate_char .. "]]" then
trim = true;
trim = true;
elseif str:sub(-2,-1) == duplicate_char .. "]" then
elseif str:sub(-4,-1) == duplicate_char .. "'']" then -- normal case when |url=something & |title=Title.
trim = true;
trim = true;
end
end
elseif end_chr == " " then
elseif end_chr == " " then -- if last char of output string is a space
if str:sub(-2,-1) == duplicate_char .. " " then
if str:sub(-2,-1) == duplicate_char .. " " then -- if last two chars of str are <sepc><space>
str = str:sub(1,-3);
str = str:sub(1,-3); -- remove them both
end
end
end
end


if trim then
if trim then
if value ~= comp then  
if value ~= comp then -- value does not equal comp when value contains html markup
local dup2 = duplicate_char;
local dup2 = duplicate_char;
if dup2:match( "%A" ) then dup2 = "%" .. dup2; end
if dup2:match( "%A" ) then dup2 = "%" .. dup2; end -- if duplicate_char not a letter then escape it
value = value:gsub( "(%b<>)" .. dup2, "%1", 1 )
value = value:gsub( "(%b<>)" .. dup2, "%1", 1 ) -- remove duplicate_char if it follows html markup
else
else
value = value:sub( 2, -1 );
value = value:sub( 2, -1 ); -- remove duplicate_char when it is first character
end
end
end
end
end
end
str = str .. value;
str = str .. value; --add it to the output string
end
end
end
end
Line 1,100: Line 1,121:
-- Formats a list of people (e.g. authors / editors)  
-- Formats a list of people (e.g. authors / editors)  
function listpeople(control, people)
function listpeople(control, people)
local sep = control.sep;
local sep;
local namesep = control.namesep
local namesep;
local format = control.format
local format = control.format
local maximum = control.maximum
local maximum = control.maximum
Line 1,107: Line 1,128:
local text = {}
local text = {}
local etal = false;
local etal = false;
if 'vanc' == format then -- Vancouver-like author/editor name styling?
sep = ','; -- name-list separator between authors is a comma
namesep = ' '; -- last/first separator is a space
else
sep = ';' -- name-list separator between authors is a semicolon
namesep = ', ' -- last/first separator is <comma><space>
end
if sep:sub(-1,-1) ~= " " then sep = sep .. " " end
if sep:sub(-1,-1) ~= " " then sep = sep .. " " end
Line 1,138: Line 1,167:
end
end


if is_set(person.link) and nil ~= person.link:find("//") then one = one .. " " .. seterror( 'bad_authorlink' ) end -- check for url in author link;
if is_set(person.link) and ((nil ~= person.link:find("//")) or (nil ~= person.link:find("[%[%]]"))) then
one = one .. " " .. seterror( 'bad_authorlink' ) end -- url or wikilink in author link;
end
end
table.insert( text, one )
table.insert( text, one )
Line 1,159: Line 1,189:
end
end
if ( "scap" == format ) then -- apply smallcaps formatting when authorformat or editorformat set to scap
result = substitute (cfg.presentation['smallcaps'], result);
end
return result, count
return result, count
end
end


-- Generates a CITEREF anchor ID.
--[[--------------------------< A N C H O R I D >--------------------------------------------------------------
function anchorid( options )
Generates a CITEREF anchor ID if we have at least one name or a date.  Otherwise returns an empty string.
return "CITEREF" .. table.concat( options );
 
end
]]
 
function anchorid( options )
local id = table.concat( options ); -- concatenate names and year for CITEREF id
if is_set (id) then -- if concatenation is not an empty string
return "CITEREF" .. id; -- add the CITEREF portion
else
return ''; -- return an empty string; no reason to include CITEREF id in this citation
end
end


--[[
--[[
Line 1,444: Line 1,480:


function get_iso639_code (lang)
function get_iso639_code (lang)
if 'Norwegian' == lang then
if 'norwegian' == lang:lower() then -- special case related to Wikimedia remap of code 'no' at Extension:CLDR
return lang, 'no'; -- special case related to Wikimedia remap of code 'no' at Extension:CLDR
return 'Norwegian', 'no'; -- Make sure rendered version is properly capitalized
end
end
Line 1,511: Line 1,547:
end
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.
]]
function get_settings_from_cite_class (ps, ref, cite_class)
local sep;
if (cite_class == "citation") then -- for citation templates (CS2)
sep = ','; -- set citation separator to its default (comma)
if not is_set (ps) then -- if |postscript= has not been set, set cs2 default
ps = ''; -- make sure it isn't nil
end
if not is_set (ref) then -- if |ref= is not set
ref = "harv"; -- set default |ref=harv
end
else -- not a citation template so CS1
sep = '.'; -- set cite xxx separator to its default (period)
if not is_set (ps) then -- if |postscript= has not been set
ps = '.'; -- set cs1 default
end
end
return sep, ps, ref -- return them all
end
--[[--------------------------< S E T _ S T Y L E >------------------------------------------------------------
Establish basic style settings to be used when rendering the citation.  Uses |mode= if set and valid or uses
config.CitationClass from the template's #invoke: to establish style.
]]


function set_style (mode, ps, ref, cite_class)
local sep;
if is_set (mode) then
if 'cs2' == mode then -- if this template is to be rendered in CS2 (citation) style
sep = ','; -- separate elements with a comma
if not is_set (ps) then -- unless explicitely set to something
ps = ''; -- make sure it isn't nil
end
if not is_set (ref) then -- unless explicitely set to something
ref = 'harv'; -- set so this template renders with CITEREF anchor id
end
elseif 'cs1' == mode then -- if this template is to be rendered in CS1 (cite xxx) style
sep = '.'; -- separate elements with a period
if not is_set (ps) then -- unless explicitely set to something
ps = '.'; -- terminate the rendered citation with a period
end
else -- anything but cs1 or cs2
table.insert( z.message_tail, { seterror( 'invalid_param_val', {'mode', mode}, true ) } ); -- add error message
sep, ps, ref = get_settings_from_cite_class (ps, ref, cite_class); -- get settings based on the template's CitationClass
end
else -- when |mode= empty or omitted
sep, ps, ref = get_settings_from_cite_class (ps, ref, cite_class); -- get settings based on the template's CitationClass
end
if 'none' == ps:lower() then -- if assigned value is 'none' then
ps = ''; -- set to empty string
end
return sep, ps, ref
end




Line 1,540: Line 1,637:
local Editors = A['Editors'];
local Editors = A['Editors'];
local e = extractnames( args, 'EditorList' );
local e = extractnames( args, 'EditorList' );
local NameListFormat = A['NameListFormat']; -- replaces |author-format= and |editor-format=
if is_set (NameListFormat) and ('vanc' ~= NameListFormat) then -- only accepted value for this parameter is 'vanc'
table.insert( z.message_tail, { seterror( 'invalid_param_val', {'name-list-format', NameListFormat}, true ) } ); -- not vanc so add error message
NameListFormat = ''; -- set to empty string
end


local Year = A['Year'];
local Year = A['Year'];
Line 1,592: Line 1,695:
local Format = A['Format'];
local Format = A['Format'];
local ChapterFormat = A['ChapterFormat'];
local ChapterFormat = A['ChapterFormat'];
local Ref = A['Ref'];
local DoiBroken = A['DoiBroken'];
local DoiBroken = A['DoiBroken'];
local ID = A['ID'];
local ID = A['ID'];
Line 1,602: Line 1,704:


local Quote = A['Quote'];
local Quote = A['Quote'];
local PostScript = A['PostScript'];


local LayURL = A['LayURL'];
local LayURL = A['LayURL'];
Line 1,609: Line 1,710:
local TranscriptURL = A['TranscriptURL']  
local TranscriptURL = A['TranscriptURL']  
local TranscriptURLorigin = A:ORIGIN('TranscriptURL'); -- get name of parameter that holds TranscriptURL
local TranscriptURLorigin = A:ORIGIN('TranscriptURL'); -- get name of parameter that holds TranscriptURL
local sepc = A['Separator'];


local LastAuthorAmp = A['LastAuthorAmp'];
local LastAuthorAmp = A['LastAuthorAmp'];
Line 1,625: Line 1,725:
local COinS_date; -- used in the COinS metadata
local COinS_date; -- used in the COinS metadata


-- Set postscript default.
-- set default parameter values defined by |mode= parameter. If |mode= is empty or omitted, use CitationClass to set these values
if not is_set (PostScript) then -- if |postscript= has not been set (Postscript is nil which is the default for {{citation}}) and
local sepc; -- separator between citation elements for CS1 a period, for CS2, a comma
if (config.CitationClass ~= "citation") then -- this template is not a citation template
local PostScript;
PostScript = '.'; -- must be a cite xxx template so set postscript to default (period)
local Ref;
end
sepc, PostScript, Ref = set_style (A['Mode']:lower(), A['PostScript'], A['Ref'], config.CitationClass);
else
use_lowercase = ( sepc == ',' ); -- used to control capitalization for certain static text
if PostScript:lower() == 'none' then -- if |postscript=none then
 
PostScript = ''; -- no postscript
--check this page to see if it is in one of the namespaces that cs1 is not supposed to add to the error categories.
end
end
 
--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 is_set(no_tracking_cats) then -- ignore if we are already not going to categorize this page
if not is_set(no_tracking_cats) then -- ignore if we are already not going to categorize this page
if inArray (this_page.nsText, cfg.uncategorized_namespaces) then
if inArray (this_page.nsText, cfg.uncategorized_namespaces) then
Line 1,675: Line 1,771:


All other combinations of |encyclopedia, |title, and |article are not modified
All other combinations of |encyclopedia, |title, and |article are not modified
TODO: script-title to script-chapter if and when we support script-chapter
]]
]]
if ( config.CitationClass == "encyclopaedia" ) then
 
local Encyclopedia = A['Encyclopedia'];
 
if ( config.CitationClass == "encyclopaedia" ) or ( config.CitationClass == "citation" and is_set (Encyclopedia)) then -- test code for citation
if is_set(Periodical) then -- Periodical is set when |encyclopedia is set
if is_set(Periodical) then -- Periodical is set when |encyclopedia is set
if is_set(Title) then
if is_set(Title) then
Line 1,684: Line 1,784:
ChapterURL = URL;
ChapterURL = URL;
Title = Periodical;
Title = Periodical;
ChapterFormat = Format;
Periodical = ''; -- redundant so unset
Periodical = ''; -- redundant so unset
TransTitle = ''; -- redundant so unset
TransTitle = ''; -- redundant so unset
URL = ''; -- redundant so unset
URL = ''; -- redundant so unset
Format = ''; -- redundant so unset
end
end
else -- |title not set
else -- |title not set
Line 1,693: Line 1,795:
end
end
end
end
end
--special cases for citation.
if (config.CitationClass == "citation") then -- for citation templates
if not is_set (Ref) then -- if |ref= is not set
Ref = "harv"; -- set default |ref=harv
end
if not is_set (sepc) then -- if |separator= is not set
sepc = ','; -- set citation separator to its default (comma)
end
else -- not a citation template
if not is_set (sepc) then -- if |separator= has not been set
sepc = '.'; -- set cite xxx separator to its default (period)
end
end
use_lowercase = ( sepc ~= '.' ); -- used to control capitalization for certain static text
-- check for special case where |separator=none
if 'none' == sepc:lower() then -- if |separator=none
sepc = ''; -- then set it to an empty string
end
end


Line 1,757: Line 1,839:
Others = '(Interview)';
Others = '(Interview)';
end
end
end
-- special case for cite mailing list
if (config.CitationClass == "mailinglist") then
Periodical = A ['MailingList'];
end
end


Line 1,768: Line 1,855:


-- 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.
--TODO: if this is only for {{cite conference}}, shouldn't we be checking? (if config.CitationClass=='conference' then ...)
if 'conference' == config.CitationClass then
if is_set(BookTitle) then
if is_set(BookTitle) then
Chapter = Title;
Chapter = Title;
ChapterLink = TitleLink;
-- ChapterLink = TitleLink; -- |chapterlink= is deprecated
TransChapter = TransTitle;
ChapterURL = URL;
Title = BookTitle;
ChapterURLorigin = URLorigin;
TitleLink = '';
URLorigin = '';
TransTitle = '';
ChapterFormat = Format;
TransChapter = TransTitle;
Title = BookTitle;
Format = '';
-- TitleLink = '';
TransTitle = '';
URL = '';
end
else
Conference = ''; -- not cite conference so make sure this is empty string
end
end


Line 1,844: Line 1,940:


-- At this point fields may be nil if they weren't specified in the template use.  We can use that fact.
-- At this point fields may be nil if they weren't specified in the template use.  We can use that fact.
-- Test if citation has no title
if not is_set(Title) and
-- not is_set(Periodical) and -- not a title
-- not is_set(Conference) and -- not a title
not is_set(TransTitle) and
not is_set(ScriptTitle) then
table.insert( z.message_tail, { seterror( 'citation_missing_title', {}, true ) } );
end
if 'none' == Title and is_set(Periodical) and not (( config.CitationClass == "encyclopaedia" ) or ( config.CitationClass == "citation" and is_set (Encyclopedia))) then -- special case
Title = ''; -- set title to empty string
table.insert( z.maintenance_cats, "CS1 maint: Untitled periodical"); -- add to maint category
end


-- COinS metadata (see <http://ocoins.info/>) for
-- COinS metadata (see <http://ocoins.info/>) for automated parsing of citation information.
-- automated parsing of citation information.
-- handle the oddity that is cite encyclopedia and {{citation |encyclopedia=something}}. Here we presume that
-- when Periodical, Title, and Chapter are all set, then Periodical is the book (encyclopedia) title, Title
-- is the article title, and Chapter is a section within the article.  So, we remap
local coins_chapter = Chapter; -- default assuming that remapping not required
local coins_title = Title; -- et tu
if 'encyclopaedia' == config.CitationClass or ('citation' == config.CitationClass and is_set (Encyclopedia)) then
if is_set (Chapter) and is_set (Title) and is_set (Periodical) then -- if all are used then
coins_chapter = Title; -- remap
coins_title = Periodical;
end
end
-- this is the function call to COinS()
-- this is the function call to COinS()
local OCinSoutput = COinS{
local OCinSoutput = COinS{
['Periodical'] = Periodical,
['Periodical'] = Periodical,
['Chapter'] = strip_apostrophe_markup (Chapter), -- Chapter stripped of bold / italic wikimarkup
['Chapter'] = strip_apostrophe_markup (coins_chapter), -- Chapter stripped of bold / italic wikimarkup
['Title'] = make_coins_title (Title, ScriptTitle), -- Title and ScriptTitle stripped of bold / italic wikimarkup
['Title'] = make_coins_title (coins_title, ScriptTitle), -- Title and ScriptTitle stripped of bold / italic wikimarkup
['PublicationPlace'] = PublicationPlace,
['PublicationPlace'] = PublicationPlace,
['Date'] = first_set(COinS_date, Date), -- COinS_date has correctly formatted date if Date is valid; any reason to keep Date here?  Should we be including invalid dates in metadata?
['Date'] = first_set(COinS_date, Date), -- COinS_date has correctly formatted date if Date is valid; any reason to keep Date here?  Should we be including invalid dates in metadata?
Line 1,876: Line 1,997:
]]
]]


-- special case for cite newsgroup.  Do this after COinS because we are modifying Publishername to include som static text
-- special case for cite newsgroup.  Do this after COinS because we are modifying Publishername to include some static text
if 'newsgroup' == config.CitationClass then
if 'newsgroup' == config.CitationClass then
if is_set (PublisherName) then
if is_set (PublisherName) then
Line 1,900: Line 2,021:


local control = {  
local control = {  
sep = A["AuthorSeparator"] .. " ",
format = NameListFormat, -- empty string or 'vanc'
namesep = (first_set(A["AuthorNameSeparator"], A["NameSeparator"]) or "") .. " ",
format = A["AuthorFormat"],
maximum = Maximum,
maximum = Maximum,
lastauthoramp = LastAuthorAmp,
lastauthoramp = LastAuthorAmp,
Line 1,933: Line 2,052:


local control = {  
local control = {  
sep = A["EditorSeparator"] .. " ",
format = NameListFormat, -- empty string or 'vanc'
namesep = (first_set(A["EditorNameSeparator"], A["NameSeparator"]) or "") .. " ",
format = A['EditorFormat'],
maximum = Maximum,
maximum = Maximum,
lastauthoramp = LastAuthorAmp,
lastauthoramp = LastAuthorAmp,
Line 1,967: Line 2,084:
if  not is_set(URL) and
if  not is_set(URL) and
not is_set(ArchiveURL) and
not is_set(ArchiveURL) and
not is_set(ConferenceURL) and
not is_set(ConferenceURL) and -- TODO: keep this here? conference as part of cite web or cite podcast?
not is_set(TranscriptURL) then
not is_set(TranscriptURL) then
-- Test if cite web or cite podcast |url= is missing or empty  
-- Test if cite web or cite podcast |url= is missing or empty  
if inArray(config.CitationClass, {"web","podcast"}) then
if inArray(config.CitationClass, {"web","podcast", "mailinglist"}) then
table.insert( z.message_tail, { seterror( 'cite_web_url', {}, true ) } );
table.insert( z.message_tail, { seterror( 'cite_web_url', {}, true ) } );
end
end
Line 1,986: Line 2,103:
end
end
end
end
 
--[[
-- Test if citation has no title
-- Test if citation has no title
if not is_set(Title) and
if not is_set(Title) and
not is_set(Periodical) and
-- not is_set(Periodical) and -- not a title
not is_set(Conference) and
-- not is_set(Conference) and -- not a title
not is_set(TransTitle) and
not is_set(TransTitle) and
not is_set(ScriptTitle) then
not is_set(ScriptTitle) then
Line 1,996: Line 2,113:
end
end
 
if 'none' == Title and is_set(Periodical) then -- special case
Title = ''; -- set title to empty string
table.insert( z.maintenance_cats, "CS1 maint: Untitled periodical"); -- add to maint category
end
]]
local OriginalURL;
local OriginalURL;
DeadURL = DeadURL:lower(); -- used later when assembling archived text
DeadURL = DeadURL:lower(); -- used later when assembling archived text
Line 2,015: Line 2,136:
end
end


if inArray(config.CitationClass, {"web","news","journal","pressrelease","conference","podcast", "newsgroup"}) or ('citation' == config.CitationClass and is_set (Periodical)) then
if inArray(config.CitationClass, {"web","news","journal","pressrelease","podcast", "newsgroup"}) or
if is_set (Chapter) or is_set (TransChapter) or is_set (ChapterURL)then -- chapter parameters not supported for these citation types
('citation' == config.CitationClass and is_set (Periodical) and not is_set (Encyclopedia)) then
table.insert( z.message_tail, { seterror( 'chapter_ignored', {}, true ) } ); -- add error message
if is_set (Chapter) or is_set (TransChapter) or is_set (ChapterURL)then -- chapter parameters not supported for these citation types
Chapter = ''; -- set to empty string to be safe with concatenation
table.insert( z.message_tail, { seterror( 'chapter_ignored', {}, true ) } ); -- add error message
TransChapter = '';
Chapter = ''; -- set to empty string to be safe with concatenation
ChapterURL = '';
TransChapter = '';
end
ChapterURL = '';
end
else -- otherwise, format chapter / article title
else -- otherwise, format chapter / article title
Chapter = format_chapter_title (Chapter, TransChapter, ChapterURL, ChapterURLorigin);
Chapter = format_chapter_title (Chapter, TransChapter, ChapterURL, ChapterURLorigin);
Line 2,038: Line 2,160:
end
end


if inArray(config.CitationClass, {"web","news","journal","pressrelease","conference","podcast", "newsgroup"}) or ('citation' == config.CitationClass and is_set (Periodical)) then
if inArray(config.CitationClass, {"web","news","journal","pressrelease","podcast", "newsgroup", "mailinglist"}) or
Title = kern_quotes (Title); -- if necessary, separate title's leading and trailing quote marks from Module provided quote marks
('citation' == config.CitationClass and is_set (Periodical) and not is_set (Encyclopedia)) then
Title = wrap_style ('quoted-title', Title);
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 );
elseif 'report' == config.CitationClass then -- no styling for cite report
Title = script_concatenate (Title, ScriptTitle); -- <bdi> tags, lang atribute, categorization, etc; must be done after title is wrapped
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 );
TransTitle= wrap_style ('trans-quoted-title', TransTitle ); -- for cite report, use this form for trans-title
else
else
Title = wrap_style ('italic-title', Title);
Title = wrap_style ('italic-title', Title);
Line 2,161: Line 2,287:
-- handle type parameter for those CS1 citations that have default values
-- handle type parameter for those CS1 citations that have default values


if inArray(config.CitationClass, {"AV-media-notes", "DVD-notes", "podcast", "pressrelease", "techreport", "thesis"}) then
if inArray(config.CitationClass, {"AV-media-notes", "DVD-notes", "mailinglist", "podcast", "pressrelease", "report", "techreport", "thesis"}) then
TitleType = set_titletype (config.CitationClass, TitleType);
TitleType = set_titletype (config.CitationClass, TitleType);
if is_set(Degree) and "Thesis" == TitleType then -- special case for cite thesis
if is_set(Degree) and "Thesis" == TitleType then -- special case for cite thesis
Line 2,196: Line 2,322:


]]
]]
if is_set(SubscriptionRequired) then
if inArray(SubscriptionRequired:lower(), {'yes', 'true', 'y'}) then
SubscriptionRequired = sepc .. " " .. cfg.messages['subscription']; -- subscription required message
SubscriptionRequired = sepc .. " " .. cfg.messages['subscription']; -- subscription required message
elseif is_set(RegistrationRequired) then
elseif inArray(RegistrationRequired:lower(), {'yes', 'true', 'y'}) then
SubscriptionRequired = sepc .. " " .. cfg.messages['registration']; -- registration required message
SubscriptionRequired = sepc .. " " .. cfg.messages['registration']; -- registration required message
else
SubscriptionRequired = ''; -- either or both might be set to something other than yes true y
end
end


Line 2,215: Line 2,343:
   if "thesis" == config.CitationClass and is_set(Docket) then
   if "thesis" == config.CitationClass and is_set(Docket) then
ID = sepc .." Docket ".. Docket .. ID;
ID = sepc .." Docket ".. Docket .. ID;
end
  if "report" == config.CitationClass and is_set(Docket) then -- for cite report when |docket= is set
ID = sepc .. ' ' .. Docket; -- overwrite ID even if |id= is set
end
end


Line 2,371: Line 2,502:
if is_set(Authors) then
if is_set(Authors) then
if is_set(Coauthors) then
if is_set(Coauthors) then
Authors = Authors .. A['AuthorSeparator'] .. " " .. Coauthors
local sep = '; ';
if 'vanc' == NameListFormat then
sep = ', ';
end
Authors = Authors .. sep .. Coauthors;
end
end
if is_set(Date) then
if is_set(Date) then
Line 2,466: Line 2,601:
end
end
end
end
names[ #names + 1 ] = first_set(Year, anchor_year); -- Year first for legacy citations
names[ #names + 1 ] = first_set(Year, anchor_year); -- Year first for legacy citations and for YMD dates that require disambiguation
id = anchorid(names)
id = anchorid(names)
end
end
Anonymous user