Module:Citation/CS1: Difference between revisions

synch from sandbox;
m (1 revision imported)
en>Trappist the monk
(synch from sandbox;)
Line 153:
if not domain:match ('^[%a%d]') then -- first character must be letter or digit
return false;
end
 
if domain:match ('^%a+:') then -- hack to detect things that look like s:Page:Title where Page: is namespace at wikisource
return false;
end
Line 399 ⟶ 403:
local path;
local base_url;
 
if not is_set( label ) then
label = URL;
Line 415 ⟶ 419:
if path then -- if there is a path portion
path = path:gsub ('[%[%]]', {['[']='%5b',[']']='%5d'}); -- replace '[' and ']' with their percent encoded values
URL = table.concat ({domain.., path}); -- and reassemble
end
 
base_url = table.concat({ "[", URL, " ", safe_for_url (label), "]" }); -- assemble a wikimarkup url
 
if is_set (access) then -- access level (subscription, registration, limited)
base_url = substitute (cfg.presentation['ext-link-access-signal'], {cfg.presentation[access].class, cfg.presentation[access].title, base_url}); -- add the appropriate icon
label = safe_for_url (label); -- replace square brackets and newlines
 
base_url = table.concat ( -- assemble external link with access signal
{
'<span class="plainlinks">[', -- opening css and url markup
URL, -- the url
' ', -- the required space
label,
'<span style="padding-left:0.15em">', -- signal spacing css
cfg.presentation[access], -- the appropriate icon
'</span>', -- close signal spacing span
']</span>' -- close url markup and plain links span
});
else
base_url = table.concat({ "[", URL, " ", safe_for_url( label ), "]" }); -- no signal markup
end
return table.concat ({ base_url, error_str });
end
 
Line 549 ⟶ 541:
end
-- if we get this far we have prefix and script
name = cfg.lang_code_remap[lang] or mw.language.fetchLanguageName( lang, "en" ); -- get language name so that we can use it to categorize
if is_set (name) then -- is prefix a proper ISO 639-1 language code?
script_value = script_value:gsub ('^%l%l%s*:%s*', ''); -- strip prefix from script
Line 605 ⟶ 597:
return substitute( cfg.messages[key], str );
end
end
 
 
--[[--------------------------< W I K I S O U R C E _ U R L _ M A K E >----------------------------------------
 
makes a wikisource url from wikisource interwiki link. returns the url and appropriate label; nil else.
 
str is the value assigned to |chapter= (or aliases) or |title= or |title-link=
 
]]
 
local function wikisource_url_make (str)
local wl_type, D, L;
local ws_url, ws_label;
 
wl_type, D, L = is_wikilink (str); -- wl_type is 0 (not a wikilink), 1 (simple wikilink), 2 (complex wikilink)
 
if 0 == wl_type then -- not a wikilink; might be from |title-link=
str = D:match ('^[Ww]ikisource:(.+)') or D:match ('^[Ss]:(.+)'); -- article title from interwiki link with long-form or short-form namespace
if is_set (str) then
ws_url = table.concat ({ -- build a wikisource url
'https://en.wikisource.org/wiki/', -- prefix
str, -- article title
});
ws_label = str; -- label for the url
end
elseif 1 == wl_type then -- simple wikilink: [[Wikisource:ws article]]
str = D:match ('^[Ww]ikisource:(.+)') or D:match ('^[Ss]:(.+)'); -- article title from interwiki link with long-form or short-form namespace
if is_set (str) then
ws_url = table.concat ({ -- build a wikisource url
'https://en.wikisource.org/wiki/', -- prefix
str, -- article title
});
ws_label = str; -- label for the url
end
elseif 2 == wl_type then -- non-so-simple wikilink: [[Wikisource:ws article|displayed text]] ([[L|D]])
str = L:match ('^[Ww]ikisource:(.+)') or L:match ('^[Ss]:(.+)'); -- article title from interwiki link with long-form or short-form namespace
if is_set (str) then
ws_label = D; -- get ws article name from display portion of interwiki link
ws_url = table.concat ({ -- build a wikisource url
'https://en.wikisource.org/wiki/', -- prefix
str, -- article title without namespace from link portion of wikilink
});
end
end
if ws_url then
ws_url = mw.uri.encode (ws_url, 'WIKI'); -- make a usable url
ws_url = ws_url:gsub ('%%23', '#'); -- undo percent encoding of anchor
end
 
return ws_url, ws_label, L or D; -- return proper url or nil and a label or nil
end
 
Line 617 ⟶ 661:
local function format_chapter_title (scriptchapter, chapter, transchapter, chapterurl, chapter_url_source, no_quotes, access)
local chapter_error = '';
 
local ws_url, ws_label, L = wikisource_url_make (chapter); -- make a wikisource url and label from a wikisource interwiki link
if ws_url then
ws_label = ws_label:gsub ('_', ''); -- replace underscore separaters with space characters
chapter = ws_label;
end
 
if not is_set (chapter) then
chapter = ''; -- to be safe for concatenation
Line 628 ⟶ 678:
 
chapter = script_concatenate (chapter, scriptchapter) -- <bdi> tags, lang atribute, categorization, etc; must be done after title is wrapped
 
if is_set (chapterurl) then
chapter = external_link (chapterurl, chapter, chapter_url_source, access); -- adds bare_url_missing_title error if appropriate
elseif ws_url then
chapter = external_link (ws_url, chapter .. '&nbsp;', 'ws link in chapter'); -- adds bare_url_missing_title error if appropriate; space char to move icon away from chap text; TODO: better way to do this?
chapter = substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, chapter});
end
 
if is_set (transchapter) then
Line 639 ⟶ 696:
end
 
-- if is_set (chapterurl) then
-- chapter = external_link (chapterurl, chapter, chapter_url_source, access); -- adds bare_url_missing_title error if appropriate
-- end
 
return chapter .. chapter_error;
Line 689 ⟶ 746:
if position then
if 'nowiki' == capture or 'math' == capture then or -- nowiki, and math stripmarkerstripmarkers (not an error condition)
('templatestyles' == capture and in_array (param, {'id', 'quote'})) then -- templatestyles stripmarker allowed in these parameters
stripmarker = true; -- set a flag
stripmarker = true; -- set a flag
elseif true == stripmarker and 'delete' == char then -- because stripmakers begin and end with the delete char, assume that we've found one end of a stripmarker
position = nil; -- unset
Line 757 ⟶ 815:
end,
});
end
 
 
--[[--------------------------< 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:
true - active, supported parameters
false - deprecated, supported parameters
nil - unsupported parameters
]]
 
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; -- not supported because not found or name is set to nil
end
 
Line 877 ⟶ 864:
--[[--------------------------< H Y P H E N _ T O _ D A S H >--------------------------------------------------
 
Converts a hyphen to a dash under certain conditions. The hyphen must separate like items; unlike items are
returned unmodified. These forms are modified:
letter - letter (A - B)
digit - digit (4-5)
digit separator digit - digit separator digit (4.1-4.5 or 4-1-4-5)
letterdigit - letterdigit (A1-A5) (an optional separator between letter and digit is supported – a.1-a.5 or a-1-a-5)
digitletter - digitletter (5a - 5d) (an optional separator between letter and digit is supported – 5.a-5.d or 5-a-5-d)
 
any other forms are returned unmodified.
 
str may be a comma- or semicolon-separated list
 
]]
 
local function hyphen_to_dash( str )
if not is_set (str) or str:match( "[%[%]{}<>]" ) ~= nil then
return str;
end
return str:gsub( '-', '–' );
str, count = str:gsub ('^%(%((.+)%)%)$', '%1'); -- remove accept-this-as-written markup when it wraps all of str
if 0 ~= count then -- non-zero when markup removed; zero else
return str; -- nothing to do, we're done
end
str = str:gsub ('&[nm]dash;', {['&ndash;'] = '–', ['&mdash;'] = '—'}); -- replace &mdash; and &ndash; entities with their characters; semicolon mucks up the text.split
local out = {};
local list = mw.text.split (str, '%s*[,;]%s*'); -- split str at comma or semicolon separators if there are any
 
for _, item in ipairs (list) do -- for each item in the list
if mw.ustring.match (item, '^%w*[%.%-]?%w+%s*[%-–—]%s*%w*[%.%-]?%w+$') then -- if a hyphenated range or has endash or emdash separators
if item:match ('%a+[%.%-]?%d+%s*%-%s*%a+[%.%-]?%d+') or -- letterdigit hyphen letterdigit (optional separator between letter and digit)
item:match ('%d+[%.%-]?%a+%s*%-%s*%d+[%.%-]?%a+') or -- digitletter hyphen digitletter (optional separator between digit and letter)
item:match ('%d+[%.%-]%d+%s*%-%s*%d+[%.%-]%d+') or -- digit separator digit hyphen digit separator digit
item:match ('%d+%s*%-%s*%d+') or -- digit hyphen digit
item:match ('%a+%s*%-%s*%a+') then -- letter hyphen letter
item = item:gsub ('(%w*[%.%-]?%w+)%s*%-%s*(%w*[%.%-]?%w+)', '%1–%2'); -- replace hyphen, remove extraneous space characters
else
item = mw.ustring.gsub (item, '%s*[–—]%s*', '–'); -- for endash or emdash separated ranges, replace em with en, remove extraneous white space
end
end
item = item:gsub ('^%(%((.+)%)%)$', '%1'); -- remove the accept-this-as-written markup
table.insert (out, item); -- add the (possibly modified) item to the output table
end
 
return table.concat (out, ', '); -- concatenate the output table into a comma separated string
end
 
Line 896 ⟶ 920:
 
local function safe_join( tbl, duplicate_char )
local f = {}; -- create a function table appropriate to type of 'dupicate character'
--[[
if 1 == #duplicate_char then -- for single byte ascii characters use the string library functions
Note: we use string functions here, rather than ustring functions.
f.gsub=string.gsub
f.match=string.match
This has considerably faster performance and should work correctly as
f.sub=string.sub
long as the duplicate_char is strict ASCII. The strings
else -- for multi-byte characters use the ustring library functions
in tbl may be ASCII or UTF8.
f.gsub=mw.ustring.gsub
]]
f.match=mw.ustring.match
f.sub=mw.ustring.sub
end
 
local str = ''; -- the output string
local comp = ''; -- what does 'comp' mean?
Line 920 ⟶ 947:
end
-- typically duplicate_char is sepc
if comp:f.sub(comp, 1,1) == duplicate_char then -- is first charactiercharacter same as duplicate_char? why test first character?
-- Because individual string segments often (always?) begin with terminal punct for ththe
-- preceding segment: 'First element' .. 'sepc next element' .. etc?
trim = false;
end_chr = str:f.sub(str, -1,-1); -- get the last character of the output string
-- str = str .. "<HERE(enchr=" .. end_chr.. ")" -- debug stuff?
if end_chr == duplicate_char then -- if same as separator
str = str:f.sub(str, 1,-2); -- remove it
elseif end_chr == "'" then -- if it might be wikimarkup
if str:f.sub(str, -3,-1) == duplicate_char .. "''" then -- if last three chars of str are sepc''
str = str:f.sub(str, 1, -4) .. "''"; -- remove them and add back ''
elseif str: f.sub(str, -5,-1) == duplicate_char .. "]]''" then -- if last five chars of str are sepc]]''
trim = true; -- why? why do this and next differently from previous?
elseif str:f.sub(str, -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:f.sub(str, -3,-1) == duplicate_char .. "]]" then -- if last three chars of str are sepc]] wikilink
trim = true;
elseif str:f.sub(str, -3,-1) == duplicate_char .. '"]' then -- if last three chars of str are sepc"] quoted external link
trim = true;
elseif str: f.sub(str, -2,-1) == duplicate_char .. "]" then -- if last two chars of str are sepc] external link
trim = true;
elseif str:f.sub(str, -4,-1) == duplicate_char .. "'']" then -- normal case when |url=something & |title=Title.
trim = true;
end
elseif end_chr == " " then -- if last char of output string is a space
if str:f.sub(str, -2,-1) == duplicate_char .. " " then -- if last two chars of str are <sepc><space>
str = str:f.sub(str, 1,-3); -- remove them both
end
end
Line 955 ⟶ 982:
if value ~= comp then -- value does not equal comp when value contains html markup
local dup2 = duplicate_char;
if dup2:f.match(dup2, "%A" ) then dup2 = "%" .. dup2; end -- if duplicate_char not a letter then escape it
value = value:f.gsub(value, "(%b<>)" .. dup2, "%1", 1 ) -- remove duplicate_char if it follows html markup
else
value = value:f.sub(value, 2, -1 ); -- remove duplicate_char when it is first character
end
end
Line 967 ⟶ 994:
end
return str;
end
 
 
Line 1,105 ⟶ 1,132:
 
if 'vanc' == format then -- Vancouver-like author/editor name styling?
sep = cfg.presentation[',sep_nl_vanc']; -- name-list separator between authors is a comma
namesep = cfg.presentation[' sep_name_vanc']; -- last/first separator is a space
else
sep = cfg.presentation[';sep_nl' ]; -- name-list separator between authors is a semicolon
namesep = cfg.presentation[', sep_name' ]; -- last/first separator is <comma><space>
end
Line 1,379 ⟶ 1,406:
return the original language name string.
 
mw.language.fetchLanguageNames(<local wiki language>, 'all') returnreturns a list of languages that in some cases may include
extensions. For example, code 'cbk-zam' and its associated name 'Chavacano de Zamboanga' (MediaWiki does not support
code 'cbk' or name 'Chavacano'. Most (all?) of these languages are not used a 'language' codes per se, rather they
are used as sub-domain names: cbk-zam.wikipedia.org. A list of language names and codes supported by fetchLanguageNames()
can be found at Template:Citation Style documentation/language/doc
 
Names but that are included in the list will be found if that name is provided in the |language= parameter. For example,
if |language=Chavacano de Zamboanga, that name will be found with the associated code 'cbk-zam'. When names are found
and the associated code is not two or three characters, this function returns only the WikimediaWikiMedia language name.
 
Some language names have multiple entries under different codes:
Aromanian has code rup and code roa-rup
When this occurs, this function returns the language name and the 2- or 3-character code
 
Adapted from code taken from Module:Check ISO 639-1.
Line 1,392 ⟶ 1,425:
 
local function get_iso639_code (lang, this_wiki_code)
if 'bangla' == cfg.lang_name_remap[lang:lower()] then -- specialif casethere relatedis toa Wikimediaremapped remapname of(because codeMediaWiki uses something that we don'bn't atthink mw:Extension:CLDRis correct)
return cfg.lang_name_remap[lang:lower()][1], cfg.lang_name_remap[lang:lower()][2]; -- for this language 'name', return a possibly new name and appropriate code
return 'Bengali', 'bn'; -- make sure rendered version is properly capitalized
end
 
local ietf_code; -- because some languages have both ietf-like codes and iso 639-like codes
local ietf_name;
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)
local langlc = mw.ustring.lower(lang); -- lower case version for comparisons
 
for code, name in pairs(languages) do -- scan the list to see if we can find our language
if langlc == mw.ustring.lower(name) then
if 2 ~== code:len() andor 3 ~== code:len() then -- two- or three-character codes only; extensions not supported
return name, code; -- so return the name but notand the code
end
returnietf_code name,= code; -- foundremember it,that returnwe namefound toan ensureietf-like proper capitalizationcode and thesave theits codename
ietf_name = name; -- but keep looking for a 2- or 3-char code
end
end
return lang; -- notdidn't validfind language;name returnwith language2- inor original3-char casecode; andif nilietf-like forcode thefound codereturn
return ietf_code and ietf_name or lang; -- associated name; return original language text else
end
 
Line 1,442 ⟶ 1,480:
 
for _, lang in ipairs (names_table) do -- reuse lang
name = cfg.lang_code_remap[lang:lower()]; -- first see if this is a code that is not supported by MediaWiki but is in remap
 
if lang:match ('^%a%a%-')name then -- stripthere ietfwas languagea tags fromremapped code; TODO: is there a need to support 3-char with tag?so
lang = lang:matchgsub ('^(%a%a%a?)%-.*', '%1') ; -- keepstrip onlyietf 639-1tags code portion to lang; TODO: do something with 3166 alpha 2 countryfrom code?
endelse
if 2 == lang:len() ormatch 3 == lang:len('^%a%a%-') then -- ifstrip two-orietf three-charactertags from code; TODO: is there a need to support 3-char with tag?
lang = lang:match ('(%a%a)%-') -- keep only 639-1 code portion to lang; TODO: do something with 3166 alpha 2 country code?
name = mw.language.fetchLanguageName( lang:lower(), this_wiki_code); -- get language name if |language= is a proper code
end
if 2 == lang:len() or 3 == lang:len() then -- if two-or three-character code
name = mw.language.fetchLanguageName (lang:lower(), this_wiki_code); -- get language name if |language= is a proper code
end
end
 
if is_set (name) then -- if |language= specified a valid code
code = lang:lower(); -- save it
Line 1,457 ⟶ 1,500:
if is_set (code) then -- only 2- or 3-character codes
ifname 'bn' == cfg.lang_code_remap[code] thenor name = 'Bengali' end; -- override wikimedia when codethey misuse islanguage 'bn'codes/names
 
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
add_prop_cat ('foreign_lang_source' .. code, {name, code}) -- categorize it
else -- or is a recognized language (but has a three-character code)
add_prop_cat ('foreign_lang_source_2' .. code, {code}) -- categorize it differently TODO: support mutliple three-character code categories per cs1|2 template
end
end
Line 1,475 ⟶ 1,519:
code = #language_list -- reuse code as number of languages in the list
if 2 >= code then
name = table.concat (language_list, cfg.messages[' and parameter-pair-separator']) -- insert '<space>and<space>' between two language names
elseif 2 < code then
language_list[code]name = 'and ' .table.concat (language_list[code], ', '); -- prependand last nameconcatenate with 'and<comma><space>' separators
name = table.concatname:gsub (language_list', ([^,]+)$', cfg.messages['parameter-final-separator'] .. '%1') ; -- andreplace concatenatelast '<comma><space>' separator with '<comma><space>and<space>' separatorsseparator
end
if this_wiki_name == name then
Line 1,493 ⟶ 1,537:
 
Set style settings for CS1 citation templates. Returns separator and postscript settings
At en.wiki, for cs1:
ps gets: '.'
sep gets: '.'
 
]]
Line 1,498 ⟶ 1,545:
local function set_cs1_style (ps)
if not is_set (ps) then -- unless explicitely set to something
ps = 'cfg.presentation['ps_cs1']; -- terminate the rendered citation with a period
end
return 'cfg.presentation['sep_cs1'], ps; -- element separator is a full stop
end
 
Line 1,507 ⟶ 1,554:
 
Set style settings for CS2 citation templates. Returns separator, postscript, ref settings
At en.wiki, for cs2:
ps gets: '' (empty string - no terminal punctuation)
sep gets: ','
 
]]
Line 1,512 ⟶ 1,562:
local function set_cs2_style (ps, ref)
if not is_set (ps) then -- if |postscript= has not been set, set cs2 default
ps = cfg.presentation['ps_cs2']; -- maketerminate surethe it isn'trendered nilcitation
end
if not is_set (ref) then -- if |ref= is not set
ref = "harv"; -- set default |ref=harv
end
return cfg.presentation[',sep_cs2'], ps, ref; -- element separator is a comma
end
 
Line 1,897 ⟶ 1,947:
end
 
local vol = ''; -- here for all cites except magazine
if is_set (volume) then
if volume:match ('^[MDCLXVI]+$') or volume:match ('^%d+$')then -- volume value is all digits or all uppercase roman numerals
if (4 < mw.ustring.len(volume)) then
vol = substitute (cfg.messagespresentation['j-vol-bold'], {sepc, hyphen_to_dash(volume)}); -- render in bold face
elseif (4 < mw.ustring.len(volume)) then -- not all digits or roman numerals and longer than 4 characters
else
vol = substitute (cfg.presentationmessages['volj-boldvol'], {sepc, hyphen_to_dash(volume)}); -- not bold
add_prop_cat ('long_vol');
else -- four or less characters
vol = substitute (cfg.presentation['vol-bold'], {sepc, hyphen_to_dash(volume)}); -- bold
end
end
Line 1,940 ⟶ 1,993:
end
 
local is_journal = 'journal' == cite_class or (in_array (cite_class, {'citation', 'map', 'interview'}) and 'journal' == origin);
if is_set (page) then
Line 1,964 ⟶ 2,017:
return '', '', '', ''; -- return empty strings
end
 
 
--[[--------------------------< I N S O U R C E _ L O C _ G E T >----------------------------------------------
 
returns one of the in-source locators: page, pages, or at.
 
If any of these are interwiki links to wikisource, returns the label portion of the interwikilink as plain text
for use in COinS. This COinS thing is done because here we convert an interwiki link to and external link and
add an icon span around that; get_coins_pages() doesn't know about the span. TODO: should it?
 
TODO: add support for sheet and sheets?; streamline;
 
TODO: make it so that this function returns only one of the three as the single in-source (the return value assigned
to a new name)?
 
]]
 
local function insource_loc_get (page, pages, at)
local ws_url, ws_label, coins_pages, L; -- for wikisource interwikilinks; TODO: this corrupts page metadata (span remains in place after cleanup; fix there?)
 
if is_set (page) then
if is_set (pages) or is_set(at) then
pages = ''; -- unset the others
at = '';
end
extra_text_in_page_check (page); -- add this page to maint cat if |page= value begins with what looks like p. or pp.
 
ws_url, ws_label, L = wikisource_url_make (page); -- make ws url from |page= interwiki link; link portion L becomes tool tip label
if ws_url then
page = external_link (ws_url, ws_label .. '&nbsp;', 'ws link in page'); -- space char after label to move icon away from in-source text; TODO: a better way to do this?
page = substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, page});
coins_pages = ws_label;
end
elseif is_set (pages) then
if is_set (at) then
at = ''; -- unset
end
extra_text_in_page_check (pages); -- add this page to maint cat if |pages= value begins with what looks like p. or pp.
 
ws_url, ws_label, L = wikisource_url_make (pages); -- make ws url from |pages= interwiki link; link portion L becomes tool tip label
if ws_url then
pages = external_link (ws_url, ws_label .. '&nbsp;', 'ws link in pages'); -- space char after label to move icon away from in-source text; TODO: a better way to do this?
pages = substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, pages});
coins_pages = ws_label;
end
elseif is_set (at) then
ws_url, ws_label, L = wikisource_url_make (at); -- make ws url from |at= interwiki link; link portion L becomes tool tip label
if ws_url then
at = external_link (ws_url, ws_label .. '&nbsp;', 'ws link in at'); -- space char after label to move icon away from in-source text; TODO: a better way to do this?
at = substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, at});
coins_pages = ws_label;
end
end
return page, pages, at, coins_pages;
end
 
 
 
Line 2,036 ⟶ 2,146:
else
return url, date; -- preview mode so return archiveURL and ArchiveDate
end
end
 
 
--[[--------------------------< M I S S I N G _ P I P E _ C H E C K >------------------------------------------
 
Look at the contents of a parameter. If the content has a string of characters and digits followed by an equal
sign, compare the alphanumeric string to the list of cs1|2 parameters. If found, then the string is possibly a
parameter that is missing its pipe:
{{cite ... |title=Title access-date=2016-03-17}}
 
cs1|2 shares some parameter names with xml/html atributes: class=, title=, etc. To prevent false positives xml/html
tags are removed before the search.
 
If a missing pipe is detected, this function adds the missing pipe maintenance category.
 
]]
 
local function missing_pipe_check (value)
local capture;
value = value:gsub ('%b<>', ''); -- remove xml/html tags because attributes: class=, title=, etc
 
capture = value:match ('%s+(%a[%a%d]+)%s*=') or value:match ('^(%a[%a%d]+)%s*='); -- find and categorize parameters with possible missing pipes
if capture and validate (capture) then -- if the capture is a valid parameter name
add_maint_cat ('missing_pipe');
end
end
Line 2,135 ⟶ 2,220:
t = extract_names (args, 'TranslatorList'); -- fetch translator list from |translatorn= / |translator-lastn=, -firstn=, -linkn=, -maskn=
 
local interviewers_list = {};
local Interviewers; -- =used A['Interviewers']later
interviewers_list = extract_names (args, 'InterviewerList'); -- process preferred interviewers parameters
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
Line 2,227 ⟶ 2,308:
-- conference & map books do not support issue
if in_array (config.CitationClass, cfg.templates_using_issue) and not (in_array (config.CitationClass, {'conference', 'map'}) and not is_set (Periodical))then
Issue = hyphen_to_dash (A['Issue']);
end
local Position = '';
if not in_array (config.CitationClass, cfg.templates_not_using_page) then
Page = A['Page'];
Pages = hyphen_to_dash ( A['Pages'] );
At = A['At'];
end
Line 2,350 ⟶ 2,431:
-- check for extra |page=, |pages= or |at= parameters. (also sheet and sheets while we're at it)
select_one( args, {'page', 'p', 'pp', 'pages', 'at', 'sheet', 'sheets'}, 'redundant_parameters' ); -- this is a dummy call simply to get the error message and category
 
local coins_pages;
Page, Pages, At, coins_pages = insource_loc_get (Page, Pages, At);
 
local NoPP = A['NoPP']
Line 2,357 ⟶ 2,442:
NoPP = nil; -- unset, used as a flag later
end
 
if is_set(Page) then
if is_set(Pages) or is_set(At) then
Pages = ''; -- unset the others
At = '';
end
extra_text_in_page_check (Page); -- add this page to maint cat if |page= value begins with what looks like p. or pp.
elseif is_set(Pages) then
if is_set(At) then
At = ''; -- unset
end
extra_text_in_page_check (Pages); -- add this page to maint cat if |pages= value begins with what looks like p. or pp.
end
 
-- both |publication-place= and |place= (|location=) allowed if different
Line 2,385 ⟶ 2,457:
|encyclopedia then map |encyclopedia to |title
|trans_titletrans-title maps to |trans_chaptertrans-chapter when |title is re-mapped
|url maps to |chapterurl when |title is remapped
Line 2,585 ⟶ 2,657:
 
-- legacy: promote PublicationDate to Date if neither Date nor Year are set.
local Date_origin; -- to hold the name of parameter promoted to Date; required for date error messaging
 
if not is_set (Date) then
Date = Year; -- promote Year to Date
Line 2,591 ⟶ 2,665:
Date = PublicationDate; -- promote PublicationDate to Date
PublicationDate = ''; -- unset, no longer needed
Date_origin = A:ORIGIN('PublicationDate'); -- save the name of the promoted parameter
else
Date_origin = A:ORIGIN('Year'); -- save the name of the promoted parameter
end
else
Date_origin = A:ORIGIN('Date'); -- not a promotion; name required for error messaging
end
 
Line 2,605 ⟶ 2,684:
local error_message = '';
-- AirDate has been promoted to Date so not necessary to check it
local date_parameters_list = {['access-date']=AccessDate, ['archive-date']=ArchiveDate, ['date']=Date, ['doi-broken-date']=DoiBroken,
['access-date'] = {val=AccessDate, name=A:ORIGIN ('AccessDate')},
['embargo']=Embargo, ['lay-date']=LayDate, ['publication-date']=PublicationDate, ['year']=Year};
['archive-date'] = {val=ArchiveDate, name=A:ORIGIN ('ArchiveDate')},
 
['date'] = {val=Date, name=Date_origin},
['doi-broken-date'] = {val=DoiBroken, name=A:ORIGIN ('DoiBroken')},
['embargo'] = {val=Embargo, name=A:ORIGIN ('Embargo')},
['lay-date'] = {val=LayDate, name=A:ORIGIN ('LayDate')},
['publication-date'] ={val=PublicationDate, name=A:ORIGIN ('PublicationDate')},
['year'] = {val=Year, name=A:ORIGIN ('Year')},
};
anchor_year, Embargo, error_message = dates(date_parameters_list, COinS_date);
 
-- start temporary Julian / Gregorian calendar uncertainty categorization
if COinS_date.inter_cal_cat then
add_prop_cat ('jul_greg_uncertainty');
end
-- end temporary Julian / Gregorian calendar uncertainty categorization
 
if is_set (Year) and is_set (Date) then -- both |date= and |year= not normally needed;
Line 2,636 ⟶ 2,728:
-- for those wikis that can and want to have English date names translated to the local language,
-- uncomment these three lines. Not supported by en.wiki (for obvious reasons)
-- set date_name_xlate() second argument to true to translate English digits to local digits (will translate ymd dates)
-- if date_name_xlate (date_parameters_list) then
-- if date_name_xlate (date_parameters_list, false) then
-- modified = true;
-- end
 
if modified then -- if the date_parameters_list values were modified
AccessDate = date_parameters_list['access-date'].val; -- overwrite date holding parameters with modified values
ArchiveDate = date_parameters_list['archive-date'].val;
Date = date_parameters_list['date'].val;
DoiBroken = date_parameters_list['doi-broken-date'].val;
LayDate = date_parameters_list['lay-date'].val;
PublicationDate = date_parameters_list['publication-date'].val;
end
else
Line 2,725 ⟶ 2,818:
['Volume'] = Volume,
['Issue'] = Issue,
['Pages'] = coins_pages or get_coins_pages (first_set ({Sheet, Sheets, Page, Pages, At}, 5)), -- pages stripped of external links
['Edition'] = Edition,
['PublisherName'] = PublisherName,
Line 2,843 ⟶ 2,936:
DeadURL = DeadURL:lower(); -- used later when assembling archived text
if is_set( ArchiveURL ) then
if is_set (ChapterURL) then -- 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
OriginalFormat = ChapterFormat; -- and original |chapter-format=
if 'no' ~= DeadURL then
ChapterURL = ArchiveURL -- swap-in the archive's url
ChapterURLorigin = A:ORIGIN('ArchiveURL') -- name of archive-url parameter for error messages
ChapterFormat = ArchiveFormat or ''; -- swap in archive's format
ChapterUrlAccess = nil; -- restricted access levels do not make sense for archived urls
end
elseif is_set (URL) then
Line 2,910 ⟶ 3,004:
 
-- Format main title.
if is_set (ArchiveURL) and mw.ustring.match (mw.ustring.lower(Title), cfg.special_case_translation['archived_copy']) then -- if title is 'Archived copy' (place holder added by bots that can't find proper title)
Title = mw.ustring.gsub(Title, '%'..sepc..'$', ''); -- remove any trailing separator character
add_maint_cat ('archived_copy'); -- add maintenance category before we modify the content of Title
if is_set(TitleLink) and is_set(Title) then
Title = make_wikilink (TitleLink, Title);
end
 
if Title:match ('^%(%(.*%)%)$') then -- if keep as written markup:
Title= Title:gsub ('^%(%((.*)%)%)$', '%1') -- remove the markup
else
if '...' == Title:sub (-3) then -- if elipsis is the last three characters of |title=
Title = Title:gsub ('(%.%.%.)%.+$', '%1'); -- limit the number of dots to three
elseif not mw.ustring.find (Title, '%.%s*%a%.$') and -- end of title is not a 'dot-(optional space-)letter-dot' initialism ...
not mw.ustring.find (Title, '%s+%a%.$') then -- ...and not a 'space-letter-dot' initial (''Allium canadense'' L.)
Title = mw.ustring.gsub(Title, '%'..sepc..'$', ''); -- remove any trailing separator character; sepc and ms.ustring() here for languages that use multibyte separator characters
end
end
if in_array(config.CitationClass, {'web', 'news', 'journal', 'magazine', 'pressrelease', 'podcast', 'newsgroup', 'mailinglist', 'interview', 'arxiv', 'biorxiv', 'citeseerx'}) or
('citation' == config.CitationClass and is_set (Periodical) and not is_set (Encyclopedia)) or
Line 2,939 ⟶ 3,043:
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;
Title = external_link( URL, Title, URLorigin, UrlAccess ) .. TransTitle .. TransError .. Format;
URL = ''; -- unset these because no longer needed
Format = "";
elseif is_set (TitleLink) and not is_set (URL) then
local ws_url;
ws_url = wikisource_url_make (TitleLink); -- ignore ws_label return; not used here
if ws_url then
Title = external_link (ws_url, Title .. '&nbsp;', 'ws link in title-link'); -- space char after Title to move icon away from italic text; TODO: a better way to do this?
Title = substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], TitleLink, Title});
Title = Title .. TransTitle .. TransError;
else
Title = make_wikilink (TitleLink, Title) .. TransTitle .. TransError;
end
else
local ws_url, ws_label;
Title = Title .. TransTitle .. TransError;
ws_url, ws_label, L = wikisource_url_make (Title); -- make ws url from |title= interwiki link; link portion L becomes tool tip label
if ws_url then
Title = Title:gsub ('%b[]', ws_label); -- replace interwiki link with ws_label to retain markup
Title = external_link (ws_url, Title .. '&nbsp;', 'ws link in title'); -- space char after Title to move icon away from italic text; TODO: a better way to do this?
Title = substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, Title});
Title = Title .. TransTitle .. TransError;
else
Title = Title .. TransTitle .. TransError;
end
end
else
Line 3,025 ⟶ 3,147:
if is_set (Translators) then
Others = safe_join ({sepc .. ' ' .., wrap_msg ('translated', Translators, use_lowercase) .., Others}, sepc);
end
if is_set (Interviewers) then
Others = safe_join ({sepc .. ' ' .., wrap_msg ('interview', Interviewers, use_lowercase) .., Others}, sepc);
end
Line 3,209 ⟶ 3,331:
if in_array(config.CitationClass, {"journal","citation"}) and is_set(Periodical) then
if is_set(Others) then Others = safe_join ({Others .., sepc .. " "}, sepc) end -- add terminal punctuation & space; check for dup sepc; TODO why do we need to do this here?
tcommon = safe_join( {Others, Title, TitleNote, Conference, Periodical, Format, TitleType, Series, Language, Edition, Publisher, Agency, Volume}, sepc );
elseif in_array(config.CitationClass, {"book","citation"}) and not is_set(Periodical) then -- special cases for book cites
Line 3,370 ⟶ 3,492:
table.insert (render, substitute (cfg.presentation['ocins'], {OCinSoutput})); -- append metadata to the citation
 
if #z.message_tail0 ~= 0#z.message_tail then
table.insert (render, ' ');
for i,v in ipairs( z.message_tail ) do
Line 3,383 ⟶ 3,505:
end
 
if #z.maintenance_cats0 ~= 0#z.maintenance_cats then
local maint_msgs = {}; -- here we collect all of the maint messages
table.insert (render, '<span class="citation-comment" style="display:none; color:#33aa33; margin-left:0.3em">');
for _, v in ipairs( z.maintenance_cats ) do -- append maintenance categories
local maint = {}; -- here we assemble a maintenence message
table.insert (render, v);
table.insert (rendermaint, ' ('v); -- maint msg is the category name
table.insert (rendermaint, make_wikilink' (':Category:'); -- ..open v,the 'link')); text
table.insert (rendermaint, make_wikilink (':Category:') .. v, 'link')); -- add the link
table.insert (maint, ')'); -- and close it
table.insert (maint_msgs, table.concat (maint)); -- assemble new maint message and add it to the maint_msgs table
end
table.insert (render, substitute (cfg.presentation['hidden-maint'], table.concat (maint_msgs, ' '))); -- wrap the group of maint message with proper presentation and save
table.insert (render, '</span>');
end
Line 3,408 ⟶ 3,532:
 
return table.concat (render);
end
 
 
--[[--------------------------< 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:
true - active, supported parameters
false - deprecated, supported parameters
nil - unsupported parameters
]]
 
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
 
state = whitelist[cite_class .. '_basic_arguments'][name]; -- look in the parameter-list for the template identified by cite_class
 
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#) (mw.ustring because non-Western 'local' digits)
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#) (mw.ustring because non-Western 'local' digits)
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; -- not supported because not found or name is set to nil
end
 
 
--[[--------------------------< M I S S I N G _ P I P E _ C H E C K >------------------------------------------
 
Look at the contents of a parameter. If the content has a string of characters and digits followed by an equal
sign, compare the alphanumeric string to the list of cs1|2 parameters. If found, then the string is possibly a
parameter that is missing its pipe:
{{cite ... |title=Title access-date=2016-03-17}}
 
cs1|2 shares some parameter names with xml/html atributes: class=, title=, etc. To prevent false positives xml/html
tags are removed before the search.
 
If a missing pipe is detected, this function adds the missing pipe maintenance category.
 
]]
 
local function missing_pipe_check (value)
local capture;
value = value:gsub ('%b<>', ''); -- remove xml/html tags because attributes: class=, title=, etc
 
capture = value:match ('%s+(%a[%a%d]+)%s*=') or value:match ('^(%a[%a%d]+)%s*='); -- find and categorize parameters with possible missing pipes
if capture and validate (capture) then -- if the capture is a valid parameter name
add_maint_cat ('missing_pipe');
end
end
 
Line 3,420 ⟶ 3,632:
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, styles;
if nil ~= string.find (frame:getTitle(), 'sandbox', 1, true) then -- did the {{#invoke:}} use sandbox version?
Line 3,429 ⟶ 3,641:
identifiers = require ('Module:Citation/CS1/Identifiers/sandbox');
metadata = require ('Module:Citation/CS1/COinS/sandbox');
styles = 'Module:Citation/CS1/sandbox/styles.css';
else -- otherwise
Line 3,437 ⟶ 3,650:
identifiers = require ('Module:Citation/CS1/Identifiers');
metadata = require ('Module:Citation/CS1/COinS');
styles = 'Module:Citation/CS1/styles.css';
 
end
 
Line 3,486 ⟶ 3,701:
for k, v in pairs( pframe.args ) do
if v ~= '' then
if ('string' == type (k)) then
k = mw.ustring.gsub (k, '%d', cfg.date_names.local_digits); -- for enumerated parameters, translate 'local' digits to Western 0-9
end
if not validate( k, config.CitationClass ) then
error_text = "";
Line 3,494 ⟶ 3,712:
end
elseif validate( k:lower(), config.CitationClass ) then
error_text, error_state = set_error( 'parameter_ignored_suggest', {k, k:lower()}, true ); -- suggest the lowercase version of the parameter
else
if nil == suggestions.suggestions then -- if this table is nil then we need to load it
Line 3,506 ⟶ 3,724:
capture = k:match (pattern); -- the whole match if no caputre in pattern else the capture if a match
if capture then -- if the pattern matches
param = substitute ( param, capture ); -- add the capture to the suggested parameter (typically the enumerator)
if validate (param, config.CitationClass) then -- validate the suggestion to make sure that the suggestion is supported by this template (necessary for limited parameter lists)
error_text, error_state = set_error( 'parameter_ignored_suggest', {k, param}, true ); -- set the error message
error_text, error_state = set_error ('parameter_ignored_suggest', {k, param}, true); -- set the suggestion error message
else
error_text, error_state = set_error( 'parameter_ignored', {param}, true ); -- suggested param not supported by this template
end
end
end
Line 3,524 ⟶ 3,746:
end
missing_pipe_check (v); -- do we think that there is a parameter that is missing a pipe?
-- TODO: is this the best place for this translation?
args[k] = v;
elseif args[k] ~= nil or (k == 'postscript') then
args[k] = v;
elseif args[k] ~= nil or (k == 'postscript') then -- here when v is empty string
args[k] = v; -- why do we do this? we don't support 'empty' parameters
end
end
Line 3,536 ⟶ 3,758:
end
end
return table.concat ({citation0( config, args), frame:extensionTag ('templatestyles', '', {src=styles})});
end
 
Anonymous user