Module:Sandbox/Awesome Aasim/CS1 LDoc Test

--- This module implements all of the {{tl|citation}} and related templates.

--

-- @author Trappist_the_monk

-- @release stable

-- @module citation

-- @alias p

--

--[[

History of changes since last sync: 2024-12-28

2025-01-05: add module entry points; see Help_talk:Citation_Style_1/Archive_97#Module_support_edit_req

2025-01-15: tighten protocol-relative url-in-title test; see Help_talk:Citation_Style_1#Double_slash_%28but_not_URL%29_in_title_causes_cite_web_to_think_title_contains_URL

2025-02-27: emit error message when isbn present for pre-1965 pub date; see Help_talk:Citation_Style_1#isbn_and_pre-isbn_publication_dates

]]

require ('strict');

--[[--------------------------< F O R W A R D D E C L A R A T I O N S >--------------------------------------

each of these counts against the Lua upvalue limit

]]

local validation; -- functions in Module:Citation/CS1/Date_validation

local utilities; -- functions in Module:Citation/CS1/Utilities

local z = {}; -- table of tables in Module:Citation/CS1/Utilities

local identifiers; -- functions and tables in Module:Citation/CS1/Identifiers

local metadata; -- functions in Module:Citation/CS1/COinS

local cfg = {}; -- table of configuration tables that are defined in Module:Citation/CS1/Configuration

local whitelist = {}; -- table of tables listing valid template parameter names; defined in Module:Citation/CS1/Whitelist

--[[------------------< P A G E S C O P E V A R I A B L E S >---------------

declare variables here that have page-wide scope that are not brought in from

other modules; that are created here and used here

]]

local added_deprecated_cat; -- Boolean flag so that the category is added only once

local added_vanc_errs; -- Boolean flag so we only emit one Vancouver error / category

local added_generic_name_errs; -- Boolean flag so we only emit one generic name error / category and stop testing names once an error is encountered

local added_numeric_name_errs; -- Boolean flag so we only emit one numeric name error / category and stop testing names once an error is encountered

local added_numeric_name_maint; -- Boolean flag so we only emit one numeric name maint category and stop testing names once a category has been emitted

local is_preview_mode; -- true when article is in preview mode; false when using 'Preview page with this template' (previewing the module)

local is_sandbox; -- true when using sandbox modules to render citation

-- Locates and returns the first set value in a table of values where the order established in the table,

-- left-to-right (or top-to-bottom), is the order in which the values are evaluated. Returns nil if none are set.

--

-- This version replaces the original 'for _, val in pairs do' and a similar version that used ipairs. With the pairs

-- version the order of evaluation could not be guaranteed. With the ipairs version, a nil value would terminate

-- the for-loop before it reached the actual end of the list.

--

-- @param {table} list

-- @param {number} count

-- @return first set list member

local function first_set (list, count)

local i = 1;

while i <= count do -- loop through all items in list

if utilities.is_set( list[i] ) then

return list[i]; -- return the first set list member

end

i = i + 1; -- point to next

end

end

--- 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

--

-- @param source Source of error

-- @param position Position of error

local function add_vanc_error (source, position)

if added_vanc_errs then return end

added_vanc_errs = true; -- note that we've added this category

utilities.set_message ('err_vancouver', {source, position});

end

--- Does this thing that purports to be a URI scheme seem to be a valid scheme? The scheme is checked to see if it

-- is in agreement with http://tools.ietf.org/html/std66#section-3.1 which says:

-- Scheme names consist of a sequence of characters beginning with a

-- letter and followed by any combination of letters, digits, plus

-- ("+"), period ("."), or hyphen ("-").

--

-- @param {string} scheme URI scheme to test

-- @return true if the scheme is valid, else false

local function is_scheme (scheme)

return scheme and scheme:match ('^%a[%a%d%+%.%-]*:'); -- true if scheme is set and matches the pattern

end

--- Does this thing that purports to be a domain name seem to be a valid domain name?

--

-- Syntax defined here: http://tools.ietf.org/html/rfc1034#section-3.5

-- BNF defined here: https://tools.ietf.org/html/rfc4234

-- Single character names are generally reserved; see https://tools.ietf.org/html/draft-ietf-dnsind-iana-dns-01#page-15;

-- see also Single-letter second-level domain

-- list of TLDs: https://www.iana.org/domains/root/db

--

-- RFC 952 (modified by RFC 1123) requires the first and last character of a hostname to be a letter or a digit. Between

-- the first and last characters the name may use letters, digits, and the hyphen.

--

-- Also allowed are IPv4 addresses. IPv6 not supported

--

-- domain is expected to be stripped of any path so that the last character in the last character of the TLD. tld

-- is two or more alpha characters. Any preceding '//' (from splitting a URL with a scheme) will be stripped

-- here. Perhaps not necessary but retained in case it is necessary for IPv4 dot decimal.

--

-- There are several tests:

-- the first character of the whole domain name including subdomains must be a letter or a digit

-- internationalized domain name (ASCII characters with .xn-- ASCII Compatible Encoding (ACE) prefix xn-- in the TLD) see https://tools.ietf.org/html/rfc3490

-- single-letter/digit second-level domains in the .org, .cash, and .today TLDs

-- q, x, and z SL domains in the .com TLD

-- i and q SL domains in the .net TLD

-- single-letter SL domains in the ccTLDs (where the ccTLD is two letters)

-- two-character SL domains in gTLDs (where the gTLD is two or more letters)

-- three-plus-character SL domains in gTLDs (where the gTLD is two or more letters)

-- IPv4 dot-decimal address format; TLD not allowed

--

-- @param {string} domain domain URL

-- @return true if domain appears to be a proper name and TLD or IPv4 address, else false

local function is_domain_name (domain)

if not domain then

return false; -- if not set, abandon

end

domain = domain:gsub ('^//', ''); -- strip '//' from domain name if present; done here so we only have to do it once

if not domain:match ('^[%w]') 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

local patterns = { -- patterns that look like URLs

'%f[%w][%w][%w%-]+[%w]%.%a%a+$', -- three or more character hostname.hostname or hostname.tld

'%f[%w][%w][%w%-]+[%w]%.xn%-%-[%w]+$', -- internationalized domain name with ACE prefix

'%f[%a][qxz]%.com$', -- assigned one character .com hostname (x.com times out 2015-12-10)

'%f[%a][iq]%.net$', -- assigned one character .net hostname (q.net registered but not active 2015-12-10)

'%f[%w][%w]%.%a%a$', -- one character hostname and ccTLD (2 chars)

'%f[%w][%w][%w]%.%a%a+$', -- two character hostname and TLD

'^%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?', -- IPv4 address

'[%a%d]+%:?' -- IPv6 address

}

for _, pattern in ipairs (patterns) do -- loop through the patterns list

if domain:match (pattern) then

return true; -- if a match then we think that this thing that purports to be a URL is a URL

end

end

for _, d in ipairs (cfg.single_letter_2nd_lvl_domains_t) do -- look for single letter second level domain names for these top level domains

if domain:match ('%f[%w][%w]%.' .. d) then

return true

end

end

return false; -- no matches, we don't know what this thing is

end

--- This function is the last step in the validation process. This function is separate because there are cases that

-- are not covered by split_url(), for example is_parameter_ext_wikilink() which is looking for bracketted external

-- wikilinks.

--

-- @param {string} scheme URI scheme

-- @param {string} domain Domain name

--

-- @return true if the scheme and domain parts of a URL appear to be a valid URL; else false.

local function is_url (scheme, domain)

if utilities.is_set (scheme) then -- if scheme is set check it and domain

return is_scheme (scheme) and is_domain_name (domain);

else

return is_domain_name (domain); -- scheme not set when URL is protocol-relative

end

end

--- Split a URL into a scheme, authority indicator, and domain.

--

-- First remove Fully Qualified Domain Name terminator (a dot following TLD) (if any) and any path(/), query(?) or fragment(#).

--

-- If protocol-relative URL, return nil scheme and domain else return nil for both scheme and domain.

--

-- When not protocol-relative, get scheme, authority indicator, and domain. If there is an authority indicator (one

-- or more '/' characters immediately following the scheme's colon), make sure that there are only 2.

--

-- Any URL that does not have news: scheme must have authority indicator (//). @todo: are there other common schemes

-- like news: that don't use authority indicator?

--

-- Strip off any port and path;

--

-- @param {string} url_str URL string

-- @return Split URL

local function split_url (url_str)

local scheme, authority, domain;

url_str = url_str:gsub ('([%a%d])%.?[/%?#].*$', '%1'); -- strip FQDN terminator and path(/), query(?), fragment (#) (the capture prevents false replacement of '//')

if url_str:match ('^//%S*') then -- if there is what appears to be a protocol-relative URL

domain = url_str:match ('^//(%S*)')

elseif url_str:match ('%S-:/*%S+') then -- if there is what appears to be a scheme, optional authority indicator, and domain name

scheme, authority, domain = url_str:match ('(%S-:)(/*)(%S+)'); -- extract the scheme, authority indicator, and domain portions

if utilities.is_set (authority) then

authority = authority:gsub ('//', '', 1); -- replace place 1 pair of '/' with nothing;

if utilities.is_set(authority) then -- if anything left (1 or 3+ '/' where authority should be) then

return scheme; -- return scheme only making domain nil which will cause an error message

end

else

if not scheme:match ('^news:') then -- except for news:..., MediaWiki won't link URLs that do not have authority indicator; @todo: a better way to do this test?

return scheme; -- return scheme only making domain nil which will cause an error message

end

end

domain = domain:gsub ('(%a):%d+', '%1'); -- strip port number if present

end

return scheme, domain;

end

--- checks the content of |title-link=, |series-link=, |author-link=, etc. for properly formatted content: no wikilinks, no URLs

--

-- Link parameters are to hold the title of a Wikipedia article, so none of the WP:TITLESPECIALCHARACTERS are allowed:

-- # < > [ ] | { } _

-- except the underscore which is used as a space in wiki URLs and # which is used for section links

--

-- returns false when the value contains any of these characters.

--

-- When there are no illegal characters, this function returns TRUE if value DOES NOT appear to be a valid URL (the

-- |-link= parameter is ok); else false when value appears to be a valid URL (the |-link= parameter is NOT ok).

--

-- @param {string} value URL parameter value

--

-- @return Whether the URL is invalid

local function link_param_ok (value)

local scheme, domain;

if value:find ('[<>%[%]|{}]') then -- if any prohibited characters

return false;

end

scheme, domain = split_url (value); -- get scheme or nil and domain or nil from URL;

return not is_url (scheme, domain); -- return true if value DOES NOT appear to be a valid URL

end

--- Use link_param_ok() to validate |-link= value and its matching |= value.</p> <p>--</p> <p>-- |<title>= may be wiki-linked but not when |<param>-link= has a value. This function emits an error message when</p> <p>-- that condition exists</p> <p>--</p> <p>-- check <link> for inter-language interwiki-link prefix. prefix must be a MediaWiki-recognized language</p> <p>-- code and must begin with a colon.</p> <p>--</p> <p>-- @param {string} link Link to check</p> <p>-- @param lorig</p> <p>-- @param title</p> <p>-- @param torig</p> <p>-- @return link if okay, empty string else</p> <p>local function link_title_ok (link, lorig, title, torig)</p> <p>local orig;</p> <p>if utilities.is_set (link) then -- don't bother if <param>-link doesn't have a value</p> <p>if not link_param_ok (link) then -- check |<param>-link= markup</p> <p>orig = lorig; -- identify the failing link parameter</p> <p>elseif title:find ('%[%[') then -- check |title= for wikilink markup</p> <p>orig = torig; -- identify the failing |title= parameter</p> <p>elseif link:match ('^%a+:') then -- if the link is what looks like an interwiki</p> <p>local prefix = link:match ('^(%a+):'):lower(); -- get the interwiki prefix</p> <p>if cfg.inter_wiki_map[prefix] then -- if prefix is in the map, must have preceding colon</p> <p>orig = lorig; -- flag as error</p> <p>end</p> <p>end</p> <p>end</p> <p>if utilities.is_set (orig) then</p> <p>link = ''; -- unset</p> <p>utilities.set_message ('err_bad_paramlink', orig); -- URL or wikilink in |title= with |title-link=;</p> <p>end</p> <p>return link; -- link if ok, empty string else</p> <p>end</p> <p>--- Determines whether a URL string appears to be valid.</p> <p>--</p> <p>-- First we test for space characters. If any are found, return false. Then split the URL into scheme and domain</p> <p>-- portions, or for protocol-relative (//example.com) URLs, just the domain. Use is_url() to validate the two</p> <p>-- portions of the URL. If both are valid, or for protocol-relative if domain is valid, return true, else false.</p> <p>--</p> <p>-- Because it is different from a standard URL, and because this module used external_link() to make external links</p> <p>-- that work for standard and news: links, we validate newsgroup names here. The specification for a newsgroup name</p> <p>-- is at https://tools.ietf.org/html/rfc5536#section-3.1.4</p> <p>--</p> <p>-- @param {string} url_str URL string to checl</p> <p>-- @return Whether URL is valid</p> <p>local function check_url( url_str )</p> <p>if nil == url_str:match ("^%S+$") then -- if there are any spaces in |url=value it can't be a proper URL</p> <p>return false;</p> <p>end</p> <p>local scheme, domain;</p> <p>scheme, domain = split_url (url_str); -- get scheme or nil and domain or nil from URL;</p> <p>if 'news:' == scheme then -- special case for newsgroups</p> <p>return domain:match('^[%a%d%+%-_]+%.[%a%d%+%-_%.]*[%a%d%+%-_]$');</p> <p>end</p> <p>return is_url (scheme, domain); -- return true if value appears to be a valid URL</p> <p>end</p> <p>--- Return true if a parameter value has a string that begins and ends with square brackets [ and ] and the first</p> <p>-- non-space characters following the opening bracket appear to be a URL. The test will also find external wikilinks</p> <p>-- that use protocol-relative URLs. Also finds bare URLs.</p> <p>--</p> <p>-- The frontier pattern prevents a match on interwiki-links which are similar to scheme:path URLs. The tests that</p> <p>-- find bracketed URLs are required because the parameters that call this test (currently |title=, |chapter=, |work=,</p> <p>-- and |publisher=) may have wikilinks and there are articles or redirects like '//Hus' so, while uncommon, |title=<a href='?title=%2F%2FHus'>//Hus</a></p> <p>-- is possible as might be <a href='?title=en%3A%2F%2FHus'>en://Hus</a>.</p> <p>--</p> <p>-- @param {string} value parameter value</p> <p>-- @return Whether URL is valid</p> <p>local function is_parameter_ext_wikilink (value)</p> <p>local scheme, domain;</p> <p>if value:match ('%f[%[]%[%a%S*:%S+.*%]') then -- if ext. wikilink with scheme and domain: [xxxx://yyyyy.zzz]</p> <p>scheme, domain = split_url (value:match ('%f[%[]%[(%a%S*:%S+).*%]'));</p> <p>elseif value:match ('%f[%[]%[//%S+.*%]') then -- if protocol-relative ext. wikilink: [//yyyyy.zzz]</p> <p>scheme, domain = split_url (value:match ('%f[%[]%[(//%S+).*%]'));</p> <p>elseif value:match ('%a%S*:%S+') then -- if bare URL with scheme; may have leading or trailing plain text</p> <p>scheme, domain = split_url (value:match ('(%a%S*:%S+)'));</p> <p>elseif value:match ('^//%S+') or value:match ('%s//%S+') then -- if protocol-relative bare URL: //yyyyy.zzz; authority indicator (//) must be be preceded nothing or by whitespace</p> <p>scheme, domain = split_url (value:match ('(//%S+)')); -- what is left should be the domain</p> <p>else</p> <p>return false; -- didn't find anything that is obviously a URL</p> <p>end</p> <p>return is_url (scheme, domain); -- return true if value appears to be a valid URL</p> <p>end</p> <p>--- loop through a list of parameters and their values. Look at the value and if it has an external link, emit an error message.</p> <p>--</p> <p>-- @param {table} parameter_list list of parameters</p> <p>-- @param {table} error_list list of citation errors</p> <p>local function check_for_url (parameter_list, error_list)</p> <p>for k, v in pairs (parameter_list) do -- for each parameter in the list</p> <p>if is_parameter_ext_wikilink (v) then -- look at the value; if there is a URL add an error message</p> <p>table.insert (error_list, utilities.wrap_style ('parameter', k));</p> <p>end</p> <p>end</p> <p>end</p> <p>--- Escape sequences for content that will be used for URL descriptions</p> <p>--</p> <p>-- @param {string} str string to escape</p> <p>-- @return escaped string</p> <p>local function safe_for_url( str )</p> <p>if str:match( "%[%[.-%]%]" ) ~= nil then</p> <p>utilities.set_message ('err_wikilink_in_url', {});</p> <p>end</p> <p>return str:gsub( '[%[%]\n]', {</p> <p>['['] = '[',</p> <p>[']'] = ']',</p> <p>['\n'] = ' ' } );</p> <p>end</p> <p>--- Format an external link with error checking</p> <p>--</p> <p>-- @param {string} URL URL of external link</p> <p>-- @param {string} label label for external link</p> <p>-- @param source</p> <p>-- @param access</p> <p>-- @raise Bare URL found but origin indicator is nil or empty</p> <p>-- @return Base URL</p> <p>local function external_link (URL, label, source, access)</p> <p>local err_msg = '';</p> <p>local domain;</p> <p>local path;</p> <p>local base_url;</p> <p>if not utilities.is_set (label) then</p> <p>label = URL;</p> <p>if utilities.is_set (source) then</p> <p>utilities.set_message ('err_bare_url_missing_title', {utilities.wrap_style ('parameter', source)});</p> <p>else</p> <p>error (cfg.messages["bare_url_no_origin"]); -- programmer error; valid parameter name does not have matching meta-parameter</p> <p>end</p> <p>end</p> <p>if not check_url (URL) then</p> <p>utilities.set_message ('err_bad_url', {utilities.wrap_style ('parameter', source)});</p> <p>end</p> <p>domain, path = URL:match ('^([/%.%-%+:%a%d]+)([/%?#].*)$'); -- split the URL into scheme plus domain and path</p> <p>if path then -- if there is a path portion</p> <p>path = path:gsub ('[%[%]]', {['['] = '%5b', [']'] = '%5d'}); -- replace '[' and ']' with their percent-encoded values</p> <p>URL = table.concat ({domain, path}); -- and reassemble</p> <p>end</p> <p>base_url = table.concat ({ "[", URL, " ", safe_for_url (label), "]" }); -- assemble a wiki-markup URL</p> <p>if utilities.is_set (access) then -- access level (subscription, registration, limited)</p> <p>base_url = utilities.substitute (cfg.presentation['ext-link-access-signal'], {cfg.presentation[access].class, cfg.presentation[access].title, base_url}); -- add the appropriate icon</p> <p>end</p> <p>return base_url;</p> <p>end</p> <p>--- Categorize and emit an error message when the citation contains one or more deprecated parameters. The function includes the</p> <p>-- offending parameter name to the error message. Only one error message is emitted regardless of the number of deprecated</p> <p>-- parameters in the citation.</p> <p>--</p> <p>-- added_deprecated_cat is a Boolean declared in page scope variables above</p> <p>--</p> <p>-- @param {string} deprecated parameter name</p> <p>local function deprecated_parameter(name)</p> <p>if not added_deprecated_cat then</p> <p>added_deprecated_cat = true; -- note that we've added this category</p> <p>utilities.set_message ('err_deprecated_params', {name}); -- add error message</p> <p>end</p> <p>end</p> <p>--- Apply kerning to open the space between the quote mark provided by the module and a leading or trailing quote</p> <p>-- mark contained in a |title= or |chapter= parameter's value.</p> <p>--</p> <p>-- This function will positive kern either single or double quotes:</p> <p>-- "'Unkerned title with leading and trailing single quote marks'"</p> <p>-- " 'Kerned title with leading and trailing single quote marks' " (in real life the kerning isn't as wide as this example)</p> <p>-- Double single quotes (italic or bold wiki-markup) are not kerned.</p> <p>--</p> <p>-- Replaces Unicode quote marks in plain text or in the label portion of a <a href='?title=L'>D</a> style wikilink with typewriter</p> <p>-- quote marks regardless of the need for kerning. Unicode quote marks are not replaced in simple <a href='?title=D'>D</a> wikilinks.</p> <p>--</p> <p>-- Call this function for chapter titles, for website titles, etc.; not for book titles.</p> <p>--</p> <p>-- @param {string} str</p> <p>-- @return escaped string</p> <p>local function kern_quotes (str)</p> <p>local cap = '';</p> <p>local wl_type, label, link;</p> <p>wl_type, label, link = utilities.is_wikilink (str); -- wl_type is: 0, no wl (text in label variable); 1, <a href='?title=D'>D</a>; 2, <a href='?title=L'>D</a></p> <p>if 1 == wl_type then -- <a href='?title=D'>D</a> simple wikilink with or without quote marks</p> <p>if mw.ustring.match (str, '%[%[[\"“”\'‘’].+[\"“”\'‘’]%]%]') then -- leading and trailing quote marks</p> <p>str = utilities.substitute (cfg.presentation['kern-left'], str);</p> <p>str = utilities.substitute (cfg.presentation['kern-right'], str);</p> <p>elseif mw.ustring.match (str, '%[%[[\"“”\'‘’].+%]%]') then -- leading quote marks</p> <p>str = utilities.substitute (cfg.presentation['kern-left'], str);</p> <p>elseif mw.ustring.match (str, '%[%[.+[\"“”\'‘’]%]%]') then -- trailing quote marks</p> <p>str = utilities.substitute (cfg.presentation['kern-right'], str);</p> <p>end</p> <p>else -- plain text or <a href='?title=L'>D</a>; text in label variable</p> <p>label = mw.ustring.gsub (label, '[“”]', '\"'); -- replace “” (U+201C & U+201D) with " (typewriter double quote mark)</p> <p>label = mw.ustring.gsub (label, '[‘’]', '\''); -- replace ‘’ (U+2018 & U+2019) with ' (typewriter single quote mark)</p> <p>cap = mw.ustring.match (label, "^([\"\'][^\'].+)"); -- match leading double or single quote but not doubled single quotes (italic markup)</p> <p>if utilities.is_set (cap) then</p> <p>label = utilities.substitute (cfg.presentation['kern-left'], cap);</p> <p>end</p> <p>cap = mw.ustring.match (label, "^(.+[^\'][\"\'])$") -- match trailing double or single quote but not doubled single quotes (italic markup)</p> <p>if utilities.is_set (cap) then</p> <p>label = utilities.substitute (cfg.presentation['kern-right'], cap);</p> <p>end</p> <p>if 2 == wl_type then</p> <p>str = utilities.make_wikilink (link, label); -- reassemble the wikilink</p> <p>else</p> <p>str = label;</p> <p>end</p> <p>end</p> <p>return str;</p> <p>end</p> <p>--- |script-title= holds title parameters that are not written in Latin-based scripts: Chinese, Japanese, Arabic, Hebrew, etc. These scripts should</p> <p>-- not be italicized and may be written right-to-left. The value supplied by |script-title= is concatenated onto Title after Title has been wrapped</p> <p>-- in italic markup.</p> <p>--</p> <p>-- Regardless of language, all values provided by |script-title= are wrapped in <bdi>...</bdi> tags to isolate RTL languages from the English left to right.</p> <p>--</p> <p>-- |script-title= provides a unique feature. The value in |script-title= may be prefixed with a two-character ISO 639-1 language code and a colon:</p> <p>-- |script-title=ja:*** *** (where * represents a Japanese character)</p> <p>-- Spaces between the two-character code and the colon and the colon and the first script character are allowed:</p> <p>-- |script-title=ja : *** ***</p> <p>-- |script-title=ja: *** ***</p> <p>-- |script-title=ja :*** ***</p> <p>-- Spaces preceding the prefix are allowed: |script-title = ja:*** ***</p> <p>--</p> <p>-- The prefix is checked for validity. If it is a valid ISO 639-1 language code, the lang attribute (lang="ja") is added to the <bdi> tag so that browsers can</p> <p>-- know the language the tag contains. This may help the browser render the script more correctly. If the prefix is invalid, the lang attribute</p> <p>-- is not added. At this time there is no error message for this condition.</p> <p>--</p> <p>-- Supports |script-title=, |script-chapter=, |script-<periodical>=</p> <p>--</p> <p>-- @param {string} script_value</p> <p>-- @param {string} script_param</p> <p>-- @return formatted script value</p> <p>local function format_script_value (script_value, script_param)</p> <p>local lang=''; -- initialize to empty string</p> <p>local name;</p> <p>if script_value:match('^%l%l%l?%s*:') then -- if first 3 or 4 non-space characters are script language prefix</p> <p>lang = script_value:match('^(%l%l%l?)%s*:%s*%S.*'); -- get the language prefix or nil if there is no script</p> <p>if not utilities.is_set (lang) then</p> <p>utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['missing title part']}); -- prefix without 'title'; add error message</p> <p>return ''; -- script_value was just the prefix so return empty string</p> <p>end</p> <p>-- if we get this far we have prefix and script</p> <p>name = cfg.lang_tag_remap[lang] or mw.language.fetchLanguageName( lang, cfg.this_wiki_code ); -- get language name so that we can use it to categorize</p> <p>if utilities.is_set (name) then -- is prefix a proper ISO 639-1 language code?</p> <p>script_value = script_value:gsub ('^%l+%s*:%s*', ''); -- strip prefix from script</p> <p>-- is prefix one of these language codes?</p> <p>if utilities.in_array (lang, cfg.script_lang_codes) then</p> <p>utilities.add_prop_cat ('script', {name, lang})</p> <p>else</p> <p>utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['unknown language code']}); -- unknown script-language; add error message</p> <p>end</p> <p>lang = ' lang="' .. lang .. '" '; -- convert prefix into a lang attribute</p> <p>else</p> <p>utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['invalid language code']}); -- invalid language code; add error message</p> <p>lang = ''; -- invalid so set lang to empty string</p> <p>end</p> <p>else</p> <p>utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['missing prefix']}); -- no language code prefix; add error message</p> <p>end</p> <p>script_value = utilities.substitute (cfg.presentation['bdi'], {lang, script_value}); -- isolate in case script is RTL</p> <p>return script_value;</p> <p>end</p> <p>--- Initially for |title= and |script-title=, this function concatenates those two parameter values after the script</p> <p>-- value has been wrapped in <bdi> tags.</p> <p>--</p> <p>-- @param {string} title passed title parameter</p> <p>-- @param {string} script script to use</p> <p>-- @param {string} script_param</p> <p>-- @return concatenated title</p> <p>local function script_concatenate (title, script, script_param)</p> <p>if utilities.is_set (script) then</p> <p>script = format_script_value (script, script_param); -- <bdi> tags, lang attribute, categorization, etc.; returns empty string on error</p> <p>if utilities.is_set (script) then</p> <p>title = title .. ' ' .. script; -- concatenate title and script title</p> <p>end</p> <p>end</p> <p>return title;</p> <p>end</p> <p>--- Applies additional message text to various parameter values. Supplied string is wrapped using a message_list</p> <p>-- configuration taking one argument. Supports lower case text for {{tl|citation}} templates. Additional text taken</p> <p>-- from citation_config.messages - the reason this function is similar to but separate from wrap_style().</p> <p>--</p> <p>-- @param {string} key message key</p> <p>-- @param {string} str string to format</p> <p>-- @param {boolean} lower whether to make message lowercase</p> <p>-- @return formatted string</p> <p>local function wrap_msg (key, str, lower)</p> <p>if not utilities.is_set ( str ) then</p> <p>return "";</p> <p>end</p> <p>if true == lower then</p> <p>local msg;</p> <p>msg = cfg.messages[key]:lower(); -- set the message to lower case before</p> <p>return utilities.substitute ( msg, str ); -- including template text</p> <p>else</p> <p>return utilities.substitute ( cfg.messages[key], str );</p> <p>end</p> <p>end</p> <p>--- Makes a Wikisource URL from Wikisource interwiki-link.</p> <p>--</p> <p>-- @param {string} str the value assigned to |chapter= (or aliases) or |title= or |title-link=</p> <p>-- @return The URL and appropriate label; nil else.</p> <p>local function wikisource_url_make (str)</p> <p>local wl_type, D, L;</p> <p>local ws_url, ws_label;</p> <p>local wikisource_prefix = table.concat ({'https://', cfg.this_wiki_code, '.wikisource.org/wiki/'});</p> <p>wl_type, D, L = utilities.is_wikilink (str); -- wl_type is 0 (not a wikilink), 1 (simple wikilink), 2 (complex wikilink)</p> <p>if 0 == wl_type then -- not a wikilink; might be from |title-link=</p> <p>str = D:match ('^[Ww]ikisource:(.+)') or D:match ('^[Ss]:(.+)'); -- article title from interwiki link with long-form or short-form namespace</p> <p>if utilities.is_set (str) then</p> <p>ws_url = table.concat ({ -- build a Wikisource URL</p> <p>wikisource_prefix, -- prefix</p> <p>str, -- article title</p> <p>});</p> <p>ws_label = str; -- label for the URL</p> <p>end</p> <p>elseif 1 == wl_type then -- simple wikilink: <a href='?title=Wikisource%3Aws_article'>Wikisource:ws article</a></p> <p>str = D:match ('^[Ww]ikisource:(.+)') or D:match ('^[Ss]:(.+)'); -- article title from interwiki link with long-form or short-form namespace</p> <p>if utilities.is_set (str) then</p> <p>ws_url = table.concat ({ -- build a Wikisource URL</p> <p>wikisource_prefix, -- prefix</p> <p>str, -- article title</p> <p>});</p> <p>ws_label = str; -- label for the URL</p> <p>end</p> <p>elseif 2 == wl_type then -- non-so-simple wikilink: <a href='?title=Wikisource%3Aws_article'>displayed text</a> (<a href='?title=L'>D</a>)</p> <p>str = L:match ('^[Ww]ikisource:(.+)') or L:match ('^[Ss]:(.+)'); -- article title from interwiki link with long-form or short-form namespace</p> <p>if utilities.is_set (str) then</p> <p>ws_label = D; -- get ws article name from display portion of interwiki link</p> <p>ws_url = table.concat ({ -- build a Wikisource URL</p> <p>wikisource_prefix, -- prefix</p> <p>str, -- article title without namespace from link portion of wikilink</p> <p>});</p> <p>end</p> <p>end</p> <p>if ws_url then</p> <p>ws_url = mw.uri.encode (ws_url, 'WIKI'); -- make a usable URL</p> <p>ws_url = ws_url:gsub ('%%23', '#'); -- undo percent-encoding of fragment marker</p> <p>end</p> <p>return ws_url, ws_label, L or D; -- return proper URL or nil and a label or nil</p> <p>end</p> <p>--- Format the three periodical parameters: |script-<periodical>=, |<periodical>=,</p> <p>-- and |trans-<periodical>= into a single Periodical meta-parameter.</p> <p>--</p> <p>-- @param {string} script_periodical</p> <p>-- @param {string} script_periodical_source</p> <p>-- @param {string} periodical</p> <p>-- @param {string} trans_periodical</p> <p>-- @return formatted periodical</p> <p>local function format_periodical (script_periodical, script_periodical_source, periodical, trans_periodical)</p> <p>if not utilities.is_set (periodical) then</p> <p>periodical = ''; -- to be safe for concatenation</p> <p>else</p> <p>periodical = utilities.wrap_style ('italic-title', periodical); -- style</p> <p>end</p> <p>periodical = script_concatenate (periodical, script_periodical, script_periodical_source); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped</p> <p>if utilities.is_set (trans_periodical) then</p> <p>trans_periodical = utilities.wrap_style ('trans-italic-title', trans_periodical);</p> <p>if utilities.is_set (periodical) then</p> <p>periodical = periodical .. ' ' .. trans_periodical;</p> <p>else -- here when trans-periodical without periodical or script-periodical</p> <p>periodical = trans_periodical;</p> <p>utilities.set_message ('err_trans_missing_title', {'periodical'});</p> <p>end</p> <p>end</p> <p>return periodical;</p> <p>end</p> <p>--- Format the four chapter parameters: |script-chapter=, |chapter=, |trans-chapter=,</p> <p>-- and |chapter-url= into a single chapter meta- parameter (chapter_url_source used</p> <p>-- for error messages).</p> <p>--</p> <p>-- @param {string} script_chapter</p> <p>-- @param {string} script_chapter_source</p> <p>-- @param {string} chapter</p> <p>-- @param {string} chapter_source</p> <p>-- @param {string} trans_chapter</p> <p>-- @param {string} trans_chapter_source</p> <p>-- @param {string} chapter_url</p> <p>-- @param {string} chapter_url_source</p> <p>-- @param {string} no_quotes</p> <p>-- @param {string} access</p> <p>-- @return formatted chapter title</p> <p>local function format_chapter_title (script_chapter, script_chapter_source, chapter, chapter_source, trans_chapter, trans_chapter_source, chapter_url, chapter_url_source, no_quotes, access)</p> <p>local ws_url, ws_label, L = wikisource_url_make (chapter); -- make a wikisource URL and label from a wikisource interwiki link</p> <p>if ws_url then</p> <p>ws_label = ws_label:gsub ('_', ' '); -- replace underscore separators with space characters</p> <p>chapter = ws_label;</p> <p>end</p> <p>if not utilities.is_set (chapter) then</p> <p>chapter = ''; -- to be safe for concatenation</p> <p>else</p> <p>if false == no_quotes then</p> <p>chapter = kern_quotes (chapter); -- if necessary, separate chapter title's leading and trailing quote marks from module provided quote marks</p> <p>chapter = utilities.wrap_style ('quoted-title', chapter);</p> <p>end</p> <p>end</p> <p>chapter = script_concatenate (chapter, script_chapter, script_chapter_source); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped</p> <p>if utilities.is_set (chapter_url) then</p> <p>chapter = external_link (chapter_url, chapter, chapter_url_source, access); -- adds bare_url_missing_title error if appropriate</p> <p>elseif ws_url then</p> <p>chapter = external_link (ws_url, chapter .. ' ', '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?</p> <p>chapter = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, chapter});</p> <p>end</p> <p>if utilities.is_set (trans_chapter) then</p> <p>trans_chapter = utilities.wrap_style ('trans-quoted-title', trans_chapter);</p> <p>if utilities.is_set (chapter) then</p> <p>chapter = chapter .. ' ' .. trans_chapter;</p> <p>else -- here when trans_chapter without chapter or script-chapter</p> <p>chapter = trans_chapter;</p> <p>chapter_source = trans_chapter_source:match ('trans%-?(.+)'); -- when no chapter, get matching name from trans-<param></p> <p>utilities.set_message ('err_trans_missing_title', {chapter_source});</p> <p>end</p> <p>end</p> <p>return chapter;</p> <p>end</p> <p>--- This function searches a parameter's value for non-printable or invisible characters.</p> <p>-- The search stops at the first match.</p> <p>--</p> <p>-- This function will detect the visible replacement character when it is part of the Wikisource.</p> <p>--</p> <p>-- Detects but ignores nowiki and math stripmarkers. Also detects other named stripmarkers</p> <p>-- (gallery, math, pre, ref) and identifies them with a slightly different error message.</p> <p>-- See also coins_cleanup().</p> <p>--</p> <p>-- Output of this function is an error message that identifies the character or the</p> <p>-- Unicode group, or the stripmarker that was detected along with its position (or,</p> <p>-- for multi-byte characters, the position of its first byte) in the parameter value.</p> <p>--</p> <p>-- @param {string} param param name</p> <p>-- @param {string} v value of parameter</p> <p>local function has_invisible_chars (param, v)</p> <p>local position = ''; -- position of invisible char or starting position of stripmarker</p> <p>local capture; -- used by stripmarker detection to hold name of the stripmarker</p> <p>local stripmarker; -- boolean set true when a stripmarker is found</p> <p>capture = string.match (v, '[%w%p ]*'); -- test for values that are simple ASCII text and bypass other tests if true</p> <p>if capture == v then -- if same there are no Unicode characters</p> <p>return;</p> <p>end</p> <p>for _, invisible_char in ipairs (cfg.invisible_chars) do</p> <p>local char_name = invisible_char[1]; -- the character or group name</p> <p>local pattern = invisible_char[2]; -- the pattern used to find it</p> <p>position, _, capture = mw.ustring.find (v, pattern); -- see if the parameter value contains characters that match the pattern</p> <p>if position and (cfg.invisible_defs.zwj == capture) then -- if we found a zero-width joiner character</p> <p>if mw.ustring.find (v, cfg.indic_script) then -- it's ok if one of the Indic scripts</p> <p>position = nil; -- unset position</p> <p>elseif cfg.emoji_t[mw.ustring.codepoint (v, position+1)] then -- is zwj followed by a character listed in emoji{}?</p> <p>position = nil; -- unset position</p> <p>end</p> <p>end</p> <p>if position then</p> <p>if 'nowiki' == capture or 'math' == capture or -- nowiki and math stripmarkers (not an error condition)</p> <p>('templatestyles' == capture and utilities.in_array (param, {'id', 'quote'})) then -- templatestyles stripmarker allowed in these parameters</p> <p>stripmarker = true; -- set a flag</p> <p>elseif true == stripmarker and cfg.invisible_defs.del == capture then -- because stripmakers begin and end with the delete char, assume that we've found one end of a stripmarker</p> <p>position = nil; -- unset</p> <p>else</p> <p>local err_msg;</p> <p>if capture and not (cfg.invisible_defs.del == capture or cfg.invisible_defs.zwj == capture) then</p> <p>err_msg = capture .. ' ' .. char_name;</p> <p>else</p> <p>err_msg = char_name .. ' ' .. 'character';</p> <p>end</p> <p>utilities.set_message ('err_invisible_char', {err_msg, utilities.wrap_style ('parameter', param), position}); -- add error message</p> <p>return; -- and done with this parameter</p> <p>end</p> <p>end</p> <p>end</p> <p>end</p> <p>-- Argument wrapper. This function provides support for argument mapping defined</p> <p>-- in the configuration file so that multiple names can be transparently aliased to</p> <p>-- single internal variable.</p> <p>--</p> <p>-- @param {table} args Arguments</p> <p>-- @return value</p> <p>local function argument_wrapper ( args )</p> <p>local origin = {};</p> <p>return setmetatable({</p> <p>ORIGIN = function ( self, k )</p> <p>local dummy = self[k]; -- force the variable to be loaded.</p> <p>return origin[k];</p> <p>end</p> <p>},</p> <p>{</p> <p>__index = function ( tbl, k )</p> <p>if origin[k] ~= nil then</p> <p>return nil;</p> <p>end</p> <p>local args, list, v = args, cfg.aliases[k];</p> <p>if type( list ) == 'table' then</p> <p>v, origin[k] = utilities.select_one ( args, list, 'err_redundant_parameters' );</p> <p>if origin[k] == nil then</p> <p>origin[k] = ''; -- Empty string, not nil</p> <p>end</p> <p>elseif list ~= nil then</p> <p>v, origin[k] = args[list], list;</p> <p>else</p> <p>-- maybe let through instead of raising an error?</p> <p>-- v, origin[k] = args[k], k;</p> <p>error( cfg.messages['unknown_argument_map'] .. ': ' .. k);</p> <p>end</p> <p>-- Empty strings, not nil;</p> <p>if v == nil then</p> <p>v = '';</p> <p>origin[k] = '';</p> <p>end</p> <p>tbl = rawset( tbl, k, v );</p> <p>return v;</p> <p>end,</p> <p>});</p> <p>end</p> <p>--- When date is YYYY-MM-DD format wrap in nowrap span: <span ...>YYYY-MM-DD</span>.</p> <p>-- When date is DD MMMM YYYY or is MMMM DD, YYYY then wrap in nowrap span:</p> <p>-- <span ...>DD MMMM</span> YYYY or <span ...>MMMM DD,</span> YYYY</p> <p>--</p> <p>-- DOES NOT yet support MMMM YYYY or any of the date ranges.</p> <p>--</p> <p>-- @param {string} date Formatted date</p> <p>-- @return Date with appropriate nowrap element</p> <p>local function nowrap_date (date)</p> <p>local cap = '';</p> <p>local cap2 = '';</p> <p>if date:match("^%d%d%d%d%-%d%d%-%d%d$") then</p> <p>date = utilities.substitute (cfg.presentation['nowrap1'], date);</p> <p>elseif date:match("^%a+%s*%d%d?,%s+%d%d%d%d$") or date:match ("^%d%d?%s*%a+%s+%d%d%d%d$") then</p> <p>cap, cap2 = string.match (date, "^(.*)%s+(%d%d%d%d)$");</p> <p>date = utilities.substitute (cfg.presentation['nowrap2'], {cap, cap2});</p> <p>end</p> <p>return date;</p> <p>end</p> <p>--- This function sets default title types (equivalent to the citation including</p> <p>-- |type=<default value>) for those templates that have defaults. Also handles the</p> <p>-- special case where it is desirable to omit the title type from the rendered citation</p> <p>-- (|type=none).</p> <p>--</p> <p>-- @param {string} cite_class class of citation</p> <p>-- @param {string} title_type title type</p> <p>-- @return {string} title type</p> <p>local function set_titletype (cite_class, title_type)</p> <p>if utilities.is_set (title_type) then</p> <p>if 'none' == cfg.keywords_xlate[title_type] then</p> <p>title_type = ''; -- if |type=none then type parameter not displayed</p> <p>end</p> <p>return title_type; -- if |type= has been set to any other value use that value</p> <p>end</p> <p>return cfg.title_types [cite_class] or ''; -- set template's default title type; else empty string for concatenation</p> <p>end</p> <p>--- Joins a sequence of strings together while checking for duplicate separation characters.</p> <p>--</p> <p>-- @param {table} tbl</p> <p>-- @param {string} duplicate_char</p> <p>-- @return {string} joined string</p> <p>local function safe_join( tbl, duplicate_char )</p> <p>local f = {}; -- create a function table appropriate to type of 'duplicate character'</p> <p>if 1 == #duplicate_char then -- for single byte ASCII characters use the string library functions</p> <p>f.gsub = string.gsub</p> <p>f.match = string.match</p> <p>f.sub = string.sub</p> <p>else -- for multi-byte characters use the ustring library functions</p> <p>f.gsub = mw.ustring.gsub</p> <p>f.match = mw.ustring.match</p> <p>f.sub = mw.ustring.sub</p> <p>end</p> <p>local str = ''; -- the output string</p> <p>local comp = ''; -- what does 'comp' mean?</p> <p>local end_chr = '';</p> <p>local trim;</p> <p>for _, value in ipairs( tbl ) do</p> <p>if value == nil then value = ''; end</p> <p>if str == '' then -- if output string is empty</p> <p>str = value; -- assign value to it (first time through the loop)</p> <p>elseif value ~= '' then</p> <p>if value:sub(1, 1) == '<' then -- special case of values enclosed in spans and other markup.</p> <p>comp = value:gsub( "%b<>", "" ); -- remove HTML markup (<span>string</span> -> string)</p> <p>else</p> <p>comp = value;</p> <p>end</p> <p>-- typically duplicate_char is sepc</p> <p>if f.sub(comp, 1, 1) == duplicate_char then -- is first character same as duplicate_char? why test first character?</p> <p>-- Because individual string segments often (always?) begin with terminal punct for the</p> <p>-- preceding segment: 'First element' .. 'sepc next element' .. etc.?</p> <p>trim = false;</p> <p>end_chr = f.sub(str, -1, -1); -- get the last character of the output string</p> <p>-- str = str .. "<HERE(enchr=" .. end_chr .. ")" -- debug stuff?</p> <p>if end_chr == duplicate_char then -- if same as separator</p> <p>str = f.sub(str, 1, -2); -- remove it</p> <p>elseif end_chr == "'" then -- if it might be wiki-markup</p> <p>if f.sub(str, -3, -1) == duplicate_char .. "<em>" then -- if last three chars of str are sepc</em></p> <p>str = f.sub(str, 1, -4) .. "<em>"; -- remove them and add back </em></p> <p>elseif f.sub(str, -5, -1) == duplicate_char .. "]]<em>" then -- if last five chars of str are sepc]]</em></p> <p>trim = true; -- why? why do this and next differently from previous?</p> <p>elseif f.sub(str, -4, -1) == duplicate_char .. "]<em>" then -- if last four chars of str are sepc]</em></p> <p>trim = true; -- same question</p> <p>end</p> <p>elseif end_chr == "]" then -- if it might be wiki-markup</p> <p>if f.sub(str, -3, -1) == duplicate_char .. "]]" then -- if last three chars of str are sepc]] wikilink</p> <p>trim = true;</p> <p>elseif f.sub(str, -3, -1) == duplicate_char .. '"]' then -- if last three chars of str are sepc"] quoted external link</p> <p>trim = true;</p> <p>elseif f.sub(str, -2, -1) == duplicate_char .. "]" then -- if last two chars of str are sepc] external link</p> <p>trim = true;</p> <p>elseif f.sub(str, -4, -1) == duplicate_char .. "'']" then -- normal case when |url=something & |title=Title.</p> <p>trim = true;</p> <p>end</p> <p>elseif end_chr == " " then -- if last char of output string is a space</p> <p>if f.sub(str, -2, -1) == duplicate_char .. " " then -- if last two chars of str are <sepc><space></p> <p>str = f.sub(str, 1, -3); -- remove them both</p> <p>end</p> <p>end</p> <p>if trim then</p> <p>if value ~= comp then -- value does not equal comp when value contains HTML markup</p> <p>local dup2 = duplicate_char;</p> <p>if f.match(dup2, "%A" ) then dup2 = "%" .. dup2; end -- if duplicate_char not a letter then escape it</p> <p>value = f.gsub(value, "(%b<>)" .. dup2, "%1", 1 ) -- remove duplicate_char if it follows HTML markup</p> <p>else</p> <p>value = f.sub(value, 2, -1 ); -- remove duplicate_char when it is first character</p> <p>end</p> <p>end</p> <p>end</p> <p>str = str .. value; -- add it to the output string</p> <p>end</p> <p>end</p> <p>return str;</p> <p>end</p> <p>--- Checks to see if string is suffix. Punctuation is not allowed.</p> <p>--</p> <p>-- @param {string} suffix suffix to check</p> <p>-- @return whether suffix is properly formed Jr, Sr, or ordinal in the range 1–9.</p> <p>local function is_suffix (suffix)</p> <p>if utilities.in_array (suffix, {'Jr', 'Sr', 'Jnr', 'Snr', '1st', '2nd', '3rd'}) or suffix:match ('^%dth$') then</p> <p>return true;</p> <p>end</p> <p>return false;</p> <p>end</p> <p>--- For Vancouver style, author/editor names are supposed to be rendered in Latin</p> <p>-- (read ASCII) characters. When a name uses characters that contain diacritical</p> <p>-- marks, those characters are to be converted to the corresponding Latin</p> <p>-- character. When a name is written using a non-Latin alphabet or logogram, that</p> <p>-- name is to be transliterated into Latin characters. The module doesn't do this</p> <p>-- so editors may/must.</p> <p>--</p> <p>-- This test allows |first= and |last= names to contain any of the letters defined</p> <p>-- in the four Unicode Latin character sets</p> <p>-- [http://www.unicode.org/charts/PDF/U0000.pdf C0 Controls and Basic Latin] 0041–005A, 0061–007A</p> <p>-- [http://www.unicode.org/charts/PDF/U0080.pdf C1 Controls and Latin-1 Supplement] 00C0–00D6, 00D8–00F6, 00F8–00FF</p> <p>-- [http://www.unicode.org/charts/PDF/U0100.pdf Latin Extended-A] 0100–017F</p> <p>-- [http://www.unicode.org/charts/PDF/U0180.pdf Latin Extended-B] 0180–01BF, 01C4–024F</p> <p>--</p> <p>-- |lastn= also allowed to contain hyphens, spaces, and apostrophes.</p> <p>-- (http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35029/)</p> <p>-- |firstn= also allowed to contain hyphens, spaces, apostrophes, and periods</p> <p>--</p> <p>-- This original test:</p> <p>-- if nil == mw.ustring.find (last, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%']*$")</p> <p>-- or nil == mw.ustring.find (first, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%'%.]+[2-6%a]*$") then</p> <p>-- was written outside of the code editor and pasted here because the code editor</p> <p>-- gets confused between character insertion point and cursor position. The test has</p> <p>-- been rewritten to use decimal character escape sequence for the individual bytes</p> <p>-- of the Unicode characters so that it is not necessary to use an external editor</p> <p>-- to maintain this code.</p> <p>--</p> <p>-- \195\128-\195\150 – À-Ö (U+00C0–U+00D6 – C0 controls)</p> <p>-- \195\152-\195\182 – Ø-ö (U+00D8-U+00F6 – C0 controls)</p> <p>-- \195\184-\198\191 – ø-ƿ (U+00F8-U+01BF – C0 controls, Latin extended A & B)</p> <p>-- \199\132-\201\143 – DŽ-ɏ (U+01C4-U+024F – Latin extended B)</p> <p>--</p> <p>-- @param {string} last Last name</p> <p>-- @param {string} first First name</p> <p>-- @param {string} suffix Suffix</p> <p>-- @param {number} position Position to check</p> <p>-- @return Whether name is valid Vancouver name</p> <p>local function is_good_vanc_name (last, first, suffix, position)</p> <p>if not suffix then</p> <p>if first:find ('[,%s]') then -- when there is a space or comma, might be first name/initials + generational suffix</p> <p>first = first:match ('(.-)[,%s]+'); -- get name/initials</p> <p>suffix = first:match ('[,%s]+(.+)$'); -- get generational suffix</p> <p>end</p> <p>end</p> <p>if utilities.is_set (suffix) then</p> <p>if not is_suffix (suffix) then</p> <p>add_vanc_error (cfg.err_msg_supl.suffix, position);</p> <p>return false; -- not a name with an appropriate suffix</p> <p>end</p> <p>end</p> <p>if nil == mw.ustring.find (last, "^[A-Za-z\195\128-\195\150\195\152-\195\182\195\184-\198\191\199\132-\201\143\225\184\128-\225\187\191%-%s%']*$") or</p> <p>nil == mw.ustring.find (first, "^[A-Za-z\195\128-\195\150\195\152-\195\182\195\184-\198\191\199\132-\201\143\225\184\128-\225\187\191%-%s%'%.]*$") then</p> <p>add_vanc_error (cfg.err_msg_supl['non-Latin char'], position);</p> <p>return false; -- not a string of Latin characters; Vancouver requires Romanization</p> <p>end;</p> <p>return true;</p> <p>end</p> <p>--- Attempts to convert names to initials in support of |name-list-style=vanc.</p> <p>--</p> <p>-- Names in |firstn= may be separated by spaces or hyphens, or for initials, a period.</p> <p>-- See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35062/.</p> <p>--</p> <p>-- Vancouver style requires family rank designations (Jr, II, III, etc.) to be rendered</p> <p>-- as Jr, 2nd, 3rd, etc. See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35085/.</p> <p>-- This code only accepts and understands generational suffix in the Vancouver format</p> <p>-- because Roman numerals look like, and can be mistaken for, initials.</p> <p>--</p> <p>-- This function uses ustring functions because firstname initials may be any of the</p> <p>-- Unicode Latin characters accepted by is_good_vanc_name ().</p> <p>--</p> <p>-- @param {string} first First name</p> <p>-- @param {number} position Position number</p> <p>-- @return Concatenated initials</p> <p>local function reduce_to_initials (first, position)</p> <p>if first:find (',', 1, true) then</p> <p>return first; -- commas not allowed; abandon</p> <p>end</p> <p>local name, suffix = mw.ustring.match (first, "^(%u+) ([%dJS][%drndth]+)$");</p> <p>if not name then -- if not initials and a suffix</p> <p>name = mw.ustring.match (first, "^(%u+)$"); -- is it just initials?</p> <p>end</p> <p>if name then -- if first is initials with or without suffix</p> <p>if 3 > mw.ustring.len (name) then -- if one or two initials</p> <p>if suffix then -- if there is a suffix</p> <p>if is_suffix (suffix) then -- is it legitimate?</p> <p>return first; -- one or two initials and a valid suffix so nothing to do</p> <p>else</p> <p>add_vanc_error (cfg.err_msg_supl.suffix, position); -- one or two initials with invalid suffix so error message</p> <p>return first; -- and return first unmolested</p> <p>end</p> <p>else</p> <p>return first; -- one or two initials without suffix; nothing to do</p> <p>end</p> <p>end</p> <p>end -- if here then name has 3 or more uppercase letters so treat them as a word</p> <p>local initials_t, names_t = {}, {}; -- tables to hold name parts and initials</p> <p>local i = 1; -- counter for number of initials</p> <p>names_t = mw.text.split (first, '[%s%-]+'); -- split into a sequence of names and possible suffix</p> <p>while names_t[i] do -- loop through the sequence</p> <p>if 1 < i and names_t[i]:match ('[%dJS][%drndth]+%.?$') then -- if not the first name, and looks like a suffix (may have trailing dot)</p> <p>names_t[i] = names_t[i]:gsub ('%.', ''); -- remove terminal dot if present</p> <p>if is_suffix (names_t[i]) then -- if a legitimate suffix</p> <p>table.insert (initials_t, ' ' .. names_t[i]); -- add a separator space, insert at end of initials sequence</p> <p>break; -- and done because suffix must fall at the end of a name</p> <p>end -- no error message if not a suffix; possibly because of Romanization</p> <p>end</p> <p>if 3 > i then</p> <p>table.insert (initials_t, mw.ustring.sub (names_t[i], 1, 1)); -- insert the initial at end of initials sequence</p> <p>end</p> <p>i = i + 1; -- bump the counter</p> <p>end</p> <p>return table.concat (initials_t); -- Vancouver format does not include spaces.</p> <p>end</p> <p>--- extract interwiki prefixen from <value>. Returns two one or two values:</p> <p>-- false – no prefixen</p> <p>-- nil – prefix exists but not recognized</p> <p>-- project prefix, language prefix – when value has either of:</p> <p>-- :<project>:<language>:<article></p> <p>-- :<language>:<project>:<article></p> <p>-- project prefix, nil – when <value> has only a known single-letter prefix</p> <p>-- nil, language prefix – when <value> has only a known language prefix</p> <p>--</p> <p>-- accepts single-letter project prefixen: 'd' (wikidata), 's' (wikisource), and 'w' (wikipedia) prefixes; at this</p> <p>-- writing, the other single-letter prefixen (b (wikibook), c (commons), m (meta), n (wikinews), q (wikiquote), and</p> <p>-- v (wikiversity)) are not supported.</p> <p>-- @param {string} value</p> <p>-- @param {boolean} is_link</p> <p>-- @return interwiki prefix</p> <p>local function interwiki_prefixen_get (value, is_link)</p> <p>if not value:find (':%l+:') then -- if no prefix</p> <p>return false; -- abandon; boolean here to distinguish from nil fail returns later</p> <p>end</p> <p>local prefix_patterns_linked_t = { -- sequence of valid interwiki and inter project prefixen</p> <p>'^%[%[:([dsw]):(%l%l+):', -- wikilinked; project and language prefixes</p> <p>'^%[%[:(%l%l+):([dsw]):', -- wikilinked; language and project prefixes</p> <p>'^%[%[:([dsw]):', -- wikilinked; project prefix</p> <p>'^%[%[:(%l%l+):', -- wikilinked; language prefix</p> <p>}</p> <p>local prefix_patterns_unlinked_t = { -- sequence of valid interwiki and inter project prefixen</p> <p>'^:([dsw]):(%l%l+):', -- project and language prefixes</p> <p>'^:(%l%l+):([dsw]):', -- language and project prefixes</p> <p>'^:([dsw]):', -- project prefix</p> <p>'^:(%l%l+):', -- language prefix</p> <p>}</p> <p>local cap1, cap2;</p> <p>for _, pattern in ipairs ((is_link and prefix_patterns_linked_t) or prefix_patterns_unlinked_t) do</p> <p>cap1, cap2 = value:match (pattern);</p> <p>if cap1 then</p> <p>break; -- found a match so stop looking</p> <p>end</p> <p>end</p> <p>if cap1 and cap2 then -- when both then :project:language: or :language:project: (both forms allowed)</p> <p>if 1 == #cap1 then -- length == 1 then :project:language:</p> <p>if cfg.inter_wiki_map[cap2] then -- is language prefix in the interwiki map?</p> <p>return cap1, cap2; -- return interwiki project and interwiki language</p> <p>end</p> <p>else -- here when :language:project:</p> <p>if cfg.inter_wiki_map[cap1] then -- is language prefix in the interwiki map?</p> <p>return cap2, cap1; -- return interwiki project and interwiki language</p> <p>end</p> <p>end</p> <p>return nil; -- unknown interwiki language</p> <p>elseif not (cap1 or cap2) then -- both are nil?</p> <p>return nil; -- we got something that looks like a project prefix but isn't; return fail</p> <p>elseif 1 == #cap1 then -- here when one capture</p> <p>return cap1, nil; -- length is 1 so return project, nil language</p> <p>else -- here when one capture and its length it more than 1</p> <p>if cfg.inter_wiki_map[cap1] then -- is language prefix in the interwiki map?</p> <p>return nil, cap1; -- return nil project, language</p> <p>end</p> <p>end</p> <p>end</p> <p>--- Formats a list of people (authors, contributors, editors, interviewers, translators)</p> <p>--</p> <p>-- names in the list will be linked when</p> <p>-- |<name>-link= has a value</p> <p>-- |<name>-mask- does NOT have a value; masked names are presumed to have been</p> <p>-- rendered previously so should have been linked there</p> <p>--</p> <p>-- when |<name>-mask=0, the associated name is not rendered</p> <p>--</p> <p>-- @param {table} control</p> <p>-- @param {table} people</p> <p>-- @param {boolean} etal</p> <p>-- @return formatted list of people</p> <p>local function list_people (control, people, etal)</p> <p>local sep;</p> <p>local namesep;</p> <p>local format = control.format;</p> <p>local maximum = control.maximum;</p> <p>local name_list = {};</p> <p>if 'vanc' == format then -- Vancouver-like name styling?</p> <p>sep = cfg.presentation['sep_nl_vanc']; -- name-list separator between names is a comma</p> <p>namesep = cfg.presentation['sep_name_vanc']; -- last/first separator is a space</p> <p>else</p> <p>sep = cfg.presentation['sep_nl']; -- name-list separator between names is a semicolon</p> <p>namesep = cfg.presentation['sep_name']; -- last/first separator is <comma><space></p> <p>end</p> <p>if sep:sub (-1, -1) ~= " " then sep = sep .. " " end</p> <p>if utilities.is_set (maximum) and maximum < 1 then return "", 0; end -- returned 0 is for EditorCount; not used for other names</p> <p>for i, person in ipairs (people) do</p> <p>if utilities.is_set (person.last) then</p> <p>local mask = person.mask;</p> <p>local one;</p> <p>local sep_one = sep;</p> <p>if utilities.is_set (maximum) and i > maximum then</p> <p>etal = true;</p> <p>break;</p> <p>end</p> <p>if mask then</p> <p>local n = tonumber (mask); -- convert to a number if it can be converted; nil else</p> <p>if n then</p> <p>one = 0 ~= n and string.rep("—", n) or nil; -- make a string of (n > 0) mdashes, nil else, to replace name</p> <p>person.link = nil; -- don't create link to name if name is replaces with mdash string or has been set nil</p> <p>else</p> <p>one = mask; -- replace name with mask text (must include name-list separator)</p> <p>sep_one = " "; -- modify name-list separator</p> <p>end</p> <p>else</p> <p>one = person.last; -- get surname</p> <p>local first = person.first -- get given name</p> <p>if utilities.is_set (first) then</p> <p>if ("vanc" == format) then -- if Vancouver format</p> <p>one = one:gsub ('%.', ''); -- remove periods from surnames (http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35029/)</p> <p>if not person.corporate and is_good_vanc_name (one, first, nil, i) then -- and name is all Latin characters; corporate authors not tested</p> <p>first = reduce_to_initials (first, i); -- attempt to convert first name(s) to initials</p> <p>end</p> <p>end</p> <p>one = one .. namesep .. first;</p> <p>end</p> <p>end</p> <p>if utilities.is_set (person.link) then</p> <p>one = utilities.make_wikilink (person.link, one); -- link author/editor</p> <p>end</p> <p>if one then -- if <one> has a value (name, mdash replacement, or mask text replacement)</p> <p>local proj, tag = interwiki_prefixen_get (one, true); -- get the interwiki prefixen if present</p> <p>if 'w' == proj and ('Wikipedia' == mw.site.namespaces.Project['name']) then</p> <p>proj = nil; -- for stuff like :w:de:<article>, :w is unnecessary @todo: maint cat?</p> <p>end</p> <p>if proj then</p> <p>local proj_name = ({['d'] = 'Wikidata', ['s'] = 'Wikisource', ['w'] = 'Wikipedia'})[proj]; -- :w (wikipedia) for linking from a non-wikipedia project</p> <p>if proj_name then</p> <p>one = one .. utilities.wrap_style ('interproj', proj_name); -- add resized leading space, brackets, static text, language name</p> <p>utilities.add_prop_cat ('interproj-linked-name', proj); -- categorize it; <proj> is sort key</p> <p>tag = nil; -- unset; don't do both project and language</p> <p>end</p> <p>end</p> <p>if tag == cfg.this_wiki_code then</p> <p>tag = nil; -- stuff like :en:<article> at en.wiki is pointless @todo: maint cat?</p> <p>end</p> <p>if tag then</p> <p>local lang = cfg.lang_tag_remap[tag] or cfg.mw_languages_by_tag_t[tag];</p> <p>if lang then -- error messaging done in extract_names() where we know parameter names</p> <p>one = one .. utilities.wrap_style ('interwiki', lang); -- add resized leading space, brackets, static text, language name</p> <p>utilities.add_prop_cat ('interwiki-linked-name', tag); -- categorize it; <tag> is sort key</p> <p>end</p> <p>end</p> <p>table.insert (name_list, one); -- add it to the list of names</p> <p>table.insert (name_list, sep_one); -- add the proper name-list separator</p> <p>end</p> <p>end</p> <p>end</p> <p>local count = #name_list / 2; -- (number of names + number of separators) divided by 2</p> <p>if 0 < count then</p> <p>if 1 < count and not etal then</p> <p>if 'amp' == format then</p> <p>name_list[#name_list-2] = " & "; -- replace last separator with ampersand text</p> <p>elseif 'and' == format then</p> <p>if 2 == count then</p> <p>name_list[#name_list-2] = cfg.presentation.sep_nl_and; -- replace last separator with 'and' text</p> <p>else</p> <p>name_list[#name_list-2] = cfg.presentation.sep_nl_end; -- replace last separator with '(sep) and' text</p> <p>end</p> <p>end</p> <p>end</p> <p>name_list[#name_list] = nil; -- erase the last separator</p> <p>end</p> <p>local result = table.concat (name_list); -- construct list</p> <p>if etal and utilities.is_set (result) then -- etal may be set by |display-authors=etal but we might not have a last-first list</p> <p>result = result .. sep .. cfg.messages['et al']; -- we've got a last-first list and etal so add et al.</p> <p>end</p> <p>return result, count; -- return name-list string and count of number of names (count used for editor names only)</p> <p>end</p> <p>--- Generates a CITEREF anchor ID if we have at least one name or a date. Otherwise</p> <p>-- returns an empty string.</p> <p>--</p> <p>-- namelist is one of the contributor-, author-, or editor-name lists chosen in that</p> <p>-- order. year is Year or anchor_year.</p> <p>--</p> <p>-- @param {table} namelist list of names</p> <p>-- @param {string} year year string</p> <p>-- @return Formatted CITEREF anchor ID</p> <p>local function make_citeref_id (namelist, year)</p> <p>local names={}; -- a table for the one to four names and year</p> <p>for i,v in ipairs (namelist) do -- loop through the list and take up to the first four last names</p> <p>names[i] = v.last</p> <p>if i == 4 then break end -- if four then done</p> <p>end</p> <p>table.insert (names, year); -- add the year at the end</p> <p>local id = table.concat(names); -- concatenate names and year for CITEREF id</p> <p>if utilities.is_set (id) then -- if concatenation is not an empty string</p> <p>return "CITEREF" .. id; -- add the CITEREF portion</p> <p>else</p> <p>return ''; -- return an empty string; no reason to include CITEREF id in this citation</p> <p>end</p> <p>end</p> <p>--- construct <cite> tag class attribute for this citation.</p> <p>--</p> <p>-- @param {string} cite_class config.CitationClass from calling template</p> <p>-- @param {string} mode value from |mode= parameter</p> <p>-- @return cite tag classes</p> <p>local function cite_class_attribute_make (cite_class, mode)</p> <p>local class_t = {};</p> <p>table.insert (class_t, 'citation'); -- required for blue highlight</p> <p>if 'citation' ~= cite_class then</p> <p>table.insert (class_t, cite_class); -- identify this template for user css</p> <p>table.insert (class_t, utilities.is_set (mode) and mode or 'cs1'); -- identify the citation style for user css or javascript</p> <p>else</p> <p>table.insert (class_t, utilities.is_set (mode) and mode or 'cs2'); -- identify the citation style for user css or javascript</p> <p>end</p> <p>for _, prop_key in ipairs (z.prop_keys_t) do</p> <p>table.insert (class_t, prop_key); -- identify various properties for user css or javascript</p> <p>end</p> <p>return table.concat (class_t, ' '); -- make a big string and done</p> <p>end</p> <p>--- Evaluates the content of name parameters (author, editor, etc.) for variations on</p> <p>-- the theme of et al. If found, the et al. is removed, a flag is set to true and</p> <p>-- the function returns the modified name and the flag.</p> <p>--</p> <p>-- This function never sets the flag to false but returns its previous state because</p> <p>-- it may have been set by previous passes through this function or by the associated</p> <p>-- |display-<names>=etal parameter</p> <p>--</p> <p>-- @param {string} name Name to check</p> <p>-- @param {boolean} etal</p> <p>-- @param {boolean} nocat</p> <p>-- @param param</p> <p>-- @return name and whether it has et. al.</p> <p>local function name_has_etal (name, etal, nocat, param)</p> <p>if utilities.is_set (name) then -- name can be nil in which case just return</p> <p>local patterns = cfg.et_al_patterns; -- get patterns from configuration</p> <p>for _, pattern in ipairs (patterns) do -- loop through all of the patterns</p> <p>if name:match (pattern) then -- if this 'et al' pattern is found in name</p> <p>name = name:gsub (pattern, ''); -- remove the offending text</p> <p>etal = true; -- set flag (may have been set previously here or by |display-<names>=etal)</p> <p>if not nocat then -- no categorization for |vauthors=</p> <p>utilities.set_message ('err_etal', {param}); -- and set an error if not added</p> <p>end</p> <p>end</p> <p>end</p> <p>end</p> <p>return name, etal;</p> <p>end</p> <p>--- Add an error message and category when <name> parameter value does not contain letters.</p> <p>--</p> <p>-- Add a maintenance category when <name> parameter value has numeric characters mixed with characters that are</p> <p>-- not numeric characters; could be letters and/or punctuation characters.</p> <p>--</p> <p>-- This function will only emit one error and one maint message for the current template. Does not emit both error</p> <p>-- and maint messages/categories for the same parameter value.</p> <p>--</p> <p>-- @param {string} name Name to test</p> <p>-- @param {string} name_alias Alias for name</p> <p>-- @param {string} list_name AuthorList, EditorList, etc</p> <p>local function name_is_numeric (name, name_alias, list_name)</p> <p>local patterns = {</p> <p>'^%D+%d', -- <name> must have digits preceded by other characters</p> <p>'^%D*%d+%D+', -- <name> must have digits followed by other characters</p> <p>}</p> <p>if not added_numeric_name_errs and mw.ustring.match (name, '^[%A]+$') then -- if we have not already set an error message and <name> does not have any alpha characters</p> <p>utilities.set_message ('err_numeric_names', name_alias); -- add an error message</p> <p>added_numeric_name_errs = true; -- set the flag so we emit only one error message</p> <p>return; -- when here no point in further testing; abandon</p> <p>end</p> <p>if not added_numeric_name_maint then -- if we have already set a maint message</p> <p>for _, pattern in ipairs (patterns) do -- spin through list of patterns</p> <p>if mw.ustring.match (name, pattern) then -- digits preceded or followed by anything but digits; %D+ includes punctuation</p> <p>utilities.set_message ('maint_numeric_names', cfg.special_case_translation [list_name]); -- add a maint cat for this template</p> <p>added_numeric_name_maint = true; -- set the flag so we emit only one maint message</p> <p>return; -- when here no point in further testing; abandon</p> <p>end</p> <p>end</p> <p>end</p> <p>end</p> <p>--- Evaluates the content of last/surname (authors etc.) parameters for multiple names.</p> <p>-- Multiple names are indicated if there is more than one comma or any "unescaped"</p> <p>-- semicolons. Escaped semicolons are ones used as part of selected HTML entities.</p> <p>-- If the condition is met, the function adds the multiple name maintenance category.</p> <p>--</p> <p>-- Same test for first except that commas should not appear in given names (MOS:JR says</p> <p>-- that the generational suffix does not take a separator character). Titles, degrees,</p> <p>-- postnominals, affiliations, all normally comma separated don't belong in a citation.</p> <p>--</p> <p>-- @param {string} name name parameter value</p> <p>-- @param {string} list_name AuthorList, EditorList, etc</p> <p>-- @param {number} limit number of allowed commas; 1 (default) for surnames; 0 for given names</p> <p>local function name_has_mult_names (name, list_name, limit)</p> <p>local _, commas, semicolons, nbsps;</p> <p>limit = limit and limit or 1;</p> <p>if utilities.is_set (name) then</p> <p>_, commas = name:gsub (',', ''); -- count the number of commas</p> <p>_, semicolons = name:gsub (';', ''); -- count the number of semicolons</p> <p>-- nbsps probably should be its own separate count rather than merged in</p> <p>-- some way with semicolons because Lua patterns do not support the</p> <p>-- grouping operator that regex does, which means there is no way to add</p> <p>-- more entities to escape except by adding more counts with the new</p> <p>-- entities</p> <p>_, nbsps = name:gsub (' ',''); -- count nbsps</p> <p>-- There is exactly 1 semicolon per   entity, so subtract nbsps</p> <p>-- from semicolons to 'escape' them. If additional entities are added,</p> <p>-- they also can be subtracted.</p> <p>if limit < commas or 0 < (semicolons - nbsps) then</p> <p>utilities.set_message ('maint_mult_names', cfg.special_case_translation [list_name]); -- add a maint message</p> <p>end</p> <p>end</p> <p>end</p> <p>--- Compares values assigned to various parameters according to the string provided as <item> in the function call.</p> <p>-- <item> can have on of two values:</p> <p>-- 'generic_names' – for name-holding parameters: |last=, |first=, |editor-last=, etc</p> <p>-- 'generic_titles' – for |title=</p> <p>--</p> <p>-- There are two types of generic tests. The 'accept' tests look for a pattern that should not be rejected by the</p> <p>-- 'reject' test. For example,</p> <p>-- |author=<a href='?title=John_Smith_%28author%29'>Smith, John</a></p> <p>-- would be rejected by the 'author' reject test. But piped wikilinks with 'author' disambiguation should not be</p> <p>-- rejected so the 'accept' test prevents that from happening. Accept tests are always performed before reject</p> <p>-- tests.</p> <p>--</p> <p>-- Each of the 'accept' and 'reject' sequence tables hold tables for en.wiki (['en']) and local.wiki (['local'])</p> <p>-- that each can hold a test sequence table The sequence table holds, at index [1], a test pattern, and, at index</p> <p>-- [2], a boolean control value. The control value tells string.find() or mw.ustring.find() to do plain-text search (true)</p> <p>-- or a pattern search (false). The intent of all this complexity is to make these searches as fast as possible so</p> <p>-- that we don't run out of processing time on very large articles.</p> <p>--</p> <p>-- @param {string} item item type</p> <p>-- @param {string} value value</p> <p>-- @param {string} wiki wiki to check</p> <p>-- @return whether parameter value was rejected</p> <p>local function is_generic (item, value, wiki)</p> <p>local test_val;</p> <p>local str_lower = { -- use string.lower() for en.wiki (['en']) and use mw.ustring.lower() or local.wiki (['local'])</p> <p>['en'] = string.lower,</p> <p>['local'] = mw.ustring.lower,</p> <p>}</p> <p>local str_find = { -- use string.find() for en.wiki (['en']) and use mw.ustring.find() or local.wiki (['local'])</p> <p>['en'] = string.find,</p> <p>['local'] = mw.ustring.find,</p> <p>}</p> <p>--- Does the actual test</p> <p>-- @param {string} val Value being tested</p> <p>-- @param {table} test_t Table of values to test</p> <p>-- @param {string} wiki Wiki to verify</p> <p>-- @return Found match</p> <p>local function test (val, test_t, wiki) -- local function to do the testing; <wiki> selects lower() and find() functions</p> <p>val = test_t[2] and str_lower[wiki](value) or val; -- when <test_t[2]> set to 'true', plaintext search using lowercase value</p> <p>return str_find[wiki] (val, test_t[1], 1, test_t[2]); -- return nil when not found or matched</p> <p>end</p> <p>local test_types_t = {'accept', 'reject'}; -- test accept patterns first, then reject patterns</p> <p>local wikis_t = {'en', 'local'}; -- do tests for each of these keys; en.wiki first, local.wiki second</p> <p>for _, test_type in ipairs (test_types_t) do -- for each test type</p> <p>for _, generic_value in pairs (cfg.special_case_translation[item][test_type]) do -- spin through the list of generic value fragments to accept or reject</p> <p>for _, wiki in ipairs (wikis_t) do</p> <p>if generic_value[wiki] then</p> <p>if test (value, generic_value[wiki], wiki) then -- go do the test</p> <p>return ('reject' == test_type); -- param value rejected, return true; false else</p> <p>end</p> <p>end</p> <p>end</p> <p>end</p> <p>end</p> <p>end</p> <p>--- calls is_generic() to determine if <name> is a 'generic name' listed in cfg.generic_names; <name_alias> is the</p> <p>-- parameter name used in error messaging</p> <p>--</p> <p>-- @param {string} name</p> <p>-- @param {string} name_alias</p> <p>local function name_is_generic (name, name_alias)</p> <p>if not added_generic_name_errs and is_generic ('generic_names', name) then</p> <p>utilities.set_message ('err_generic_name', name_alias); -- set an error message</p> <p>added_generic_name_errs = true;</p> <p>end</p> <p>end</p> <p>--- This function calls various name checking functions used to validate the content of the various name-holding parameters.</p> <p>--</p> <p>-- @param {string} last Last name</p> <p>-- @param {string} first First name</p> <p>-- @param {string} list_name</p> <p>-- @param {string} last_alias</p> <p>-- @param {string} first_alias</p> <p>-- @return Validated last and first name</p> <p>local function name_checks (last, first, list_name, last_alias, first_alias)</p> <p>local accept_name;</p> <p>if utilities.is_set (last) then</p> <p>last, accept_name = utilities.has_accept_as_written (last); -- remove accept-this-as-written markup when it wraps all of <last></p> <p>if not accept_name then -- <last> not wrapped in accept-as-written markup</p> <p>name_has_mult_names (last, list_name); -- check for multiple names in the parameter</p> <p>name_is_numeric (last, last_alias, list_name); -- check for names that have no letters or are a mix of digits and other characters</p> <p>name_is_generic (last, last_alias); -- check for names found in the generic names list</p> <p>end</p> <p>end</p> <p>if utilities.is_set (first) then</p> <p>first, accept_name = utilities.has_accept_as_written (first); -- remove accept-this-as-written markup when it wraps all of <first></p> <p>if not accept_name then -- <first> not wrapped in accept-as-written markup</p> <p>name_has_mult_names (first, list_name, 0); -- check for multiple names in the parameter; 0 is number of allowed commas in a given name</p> <p>name_is_numeric (first, first_alias, list_name); -- check for names that have no letters or are a mix of digits and other characters</p> <p>name_is_generic (first, first_alias); -- check for names found in the generic names list</p> <p>end</p> <p>local wl_type, D = utilities.is_wikilink (first);</p> <p>if 0 ~= wl_type then</p> <p>first = D;</p> <p>utilities.set_message ('err_bad_paramlink', first_alias);</p> <p>end</p> <p>end</p> <p>return last, first; -- done</p> <p>end</p> <p>--- Gets name list from the input arguments</p> <p>--</p> <p>-- Searches through args in sequential order to find |lastn= and |firstn= parameters</p> <p>-- (or their aliases), and their matching link and mask parameters. Stops searching</p> <p>-- when both |lastn= and |firstn= are not found in args after two sequential attempts:</p> <p>-- found |last1=, |last2=, and |last3= but doesn't find |last4= and |last5= then the</p> <p>-- search is done.</p> <p>--</p> <p>-- This function emits an error message when there is a |firstn= without a matching</p> <p>-- |lastn=. When there are 'holes' in the list of last names, |last1= and |last3=</p> <p>-- are present but |last2= is missing, an error message is emitted. |lastn= is not</p> <p>-- required to have a matching |firstn=.</p> <p>--</p> <p>-- When an author or editor parameter contains some form of 'et al.', the 'et al.'</p> <p>-- is stripped from the parameter and a flag (etal) returned that will cause list_people()</p> <p>-- to add the static 'et al.' text from Module:Citation/CS1/Configuration. This keeps</p> <p>-- 'et al.' out of the template's metadata. When this occurs, an error is emitted.</p> <p>--</p> <p>-- @param {table} args Arguments</p> <p>-- @param {string} list_name</p> <p>-- @return List of names, et. al.</p> <p>local function extract_names(args, list_name)</p> <p>local names = {}; -- table of names</p> <p>local last; -- individual name components</p> <p>local first;</p> <p>local link;</p> <p>local mask;</p> <p>local i = 1; -- loop counter/indexer</p> <p>local n = 1; -- output table indexer</p> <p>local count = 0; -- used to count the number of times we haven't found a |last= (or alias for authors, |editor-last or alias for editors)</p> <p>local etal = false; -- return value set to true when we find some form of et al. in an author parameter</p> <p>local last_alias, first_alias, link_alias; -- selected parameter aliases used in error messaging</p> <p>while true do</p> <p>last, last_alias = utilities.select_one ( args, cfg.aliases[list_name .. '-Last'], 'err_redundant_parameters', i ); -- search through args for name components beginning at 1</p> <p>first, first_alias = utilities.select_one ( args, cfg.aliases[list_name .. '-First'], 'err_redundant_parameters', i );</p> <p>link, link_alias = utilities.select_one ( args, cfg.aliases[list_name .. '-Link'], 'err_redundant_parameters', i );</p> <p>mask = utilities.select_one ( args, cfg.aliases[list_name .. '-Mask'], 'err_redundant_parameters', i );</p> <p>if last then -- error check |lastn= alias for unknown interwiki link prefix; done here because this is where we have the parameter name</p> <p>local project, language = interwiki_prefixen_get (last, true); -- true because we expect interwiki links in |lastn= to be wikilinked</p> <p>if nil == project and nil == language then -- when both are nil</p> <p>utilities.set_message ('err_bad_paramlink', last_alias); -- not known, emit an error message -- @todo: err_bad_interwiki?</p> <p>last = utilities.remove_wiki_link (last); -- remove wikilink markup; show display value only</p> <p>end</p> <p>end</p> <p>if link then -- error check |linkn= alias for unknown interwiki link prefix</p> <p>local project, language = interwiki_prefixen_get (link, false); -- false because wiki links in |author-linkn= is an error</p> <p>if nil == project and nil == language then -- when both are nil</p> <p>utilities.set_message ('err_bad_paramlink', link_alias); -- not known, emit an error message -- @todo: err_bad_interwiki?</p> <p>link = nil; -- unset so we don't link</p> <p>link_alias = nil;</p> <p>end</p> <p>end</p> <p>last, etal = name_has_etal (last, etal, false, last_alias); -- find and remove variations on et al.</p> <p>first, etal = name_has_etal (first, etal, false, first_alias); -- find and remove variations on et al.</p> <p>last, first = name_checks (last, first, list_name, last_alias, first_alias); -- multiple names, extraneous annotation, etc. checks</p> <p>if first and not last then -- if there is a firstn without a matching lastn</p> <p>local alias = first_alias:find ('given', 1, true) and 'given' or 'first'; -- get first or given form of the alias</p> <p>utilities.set_message ('err_first_missing_last', {</p> <p>first_alias, -- param name of alias missing its mate</p> <p>first_alias:gsub (alias, {['first'] = 'last', ['given'] = 'surname'}), -- make param name appropriate to the alias form</p> <p>}); -- add this error message</p> <p>elseif not first and not last then -- if both firstn and lastn aren't found, are we done?</p> <p>count = count + 1; -- number of times we haven't found last and first</p> <p>if 2 <= count then -- two missing names and we give up</p> <p>break; -- normal exit or there is a two-name hole in the list; can't tell which</p> <p>end</p> <p>else -- we have last with or without a first</p> <p>local result;</p> <p>link = link_title_ok (link, link_alias, last, last_alias); -- check for improper wiki-markup</p> <p>if first then</p> <p>link = link_title_ok (link, link_alias, first, first_alias); -- check for improper wiki-markup</p> <p>end</p> <p>names[n] = {last = last, first = first, link = link, mask = mask, corporate = false}; -- add this name to our names list (corporate for |vauthors= only)</p> <p>n = n + 1; -- point to next location in the names table</p> <p>if 1 == count then -- if the previous name was missing</p> <p>utilities.set_message ('err_missing_name', {list_name:match ("(%w+)List"):lower(), i - 1}); -- add this error message</p> <p>end</p> <p>count = 0; -- reset the counter, we're looking for two consecutive missing names</p> <p>end</p> <p>i = i + 1; -- point to next args location</p> <p>end</p> <p>return names, etal; -- all done, return our list of names and the etal flag</p> <p>end</p> <p>--- attempt to decode |language=<lang_param> and return language name and matching tag; nil else.</p> <p>--</p> <p>-- This function looks for:</p> <p>-- <lang_param> as a tag in cfg.lang_tag_remap{}</p> <p>-- <lang_param> as a name in cfg.lang_name_remap{}</p> <p>--</p> <p>-- <lang_param> as a name in cfg.mw_languages_by_name_t</p> <p>-- <lang_param> as a tag in cfg.mw_languages_by_tag_t</p> <p>-- when those fail, presume that <lang_param> is an IETF-like tag that MediaWiki does not recognize. Strip all</p> <p>-- script, region, variant, whatever subtags from <lang_param> to leave just a two or three character language tag</p> <p>-- and look for the new <lang_param> in cfg.mw_languages_by_tag_t{}</p> <p>--</p> <p>-- @param {string} lang_param Language parameter</p> <p>-- @return Name (in properly capitalized form) and matching tag (in lowercase)</p> <p>local function name_tag_get (lang_param)</p> <p>local lang_param_lc = mw.ustring.lower (lang_param); -- use lowercase as an index into the various tables</p> <p>local name;</p> <p>local tag;</p> <p>name = cfg.lang_tag_remap[lang_param_lc]; -- assume <lang_param_lc> is a tag; attempt to get remapped language name</p> <p>if name then -- when <name>, <lang_param> is a tag for a remapped language name</p> <p>if cfg.lang_name_remap[name:lower()][2] ~= lang_param_lc then</p> <p>utilities.set_message ('maint_unknown_lang'); -- add maint category if not already added</p> <p>return name, cfg.lang_name_remap[name:lower()][2]; -- so return name and tag from lang_name_remap[name]; special case to xlate sr-ec and sr-el to sr-cyrl and sr-latn</p> <p>end</p> <p>return name, lang_param_lc; -- so return <name> from remap and <lang_param_lc></p> <p>end</p> <p>tag = lang_param_lc:match ('^(%a%a%a?)%-.*'); -- still assuming that <lang_param_lc> is a tag; strip script, region, variant subtags</p> <p>name = cfg.lang_tag_remap[tag]; -- attempt to get remapped language name with language subtag only</p> <p>if name then -- when <name>, <tag> is a tag for a remapped language name</p> <p>return name, tag; -- so return <name> from remap and <tag></p> <p>end</p> <p>if cfg.lang_name_remap[lang_param_lc] then -- not a remapped tag, assume <lang_param_lc> is a name; attempt to get remapped language tag</p> <p>return cfg.lang_name_remap[lang_param_lc][1], cfg.lang_name_remap[lang_param_lc][2]; -- for this <lang_param_lc>, return a (possibly) new name and appropriate tag</p> <p>end</p> <p>name = cfg.mw_languages_by_tag_t[lang_param_lc]; -- assume that <lang_param_lc> is a tag; attempt to get its matching language name</p> <p>if name then</p> <p>return name, lang_param_lc; -- <lang_param_lc> is a tag so return it and <name></p> <p>end</p> <p>tag = cfg.mw_languages_by_name_t[lang_param_lc]; -- assume that <lang_param_lc> is a language name; attempt to get its matching tag</p> <p>if tag then</p> <p>return cfg.mw_languages_by_tag_t[tag], tag; -- <lang_param_lc> is a name so return the name from the table and <tag></p> <p>end</p> <p>tag = lang_param_lc:match ('^(%a%a%a?)%-.*'); -- is <lang_param_lc> an IETF-like tag that MediaWiki doesn't recognize? <tag> gets the language subtag; nil else</p> <p>if tag then</p> <p>name = cfg.mw_languages_by_tag_t[tag]; -- attempt to get a language name using the shortened <tag></p> <p>if name then</p> <p>return name, tag; -- <lang_param_lc> is an unrecognized IETF-like tag so return <name> and language subtag</p> <p>end</p> <p>end</p> <p>end</p> <p>--- When |language= contains a recognized language (either code or name), the page is</p> <p>-- assigned to the category for that code: Category:Norwegian-language sources (no).</p> <p>-- For valid three-character code languages, the page is assigned to the single category</p> <p>-- for '639-2' codes: Category:CS1 ISO 639-2 language sources.</p> <p>--</p> <p>-- Languages that are the same as the local wiki are not categorized. MediaWiki does</p> <p>-- not recognize three-character equivalents of two-character codes: code 'ar' is</p> <p>-- recognized but code 'ara' is not.</p> <p>--</p> <p>-- This function supports multiple languages in the form |language=nb, French, th</p> <p>-- where the language names or codes are separated from each other by commas with</p> <p>-- optional space characters.</p> <p>--</p> <p>-- @param {string} lang Language code</p> <p>-- @return Formatted language name</p> <p>local function language_parameter (lang)</p> <p>local tag; -- some form of IETF-like language tag; language subtag with optional region, sript, vatiant, etc subtags</p> <p>local lang_subtag; -- ve populates |language= with mostly unecessary region subtags the MediaWiki does not recognize; this is the base language subtag</p> <p>local name; -- the language name</p> <p>local language_list = {}; -- table of language names to be rendered</p> <p>local names_t = {}; -- table made from the value assigned to |language=</p> <p>local this_wiki_name = mw.language.fetchLanguageName (cfg.this_wiki_code, cfg.this_wiki_code); -- get this wiki's language name</p> <p>names_t = mw.text.split (lang, '%s*,%s*'); -- names should be a comma separated list</p> <p>for _, lang in ipairs (names_t) do -- reuse lang here because we don't yet know if lang is a language name or a language tag</p> <p>name, tag = name_tag_get (lang); -- attempt to get name/tag pair for <lang>; <name> has proper capitalization; <tag> is lowercase</p> <p>if utilities.is_set (tag) then</p> <p>lang_subtag = tag:gsub ('^(%a%a%a?)%-.*', '%1'); -- for categorization, strip any IETF-like tags from language tag</p> <p>if cfg.this_wiki_code ~= lang_subtag then -- when the language is not the same as this wiki's language</p> <p>if 2 == lang_subtag:len() then -- and is a two-character tag</p> <p>utilities.add_prop_cat ('foreign-lang-source', {name, tag}, lang_subtag); -- categorize it; tag appended to allow for multiple language categorization</p> <p>else -- or is a recognized language (but has a three-character tag)</p> <p>utilities.add_prop_cat ('foreign-lang-source-2', {lang_subtag}, lang_subtag); -- categorize it differently @todo: support multiple three-character tag categories per cs1|2 template?</p> <p>end</p> <p>elseif cfg.local_lang_cat_enable then -- when the language and this wiki's language are the same and categorization is enabled</p> <p>utilities.add_prop_cat ('local-lang-source', {name, lang_subtag}); -- categorize it</p> <p>end</p> <p>else</p> <p>name = lang; -- return whatever <lang> has so that we show something</p> <p>utilities.set_message ('maint_unknown_lang'); -- add maint category if not already added</p> <p>end</p> <p>table.insert (language_list, name);</p> <p>name = ''; -- so we can reuse it</p> <p>end</p> <p>name = utilities.make_sep_list (#language_list, language_list);</p> <p>if (1 == #language_list) and (lang_subtag == cfg.this_wiki_code) then -- when only one language, find lang name in this wiki lang name; for |language=en-us, 'English' in 'American English'</p> <p>return ''; -- if one language and that language is this wiki's return an empty string (no annotation)</p> <p>end</p> <p>return (" " .. wrap_msg ('language', name)); -- otherwise wrap with '(in ...)'</p> <p>--[[ @todo: should only return blank or name rather than full list</p> <p>so we can clean up the bunched parenthetical elements Language, Type, Format</p> <p>]]</p> <p>end</p> <p>--- Gets the default CS style configuration for the given mode.</p> <p>--</p> <p>-- In CS1, the default postscript and separator are '.'.</p> <p>-- In CS2, the default postscript is the empty string and the default separator is ','.</p> <p>--</p> <p>-- @param {string} postscript</p> <p>-- @param {string} mode CS mode</p> <p>-- @return default separator and either postscript as passed in or the default.</p> <p>local function set_cs_style (postscript, mode)</p> <p>if utilities.is_set(postscript) then</p> <p>-- emit a maintenance message if user postscript is the default cs1 postscript</p> <p>-- we catch the opposite case for cs2 in set_style</p> <p>if mode == 'cs1' and postscript == cfg.presentation['ps_' .. mode] then</p> <p>utilities.set_message ('maint_postscript');</p> <p>end</p> <p>else</p> <p>postscript = cfg.presentation['ps_' .. mode];</p> <p>end</p> <p>return cfg.presentation['sep_' .. mode], postscript;</p> <p>end</p> <p>--- Sets the separator and postscript styles. Checks the |mode= first and the</p> <p>-- #invoke CitationClass second. Removes the postscript if postscript == none.</p> <p>--</p> <p>-- @param {string} mode CS mode</p> <p>-- @param {string} postscript</p> <p>-- @param {string} cite_class</p> <p>-- @return Separator and the postscript</p> <p>local function set_style (mode, postscript, cite_class)</p> <p>local sep;</p> <p>if 'cs2' == mode then</p> <p>sep, postscript = set_cs_style (postscript, 'cs2');</p> <p>elseif 'cs1' == mode then</p> <p>sep, postscript = set_cs_style (postscript, 'cs1');</p> <p>elseif 'citation' == cite_class then</p> <p>sep, postscript = set_cs_style (postscript, 'cs2');</p> <p>else</p> <p>sep, postscript = set_cs_style (postscript, 'cs1');</p> <p>end</p> <p>if cfg.keywords_xlate[postscript:lower()] == 'none' then</p> <p>-- emit a maintenance message if user postscript is the default cs2 postscript</p> <p>-- we catch the opposite case for cs1 in set_cs_style</p> <p>if 'cs2' == mode or ('cs1' ~= mode and 'citation' == cite_class) then -- {{tl|citation |title=Title |mode=cs1 |postscript=none}} should not emit maint message</p> <p>utilities.set_message ('maint_postscript');</p> <p>end</p> <p>postscript = '';</p> <p>end</p> <p>return sep, postscript</p> <p>end</p> <p>--- Determines if a URL has the file extension that is one of the PDF file extensions</p> <p>-- used by <a href='?title=MediaWiki%3ACommon.css'>MediaWiki:Common.css</a> when applying the PDF icon to external links.</p> <p>--</p> <p>-- @param {string} url URL to check</p> <p>-- @return Whether a PDF file extension is matched</p> <p>local function is_pdf (url)</p> <p>return url:match ('%.pdf$') or url:match ('%.PDF$') or</p> <p>url:match ('%.pdf[%?#]') or url:match ('%.PDF[%?#]') or</p> <p>url:match ('%.PDF#') or url:match ('%.pdf#');</p> <p>end</p> <p>--- Applies CSS style to |format=, |chapter-format=, etc. Also emits an error message</p> <p>-- if the format parameter does not have a matching URL parameter. If the format parameter</p> <p>-- is not set and the URL contains a file extension that is recognized as a PDF document</p> <p>-- by MediaWiki's commons.css, this code will set the format parameter to (PDF) with</p> <p>-- the appropriate styling.</p> <p>--</p> <p>-- @param {string} format</p> <p>-- @param {string} url</p> <p>-- @param {string} fmt_param</p> <p>-- @param {string} url_param</p> <p>-- @return formatted style</p> <p>local function style_format (format, url, fmt_param, url_param)</p> <p>if utilities.is_set (format) then</p> <p>format = utilities.wrap_style ('format', format); -- add leading space, parentheses, resize</p> <p>if not utilities.is_set (url) then</p> <p>utilities.set_message ('err_format_missing_url', {fmt_param, url_param}); -- add an error message</p> <p>end</p> <p>elseif is_pdf (url) then -- format is not set so if URL is a PDF file then</p> <p>format = utilities.wrap_style ('format', 'PDF'); -- set format to PDF</p> <p>else</p> <p>format = ''; -- empty string for concatenation</p> <p>end</p> <p>return format;</p> <p>end</p> <p>--- Returns a number that defines the number of names displayed for author and editor</p> <p>-- name lists and a Boolean flag to indicate when et al. should be appended to the name list.</p> <p>--</p> <p>-- When the value assigned to |display-xxxxors= is a number greater than or equal to zero,</p> <p>-- return the number and the previous state of the 'etal' flag (false by default</p> <p>-- but may have been set to true if the name list contains some variant of the text 'et al.').</p> <p>--</p> <p>-- When the value assigned to |display-xxxxors= is the keyword 'etal', return a number</p> <p>-- that is one greater than the number of authors in the list and set the 'etal' flag true.</p> <p>-- This will cause the list_people() to display all of the names in the name list followed by 'et al.'</p> <p>--</p> <p>-- In all other cases, returns nil and the previous state of the 'etal' flag.</p> <p>--</p> <p>-- inputs:</p> <p>-- max: A['DisplayAuthors'] or A['DisplayEditors'], etc; a number or some flavor of etal</p> <p>-- count: #a or #e</p> <p>-- list_name: 'authors' or 'editors'</p> <p>-- etal: author_etal or editor_etal</p> <p>--</p> <p>-- This function sets an error message when |display-xxxxors= value greater than or equal to number of names but</p> <p>-- not when <max> comes from {{tl|cs1 config}} global settings. When using global settings, <param> is set to the</p> <p>-- keyword 'cs1 config' which is used to supress the normal error. Error is suppressed because it is to be expected</p> <p>-- that some citations in an article will have the same or fewer names that the limit specified in {{tl|cs1 config}}.</p> <p>--</p> <p>-- @param {number} max</p> <p>-- @param {number} count</p> <p>-- @param list_name</p> <p>-- @param etal</p> <p>-- @param param</p> <p>local function get_display_names (max, count, list_name, etal, param)</p> <p>if utilities.is_set (max) then</p> <p>if 'etal' == max:lower():gsub("[ '%.]", '') then -- the :gsub() portion makes 'etal' from a variety of 'et al.' spellings and stylings</p> <p>max = count + 1; -- number of authors + 1 so display all author name plus et al.</p> <p>etal = true; -- overrides value set by extract_names()</p> <p>elseif max:match ('^%d+$') then -- if is a string of numbers</p> <p>max = tonumber (max); -- make it a number</p> <p>if (max >= count) and ('cs1 config' ~= param) then -- error when local |display-xxxxors= value greater than or equal to number of names; not an error when using global setting</p> <p>utilities.set_message ('err_disp_name', {param, max}); -- add error message</p> <p>max = nil;</p> <p>end</p> <p>else -- not a valid keyword or number</p> <p>utilities.set_message ('err_disp_name', {param, max}); -- add error message</p> <p>max = nil; -- unset; as if |display-xxxxors= had not been set</p> <p>end</p> <p>end</p> <p>return max, etal;</p> <p>end</p> <p>--- Adds error if |page=, |pages=, |quote-page=, |quote-pages= has what appears to be</p> <p>-- some form of p. or pp. abbreviation in the first characters of the parameter content.</p> <p>--</p> <p>-- check page for extraneous p, p., pp, pp., pg, pg. at start of parameter value:</p> <p>-- good pattern: '^P[^%.P%l]' matches when page begins PX or P# but not Px</p> <p>-- where x and X are letters and # is a digit</p> <p>-- bad pattern: '^[Pp][PpGg]' matches when page begins pp, pP, Pp, PP, pg, pG, Pg, PG</p> <p>--</p> <p>-- @param {string} val parameter value</p> <p>-- @param {string} name parameter name</p> <p>local function extra_text_in_page_check (val, name)</p> <p>if not val:match (cfg.vol_iss_pg_patterns.good_ppattern) then</p> <p>for _, pattern in ipairs (cfg.vol_iss_pg_patterns.bad_ppatterns) do -- spin through the selected sequence table of patterns</p> <p>if val:match (pattern) then -- when a match, error so</p> <p>utilities.set_message ('err_extra_text_pages', name); -- add error message</p> <p>return; -- and done</p> <p>end</p> <p>end</p> <p>end</p> <p>end</p> <p>--- Adds error if |volume= or |issue= has what appears to be some form of redundant 'type' indicator. Applies to</p> <p>-- both; this function looks for issue text in both |issue= and |volume= and looks for volume-like text in |voluem=</p> <p>-- and |issue=.</p> <p>--</p> <p>-- For |volume=:</p> <p>-- 'V.', or 'Vol.' (with or without the dot) abbreviations or 'Volume' in the first characters of the parameter</p> <p>-- content (all case insensitive). 'V' and 'v' (without the dot) are presumed to be roman numerals so</p> <p>-- are allowed.</p> <p>--</p> <p>-- For |issue=:</p> <p>-- 'No.', 'I.', 'Iss.' (with or without the dot) abbreviations, or 'Issue' in the first characters of the</p> <p>-- parameter content (all case insensitive); numero styling: 'n°' with degree sign U+00B0, and № precomposed</p> <p>-- numero sign U+2116.</p> <p>--</p> <p>-- Single character values ('v', 'i', 'n') allowed when not followed by separator character ('.', ':', '=', or</p> <p>-- whitespace character) – param values are trimmed of whitespace by MediaWiki before delivered to the module.</p> <p>--</p> <p>-- sets error message on failure</p> <p>--</p> <p>-- @param {string} val `|volume=` or `|issue=` parameter value</p> <p>-- @param {string} name `|volume=` or `|issue=` parameter name for error message</p> <p>-- @param {string} selector 'v' for `|volume=`, 'i' for `|issue=`</p> <p>local function extra_text_in_vol_iss_check (val, name, selector)</p> <p>if not utilities.is_set (val) then</p> <p>return;</p> <p>end</p> <p>local handler = 'v' == selector and 'err_extra_text_volume' or 'err_extra_text_issue';</p> <p>val = val:lower(); -- force parameter value to lower case</p> <p>for _, pattern in ipairs (cfg.vol_iss_pg_patterns.vi_patterns_t) do -- spin through the sequence table of patterns</p> <p>if val:match (pattern) then -- when a match, error so</p> <p>utilities.set_message (handler, name); -- add error message</p> <p>return; -- and done</p> <p>end</p> <p>end</p> <p>end</p> <p>--- split apart a `|vauthors=` or `|veditors=` parameter. This function allows for corporate names, wrapped in doubled</p> <p>-- parentheses to also have commas; in the old version of the code, the doubled parentheses were included in the</p> <p>-- rendered citation and in the metadata. Individual author names may be wikilinked</p> <p>--</p> <p>-- @param {string} vparam</p> <p>-- @param {table} output_table</p> <p>-- @param {table} output_link_table</p> <p>-- @return Output table</p> <p>local function get_v_name_table (vparam, output_table, output_link_table)</p> <p>local name_table = mw.text.split(vparam, "%s*,%s*"); -- names are separated by commas</p> <p>local wl_type, label, link; -- wl_type not used here; just a placeholder</p> <p>local i = 1;</p> <p>while name_table[i] do</p> <p>if name_table[i]:match ('^%(%(.*[^%)][^%)]$') then -- first segment of corporate with one or more commas; this segment has the opening doubled parentheses</p> <p>local name = name_table[i];</p> <p>i = i + 1; -- bump indexer to next segment</p> <p>while name_table[i] do</p> <p>name = name .. ', ' .. name_table[i]; -- concatenate with previous segments</p> <p>if name_table[i]:match ('^.*%)%)$') then -- if this table member has the closing doubled parentheses</p> <p>break; -- and done reassembling so</p> <p>end</p> <p>i = i + 1; -- bump indexer</p> <p>end</p> <p>table.insert (output_table, name); -- and add corporate name to the output table</p> <p>table.insert (output_link_table, ''); -- no wikilink</p> <p>else</p> <p>wl_type, label, link = utilities.is_wikilink (name_table[i]); -- wl_type is: 0, no wl (text in label variable); 1, <a href='?title=D'>D</a>; 2, <a href='?title=L'>D</a></p> <p>table.insert (output_table, label); -- add this name</p> <p>if 1 == wl_type then</p> <p>table.insert (output_link_table, label); -- simple wikilink <a href='?title=D'>D</a></p> <p>else</p> <p>table.insert (output_link_table, link); -- no wikilink or <a href='?title=L'>D</a>; add this link if there is one, else empty string</p> <p>end</p> <p>end</p> <p>i = i + 1;</p> <p>end</p> <p>return output_table;</p> <p>end</p> <p>--- This function extracts author / editor names from |vauthors= or |veditors= and finds matching |xxxxor-maskn= and</p> <p>-- |xxxxor-linkn= in args. It then returns a table of assembled names just as extract_names() does.</p> <p>--</p> <p>-- Author / editor names in |vauthors= or |veditors= must be in Vancouver system style. Corporate or institutional names</p> <p>-- may sometimes be required and because such names will often fail the is_good_vanc_name() and other format compliance</p> <p>-- tests, are wrapped in doubled parentheses ((corporate name)) to suppress the format tests.</p> <p>--</p> <p>-- Supports generational suffixes Jr, 2nd, 3rd, 4th–6th.</p> <p>--</p> <p>-- This function sets the Vancouver error when a required comma is missing and when there is a space between an author's initials.</p> <p>--</p> <p>-- @param {table} args Arguments</p> <p>-- @param {string} vparam</p> <p>-- @param {string} list_name</p> <p>-- @return names, et. al.</p> <p>local function parse_vauthors_veditors (args, vparam, list_name)</p> <p>local names = {}; -- table of names assembled from |vauthors=, |author-maskn=, |author-linkn=</p> <p>local v_name_table = {};</p> <p>local v_link_table = {}; -- when name is wikilinked, targets go in this table</p> <p>local etal = false; -- return value set to true when we find some form of et al. vauthors parameter</p> <p>local last, first, link, mask, suffix;</p> <p>local corporate = false;</p> <p>vparam, etal = name_has_etal (vparam, etal, true); -- find and remove variations on et al. do not categorize (do it here because et al. might have a period)</p> <p>v_name_table = get_v_name_table (vparam, v_name_table, v_link_table); -- names are separated by commas</p> <p>for i, v_name in ipairs(v_name_table) do</p> <p>first = ''; -- set to empty string for concatenation and because it may have been set for previous author/editor</p> <p>local accept_name;</p> <p>v_name, accept_name = utilities.has_accept_as_written (v_name); -- remove accept-this-as-written markup when it wraps all of <v_name></p> <p>if accept_name then</p> <p>last = v_name;</p> <p>corporate = true; -- flag used in list_people()</p> <p>elseif string.find(v_name, "%s") then</p> <p>if v_name:find('[;%.]') then -- look for commonly occurring punctuation characters;</p> <p>add_vanc_error (cfg.err_msg_supl.punctuation, i);</p> <p>end</p> <p>local lastfirstTable = {}</p> <p>lastfirstTable = mw.text.split(v_name, "%s+")</p> <p>first = table.remove(lastfirstTable); -- removes and returns value of last element in table which should be initials or generational suffix</p> <p>if not mw.ustring.match (first, '^%u+$') then -- mw.ustring here so that later we will catch non-Latin characters</p> <p>suffix = first; -- not initials so assume that whatever we got is a generational suffix</p> <p>first = table.remove(lastfirstTable); -- get what should be the initials from the table</p> <p>end</p> <p>last = table.concat(lastfirstTable, ' ') -- returns a string that is the concatenation of all other names that are not initials and generational suffix</p> <p>if not utilities.is_set (last) then</p> <p>first = ''; -- unset</p> <p>last = v_name; -- last empty because something wrong with first</p> <p>add_vanc_error (cfg.err_msg_supl.name, i);</p> <p>end</p> <p>if mw.ustring.match (last, '%a+%s+%u+%s+%a+') then</p> <p>add_vanc_error (cfg.err_msg_supl['missing comma'], i); -- matches last II last; the case when a comma is missing</p> <p>end</p> <p>if mw.ustring.match (v_name, ' %u %u$') then -- this test is in the wrong place @todo: move or replace with a more appropriate test</p> <p>add_vanc_error (cfg.err_msg_supl.initials, i); -- matches a space between two initials</p> <p>end</p> <p>else</p> <p>last = v_name; -- last name or single corporate name? Doesn't support multiword corporate names? do we need this?</p> <p>end</p> <p>if utilities.is_set (first) then</p> <p>if not mw.ustring.match (first, "^%u?%u$") then -- first shall contain one or two upper-case letters, nothing else</p> <p>add_vanc_error (cfg.err_msg_supl.initials, i); -- too many initials; mixed case initials (which may be ok Romanization); hyphenated initials</p> <p>end</p> <p>is_good_vanc_name (last, first, suffix, i); -- check first and last before restoring the suffix which may have a non-Latin digit</p> <p>if utilities.is_set (suffix) then</p> <p>first = first .. ' ' .. suffix; -- if there was a suffix concatenate with the initials</p> <p>suffix = ''; -- unset so we don't add this suffix to all subsequent names</p> <p>end</p> <p>else</p> <p>if not corporate then</p> <p>is_good_vanc_name (last, '', nil, i);</p> <p>end</p> <p>end</p> <p>link = utilities.select_one ( args, cfg.aliases[list_name .. '-Link'], 'err_redundant_parameters', i ) or v_link_table[i];</p> <p>mask = utilities.select_one ( args, cfg.aliases[list_name .. '-Mask'], 'err_redundant_parameters', i );</p> <p>names[i] = {last = last, first = first, link = link, mask = mask, corporate = corporate}; -- add this assembled name to our names list</p> <p>end</p> <p>return names, etal; -- all done, return our list of names</p> <p>end</p> <p>--- Select one of |authors=, |authorn= / |lastn / firstn=, or |vauthors= as the source of the author name list or</p> <p>-- select one of |editorn= / editor-lastn= / |editor-firstn= or |veditors= as the source of the editor name list.</p> <p>--</p> <p>-- Only one of these appropriate three will be used. The hierarchy is: |authorn= (and aliases) highest and |authors= lowest;</p> <p>-- |editorn= (and aliases) highest and |veditors= lowest (support for |editors= withdrawn)</p> <p>--</p> <p>-- When looking for |authorn= / |editorn= parameters, test |xxxxor1= and |xxxxor2= (and all of their aliases); stops after the second</p> <p>-- test which mimicks the test used in extract_names() when looking for a hole in the author name list. There may be a better</p> <p>-- way to do this, I just haven't discovered what that way is.</p> <p>--</p> <p>-- Emits an error message when more than one xxxxor name source is provided.</p> <p>--</p> <p>-- In this function, vxxxxors = vauthors or veditors; xxxxors = authors as appropriate.</p> <p>--</p> <p>-- @param {string} vxxxxors</p> <p>-- @param {string} xxxxors</p> <p>-- @param {table} args</p> <p>-- @param {string} list_name</p> <p>-- @return author source that should be used</p> <p>local function select_author_editor_source (vxxxxors, xxxxors, args, list_name)</p> <p>local lastfirst = false;</p> <p>if utilities.select_one ( args, cfg.aliases[list_name .. '-Last'], 'none', 1 ) or -- do this twice in case we have a |first1= without a |last1=; this ...</p> <p>utilities.select_one ( args, cfg.aliases[list_name .. '-First'], 'none', 1 ) or -- ... also catches the case where |first= is used with |vauthors=</p> <p>utilities.select_one ( args, cfg.aliases[list_name .. '-Last'], 'none', 2 ) or</p> <p>utilities.select_one ( args, cfg.aliases[list_name .. '-First'], 'none', 2 ) then</p> <p>lastfirst = true;</p> <p>end</p> <p>if (utilities.is_set (vxxxxors) and true == lastfirst) or -- these are the three error conditions</p> <p>(utilities.is_set (vxxxxors) and utilities.is_set (xxxxors)) or</p> <p>(true == lastfirst and utilities.is_set (xxxxors)) then</p> <p>local err_name;</p> <p>if 'AuthorList' == list_name then -- figure out which name should be used in error message</p> <p>err_name = 'author';</p> <p>else</p> <p>err_name = 'editor';</p> <p>end</p> <p>utilities.set_message ('err_redundant_parameters', err_name .. '-name-list parameters'); -- add error message</p> <p>end</p> <p>if true == lastfirst then return 1 end; -- return a number indicating which author name source to use</p> <p>if utilities.is_set (vxxxxors) then return 2 end;</p> <p>if utilities.is_set (xxxxors) then return 3 end;</p> <p>return 1; -- no authors so return 1; this allows missing author name test to run in case there is a first without last</p> <p>end</p> <p>--- This function is used to validate a parameter's assigned value for those parameters that have only a limited number</p> <p>-- of allowable values (yes, y, true, live, dead, etc.). When the parameter value has not been assigned a value (missing</p> <p>-- or empty in the source template) the function returns the value specified by ret_val. If the parameter value is one</p> <p>-- of the list of allowed values returns the translated value; else, emits an error message and returns the value</p> <p>-- specified by ret_val.</p> <p>--</p> <p>-- @todo: explain <invert></p> <p>--</p> <p>-- @param {string} value</p> <p>-- @param {string} name</p> <p>-- @param possible</p> <p>-- @param ret_val</p> <p>-- @param invert</p> <p>-- @return appropriate value</p> <p>local function is_valid_parameter_value (value, name, possible, ret_val, invert)</p> <p>if not utilities.is_set (value) then</p> <p>return ret_val; -- an empty parameter is ok</p> <p>end</p> <p>if (not invert and utilities.in_array (value, possible)) then -- normal; <value> is in <possible> table</p> <p>return cfg.keywords_xlate[value]; -- return translation of parameter keyword</p> <p>elseif invert and not utilities.in_array (value, possible) then -- invert; <value> is not in <possible> table</p> <p>return value; -- return <value> as it is</p> <p>else</p> <p>utilities.set_message ('err_invalid_param_val', {name, value}); -- not an allowed value so add error message</p> <p>return ret_val;</p> <p>end</p> <p>end</p> <p>--- This function terminates a name list (author, contributor, editor) with a separator character (sepc) and a space</p> <p>-- when the last character is not a sepc character or when the last three characters are not sepc followed by two</p> <p>-- closing square brackets (close of a wikilink). When either of these is true, the name_list is terminated with a</p> <p>-- single space character.</p> <p>--</p> <p>-- @param {string} name_list List of names</p> <p>-- @param {string} sepc Separator</p> <p>-- @return Appropriately formatted name list</p> <p>local function terminate_name_list (name_list, sepc)</p> <p>if (string.sub (name_list, -3, -1) == sepc .. '. ') then -- if already properly terminated</p> <p>return name_list; -- just return the name list</p> <p>elseif (string.sub (name_list, -1, -1) == sepc) or (string.sub (name_list, -3, -1) == sepc .. ']]') then -- if last name in list ends with sepc char</p> <p>return name_list .. " "; -- don't add another</p> <p>else</p> <p>return name_list .. sepc .. ' '; -- otherwise terminate the name list</p> <p>end</p> <p>end</p> <p>--- returns the concatenation of the formatted volume and issue (or journal article number) parameters as a single</p> <p>-- string; or formatted volume or formatted issue, or an empty string if neither are set.</p> <p>--</p> <p>-- @param {string} volume</p> <p>-- @param {string} issue</p> <p>-- @param {string} article</p> <p>-- @param {string} cite_class</p> <p>-- @param {string} origin</p> <p>-- @param {string} sepc</p> <p>-- @param lower</p> <p>-- @return formatted volume and issue</p> <p>local function format_volume_issue (volume, issue, article, cite_class, origin, sepc, lower)</p> <p>if not utilities.is_set (volume) and not utilities.is_set (issue) and not utilities.is_set (article) then</p> <p>return '';</p> <p>end</p> <p>-- same condition as in format_pages_sheets()</p> <p>local is_journal = 'journal' == cite_class or (utilities.in_array (cite_class, {'citation', 'map', 'interview'}) and 'journal' == origin);</p> <p>local is_numeric_vol = volume and (volume:match ('^[MDCLXVI]+$') or volume:match ('^%d+$')); -- is only uppercase roman numerals or only digits?</p> <p>local is_long_vol = volume and (4 < mw.ustring.len(volume)); -- is |volume= value longer than 4 characters?</p> <p>if volume and (not is_numeric_vol and is_long_vol) then -- when not all digits or Roman numerals, is |volume= longer than 4 characters?</p> <p>utilities.add_prop_cat ('long-vol'); -- yes, add properties cat</p> <p>end</p> <p>if is_journal then -- journal-style formatting</p> <p>local vol = '';</p> <p>if utilities.is_set (volume) then</p> <p>if is_numeric_vol then -- |volume= value all digits or all uppercase Roman numerals?</p> <p>vol = utilities.substitute (cfg.presentation['vol-bold'], {sepc, volume}); -- render in bold face</p> <p>elseif is_long_vol then -- not all digits or Roman numerals; longer than 4 characters?</p> <p>vol = utilities.substitute (cfg.messages['j-vol'], {sepc, utilities.hyphen_to_dash (volume)}); -- not bold</p> <p>else -- four or fewer characters</p> <p>vol = utilities.substitute (cfg.presentation['vol-bold'], {sepc, utilities.hyphen_to_dash (volume)}); -- bold</p> <p>end</p> <p>end</p> <p>vol = vol .. (utilities.is_set (issue) and utilities.substitute (cfg.messages['j-issue'], issue) or '')</p> <p>vol = vol .. (utilities.is_set (article) and utilities.substitute (cfg.messages['j-article-num'], article) or '')</p> <p>return vol;</p> <p>end</p> <p>if 'podcast' == cite_class and utilities.is_set (issue) then</p> <p>return wrap_msg ('issue', {sepc, issue}, lower);</p> <p>end</p> <p>if 'conference' == cite_class and utilities.is_set (article) then -- |article-number= supported only in journal and conference cites</p> <p>if utilities.is_set (volume) and utilities.is_set (article) then -- both volume and article number</p> <p>return wrap_msg ('vol-art', {sepc, utilities.hyphen_to_dash (volume), article}, lower);</p> <p>elseif utilities.is_set (article) then -- article number alone; when volume alone, handled below</p> <p>return wrap_msg ('art', {sepc, article}, lower);</p> <p>end</p> <p>end</p> <p>-- all other types of citation</p> <p>if utilities.is_set (volume) and utilities.is_set (issue) then</p> <p>return wrap_msg ('vol-no', {sepc, utilities.hyphen_to_dash (volume), issue}, lower);</p> <p>elseif utilities.is_set (volume) then</p> <p>return wrap_msg ('vol', {sepc, utilities.hyphen_to_dash (volume)}, lower);</p> <p>else</p> <p>return wrap_msg ('issue', {sepc, issue}, lower);</p> <p>end</p> <p>end</p> <p>--- adds static text to one of `|page(s)=` or `|sheet(s)=` values and returns it with all of the others set to empty strings.</p> <p>-- The return order is:</p> <p>-- page, pages, sheet, sheets</p> <p>--</p> <p>-- Singular has priority over plural when both are provided.</p> <p>--</p> <p>-- @param {string} page</p> <p>-- @param {string} pages</p> <p>-- @param {string} sheet</p> <p>-- @param {string} sheets</p> <p>-- @param {string} cite_class</p> <p>-- @param {string} origin</p> <p>-- @param {string} sepc</p> <p>-- @param {boolean} nopp</p> <p>-- @param lower</p> <p>-- @return appropriately formatted strings</p> <p>local function format_pages_sheets (page, pages, sheet, sheets, cite_class, origin, sepc, nopp, lower)</p> <p>if 'map' == cite_class then -- only cite map supports sheet(s) as in-source locators</p> <p>if utilities.is_set (sheet) then</p> <p>if 'journal' == origin then</p> <p>return <em>, </em>, wrap_msg ('j-sheet', sheet, lower), '';</p> <p>else</p> <p>return <em>, </em>, wrap_msg ('sheet', {sepc, sheet}, lower), '';</p> <p>end</p> <p>elseif utilities.is_set (sheets) then</p> <p>if 'journal' == origin then</p> <p>return <em>, </em>, '', wrap_msg ('j-sheets', sheets, lower);</p> <p>else</p> <p>return <em>, </em>, '', wrap_msg ('sheets', {sepc, sheets}, lower);</p> <p>end</p> <p>end</p> <p>end</p> <p>local is_journal = 'journal' == cite_class or (utilities.in_array (cite_class, {'citation', 'map', 'interview'}) and 'journal' == origin);</p> <p>if utilities.is_set (page) then</p> <p>if is_journal then</p> <p>return utilities.substitute (cfg.messages['j-page(s)'], page), <em>, </em>, '';</p> <p>elseif not nopp then</p> <p>return utilities.substitute (cfg.messages['p-prefix'], {sepc, page}), <em>, </em>, '';</p> <p>else</p> <p>return utilities.substitute (cfg.messages['nopp'], {sepc, page}), <em>, </em>, '';</p> <p>end</p> <p>elseif utilities.is_set (pages) then</p> <p>if is_journal then</p> <p>return utilities.substitute (cfg.messages['j-page(s)'], pages), <em>, </em>, '';</p> <p>elseif tonumber(pages) ~= nil and not nopp then -- if pages is only digits, assume a single page number</p> <p>return <em>, utilities.substitute (cfg.messages['p-prefix'], {sepc, pages}), </em>, '';</p> <p>elseif not nopp then</p> <p>return <em>, utilities.substitute (cfg.messages['pp-prefix'], {sepc, pages}), </em>, '';</p> <p>else</p> <p>return <em>, utilities.substitute (cfg.messages['nopp'], {sepc, pages}), </em>, '';</p> <p>end</p> <p>end</p> <p>return <em>, </em>, <em>, </em>; -- return empty strings</p> <p>end</p> <p>--- If any of these are interwiki links to Wikisource, returns the label portion of the interwiki-link as plain text</p> <p>-- for use in COinS. This COinS thing is done because here we convert an interwiki-link to an external link and</p> <p>-- add an icon span around that; get_coins_pages() doesn't know about the span. @todo: should it?</p> <p>--</p> <p>-- @todo: add support for sheet and sheets?; streamline;</p> <p>--</p> <p>-- @todo: make it so that this function returns only one of the three as the single in-source (the return value assigned</p> <p>-- to a new name)?</p> <p>--</p> <p>-- @param {string} page Page</p> <p>-- @param {string} page_orig</p> <p>-- @param {string} pages</p> <p>-- @param {string} pages_orig</p> <p>-- @param {string} at</p> <p>-- @return Label for interwiki link</p> <p>local function insource_loc_get (page, page_orig, pages, pages_orig, at)</p> <p>local ws_url, ws_label, coins_pages, L; -- for Wikisource interwiki-links; @todo: this corrupts page metadata (span remains in place after cleanup; fix there?)</p> <p>if utilities.is_set (page) then</p> <p>if utilities.is_set (pages) or utilities.is_set (at) then</p> <p>pages = ''; -- unset the others</p> <p>at = '';</p> <p>end</p> <p>extra_text_in_page_check (page, page_orig); -- emit error message when |page= value begins with what looks like p., pp., etc.</p> <p>ws_url, ws_label, L = wikisource_url_make (page); -- make ws URL from |page= interwiki link; link portion L becomes tooltip label</p> <p>if ws_url then</p> <p>page = external_link (ws_url, ws_label .. ' ', 'ws link in page'); -- space char after label to move icon away from in-source text; @todo: a better way to do this?</p> <p>page = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, page});</p> <p>coins_pages = ws_label;</p> <p>end</p> <p>elseif utilities.is_set (pages) then</p> <p>if utilities.is_set (at) then</p> <p>at = ''; -- unset</p> <p>end</p> <p>extra_text_in_page_check (pages, pages_orig); -- emit error message when |page= value begins with what looks like p., pp., etc.</p> <p>ws_url, ws_label, L = wikisource_url_make (pages); -- make ws URL from |pages= interwiki link; link portion L becomes tooltip label</p> <p>if ws_url then</p> <p>pages = external_link (ws_url, ws_label .. ' ', 'ws link in pages'); -- space char after label to move icon away from in-source text; @todo: a better way to do this?</p> <p>pages = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, pages});</p> <p>coins_pages = ws_label;</p> <p>end</p> <p>elseif utilities.is_set (at) then</p> <p>ws_url, ws_label, L = wikisource_url_make (at); -- make ws URL from |at= interwiki link; link portion L becomes tooltip label</p> <p>if ws_url then</p> <p>at = external_link (ws_url, ws_label .. ' ', 'ws link in at'); -- space char after label to move icon away from in-source text; @todo: a better way to do this?</p> <p>at = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, at});</p> <p>coins_pages = ws_label;</p> <p>end</p> <p>end</p> <p>return page, pages, at, coins_pages;</p> <p>end</p> <p>--- add error message when |archive-url= value is same as |url= or chapter-url= (or alias...) value</p> <p>--</p> <p>-- @param {string} archive archive URL</p> <p>-- @param {string} url URL</p> <p>-- @param {string} c_url chapter URL</p> <p>-- @param {string} source</p> <p>-- @param {string} date</p> <p>-- @return archive URL and its date</p> <p>local function is_unique_archive_url (archive, url, c_url, source, date)</p> <p>if utilities.is_set (archive) then</p> <p>if archive == url or archive == c_url then</p> <p>utilities.set_message ('err_bad_url', {utilities.wrap_style ('parameter', source)}); -- add error message</p> <p>return <em>, </em>; -- unset |archive-url= and |archive-date= because same as |url= or |chapter-url=</p> <p>end</p> <p>end</p> <p>return archive, date;</p> <p>end</p> <p>--- Check archive.org URLs to make sure they at least look like they are pointing at valid archives and not to the</p> <p>-- save snapshot URL or to calendar pages. When the archive URL is 'https://web.archive.org/save/' (or http://...)</p> <p>-- archive.org saves a snapshot of the target page in the URL. That is something that Wikipedia should not allow</p> <p>-- unwitting readers to do.</p> <p>--</p> <p>-- When the archive.org URL does not have a complete timestamp, archive.org chooses a snapshot according to its own</p> <p>-- algorithm or provides a calendar 'search' result. <a href='?title=WP%3AELNO'>WP:ELNO</a> discourages links to search results.</p> <p>--</p> <p>-- This function looks at the value assigned to |archive-url= and returns empty strings for |archive-url= and</p> <p>-- |archive-date= and an error message when:</p> <p>-- |archive-url= holds an archive.org save command URL</p> <p>-- |archive-url= is an archive.org URL that does not have a complete timestamp (YYYYMMDDhhmmss 14 digits) in the</p> <p>-- correct place</p> <p>-- otherwise returns |archive-url= and |archive-date=</p> <p>--</p> <p>-- There are two mostly compatible archive.org URLs:</p> <p>-- //web.archive.org/<timestamp>... -- the old form</p> <p>-- //web.archive.org/web/<timestamp>... -- the new form</p> <p>--</p> <p>-- The old form does not support or map to the new form when it contains a display flag. There are four identified flags</p> <p>-- ('id_', 'js_', 'cs_', 'im_') but since archive.org ignores others following the same form (two letters and an underscore)</p> <p>-- we don't check for these specific flags but we do check the form.</p> <p>--</p> <p>-- This function supports a preview mode. When the article is rendered in preview mode, this function may return a modified</p> <p>-- archive URL:</p> <p>-- for save command errors, return undated wildcard (/*/)</p> <p>-- for timestamp errors when the timestamp has a wildcard, return the URL unmodified</p> <p>-- for timestamp errors when the timestamp does not have a wildcard, return with timestamp limited to six digits plus wildcard (/yyyymm*/)</p> <p>--</p> <p>-- A secondary function is to return an archive-url timestamp from those urls that have them (archive.org and</p> <p>-- archive.today). The timestamp is used by validation.archive_date_check() to see if the value in |archive-date=</p> <p>-- matches the timestamp in the archive url.</p> <p>--</p> <p>-- @param {string} url URL to check</p> <p>-- @param {string} date Archive date</p> <p>-- @return Archive URL, date, and timestamp</p> <p>local function archive_url_check (url, date)</p> <p>local err_msg = ''; -- start with the error message empty</p> <p>local path, timestamp, flag; -- portions of the archive.org URL</p> <p>timestamp = url:match ('//archive.today/(%d%d%d%d%d%d%d%d%d%d%d%d%d%d)/') or -- get timestamp from archive.today urls</p> <p>url:match ('//archive.today/(%d%d%d%d%.%d%d%.%d%d%-%d%d%d%d%d%d)/'); -- this timestamp needs cleanup</p> <p>if timestamp then -- if this was an archive.today url ...</p> <p>return url, date, timestamp:gsub ('[%.%-]', ''); -- return ArchiveURL, ArchiveDate, and timestamp (dots and dashes removed) from |archive-url=, and done</p> <p>end</p> <p>-- here for archive.org urls</p> <p>if (not url:match('//web%.archive%.org/')) and (not url:match('//liveweb%.archive%.org/')) then -- also deprecated liveweb Wayback machine URL</p> <p>return url, date; -- not an archive.org archive, return ArchiveURL and ArchiveDate</p> <p>end</p> <p>if url:match('//web%.archive%.org/save/') then -- if a save command URL, we don't want to allow saving of the target page</p> <p>err_msg = cfg.err_msg_supl.save;</p> <p>url = url:gsub ('(//web%.archive%.org)/save/', '%1/*/', 1); -- for preview mode: modify ArchiveURL</p> <p>elseif url:match('//liveweb%.archive%.org/') then</p> <p>err_msg = cfg.err_msg_supl.liveweb;</p> <p>else</p> <p>path, timestamp, flag = url:match('//web%.archive%.org/([^%d]*)(%d+)([^/]*)/'); -- split out some of the URL parts for evaluation</p> <p>if not path then -- malformed in some way; pattern did not match</p> <p>err_msg = cfg.err_msg_supl.timestamp;</p> <p>elseif 14 ~= timestamp:len() then -- path and flag optional, must have 14-digit timestamp here</p> <p>err_msg = cfg.err_msg_supl.timestamp;</p> <p>if '*' ~= flag then</p> <p>local replacement = timestamp:match ('^%d%d%d%d%d%d') or timestamp:match ('^%d%d%d%d'); -- get the first 6 (YYYYMM) or first 4 digits (YYYY)</p> <p>if replacement then -- nil if there aren't at least 4 digits (year)</p> <p>replacement = replacement .. string.rep ('0', 14 - replacement:len()); -- year or yearmo (4 or 6 digits) zero-fill to make 14-digit timestamp</p> <p>url=url:gsub ('(//web%.archive%.org/[^%d]*)%d[^/]*', '%1' .. replacement .. '*', 1) -- for preview, modify ts to 14 digits plus splat for calendar display</p> <p>end</p> <p>end</p> <p>elseif utilities.is_set (path) and 'web/' ~= path then -- older archive URLs do not have the extra 'web/' path element</p> <p>err_msg = cfg.err_msg_supl.path;</p> <p>elseif utilities.is_set (flag) and not utilities.is_set (path) then -- flag not allowed with the old form URL (without the 'web/' path element)</p> <p>err_msg = cfg.err_msg_supl.flag;</p> <p>elseif utilities.is_set (flag) and not flag:match ('%a%a_') then -- flag if present must be two alpha characters and underscore (requires 'web/' path element)</p> <p>err_msg = cfg.err_msg_supl.flag;</p> <p>else</p> <p>return url, date, timestamp; -- return ArchiveURL, ArchiveDate, and timestamp from |archive-url=</p> <p>end</p> <p>end</p> <p>-- if here, something not right so</p> <p>utilities.set_message ('err_archive_url', {err_msg}); -- add error message and</p> <p>if is_preview_mode then</p> <p>return url, date, timestamp; -- preview mode so return ArchiveURL, ArchiveDate, and timestamp from |archive-url=</p> <p>else</p> <p>return <em>, </em>; -- return empty strings for ArchiveURL and ArchiveDate</p> <p>end</p> <p>end</p> <p>--- check `|place=`, `|publication-place=`, `|location=` to see if these params include digits. This function added because</p> <p>-- many editors misuse location to specify the in-source location (`|page(s)=` and `|at=` are supposed to do that)</p> <p>--</p> <p>-- @param {string} param_val Parameter value</p> <p>-- @return the original parameter value without modification; added maint cat when parameter value contains digits</p> <p>local function place_check (param_val)</p> <p>if not utilities.is_set (param_val) then -- parameter empty or omitted</p> <p>return param_val; -- return that empty state</p> <p>end</p> <p>if mw.ustring.find (param_val, '%d') then -- not empty, are there digits in the parameter value</p> <p>utilities.set_message ('maint_location'); -- yep, add maint cat</p> <p>end</p> <p>return param_val; -- and done</p> <p>end</p> <p>--- compares |title= to 'Archived copy' (placeholder added by bots that can't find proper title); if matches, return true; nil else</p> <p>--</p> <p>-- @param {string} title Title name</p> <p>-- @return whether title matches archived copy</p> <p>local function is_archived_copy (title)</p> <p>title = mw.ustring.lower(title); -- switch title to lower case</p> <p>if title:find (cfg.special_case_translation.archived_copy.en) then -- if title is 'Archived copy'</p> <p>return true;</p> <p>elseif cfg.special_case_translation.archived_copy['local'] then</p> <p>if mw.ustring.find (title, cfg.special_case_translation.archived_copy['local']) then -- mw.ustring() because might not be Latin script</p> <p>return true;</p> <p>end</p> <p>end</p> <p>end</p> <p>--- for any of the `|display-authors=`, `|display-editors=`, etc parameters, select either the local or global setting.</p> <p>-- When both are present, look at <local_display_names> value. When the value is some sort of 'et al.'string,</p> <p>-- special handling is required.</p> <p>--</p> <p>-- When {{tl|cs1 config}} has |display-<namelist>= AND this template has |display-<namelist>=etal AND:</p> <p>-- the number of names specified by <number_of_names> is:</p> <p>-- greater than the number specified in the global |display-<namelist>= parameter (<global_display_names>)</p> <p>-- use global |display-<namelist>= parameter value</p> <p>-- set overridden maint category</p> <p>-- less than or equal to the number specified in the global |display-<namelist>= parameter</p> <p>-- use local |display-<namelist>= parameter value</p> <p>--</p> <p>-- The purpose of this function is to prevent categorizing a template that has fewer names than the global setting</p> <p>-- to keep the etal annotation specified by <local_display_names>.</p> <p>--</p> <p>-- @param {number} global_display_names</p> <p>-- @param {number} local_display_names</p> <p>-- @param {string} param_name</p> <p>-- @param {string} number_of_names</p> <p>-- @param test</p> <p>local function display_names_select (global_display_names, local_display_names, param_name, number_of_names, test)</p> <p>if global_display_names and utilities.is_set (local_display_names) then -- when both</p> <p>if 'etal' == local_display_names:lower():gsub("[ '%.]", '') then -- the :gsub() portion makes 'etal' from a variety of 'et al.' spellings and stylings</p> <p>number_of_names = tonumber (number_of_names); -- convert these to numbers for comparison</p> <p>local global_display_names_num = tonumber (global_display_names); -- <global_display_names> not set when parameter value is not digits</p> <p>if number_of_names > global_display_names_num then -- template has more names than global config allows to be displayed?</p> <p>utilities.set_message ('maint_overridden_setting'); -- set a maint message because global is overriding local |display-<namelist>=etal</p> <p>return global_display_names, 'cs1 config'; -- return global with spoof parameter name (for get_display_names())</p> <p>else</p> <p>return local_display_names, param_name; -- return local because fewer names so let <local_display_names> control</p> <p>end</p> <p>end</p> <p>-- here when <global_display_names> and <local_display_names> both numbers; <global_display_names> controls</p> <p>utilities.set_message ('maint_overridden_setting'); -- set a maint message</p> <p>return global_display_names, 'cs1 config'; -- return global with spoof parameter name (for get_display_names())</p> <p>end</p> <p>-- here when only one of <global_display_names> or <local_display_names> set</p> <p>if global_display_names then</p> <p>return global_display_names, 'cs1 config'; -- return global with spoof parameter name (for get_display_names())</p> <p>else</p> <p>return local_display_names, param_name; -- return local</p> <p>end</p> <p>end</p> <p>--- fetch global mode setting from {{tl|cs1 config}} (if present) or from |mode= (if present); global setting overrides</p> <p>-- overrides local |mode= parameter value. When both are present, emit maintenance message</p> <p>--</p> <p>-- @param Mode</p> <p>-- @param Mode_origin</p> <p>local function mode_set (Mode, Mode_origin)</p> <p>local mode;</p> <p>if cfg.global_cs1_config_t['Mode'] then -- global setting in {{tl|cs1 config}}; nil when empty or assigned value invalid</p> <p>mode = is_valid_parameter_value (cfg.global_cs1_config_t['Mode'], 'cs1 config: mode', cfg.keywords_lists['mode'], ''); -- error messaging 'param' here is a hoax</p> <p>else</p> <p>mode = is_valid_parameter_value (Mode, Mode_origin, cfg.keywords_lists['mode'], '');</p> <p>end</p> <p>if cfg.global_cs1_config_t['Mode'] and utilities.is_set (Mode) then -- when template has |mode=<something> which global setting has overridden</p> <p>utilities.set_message ('maint_overridden_setting'); -- set a maint message</p> <p>end</p> <p>return mode;</p> <p>end</p> <p>--- create quotation from |quote=, |trans-quote=, and/or script-quote= with or without |quote-page= or |quote-pages=</p> <p>--</p> <p>-- when any of those three quote parameters are set, this function unsets <PostScript>. When none of those parameters</p> <p>-- are set, |quote-page= and |quote-pages= are unset to nil so that they are not included in the template's metadata</p> <p>--</p> <p>-- @param quote</p> <p>-- @param trans_quote</p> <p>-- @param script_quote</p> <p>-- @param quote_page</p> <p>-- @param quote_pages</p> <p>-- @param nopp</p> <p>-- @param sepc</p> <p>-- @param postscript</p> <p>-- @return quotation data</p> <p>local function quote_make (quote, trans_quote, script_quote, quote_page, quote_pages, nopp, sepc, postscript)</p> <p>if utilities.is_set (quote) or utilities.is_set (trans_quote) or utilities.is_set (script_quote) then</p> <p>if utilities.is_set (quote) then</p> <p>if quote:sub(1, 1) == '"' and quote:sub(-1, -1) == '"' then -- if first and last characters of quote are quote marks</p> <p>quote = quote:sub(2, -2); -- strip them off</p> <p>end</p> <p>end</p> <p>quote = kern_quotes (quote); -- kern if needed</p> <p>quote = utilities.wrap_style ('quoted-text', quote ); -- wrap in <q>...</q> tags</p> <p>if utilities.is_set (script_quote) then</p> <p>quote = script_concatenate (quote, script_quote, 'script-quote'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after quote is wrapped</p> <p>end</p> <p>if utilities.is_set (trans_quote) then</p> <p>if trans_quote:sub(1, 1) == '"' and trans_quote:sub(-1, -1) == '"' then -- if first and last characters of |trans-quote are quote marks</p> <p>trans_quote = trans_quote:sub(2, -2); -- strip them off</p> <p>end</p> <p>quote = quote .. " " .. utilities.wrap_style ('trans-quoted-title', trans_quote );</p> <p>end</p> <p>if utilities.is_set (quote_page) or utilities.is_set (quote_pages) then -- add page prefix</p> <p>local quote_prefix = '';</p> <p>if utilities.is_set (quote_page) then</p> <p>extra_text_in_page_check (quote_page, 'quote-page'); -- add to maint cat if |quote-page= value begins with what looks like p., pp., etc.</p> <p>if not nopp then</p> <p>quote_prefix = utilities.substitute (cfg.messages['p-prefix'], {sepc, quote_page}), <em>, </em>, '';</p> <p>else</p> <p>quote_prefix = utilities.substitute (cfg.messages['nopp'], {sepc, quote_page}), <em>, </em>, '';</p> <p>end</p> <p>elseif utilities.is_set (quote_pages) then</p> <p>extra_text_in_page_check (quote_pages, 'quote-pages'); -- add to maint cat if |quote-pages= value begins with what looks like p., pp., etc.</p> <p>if tonumber(quote_pages) ~= nil and not nopp then -- if only digits, assume single page</p> <p>quote_prefix = utilities.substitute (cfg.messages['p-prefix'], {sepc, quote_pages}), <em>, </em>;</p> <p>elseif not nopp then</p> <p>quote_prefix = utilities.substitute (cfg.messages['pp-prefix'], {sepc, quote_pages}), <em>, </em>;</p> <p>else</p> <p>quote_prefix = utilities.substitute (cfg.messages['nopp'], {sepc, quote_pages}), <em>, </em>;</p> <p>end</p> <p>end</p> <p>quote = quote_prefix .. ": " .. quote;</p> <p>else</p> <p>quote = sepc .. " " .. quote;</p> <p>end</p> <p>postscript = ""; -- cs1|2 does not supply terminal punctuation when |quote= is set</p> <p>elseif utilities.is_set (quote_page) or utilities.is_set (quote_pages) then</p> <p>quote_page = nil; -- unset; these require |quote=; @todo: error message?</p> <p>quote_pages = nil;</p> <p>end</p> <p>return quote, quote_page, quote_pages, postscript;</p> <p>end</p> <p>--- This is the main function doing the majority of the citation formatting.</p> <p>--</p> <p>-- @param {table} config Configuration</p> <p>-- @param {table} args Arguments</p> <p>-- @return Formatted citation</p> <p>local function citation0( config, args )</p> <p>--[[</p> <p>Load Input Parameters</p> <p>The argument_wrapper facilitates the mapping of multiple aliases to single internal variable.</p> <p>]]</p> <p>local A = argument_wrapper ( args );</p> <p>local i</p> <p>-- Pick out the relevant fields from the arguments. Different citation templates</p> <p>-- define different field names for the same underlying things.</p> <p>local author_etal;</p> <p>local a = {}; -- authors list from |lastn= / |firstn= pairs or |vauthors=</p> <p>local Authors;</p> <p>local NameListStyle;</p> <p>if cfg.global_cs1_config_t['NameListStyle'] then -- global setting in {{tl|cs1 config}} overrides local |name-list-style= parameter value; nil when empty or assigned value invalid</p> <p>NameListStyle = is_valid_parameter_value (cfg.global_cs1_config_t['NameListStyle'], 'cs1 config: name-list-style', cfg.keywords_lists['name-list-style'], ''); -- error messaging 'param' here is a hoax</p> <p>else</p> <p>NameListStyle = is_valid_parameter_value (A['NameListStyle'], A:ORIGIN('NameListStyle'), cfg.keywords_lists['name-list-style'], '');</p> <p>end</p> <p>if cfg.global_cs1_config_t['NameListStyle'] and utilities.is_set (A['NameListStyle']) then -- when template has |name-list-style=<something> which global setting has overridden</p> <p>utilities.set_message ('maint_overridden_setting'); -- set a maint message</p> <p>end</p> <p>local Collaboration = A['Collaboration'];</p> <p>do -- to limit scope of selected</p> <p>local selected = select_author_editor_source (A['Vauthors'], A['Authors'], args, 'AuthorList');</p> <p>if 1 == selected then</p> <p>a, author_etal = extract_names (args, 'AuthorList'); -- fetch author list from |authorn= / |lastn= / |firstn=, |author-linkn=, and |author-maskn=</p> <p>elseif 2 == selected then</p> <p>NameListStyle = 'vanc'; -- override whatever |name-list-style= might be</p> <p>a, author_etal = parse_vauthors_veditors (args, A['Vauthors'], 'AuthorList'); -- fetch author list from |vauthors=, |author-linkn=, and |author-maskn=</p> <p>elseif 3 == selected then</p> <p>Authors = A['Authors']; -- use content of |people= or |credits=; |authors= is deprecated; @todo: constrain |people= and |credits= to cite av media, episode, serial?</p> <p>end</p> <p>if utilities.is_set (Collaboration) then</p> <p>author_etal = true; -- so that |display-authors=etal not required</p> <p>end</p> <p>end</p> <p>local editor_etal;</p> <p>local e = {}; -- editors list from |editor-lastn= / |editor-firstn= pairs or |veditors=</p> <p>do -- to limit scope of selected</p> <p>local selected = select_author_editor_source (A['Veditors'], nil, args, 'EditorList'); -- support for |editors= withdrawn</p> <p>if 1 == selected then</p> <p>e, editor_etal = extract_names (args, 'EditorList'); -- fetch editor list from |editorn= / |editor-lastn= / |editor-firstn=, |editor-linkn=, and |editor-maskn=</p> <p>elseif 2 == selected then</p> <p>NameListStyle = 'vanc'; -- override whatever |name-list-style= might be</p> <p>e, editor_etal = parse_vauthors_veditors (args, args.veditors, 'EditorList'); -- fetch editor list from |veditors=, |editor-linkn=, and |editor-maskn=</p> <p>end</p> <p>end</p> <p>local Chapter = A['Chapter']; -- done here so that we have access to |contribution= from |chapter= aliases</p> <p>local Chapter_origin = A:ORIGIN ('Chapter');</p> <p>local Contribution; -- because contribution is required for contributor(s)</p> <p>if 'contribution' == Chapter_origin then</p> <p>Contribution = Chapter; -- get the name of the contribution</p> <p>end</p> <p>local c = {}; -- contributors list from |contributor-lastn= / contributor-firstn= pairs</p> <p>if utilities.in_array (config.CitationClass, {"book", "citation"}) and not utilities.is_set (A['Periodical']) then -- |contributor= and |contribution= only supported in book cites</p> <p>c = extract_names (args, 'ContributorList'); -- fetch contributor list from |contributorn= / |contributor-lastn=, -firstn=, -linkn=, -maskn=</p> <p>if 0 < #c then</p> <p>if not utilities.is_set (Contribution) then -- |contributor= requires |contribution=</p> <p>utilities.set_message ('err_contributor_missing_required_param', 'contribution'); -- add missing contribution error message</p> <p>c = {}; -- blank the contributors' table; it is used as a flag later</p> <p>end</p> <p>if 0 == #a then -- |contributor= requires |author=</p> <p>utilities.set_message ('err_contributor_missing_required_param', 'author'); -- add missing author error message</p> <p>c = {}; -- blank the contributors' table; it is used as a flag later</p> <p>end</p> <p>end</p> <p>else -- if not a book cite</p> <p>if utilities.select_one (args, cfg.aliases['ContributorList-Last'], 'err_redundant_parameters', 1 ) then -- are there contributor name list parameters?</p> <p>utilities.set_message ('err_contributor_ignored'); -- add contributor ignored error message</p> <p>end</p> <p>Contribution = nil; -- unset</p> <p>end</p> <p>local Title = A['Title'];</p> <p>local TitleLink = A['TitleLink'];</p> <p>local auto_select = ''; -- default is auto</p> <p>local accept_link;</p> <p>TitleLink, accept_link = utilities.has_accept_as_written (TitleLink, true); -- test for accept-this-as-written markup</p> <p>if (not accept_link) and utilities.in_array (TitleLink, {'none', 'pmc', 'doi'}) then -- check for special keywords</p> <p>auto_select = TitleLink; -- remember selection for later</p> <p>TitleLink = ''; -- treat as if |title-link= would have been empty</p> <p>end</p> <p>TitleLink = link_title_ok (TitleLink, A:ORIGIN ('TitleLink'), Title, 'title'); -- check for wiki-markup in |title-link= or wiki-markup in |title= when |title-link= is set</p> <p>local Section = ''; -- {{tl|cite map}} only; preset to empty string for concatenation if not used</p> <p>if 'map' == config.CitationClass and 'section' == Chapter_origin then</p> <p>Section = A['Chapter']; -- get |section= from |chapter= alias list; |chapter= and the other aliases not supported in {{tl|cite map}}</p> <p>Chapter = ''; -- unset for now; will be reset later from |map= if present</p> <p>end</p> <p>local Periodical = A['Periodical'];</p> <p>local Periodical_origin = A:ORIGIN('Periodical');</p> <p>local ScriptPeriodical = A['ScriptPeriodical'];</p> <p>local ScriptPeriodical_origin = A:ORIGIN('ScriptPeriodical');</p> <p>local TransPeriodical = A['TransPeriodical'];</p> <p>local TransPeriodical_origin = A:ORIGIN ('TransPeriodical');</p> <p>if (utilities.in_array (config.CitationClass, {'book', 'encyclopaedia'}) and (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical) or utilities.is_set (TransPeriodical))) then</p> <p>local param;</p> <p>if utilities.is_set (Periodical) then -- get a parameter name from one of these periodical related meta-parameters</p> <p>Periodical = ''; -- unset because not valid {{tl|cite book}} or {{tl|cite encyclopedia}} parameters</p> <p>param = Periodical_origin -- get parameter name for error messaging</p> <p>elseif utilities.is_set (TransPeriodical) then</p> <p>TransPeriodical = ''; -- unset because not valid {{tl|cite book}} or {{tl|cite encyclopedia}} parameters</p> <p>param = TransPeriodical_origin; -- get parameter name for error messaging</p> <p>elseif utilities.is_set (ScriptPeriodical) then</p> <p>ScriptPeriodical = ''; -- unset because not valid {{tl|cite book}} or {{tl|cite encyclopedia}} parameters</p> <p>param = ScriptPeriodical_origin; -- get parameter name for error messaging</p> <p>end</p> <p>if utilities.is_set (param) then -- if we found one</p> <p>utilities.set_message ('err_periodical_ignored', {param}); -- emit an error message</p> <p>end</p> <p>end</p> <p>if utilities.is_set (Periodical) then</p> <p>local i;</p> <p>Periodical, i = utilities.strip_apostrophe_markup (Periodical); -- strip apostrophe markup so that metadata isn't contaminated</p> <p>if i then -- non-zero when markup was stripped so emit an error message</p> <p>utilities.set_message ('err_apostrophe_markup', {Periodical_origin});</p> <p>end</p> <p>end</p> <p>if 'mailinglist' == config.CitationClass then -- special case for {{tl|cite mailing list}}</p> <p>if utilities.is_set (Periodical) and utilities.is_set (A ['MailingList']) then -- both set emit an error @todo: make a function for this and similar?</p> <p>utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', Periodical_origin) .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', 'mailinglist')});</p> <p>end</p> <p>Periodical = A ['MailingList']; -- error or no, set Periodical to |mailinglist= value because this template is {{tl|cite mailing list}}</p> <p>Periodical_origin = A:ORIGIN('MailingList');</p> <p>end</p> <p>-- web and news not tested for now because of</p> <p>-- Wikipedia:Administrators%27_noticeboard#Is_there_a_semi-automated_tool_that_could_fix_these_annoying_"Cite_Web"_errors?</p> <p>if not (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical)) then -- 'periodical' templates require periodical parameter</p> <p>-- local p = {['journal'] = 'journal', ['magazine'] = 'magazine', ['news'] = 'newspaper', ['web'] = 'website'}; -- for error message</p> <p>local p = {['journal'] = 'journal', ['magazine'] = 'magazine'}; -- for error message</p> <p>if p[config.CitationClass] then</p> <p>utilities.set_message ('err_missing_periodical', {config.CitationClass, p[config.CitationClass]});</p> <p>end</p> <p>end</p> <p>local Volume;</p> <p>if 'citation' == config.CitationClass then</p> <p>if utilities.is_set (Periodical) then</p> <p>if not utilities.in_array (Periodical_origin, cfg.citation_no_volume_t) then -- {{tl|citation}} does not render |volume= when these parameters are used</p> <p>Volume = A['Volume']; -- but does for all other 'periodicals'</p> <p>end</p> <p>elseif utilities.is_set (ScriptPeriodical) then</p> <p>if 'script-website' ~= ScriptPeriodical_origin then -- {{tl|citation}} does not render volume for |script-website=</p> <p>Volume = A['Volume']; -- but does for all other 'periodicals'</p> <p>end</p> <p>else</p> <p>Volume = A['Volume']; -- and does for non-'periodical' cites</p> <p>end</p> <p>elseif utilities.in_array (config.CitationClass, cfg.templates_using_volume) then -- render |volume= for cs1 according to the configuration settings</p> <p>Volume = A['Volume'];</p> <p>end</p> <p>extra_text_in_vol_iss_check (Volume, A:ORIGIN ('Volume'), 'v');</p> <p>local Issue;</p> <p>if 'citation' == config.CitationClass then</p> <p>if utilities.is_set (Periodical) and utilities.in_array (Periodical_origin, cfg.citation_issue_t) then -- {{tl|citation}} may render |issue= when these parameters are used</p> <p>Issue = utilities.hyphen_to_dash (A['Issue']);</p> <p>end</p> <p>elseif utilities.in_array (config.CitationClass, cfg.templates_using_issue) then -- conference & map books do not support issue; {{tl|citation}} listed here because included in settings table</p> <p>if not (utilities.in_array (config.CitationClass, {'conference', 'map', 'citation'}) and not (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical))) then</p> <p>Issue = utilities.hyphen_to_dash (A['Issue']);</p> <p>end</p> <p>end</p> <p>local ArticleNumber;</p> <p>if utilities.in_array (config.CitationClass, {'journal', 'conference'}) or ('citation' == config.CitationClass and utilities.is_set (Periodical) and 'journal' == Periodical_origin) then</p> <p>ArticleNumber = A['ArticleNumber'];</p> <p>end</p> <p>extra_text_in_vol_iss_check (Issue, A:ORIGIN ('Issue'), 'i');</p> <p>local Page;</p> <p>local Pages;</p> <p>local At;</p> <p>local QuotePage;</p> <p>local QuotePages;</p> <p>if not utilities.in_array (config.CitationClass, cfg.templates_not_using_page) then -- @todo: rewrite to emit ignored parameter error message?</p> <p>Page = A['Page'];</p> <p>Pages = utilities.hyphen_to_dash (A['Pages']);</p> <p>At = A['At'];</p> <p>QuotePage = A['QuotePage'];</p> <p>QuotePages = utilities.hyphen_to_dash (A['QuotePages']);</p> <p>end</p> <p>local NoPP = is_valid_parameter_value (A['NoPP'], A:ORIGIN('NoPP'), cfg.keywords_lists['yes_true_y'], nil);</p> <p>local Mode = mode_set (A['Mode'], A:ORIGIN('Mode'));</p> <p>-- separator character and postscript</p> <p>local sepc, PostScript = set_style (Mode:lower(), A['PostScript'], config.CitationClass);</p> <p>local Quote;</p> <p>Quote, QuotePage, QuotePages, PostScript = quote_make (A['Quote'], A['TransQuote'], A['ScriptQuote'], QuotePage, QuotePages, NoPP, sepc, PostScript);</p> <p>local Edition = A['Edition'];</p> <p>local PublicationPlace = place_check (A['PublicationPlace'], A:ORIGIN('PublicationPlace'));</p> <p>local Place = place_check (A['Place'], A:ORIGIN('Place'));</p> <p>local PublisherName = A['PublisherName'];</p> <p>local PublisherName_origin = A:ORIGIN('PublisherName');</p> <p>if utilities.is_set (PublisherName) and (cfg.keywords_xlate['none'] ~= PublisherName) then</p> <p>local i = 0;</p> <p>PublisherName, i = utilities.strip_apostrophe_markup (PublisherName); -- strip apostrophe markup so that metadata isn't contaminated; publisher is never italicized</p> <p>if i and (0 < i) then -- non-zero when markup was stripped so emit an error message</p> <p>utilities.set_message ('err_apostrophe_markup', {PublisherName_origin});</p> <p>end</p> <p>end</p> <p>if ('document' == config.CitationClass) and not utilities.is_set (PublisherName) then</p> <p>utilities.set_message ('err_missing_publisher', {config.CitationClass, 'publisher'});</p> <p>end</p> <p>local Newsgroup = A['Newsgroup']; -- @todo: strip apostrophe markup?</p> <p>local Newsgroup_origin = A:ORIGIN('Newsgroup');</p> <p>if 'newsgroup' == config.CitationClass then</p> <p>if utilities.is_set (PublisherName) and (cfg.keywords_xlate['none'] ~= PublisherName) then -- general use parameter |publisher= not allowed in cite newsgroup</p> <p>utilities.set_message ('err_parameter_ignored', {PublisherName_origin});</p> <p>end</p> <p>PublisherName = nil; -- ensure that this parameter is unset for the time being; will be used again after COinS</p> <p>end</p> <p>local URL = A['URL']; -- @todo: better way to do this for URL, ChapterURL, and MapURL?</p> <p>local UrlAccess = is_valid_parameter_value (A['UrlAccess'], A:ORIGIN('UrlAccess'), cfg.keywords_lists['url-access'], nil);</p> <p>if not utilities.is_set (URL) and utilities.is_set (UrlAccess) then</p> <p>UrlAccess = nil;</p> <p>utilities.set_message ('err_param_access_requires_param', 'url');</p> <p>end</p> <p>local ChapterURL = A['ChapterURL'];</p> <p>local ChapterUrlAccess = is_valid_parameter_value (A['ChapterUrlAccess'], A:ORIGIN('ChapterUrlAccess'), cfg.keywords_lists['url-access'], nil);</p> <p>if not utilities.is_set (ChapterURL) and utilities.is_set (ChapterUrlAccess) then</p> <p>ChapterUrlAccess = nil;</p> <p>utilities.set_message ('err_param_access_requires_param', {A:ORIGIN('ChapterUrlAccess'):gsub ('%-access', '')});</p> <p>end</p> <p>local MapUrlAccess = is_valid_parameter_value (A['MapUrlAccess'], A:ORIGIN('MapUrlAccess'), cfg.keywords_lists['url-access'], nil);</p> <p>if not utilities.is_set (A['MapURL']) and utilities.is_set (MapUrlAccess) then</p> <p>MapUrlAccess = nil;</p> <p>utilities.set_message ('err_param_access_requires_param', {'map-url'});</p> <p>end</p> <p>local this_page = mw.title.getCurrentTitle(); -- also used for COinS and for language</p> <p>local no_tracking_cats = is_valid_parameter_value (A['NoTracking'], A:ORIGIN('NoTracking'), cfg.keywords_lists['yes_true_y'], nil);</p> <p>-- check this page to see if it is in one of the namespaces that cs1 is not supposed to add to the error categories</p> <p>if not utilities.is_set (no_tracking_cats) then -- ignore if we are already not going to categorize this page</p> <p>if cfg.uncategorized_namespaces[this_page.namespace] then -- is this page's namespace id one of the uncategorized namespace ids?</p> <p>no_tracking_cats = "true"; -- set no_tracking_cats</p> <p>end</p> <p>for _, v in ipairs (cfg.uncategorized_subpages) do -- cycle through page name patterns</p> <p>if this_page.text:match (v) then -- test page name against each pattern</p> <p>no_tracking_cats = "true"; -- set no_tracking_cats</p> <p>break; -- bail out if one is found</p> <p>end</p> <p>end</p> <p>end</p> <p>-- check for extra |page=, |pages= or |at= parameters. (also sheet and sheets while we're at it)</p> <p>utilities.select_one (args, {'page', 'p', 'pp', 'pages', 'at', 'sheet', 'sheets'}, 'err_redundant_parameters'); -- this is a dummy call simply to get the error message and category</p> <p>local coins_pages;</p> <p>Page, Pages, At, coins_pages = insource_loc_get (Page, A:ORIGIN('Page'), Pages, A:ORIGIN('Pages'), At);</p> <p>-- local NoPP = is_valid_parameter_value (A['NoPP'], A:ORIGIN('NoPP'), cfg.keywords_lists['yes_true_y'], nil);</p> <p>if utilities.is_set (PublicationPlace) and utilities.is_set (Place) then -- both |publication-place= and |place= (|location=) allowed if different</p> <p>utilities.add_prop_cat ('location-test'); -- add property cat to evaluate how often PublicationPlace and Place are used together</p> <p>if PublicationPlace == Place then</p> <p>Place = ''; -- unset; don't need both if they are the same</p> <p>end</p> <p>elseif not utilities.is_set (PublicationPlace) and utilities.is_set (Place) then -- when only |place= (|location=) is set ...</p> <p>PublicationPlace = Place; -- promote |place= (|location=) to |publication-place</p> <p>end</p> <p>if PublicationPlace == Place then Place = ''; end -- don't need both if they are the same</p> <p>local URL_origin = A:ORIGIN('URL'); -- get name of parameter that holds URL</p> <p>local ChapterURL_origin = A:ORIGIN('ChapterURL'); -- get name of parameter that holds ChapterURL</p> <p>local ScriptChapter = A['ScriptChapter'];</p> <p>local ScriptChapter_origin = A:ORIGIN ('ScriptChapter');</p> <p>local Format = A['Format'];</p> <p>local ChapterFormat = A['ChapterFormat'];</p> <p>local TransChapter = A['TransChapter'];</p> <p>local TransChapter_origin = A:ORIGIN ('TransChapter');</p> <p>local TransTitle = A['TransTitle'];</p> <p>local ScriptTitle = A['ScriptTitle'];</p> <p>--[[</p> <p>Parameter remapping for cite encyclopedia:</p> <p>When the citation has these parameters:</p> <p>|encyclopedia= and |title= then map |title= to |article= and |encyclopedia= to |title= for rendering</p> <p>|encyclopedia= and |article= then map |encyclopedia= to |title= for rendering</p> <p>|trans-title= maps to |trans-chapter= when |title= is re-mapped</p> <p>|url= maps to |chapter-url= when |title= is remapped</p> <p>All other combinations of |encyclopedia=, |title=, and |article= are not modified</p> <p>]]</p> <p>local Encyclopedia = A['Encyclopedia']; -- used as a flag by this module and by ~/COinS</p> <p>local ScriptEncyclopedia = A['ScriptEncyclopedia'];</p> <p>local TransEncyclopedia = A['TransEncyclopedia'];</p> <p>if utilities.is_set (Encyclopedia) or utilities.is_set (ScriptEncyclopedia) then -- emit error message when Encyclopedia set but template is other than {{tl|cite encyclopedia}} or {{tl|citation}}</p> <p>if 'encyclopaedia' ~= config.CitationClass and 'citation' ~= config.CitationClass then</p> <p>if utilities.is_set (Encyclopedia) then</p> <p>utilities.set_message ('err_parameter_ignored', {A:ORIGIN ('Encyclopedia')});</p> <p>else</p> <p>utilities.set_message ('err_parameter_ignored', {A:ORIGIN ('ScriptEncyclopedia')});</p> <p>end</p> <p>Encyclopedia = nil; -- unset these because not supported by this template</p> <p>ScriptEncyclopedia = nil;</p> <p>TransEncyclopedia = nil;</p> <p>end</p> <p>elseif utilities.is_set (TransEncyclopedia) then</p> <p>utilities.set_message ('err_trans_missing_title', {'encyclopedia'});</p> <p>end</p> <p>if ('encyclopaedia' == config.CitationClass) or ('citation' == config.CitationClass and utilities.is_set (Encyclopedia)) then</p> <p>if utilities.is_set (Periodical) and utilities.is_set (Encyclopedia) then -- when both parameters set emit an error message; {{tl|citation}} only; Periodical not allowed in {{tl|cite encyclopedia}}</p> <p>utilities.set_message ('err_periodical_ignored', {Periodical_origin});</p> <p>end</p> <p>if utilities.is_set (Encyclopedia) or utilities.is_set (ScriptEncyclopedia) then</p> <p>Periodical = Encyclopedia; -- error or no, set Periodical to Encyclopedia for rendering; {{tl|citation}} could (not legitimately) have both; use Encyclopedia</p> <p>Periodical_origin = A:ORIGIN ('Encyclopedia');</p> <p>ScriptPeriodical = ScriptEncyclopedia;</p> <p>ScriptPeriodical_origin = A:ORIGIN ('ScriptEncyclopedia');</p> <p>if utilities.is_set (Title) or utilities.is_set (ScriptTitle) then</p> <p>if not utilities.is_set (Chapter) then</p> <p>Chapter = Title; -- |encyclopedia= and |title= are set so map |title= params to |article= params for rendering</p> <p>ScriptChapter = ScriptTitle;</p> <p>ScriptChapter_origin = A:ORIGIN('ScriptTitle')</p> <p>TransChapter = TransTitle;</p> <p>ChapterURL = URL;</p> <p>ChapterURL_origin = URL_origin;</p> <p>ChapterUrlAccess = UrlAccess;</p> <p>ChapterFormat = Format;</p> <p>if not utilities.is_set (ChapterURL) and utilities.is_set (TitleLink) then</p> <p>Chapter = utilities.make_wikilink (TitleLink, Chapter);</p> <p>end</p> <p>Title = Periodical; -- now map |encyclopedia= params to |title= params for rendering</p> <p>ScriptTitle = ScriptPeriodical or '';</p> <p>TransTitle = TransEncyclopedia or '';</p> <p>Periodical = ''; -- redundant so unset</p> <p>ScriptPeriodical = '';</p> <p>URL = '';</p> <p>Format = '';</p> <p>TitleLink = '';</p> <p>end</p> <p>elseif utilities.is_set (Chapter) or utilities.is_set (ScriptChapter) then -- |title= not set</p> <p>Title = Periodical; -- |encyclopedia= set and |article= set so map |encyclopedia= to |title= for rendering</p> <p>ScriptTitle = ScriptPeriodical or '';</p> <p>TransTitle = TransEncyclopedia or '';</p> <p>Periodical = ''; -- redundant so unset</p> <p>ScriptPeriodical = '';</p> <p>end</p> <p>end</p> <p>end</p> <p>-- special case for cite techreport.</p> <p>local ID = A['ID'];</p> <p>if (config.CitationClass == "techreport") then -- special case for cite techreport</p> <p>if utilities.is_set (A['Number']) then -- cite techreport uses 'number', which other citations alias to 'issue'</p> <p>if not utilities.is_set (ID) then -- can we use ID for the "number"?</p> <p>ID = A['Number']; -- yes, use it</p> <p>else -- ID has a value so emit error message</p> <p>utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', 'id') .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', 'number')});</p> <p>end</p> <p>end</p> <p>end</p> <p>-- Account for the oddity that is {{tl|cite conference}}, before generation of COinS data.</p> <p>local ChapterLink -- = A['ChapterLink']; -- deprecated as a parameter but still used internally by cite episode</p> <p>local Conference = A['Conference'];</p> <p>local BookTitle = A['BookTitle'];</p> <p>local TransTitle_origin = A:ORIGIN ('TransTitle');</p> <p>if 'conference' == config.CitationClass then</p> <p>if utilities.is_set (BookTitle) then</p> <p>Chapter = Title;</p> <p>Chapter_origin = 'title';</p> <p>-- ChapterLink = TitleLink; -- |chapter-link= is deprecated</p> <p>ChapterURL = URL;</p> <p>ChapterUrlAccess = UrlAccess;</p> <p>ChapterURL_origin = URL_origin;</p> <p>URL_origin = '';</p> <p>ChapterFormat = Format;</p> <p>TransChapter = TransTitle;</p> <p>TransChapter_origin = TransTitle_origin;</p> <p>Title = BookTitle;</p> <p>Format = '';</p> <p>-- TitleLink = '';</p> <p>TransTitle = '';</p> <p>URL = '';</p> <p>end</p> <p>elseif 'speech' ~= config.CitationClass then</p> <p>Conference = ''; -- not cite conference or cite speech so make sure this is empty string</p> <p>end</p> <p>-- CS1/2 mode</p> <p>-- local Mode;</p> <p>-- if cfg.global_cs1_config_t['Mode'] then -- global setting in {{tl|cs1 config}} overrides local |mode= parameter value; nil when empty or assigned value invalid</p> <p>-- Mode = is_valid_parameter_value (cfg.global_cs1_config_t['Mode'], 'cs1 config: mode', cfg.keywords_lists['mode'], ''); -- error messaging 'param' here is a hoax</p> <p>-- else</p> <p>-- Mode = is_valid_parameter_value (A['Mode'], A:ORIGIN('Mode'), cfg.keywords_lists['mode'], '');</p> <p>-- end</p> <p>--</p> <p>-- if cfg.global_cs1_config_t['Mode'] and utilities.is_set (A['Mode']) then -- when template has |mode=<something> which global setting has overridden</p> <p>-- utilities.set_message ('maint_overridden_setting'); -- set a maint message</p> <p>-- end</p> <p>-- -- separator character and postscript</p> <p>-- local sepc, PostScript = set_style (Mode:lower(), A['PostScript'], config.CitationClass);</p> <p>-- controls capitalization of certain static text</p> <p>local use_lowercase = ( sepc == ',' );</p> <p>-- cite map oddities</p> <p>local Cartography = "";</p> <p>local Scale = "";</p> <p>local Sheet = A['Sheet'] or '';</p> <p>local Sheets = A['Sheets'] or '';</p> <p>if config.CitationClass == "map" then</p> <p>--@todo: make a function for this and similar?</p> <p>if utilities.is_set (Chapter) then</p> <p>utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', 'map') .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', Chapter_origin)}); -- add error message</p> <p>end</p> <p>Chapter = A['Map'];</p> <p>Chapter_origin = A:ORIGIN('Map');</p> <p>ChapterURL = A['MapURL'];</p> <p>ChapterURL_origin = A:ORIGIN('MapURL');</p> <p>TransChapter = A['TransMap'];</p> <p>ScriptChapter = A['ScriptMap']</p> <p>ScriptChapter_origin = A:ORIGIN('ScriptMap')</p> <p>ChapterUrlAccess = MapUrlAccess;</p> <p>ChapterFormat = A['MapFormat'];</p> <p>Cartography = A['Cartography'];</p> <p>if utilities.is_set ( Cartography ) then</p> <p>Cartography = sepc .. " " .. wrap_msg ('cartography', Cartography, use_lowercase);</p> <p>end</p> <p>Scale = A['Scale'];</p> <p>if utilities.is_set ( Scale ) then</p> <p>Scale = sepc .. " " .. Scale;</p> <p>end</p> <p>end</p> <p>-- Account for the oddities that are {{tl|cite episode}} and {{tl|cite serial}}, before generation of COinS data.</p> <p>local Series = A['Series'];</p> <p>if 'episode' == config.CitationClass or 'serial' == config.CitationClass then</p> <p>local SeriesLink = A['SeriesLink'];</p> <p>SeriesLink = link_title_ok (SeriesLink, A:ORIGIN ('SeriesLink'), Series, 'series'); -- check for wiki-markup in |series-link= or wiki-markup in |series= when |series-link= is set</p> <p>local Network = A['Network'];</p> <p>local Station = A['Station'];</p> <p>local s, n = {}, {};</p> <p>-- do common parameters first</p> <p>if utilities.is_set (Network) then table.insert(n, Network); end</p> <p>if utilities.is_set (Station) then table.insert(n, Station); end</p> <p>ID = table.concat(n, sepc .. ' ');</p> <p>if 'episode' == config.CitationClass then -- handle the oddities that are strictly {{tl|cite episode}}</p> <p>local Season = A['Season'];</p> <p>local SeriesNumber = A['SeriesNumber'];</p> <p>-- these are mutually exclusive so if both are set</p> <p>-- @todo: make a function for this and similar?</p> <p>if utilities.is_set (Season) and utilities.is_set (SeriesNumber) then</p> <p>utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', 'season') .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', 'seriesno')}); -- add error message</p> <p>SeriesNumber = ''; -- unset; prefer |season= over |seriesno=</p> <p>end</p> <p>-- assemble a table of parts concatenated later into Series</p> <p>if utilities.is_set (Season) then table.insert(s, wrap_msg ('season', Season, use_lowercase)); end</p> <p>if utilities.is_set (SeriesNumber) then table.insert(s, wrap_msg ('seriesnum', SeriesNumber, use_lowercase)); end</p> <p>if utilities.is_set (Issue) then table.insert(s, wrap_msg ('episode', Issue, use_lowercase)); end</p> <p>Issue = ''; -- unset because this is not a unique parameter</p> <p>Chapter = Title; -- promote title parameters to chapter</p> <p>ScriptChapter = ScriptTitle;</p> <p>ScriptChapter_origin = A:ORIGIN('ScriptTitle');</p> <p>ChapterLink = TitleLink; -- alias |episode-link=</p> <p>TransChapter = TransTitle;</p> <p>ChapterURL = URL;</p> <p>ChapterUrlAccess = UrlAccess;</p> <p>ChapterURL_origin = URL_origin;</p> <p>ChapterFormat = Format;</p> <p>Title = Series; -- promote series to title</p> <p>TitleLink = SeriesLink;</p> <p>Series = table.concat(s, sepc .. ' '); -- this is concatenation of season, seriesno, episode number</p> <p>if utilities.is_set (ChapterLink) and not utilities.is_set (ChapterURL) then -- link but not URL</p> <p>Chapter = utilities.make_wikilink (ChapterLink, Chapter);</p> <p>elseif utilities.is_set (ChapterLink) and utilities.is_set (ChapterURL) then -- if both are set, URL links episode;</p> <p>Series = utilities.make_wikilink (ChapterLink, Series);</p> <p>end</p> <p>URL = ''; -- unset</p> <p>TransTitle = '';</p> <p>ScriptTitle = '';</p> <p>Format = '';</p> <p>else -- now oddities that are cite serial</p> <p>Issue = ''; -- unset because this parameter no longer supported by the citation/core version of cite serial</p> <p>--- @todo: make `|episode=` available to cite episode someday?</p> <p>Chapter = A['Episode'];</p> <p>if utilities.is_set (Series) and utilities.is_set (SeriesLink) then</p> <p>Series = utilities.make_wikilink (SeriesLink, Series);</p> <p>end</p> <p>Series = utilities.wrap_style ('italic-title', Series); -- series is italicized</p> <p>end</p> <p>end</p> <p>-- end of {{tl|cite episode}} stuff</p> <p>-- handle type parameter for those CS1 citations that have default values</p> <p>local TitleType = A['TitleType'];</p> <p>local Degree = A['Degree'];</p> <p>if utilities.in_array (config.CitationClass, {'AV-media-notes', 'document', 'interview', 'mailinglist', 'map', 'podcast', 'pressrelease', 'report', 'speech', 'techreport', 'thesis'}) then</p> <p>TitleType = set_titletype (config.CitationClass, TitleType);</p> <p>if utilities.is_set (Degree) and "Thesis" == TitleType then -- special case for cite thesis</p> <p>TitleType = Degree .. ' ' .. cfg.title_types ['thesis']:lower();</p> <p>end</p> <p>end</p> <p>if utilities.is_set (TitleType) then -- if type parameter is specified</p> <p>TitleType = utilities.substitute ( cfg.messages['type'], TitleType); -- display it in parentheses</p> <p>-- @todo: Hack on TitleType to fix bunched parentheses problem</p> <p>end</p> <p>-- legacy: promote PublicationDate to Date if neither Date nor Year are set.</p> <p>local Date = A['Date'];</p> <p>local Date_origin; -- to hold the name of parameter promoted to Date; required for date error messaging</p> <p>local PublicationDate = A['PublicationDate'];</p> <p>local Year = A['Year'];</p> <p>if utilities.is_set (Year) then</p> <p>validation.year_check (Year); -- returns nothing; emits maint message when |year= doesn't hold a 'year' value</p> <p>end</p> <p>if not utilities.is_set (Date) then</p> <p>Date = Year; -- promote Year to Date</p> <p>Year = nil; -- make nil so Year as empty string isn't used for CITEREF</p> <p>if not utilities.is_set (Date) and utilities.is_set (PublicationDate) then -- use PublicationDate when |date= and |year= are not set</p> <p>Date = PublicationDate; -- promote PublicationDate to Date</p> <p>PublicationDate = ''; -- unset, no longer needed</p> <p>Date_origin = A:ORIGIN('PublicationDate'); -- save the name of the promoted parameter</p> <p>else</p> <p>Date_origin = A:ORIGIN('Year'); -- save the name of the promoted parameter</p> <p>end</p> <p>else</p> <p>Date_origin = A:ORIGIN('Date'); -- not a promotion; name required for error messaging</p> <p>end</p> <p>if PublicationDate == Date then PublicationDate = ''; end -- if PublicationDate is same as Date, don't display in rendered citation</p> <p>--[[</p> <p>Go test all of the date-holding parameters for valid MOS:DATE format and make sure that dates are real dates. This must be done before we do COinS because here is where</p> <p>we get the date used in the metadata.</p> <p>Date validation supporting code is in Module:Citation/CS1/Date_validation</p> <p>]]</p> <p>local DF = is_valid_parameter_value (A['DF'], A:ORIGIN('DF'), cfg.keywords_lists['df'], '');</p> <p>if not utilities.is_set (DF) then</p> <p>DF = cfg.global_df; -- local |df= if present overrides global df set by {{use xxx date}} template</p> <p>end</p> <p>local ArchiveURL;</p> <p>local ArchiveDate;</p> <p>local ArchiveFormat = A['ArchiveFormat'];</p> <p>local archive_url_timestamp; -- timestamp from wayback machine url</p> <p>ArchiveURL, ArchiveDate, archive_url_timestamp = archive_url_check (A['ArchiveURL'], A['ArchiveDate'])</p> <p>ArchiveFormat = style_format (ArchiveFormat, ArchiveURL, 'archive-format', 'archive-url');</p> <p>ArchiveURL, ArchiveDate = is_unique_archive_url (ArchiveURL, URL, ChapterURL, A:ORIGIN('ArchiveURL'), ArchiveDate); -- add error message when URL or ChapterURL == ArchiveURL</p> <p>local AccessDate = A['AccessDate'];</p> <p>local COinS_date = {}; -- holds date info extracted from |date= for the COinS metadata by Module:Date verification</p> <p>local DoiBroken = A['DoiBroken'];</p> <p>local Embargo = A['Embargo'];</p> <p>local anchor_year; -- used in the CITEREF identifier</p> <p>do -- create defined block to contain local variables error_message, date_parameters_list, mismatch</p> <p>local error_message = '';</p> <p>-- AirDate has been promoted to Date so not necessary to check it</p> <p>local date_parameters_list = {</p> <p>['access-date'] = {val = AccessDate, name = A:ORIGIN ('AccessDate')},</p> <p>['archive-date'] = {val = ArchiveDate, name = A:ORIGIN ('ArchiveDate')},</p> <p>['date'] = {val = Date, name = Date_origin},</p> <p>['doi-broken-date'] = {val = DoiBroken, name = A:ORIGIN ('DoiBroken')},</p> <p>['pmc-embargo-date'] = {val = Embargo, name = A:ORIGIN ('Embargo')},</p> <p>['publication-date'] = {val = PublicationDate, name = A:ORIGIN ('PublicationDate')},</p> <p>['year'] = {val = Year, name = A:ORIGIN ('Year')},</p> <p>};</p> <p>local error_list = {};</p> <p>anchor_year, Embargo = validation.dates(date_parameters_list, COinS_date, error_list);</p> <p>if utilities.is_set (Year) and utilities.is_set (Date) then -- both |date= and |year= not normally needed;</p> <p>validation.year_date_check (Year, A:ORIGIN ('Year'), Date, A:ORIGIN ('Date'), error_list);</p> <p>end</p> <p>if 0 == #error_list then -- error free dates only; 0 when error_list is empty</p> <p>local modified = false; -- flag</p> <p>if utilities.is_set (DF) then -- if we need to reformat dates</p> <p>modified = validation.reformat_dates (date_parameters_list, DF); -- reformat to DF format, use long month names if appropriate</p> <p>end</p> <p>if true == validation.date_hyphen_to_dash (date_parameters_list) then -- convert hyphens to dashes where appropriate</p> <p>modified = true;</p> <p>utilities.set_message ('maint_date_format'); -- hyphens were converted so add maint category</p> <p>end</p> <p>-- for those wikis that can and want to have English date names translated to the local language; not supported at en.wiki</p> <p>if cfg.date_name_auto_xlate_enable and validation.date_name_xlate (date_parameters_list, cfg.date_digit_auto_xlate_enable ) then</p> <p>utilities.set_message ('maint_date_auto_xlated'); -- add maint cat</p> <p>modified = true;</p> <p>end</p> <p>if modified then -- if the date_parameters_list values were modified</p> <p>AccessDate = date_parameters_list['access-date'].val; -- overwrite date holding parameters with modified values</p> <p>ArchiveDate = date_parameters_list['archive-date'].val;</p> <p>Date = date_parameters_list['date'].val;</p> <p>DoiBroken = date_parameters_list['doi-broken-date'].val;</p> <p>PublicationDate = date_parameters_list['publication-date'].val;</p> <p>end</p> <p>if archive_url_timestamp and utilities.is_set (ArchiveDate) then</p> <p>validation.archive_date_check (ArchiveDate, archive_url_timestamp, DF); -- does YYYYMMDD in archive_url_timestamp match date in ArchiveDate</p> <p>end</p> <p>else</p> <p>utilities.set_message ('err_bad_date', {utilities.make_sep_list (#error_list, error_list)}); -- add this error message</p> <p>end</p> <p>end -- end of do</p> <p>if utilities.in_array (config.CitationClass, {'book', 'encyclopaedia'}) or -- {{tl|cite book}}, {{tl|cite encyclopedia}};</p> <p>-- @todo: {{tl|cite conference}} and others?</p> <p>('citation' == config.CitationClass and utilities.is_set (Encyclopedia)) or -- {{tl|citation}} as an encylopedia citation</p> <p>('citation' == config.CitationClass and not utilities.is_set (Periodical)) then -- {{tl|citation}} as a book citation</p> <p>if utilities.is_set (PublicationPlace) then</p> <p>if not utilities.is_set (PublisherName) then</p> <p>local date = COinS_date.rftdate and tonumber (COinS_date.rftdate:match ('%d%d%d%d')); -- get year portion of COinS date (because in Arabic numerals); convert string to number</p> <p>if date and (1850 <= date) then -- location has no publisher; if date is 1850 or later</p> <p>utilities.set_message ('maint_location_no_publisher'); -- add maint cat</p> <p>end</p> <p>else -- PublisherName has a value</p> <p>if cfg.keywords_xlate['none'] == PublisherName then -- if that value is 'none' (only for book and encyclopedia citations)</p> <p>PublisherName = ''; -- unset</p> <p>end</p> <p>end</p> <p>end</p> <p>end</p> <p>local ID_list = {}; -- sequence table of rendered identifiers</p> <p>local ID_list_coins = {}; -- table of identifiers and their values from args; key is same as cfg.id_handlers's key</p> <p>local Class = A['Class']; -- arxiv class identifier</p> <p>local ID_support = {</p> <p>{A['ASINTLD'], 'ASIN', 'err_asintld_missing_asin', A:ORIGIN ('ASINTLD')},</p> <p>{DoiBroken, 'DOI', 'err_doibroken_missing_doi', A:ORIGIN ('DoiBroken')},</p> <p>{Embargo, 'PMC', 'err_embargo_missing_pmc', A:ORIGIN ('Embargo')},</p> <p>}</p> <p>ID_list, ID_list_coins = identifiers.identifier_lists_get (args, {DoiBroken = DoiBroken, ASINTLD = A['ASINTLD'], Embargo = Embargo, Class = Class, Year=anchor_year}, ID_support);</p> <p>-- Account for the oddities that are {{tl|cite arxiv}}, {{tl|cite biorxiv}}, {{tl|cite citeseerx}}, {{tl|cite medrxiv}}, {{tl|cite ssrn}}, before generation of COinS data.</p> <p>if utilities.in_array (config.CitationClass, whitelist.preprint_template_list_t) then -- `|arxiv=` or `|eprint=` required for cite arxiv; `|biorxiv=`, |citeseerx=, |medrxiv=, |ssrn= required for their templates</p> <p>if not (args[cfg.id_handlers[config.CitationClass:upper()].parameters[1]] or -- can't use ID_list_coins k/v table here because invalid parameters omitted</p> <p>args[cfg.id_handlers[config.CitationClass:upper()].parameters[2]]) then -- which causes unexpected parameter missing error message</p> <p>utilities.set_message ('err_' .. config.CitationClass .. '_missing'); -- add error message</p> <p>end</p> <p>Periodical = ({['arxiv'] = 'arXiv', ['biorxiv'] = 'bioRxiv', ['citeseerx'] = 'CiteSeerX', ['medrxiv'] = 'medRxiv', ['ssrn'] = 'Social Science Research Network'})[config.CitationClass];</p> <p>end</p> <p>-- Link the title of the work if no |url= was provided, but we have a |pmc= or a |doi= with |doi-access=free</p> <p>if config.CitationClass == "journal" and not utilities.is_set (URL) and not utilities.is_set (TitleLink) and not utilities.in_array (cfg.keywords_xlate[Title], {'off', 'none'}) then -- @todo: remove 'none' once existing citations have been switched to 'off', so 'none' can be used as token for "no title" instead</p> <p>if 'none' ~= cfg.keywords_xlate[auto_select] then -- if auto-linking not disabled</p> <p>if identifiers.auto_link_urls[auto_select] then -- manual selection</p> <p>URL = identifiers.auto_link_urls[auto_select]; -- set URL to be the same as identifier's external link</p> <p>URL_origin = cfg.id_handlers[auto_select:upper()].parameters[1]; -- set URL_origin to parameter name for use in error message if citation is missing a |title=</p> <p>elseif identifiers.auto_link_urls['pmc'] then -- auto-select PMC</p> <p>URL = identifiers.auto_link_urls['pmc']; -- set URL to be the same as the PMC external link if not embargoed</p> <p>URL_origin = cfg.id_handlers['PMC'].parameters[1]; -- set URL_origin to parameter name for use in error message if citation is missing a |title=</p> <p>elseif identifiers.auto_link_urls['doi'] then -- auto-select DOI</p> <p>URL = identifiers.auto_link_urls['doi'];</p> <p>URL_origin = cfg.id_handlers['DOI'].parameters[1];</p> <p>end</p> <p>end</p> <p>if utilities.is_set (URL) then -- set when using an identifier-created URL</p> <p>if utilities.is_set (AccessDate) then -- |access-date= requires |url=; identifier-created URL is not |url=</p> <p>utilities.set_message ('err_accessdate_missing_url'); -- add an error message</p> <p>AccessDate = ''; -- unset</p> <p>end</p> <p>if utilities.is_set (ArchiveURL) then -- |archive-url= requires |url=; identifier-created URL is not |url=</p> <p>utilities.set_message ('err_archive_missing_url'); -- add an error message</p> <p>ArchiveURL = ''; -- unset</p> <p>end</p> <p>end</p> <p>end</p> <p>-- At this point fields may be nil if they weren't specified in the template use. We can use that fact.</p> <p>-- Test if citation has no title</p> <p>if not utilities.is_set (Title) and not utilities.is_set (TransTitle) and not utilities.is_set (ScriptTitle) then -- has special case for cite episode</p> <p>utilities.set_message ('err_citation_missing_title', {'episode' == config.CitationClass and 'series' or 'title'});</p> <p>end</p> <p>if utilities.in_array (cfg.keywords_xlate[Title], {'off', 'none'}) and</p> <p>utilities.in_array (config.CitationClass, {'journal', 'citation'}) and</p> <p>(utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical)) and</p> <p>('journal' == Periodical_origin or 'script-journal' == ScriptPeriodical_origin) then -- special case for journal cites</p> <p>Title = ''; -- set title to empty string</p> <p>utilities.set_message ('maint_untitled'); -- add maint cat</p> <p>end</p> <p>-- COinS metadata (see <http://ocoins.info/>) for automated parsing of citation information.</p> <p>-- handle the oddity that is cite encyclopedia and {{tl|citation |encyclopedia=something}}. Here we presume that</p> <p>-- when Periodical, Title, and Chapter are all set, then Periodical is the book (encyclopedia) title, Title</p> <p>-- is the article title, and Chapter is a section within the article. So, we remap</p> <p>local coins_chapter = Chapter; -- default assuming that remapping not required</p> <p>local coins_title = Title; -- et tu</p> <p>if 'encyclopaedia' == config.CitationClass or ('citation' == config.CitationClass and utilities.is_set (Encyclopedia)) then</p> <p>if utilities.is_set (Chapter) and utilities.is_set (Title) and utilities.is_set (Periodical) then -- if all are used then</p> <p>coins_chapter = Title; -- remap</p> <p>coins_title = Periodical;</p> <p>end</p> <p>end</p> <p>local coins_author = a; -- default for coins rft.au</p> <p>if 0 < #c then -- but if contributor list</p> <p>coins_author = c; -- use that instead</p> <p>end</p> <p>-- this is the function call to COinS()</p> <p>local OCinSoutput = metadata.COinS({</p> <p>['Periodical'] = utilities.strip_apostrophe_markup (Periodical), -- no markup in the metadata</p> <p>['Encyclopedia'] = Encyclopedia, -- just a flag; content ignored by ~/COinS</p> <p>['Chapter'] = metadata.make_coins_title (coins_chapter, ScriptChapter), -- Chapter and ScriptChapter stripped of bold / italic / accept-as-written markup</p> <p>['Degree'] = Degree; -- cite thesis only</p> <p>['Title'] = metadata.make_coins_title (coins_title, ScriptTitle), -- Title and ScriptTitle stripped of bold / italic / accept-as-written markup</p> <p>['PublicationPlace'] = PublicationPlace,</p> <p>['Date'] = COinS_date.rftdate, -- COinS_date.* has correctly formatted date values if Date is valid;</p> <p>['Season'] = COinS_date.rftssn,</p> <p>['Quarter'] = COinS_date.rftquarter,</p> <p>['Chron'] = COinS_date.rftchron,</p> <p>['Series'] = Series,</p> <p>['Volume'] = Volume,</p> <p>['Issue'] = Issue,</p> <p>['ArticleNumber'] = ArticleNumber,</p> <p>['Pages'] = coins_pages or metadata.get_coins_pages (first_set ({Sheet, Sheets, Page, Pages, At, QuotePage, QuotePages}, 7)), -- pages stripped of external links</p> <p>['Edition'] = Edition,</p> <p>['PublisherName'] = PublisherName or Newsgroup, -- any apostrophe markup already removed from PublisherName</p> <p>['URL'] = first_set ({ChapterURL, URL}, 2),</p> <p>['Authors'] = coins_author,</p> <p>['ID_list'] = ID_list_coins,</p> <p>['RawPage'] = this_page.prefixedText,</p> <p>}, config.CitationClass);</p> <p>-- Account for the oddities that are {{tl|cite arxiv}}, {{tl|cite biorxiv}}, {{tl|cite citeseerx}}, {{tl|cite medrxiv}}, and {{tl|cite ssrn}} AFTER generation of COinS data.</p> <p>if utilities.in_array (config.CitationClass, whitelist.preprint_template_list_t) then -- we have set rft.jtitle in COinS to arXiv, bioRxiv, CiteSeerX, medRxiv, or ssrn now unset so it isn't displayed</p> <p>Periodical = ''; -- periodical not allowed in these templates; if article has been published, use cite journal</p> <p>end</p> <p>-- special case for cite newsgroup. Do this after COinS because we are modifying Publishername to include some static text</p> <p>if 'newsgroup' == config.CitationClass and utilities.is_set (Newsgroup) then</p> <p>PublisherName = utilities.substitute (cfg.messages['newsgroup'], external_link( 'news:' .. Newsgroup, Newsgroup, Newsgroup_origin, nil ));</p> <p>end</p> <p>local Editors;</p> <p>local EditorCount; -- used only for choosing {ed.) or (eds.) annotation at end of editor name-list</p> <p>local Contributors; -- assembled contributors name list</p> <p>local contributor_etal;</p> <p>local Translators; -- assembled translators name list</p> <p>local translator_etal;</p> <p>local t = {}; -- translators list from |translator-lastn= / translator-firstn= pairs</p> <p>t = extract_names (args, 'TranslatorList'); -- fetch translator list from |translatorn= / |translator-lastn=, -firstn=, -linkn=, -maskn=</p> <p>local Interviewers;</p> <p>local interviewers_list = {};</p> <p>interviewers_list = extract_names (args, 'InterviewerList'); -- process preferred interviewers parameters</p> <p>local interviewer_etal;</p> <p>-- Now perform various field substitutions.</p> <p>-- We also add leading spaces and surrounding markup and punctuation to the</p> <p>-- various parts of the citation, but only when they are non-nil.</p> <p>do</p> <p>local last_first_list;</p> <p>local control = {</p> <p>format = NameListStyle, -- empty string, '&', 'amp', 'and', or 'vanc'</p> <p>maximum = nil, -- as if display-authors or display-editors not set</p> <p>mode = Mode</p> <p>};</p> <p>do -- do editor name list first because the now unsupported coauthors used to modify control table</p> <p>local display_names, param = display_names_select (cfg.global_cs1_config_t['DisplayEditors'], A['DisplayEditors'], A:ORIGIN ('DisplayEditors'), #e);</p> <p>control.maximum, editor_etal = get_display_names (display_names, #e, 'editors', editor_etal, param);</p> <p>Editors, EditorCount = list_people (control, e, editor_etal);</p> <p>if 1 == EditorCount and (true == editor_etal or 1 < #e) then -- only one editor displayed but includes etal then</p> <p>EditorCount = 2; -- spoof to display (eds.) annotation</p> <p>end</p> <p>end</p> <p>do -- now do interviewers</p> <p>local display_names, param = display_names_select (cfg.global_cs1_config_t['DisplayInterviewers'], A['DisplayInterviewers'], A:ORIGIN ('DisplayInterviewers'), #interviewers_list);</p> <p>control.maximum, interviewer_etal = get_display_names (display_names, #interviewers_list, 'interviewers', interviewer_etal, param);</p> <p>Interviewers = list_people (control, interviewers_list, interviewer_etal);</p> <p>end</p> <p>do -- now do translators</p> <p>local display_names, param = display_names_select (cfg.global_cs1_config_t['DisplayTranslators'], A['DisplayTranslators'], A:ORIGIN ('DisplayTranslators'), #t);</p> <p>control.maximum, translator_etal = get_display_names (display_names, #t, 'translators', translator_etal, param);</p> <p>Translators = list_people (control, t, translator_etal);</p> <p>end</p> <p>do -- now do contributors</p> <p>local display_names, param = display_names_select (cfg.global_cs1_config_t['DisplayContributors'], A['DisplayContributors'], A:ORIGIN ('DisplayContributors'), #c);</p> <p>control.maximum, contributor_etal = get_display_names (display_names, #c, 'contributors', contributor_etal, param);</p> <p>Contributors = list_people (control, c, contributor_etal);</p> <p>end</p> <p>do -- now do authors</p> <p>local display_names, param = display_names_select (cfg.global_cs1_config_t['DisplayAuthors'], A['DisplayAuthors'], A:ORIGIN ('DisplayAuthors'), #a, author_etal);</p> <p>control.maximum, author_etal = get_display_names (display_names, #a, 'authors', author_etal, param);</p> <p>last_first_list = list_people (control, a, author_etal);</p> <p>if utilities.is_set (Authors) then</p> <p>Authors, author_etal = name_has_etal (Authors, author_etal, false, 'authors'); -- find and remove variations on et al.</p> <p>if author_etal then</p> <p>Authors = Authors .. ' ' .. cfg.messages['et al']; -- add et al. to authors parameter</p> <p>end</p> <p>else</p> <p>Authors = last_first_list; -- either an author name list or an empty string</p> <p>end</p> <p>end -- end of do</p> <p>if utilities.is_set (Authors) and utilities.is_set (Collaboration) then</p> <p>Authors = Authors .. ' (' .. Collaboration .. ')'; -- add collaboration after et al.</p> <p>end</p> <p>end</p> <p>local ConferenceFormat = A['ConferenceFormat'];</p> <p>local ConferenceURL = A['ConferenceURL'];</p> <p>ConferenceFormat = style_format (ConferenceFormat, ConferenceURL, 'conference-format', 'conference-url');</p> <p>Format = style_format (Format, URL, 'format', 'url');</p> <p>-- special case for chapter format so no error message or cat when chapter not supported</p> <p>if not (utilities.in_array (config.CitationClass, {'web', 'news', 'journal', 'magazine', 'pressrelease', 'podcast', 'newsgroup', 'arxiv', 'biorxiv', 'citeseerx', 'medrxiv', 'ssrn'}) or</p> <p>('citation' == config.CitationClass and (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical)) and not utilities.is_set (Encyclopedia))) then</p> <p>ChapterFormat = style_format (ChapterFormat, ChapterURL, 'chapter-format', 'chapter-url');</p> <p>end</p> <p>if not utilities.is_set (URL) then</p> <p>if utilities.in_array (config.CitationClass, {"web", "podcast", "mailinglist"}) or -- |url= required for cite web, cite podcast, and cite mailinglist</p> <p>('citation' == config.CitationClass and ('website' == Periodical_origin or 'script-website' == ScriptPeriodical_origin)) then -- and required for {{tl|citation}} with |website= or |script-website=</p> <p>utilities.set_message ('err_cite_web_url');</p> <p>end</p> <p>-- do we have |accessdate= without either |url= or |chapter-url=?</p> <p>if utilities.is_set (AccessDate) and not utilities.is_set (ChapterURL) then -- ChapterURL may be set when URL is not set;</p> <p>utilities.set_message ('err_accessdate_missing_url');</p> <p>AccessDate = '';</p> <p>end</p> <p>end</p> <p>local UrlStatus = is_valid_parameter_value (A['UrlStatus'], A:ORIGIN('UrlStatus'), cfg.keywords_lists['url-status'], '');</p> <p>local OriginalURL</p> <p>local OriginalURL_origin</p> <p>local OriginalFormat</p> <p>local OriginalAccess;</p> <p>UrlStatus = UrlStatus:lower(); -- used later when assembling archived text</p> <p>if utilities.is_set ( ArchiveURL ) then</p> <p>if utilities.is_set (ChapterURL) then -- if chapter-url= is set apply archive url to it</p> <p>OriginalURL = ChapterURL; -- save copy of source chapter's url for archive text</p> <p>OriginalURL_origin = ChapterURL_origin; -- name of |chapter-url= parameter for error messages</p> <p>OriginalFormat = ChapterFormat; -- and original |chapter-format=</p> <p>if 'live' ~= UrlStatus then</p> <p>ChapterURL = ArchiveURL -- swap-in the archive's URL</p> <p>ChapterURL_origin = A:ORIGIN('ArchiveURL') -- name of |archive-url= parameter for error messages</p> <p>ChapterFormat = ArchiveFormat or ''; -- swap in archive's format</p> <p>ChapterUrlAccess = nil; -- restricted access levels do not make sense for archived URLs</p> <p>end</p> <p>elseif utilities.is_set (URL) then</p> <p>OriginalURL = URL; -- save copy of original source URL</p> <p>OriginalURL_origin = URL_origin; -- name of URL parameter for error messages</p> <p>OriginalFormat = Format; -- and original |format=</p> <p>OriginalAccess = UrlAccess;</p> <p>if 'live' ~= UrlStatus then -- if URL set then |archive-url= applies to it</p> <p>URL = ArchiveURL -- swap-in the archive's URL</p> <p>URL_origin = A:ORIGIN('ArchiveURL') -- name of archive URL parameter for error messages</p> <p>Format = ArchiveFormat or ''; -- swap in archive's format</p> <p>UrlAccess = nil; -- restricted access levels do not make sense for archived URLs</p> <p>end</p> <p>end</p> <p>elseif utilities.is_set (UrlStatus) then -- if |url-status= is set when |archive-url= is not set</p> <p>utilities.set_message ('maint_url_status'); -- add maint cat</p> <p>end</p> <p>if utilities.in_array (config.CitationClass, {'web', 'news', 'journal', 'magazine', 'pressrelease', 'podcast', 'newsgroup', 'arxiv', 'biorxiv', 'citeseerx', 'medrxiv', 'ssrn'}) or -- if any of the 'periodical' cites except encyclopedia</p> <p>('citation' == config.CitationClass and (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical)) and not utilities.is_set (Encyclopedia)) then</p> <p>local chap_param;</p> <p>if utilities.is_set (Chapter) then -- get a parameter name from one of these chapter related meta-parameters</p> <p>chap_param = A:ORIGIN ('Chapter')</p> <p>elseif utilities.is_set (TransChapter) then</p> <p>chap_param = A:ORIGIN ('TransChapter')</p> <p>elseif utilities.is_set (ChapterURL) then</p> <p>chap_param = A:ORIGIN ('ChapterURL')</p> <p>elseif utilities.is_set (ScriptChapter) then</p> <p>chap_param = ScriptChapter_origin;</p> <p>else utilities.is_set (ChapterFormat)</p> <p>chap_param = A:ORIGIN ('ChapterFormat')</p> <p>end</p> <p>if utilities.is_set (chap_param) then -- if we found one</p> <p>utilities.set_message ('err_chapter_ignored', {chap_param}); -- add error message</p> <p>Chapter = ''; -- and set them to empty string to be safe with concatenation</p> <p>TransChapter = '';</p> <p>ChapterURL = '';</p> <p>ScriptChapter = '';</p> <p>ChapterFormat = '';</p> <p>end</p> <p>else -- otherwise, format chapter / article title</p> <p>local no_quotes = false; -- default assume that we will be quoting the chapter parameter value</p> <p>if utilities.is_set (Contribution) and 0 < #c then -- if this is a contribution with contributor(s)</p> <p>if utilities.in_array (Contribution:lower(), cfg.keywords_lists.contribution) then -- and a generic contribution title</p> <p>no_quotes = true; -- then render it unquoted</p> <p>end</p> <p>end</p> <p>Chapter = format_chapter_title (ScriptChapter, ScriptChapter_origin, Chapter, Chapter_origin, TransChapter, TransChapter_origin, ChapterURL, ChapterURL_origin, no_quotes, ChapterUrlAccess); -- Contribution is also in Chapter</p> <p>if utilities.is_set (Chapter) then</p> <p>Chapter = Chapter .. ChapterFormat ;</p> <p>if 'map' == config.CitationClass and utilities.is_set (TitleType) then</p> <p>Chapter = Chapter .. ' ' .. TitleType; -- map annotation here; not after title</p> <p>end</p> <p>Chapter = Chapter .. sepc .. ' ';</p> <p>elseif utilities.is_set (ChapterFormat) then -- |chapter= not set but |chapter-format= is so ...</p> <p>Chapter = ChapterFormat .. sepc .. ' '; -- ... ChapterFormat has error message, we want to see it</p> <p>end</p> <p>end</p> <p>-- Format main title</p> <p>local plain_title = false;</p> <p>local accept_title;</p> <p>Title, accept_title = utilities.has_accept_as_written (Title, true); -- remove accept-this-as-written markup when it wraps all of <Title></p> <p>if accept_title and ('' == Title) then -- only support forced empty for now "(())"</p> <p>Title = cfg.messages['notitle']; -- replace by predefined "No title" message</p> <p>-- @todo: utilities.set_message ( 'err_redundant_parameters', ...); -- issue proper error message instead of muting</p> <p>ScriptTitle = ''; -- just mute for now</p> <p>TransTitle = ''; -- just mute for now</p> <p>plain_title = true; -- suppress text decoration for descriptive title</p> <p>utilities.set_message ('maint_untitled'); -- add maint cat</p> <p>end</p> <p>if not accept_title then -- <Title> not wrapped in accept-as-written markup</p> <p>if '...' == Title:sub (-3) then -- if ellipsis is the last three characters of |title=</p> <p>Title = Title:gsub ('(%.%.%.)%.+$', '%1'); -- limit the number of dots to three</p> <p>elseif not mw.ustring.find (Title, '%.%s*%a%.$') and -- end of title is not a 'dot-(optional space-)letter-dot' initialism ...</p> <p>not mw.ustring.find (Title, '%s+%a%.$') then -- ...and not a 'space-letter-dot' initial (<em>Allium canadense</em> L.)</p> <p>Title = mw.ustring.gsub(Title, '%' .. sepc .. '$', ''); -- remove any trailing separator character; sepc and ms.ustring() here for languages that use multibyte separator characters</p> <p>end</p> <p>if utilities.is_set (ArchiveURL) and is_archived_copy (Title) then</p> <p>utilities.set_message ('maint_archived_copy'); -- add maintenance category before we modify the content of Title</p> <p>end</p> <p>if is_generic ('generic_titles', Title) then</p> <p>utilities.set_message ('err_generic_title'); -- set an error message</p> <p>end</p> <p>end</p> <p>if (not plain_title) and (utilities.in_array (config.CitationClass, {'web', 'news', 'journal', 'magazine', 'document', 'pressrelease', 'podcast', 'newsgroup', 'mailinglist', 'interview', 'arxiv', 'biorxiv', 'citeseerx', 'medrxiv', 'ssrn'}) or</p> <p>('citation' == config.CitationClass and (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical)) and not utilities.is_set (Encyclopedia)) or</p> <p>('map' == config.CitationClass and (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical)))) then -- special case for cite map when the map is in a periodical treat as an article</p> <p>Title = kern_quotes (Title); -- if necessary, separate title's leading and trailing quote marks from module provided quote marks</p> <p>Title = utilities.wrap_style ('quoted-title', Title);</p> <p>Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped</p> <p>TransTitle = utilities.wrap_style ('trans-quoted-title', TransTitle );</p> <p>elseif plain_title or ('report' == config.CitationClass) then -- no styling for cite report and descriptive titles (otherwise same as above)</p> <p>Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped</p> <p>TransTitle = utilities.wrap_style ('trans-quoted-title', TransTitle ); -- for cite report, use this form for trans-title</p> <p>else</p> <p>Title = utilities.wrap_style ('italic-title', Title);</p> <p>Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped</p> <p>TransTitle = utilities.wrap_style ('trans-italic-title', TransTitle);</p> <p>end</p> <p>if utilities.is_set (TransTitle) then</p> <p>if utilities.is_set (Title) then</p> <p>TransTitle = " " .. TransTitle;</p> <p>else</p> <p>utilities.set_message ('err_trans_missing_title', {'title'});</p> <p>end</p> <p>end</p> <p>if utilities.is_set (Title) then -- @todo: is this the right place to be making Wikisource URLs?</p> <p>if utilities.is_set (TitleLink) and utilities.is_set (URL) then</p> <p>utilities.set_message ('err_wikilink_in_url'); -- set an error message because we can't have both</p> <p>TitleLink = ''; -- unset</p> <p>end</p> <p>if not utilities.is_set (TitleLink) and utilities.is_set (URL) then</p> <p>Title = external_link (URL, Title, URL_origin, UrlAccess) .. TransTitle .. Format;</p> <p>URL = ''; -- unset these because no longer needed</p> <p>Format = "";</p> <p>elseif utilities.is_set (TitleLink) and not utilities.is_set (URL) then</p> <p>local ws_url;</p> <p>ws_url = wikisource_url_make (TitleLink); -- ignore ws_label return; not used here</p> <p>if ws_url then</p> <p>Title = external_link (ws_url, Title .. ' ', 'ws link in title-link'); -- space char after Title to move icon away from italic text</p> <p>-- @todo: a better way to do this?</p> <p>Title = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], TitleLink, Title});</p> <p>Title = Title .. TransTitle;</p> <p>else</p> <p>Title = utilities.make_wikilink (TitleLink, Title) .. TransTitle;</p> <p>end</p> <p>else</p> <p>local ws_url, ws_label, L; -- Title has italic or quote markup by the time we get here which causes is_wikilink() to return 0 (not a wikilink)</p> <p>ws_url, ws_label, L = wikisource_url_make (Title:gsub('^[\'"]*(.-)[\'"]*$', '%1')); -- make ws URL from |title= interwiki link (strip italic or quote markup); link portion L becomes tooltip label</p> <p>if ws_url then</p> <p>Title = Title:gsub ('%b[]', ws_label); -- replace interwiki link with ws_label to retain markup</p> <p>Title = external_link (ws_url, Title .. ' ', 'ws link in title'); -- space char after Title to move icon away from italic text</p> <p>-- @todo: a better way to do this?</p> <p>Title = utilities.substitute (cfg.presentation['interwiki-icon'], {cfg.presentation['class-wikisource'], L, Title});</p> <p>Title = Title .. TransTitle;</p> <p>else</p> <p>Title = Title .. TransTitle;</p> <p>end</p> <p>end</p> <p>else</p> <p>Title = TransTitle;</p> <p>end</p> <p>if utilities.is_set (Place) then</p> <p>Place = " " .. wrap_msg ('written', Place, use_lowercase) .. sepc .. " ";</p> <p>end</p> <p>local ConferenceURL_origin = A:ORIGIN('ConferenceURL'); -- get name of parameter that holds ConferenceURL</p> <p>if utilities.is_set (Conference) then</p> <p>if utilities.is_set (ConferenceURL) then</p> <p>Conference = external_link( ConferenceURL, Conference, ConferenceURL_origin, nil );</p> <p>end</p> <p>Conference = sepc .. " " .. Conference .. ConferenceFormat;</p> <p>elseif utilities.is_set (ConferenceURL) then</p> <p>Conference = sepc .. " " .. external_link( ConferenceURL, nil, ConferenceURL_origin, nil );</p> <p>end</p> <p>local Position = '';</p> <p>if not utilities.is_set (Position) then</p> <p>local Minutes = A['Minutes'];</p> <p>local Time = A['Time'];</p> <p>if utilities.is_set (Minutes) then</p> <p>if utilities.is_set (Time) then --@todo: make a function for this and similar?</p> <p>utilities.set_message ('err_redundant_parameters', {utilities.wrap_style ('parameter', 'minutes') .. cfg.presentation['sep_list_pair'] .. utilities.wrap_style ('parameter', 'time')});</p> <p>end</p> <p>Position = " " .. Minutes .. " " .. cfg.messages['minutes'];</p> <p>else</p> <p>if utilities.is_set (Time) then</p> <p>local TimeCaption = A['TimeCaption']</p> <p>if not utilities.is_set (TimeCaption) then</p> <p>TimeCaption = cfg.messages['event'];</p> <p>if sepc ~= '.' then</p> <p>TimeCaption = TimeCaption:lower();</p> <p>end</p> <p>end</p> <p>Position = " " .. TimeCaption .. " " .. Time;</p> <p>end</p> <p>end</p> <p>else</p> <p>Position = " " .. Position;</p> <p>At = '';</p> <p>end</p> <p>Page, Pages, Sheet, Sheets = format_pages_sheets (Page, Pages, Sheet, Sheets, config.CitationClass, Periodical_origin, sepc, NoPP, use_lowercase);</p> <p>At = utilities.is_set (At) and (sepc .. " " .. At) or "";</p> <p>Position = utilities.is_set (Position) and (sepc .. " " .. Position) or "";</p> <p>if config.CitationClass == 'map' then</p> <p>local Sections = A['Sections']; -- Section (singular) is an alias of Chapter so set earlier</p> <p>local Inset = A['Inset'];</p> <p>if utilities.is_set ( Inset ) then</p> <p>Inset = sepc .. " " .. wrap_msg ('inset', Inset, use_lowercase);</p> <p>end</p> <p>if utilities.is_set ( Sections ) then</p> <p>Section = sepc .. " " .. wrap_msg ('sections', Sections, use_lowercase);</p> <p>elseif utilities.is_set ( Section ) then</p> <p>Section = sepc .. " " .. wrap_msg ('section', Section, use_lowercase);</p> <p>end</p> <p>At = At .. Inset .. Section;</p> <p>end</p> <p>local Others = A['Others'];</p> <p>if utilities.is_set (Others) and 0 == #a and 0 == #e then -- add maint cat when |others= has value and used without |author=, |editor=</p> <p>if config.CitationClass == "AV-media-notes"</p> <p>or config.CitationClass == "audio-visual" then -- special maint for AV/M which has a lot of 'false' positives right now</p> <p>utilities.set_message ('maint_others_avm')</p> <p>else</p> <p>utilities.set_message ('maint_others');</p> <p>end</p> <p>end</p> <p>Others = utilities.is_set (Others) and (sepc .. " " .. Others) or "";</p> <p>if utilities.is_set (Translators) then</p> <p>Others = safe_join ({sepc .. ' ', wrap_msg ('translated', Translators, use_lowercase), Others}, sepc);</p> <p>end</p> <p>if utilities.is_set (Interviewers) then</p> <p>Others = safe_join ({sepc .. ' ', wrap_msg ('interview', Interviewers, use_lowercase), Others}, sepc);</p> <p>end</p> <p>local TitleNote = A['TitleNote'];</p> <p>TitleNote = utilities.is_set (TitleNote) and (sepc .. " " .. TitleNote) or "";</p> <p>if utilities.is_set (Edition) then</p> <p>if Edition:match ('%f[%a][Ee]d%n?%.?$') or Edition:match ('%f[%a][Ee]dition$') then -- Ed, ed, Ed., ed., Edn, edn, Edn., edn.</p> <p>utilities.set_message ('err_extra_text_edition'); -- add error message</p> <p>end</p> <p>Edition = " " .. wrap_msg ('edition', Edition);</p> <p>else</p> <p>Edition = '';</p> <p>end</p> <p>Series = utilities.is_set (Series) and wrap_msg ('series', {sepc, Series}) or ""; -- not the same as SeriesNum</p> <p>local Agency = A['Agency'] or ''; -- |agency= is supported by {{tl|cite magazine}}, {{tl|cite news}}, {{tl|cite press release}}, {{tl|cite web}}, and certain {{tl|citation}} templates</p> <p>if utilities.is_set (Agency) then -- this testing done here because {{tl|citation}} supports 'news' citations</p> <p>if utilities.in_array (config.CitationClass, {'magazine', 'news', 'pressrelease', 'web'}) or ('citation' == config.CitationClass and utilities.in_array (Periodical_origin, {"magazine", "newspaper", "work"})) then</p> <p>Agency = wrap_msg ('agency', {sepc, Agency}); -- format for rendering</p> <p>else</p> <p>Agency = ''; -- unset; not supported</p> <p>utilities.set_message ('err_parameter_ignored', {'agency'}); -- add error message</p> <p>end</p> <p>end</p> <p>Volume = format_volume_issue (Volume, Issue, ArticleNumber, config.CitationClass, Periodical_origin, sepc, use_lowercase);</p> <p>if utilities.is_set (AccessDate) then</p> <p>local retrv_text = " " .. cfg.messages['retrieved']</p> <p>AccessDate = nowrap_date (AccessDate); -- wrap in nowrap span if date in appropriate format</p> <p>if (sepc ~= ".") then retrv_text = retrv_text:lower() end -- if mode is cs2, lower case</p> <p>AccessDate = utilities.substitute (retrv_text, AccessDate); -- add retrieved text</p> <p>AccessDate = utilities.substitute (cfg.presentation['accessdate'], {sepc, AccessDate}); -- allow editors to hide accessdates</p> <p>end</p> <p>if utilities.is_set (ID) then ID = sepc .. " " .. ID; end</p> <p>local Docket = A['Docket'];</p> <p>if "thesis" == config.CitationClass and utilities.is_set (Docket) then</p> <p>ID = sepc .. " Docket " .. Docket .. ID;</p> <p>end</p> <p>if "report" == config.CitationClass and utilities.is_set (Docket) then -- for cite report when |docket= is set</p> <p>ID = sepc .. ' ' .. Docket; -- overwrite ID even if |id= is set</p> <p>end</p> <p>if utilities.is_set (URL) then</p> <p>URL = " " .. external_link( URL, nil, URL_origin, UrlAccess );</p> <p>end</p> <p>--[[</p> <p>local Quote = A['Quote'];</p> <p>local TransQuote = A['TransQuote'];</p> <p>local ScriptQuote = A['ScriptQuote'];</p> <p>if utilities.is_set (Quote) or utilities.is_set (TransQuote) or utilities.is_set (ScriptQuote) then</p> <p>if utilities.is_set (Quote) then</p> <p>if Quote:sub(1, 1) == '"' and Quote:sub(-1, -1) == '"' then -- if first and last characters of quote are quote marks</p> <p>Quote = Quote:sub(2, -2); -- strip them off</p> <p>end</p> <p>end</p> <p>Quote = kern_quotes (Quote); -- kern if needed</p> <p>Quote = utilities.wrap_style ('quoted-text', Quote ); -- wrap in <q>...</q> tags</p> <p>if utilities.is_set (ScriptQuote) then</p> <p>Quote = script_concatenate (Quote, ScriptQuote, 'script-quote'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after quote is wrapped</p> <p>end</p> <p>if utilities.is_set (TransQuote) then</p> <p>if TransQuote:sub(1, 1) == '"' and TransQuote:sub(-1, -1) == '"' then -- if first and last characters of |trans-quote are quote marks</p> <p>TransQuote = TransQuote:sub(2, -2); -- strip them off</p> <p>end</p> <p>Quote = Quote .. " " .. utilities.wrap_style ('trans-quoted-title', TransQuote );</p> <p>end</p> <p>if utilities.is_set (QuotePage) or utilities.is_set (QuotePages) then -- add page prefix</p> <p>local quote_prefix = '';</p> <p>if utilities.is_set (QuotePage) then</p> <p>extra_text_in_page_check (QuotePage, 'quote-page'); -- add to maint cat if |quote-page= value begins with what looks like p., pp., etc.</p> <p>if not NoPP then</p> <p>quote_prefix = utilities.substitute (cfg.messages['p-prefix'], {sepc, QuotePage}), <em>, </em>, '';</p> <p>else</p> <p>quote_prefix = utilities.substitute (cfg.messages['nopp'], {sepc, QuotePage}), <em>, </em>, '';</p> <p>end</p> <p>elseif utilities.is_set (QuotePages) then</p> <p>extra_text_in_page_check (QuotePages, 'quote-pages'); -- add to maint cat if |quote-pages= value begins with what looks like p., pp., etc.</p> <p>if tonumber(QuotePages) ~= nil and not NoPP then -- if only digits, assume single page</p> <p>quote_prefix = utilities.substitute (cfg.messages['p-prefix'], {sepc, QuotePages}), <em>, </em>;</p> <p>elseif not NoPP then</p> <p>quote_prefix = utilities.substitute (cfg.messages['pp-prefix'], {sepc, QuotePages}), <em>, </em>;</p> <p>else</p> <p>quote_prefix = utilities.substitute (cfg.messages['nopp'], {sepc, QuotePages}), <em>, </em>;</p> <p>end</p> <p>end</p> <p>Quote = quote_prefix .. ": " .. Quote;</p> <p>else</p> <p>Quote = sepc .. " " .. Quote;</p> <p>end</p> <p>PostScript = ""; -- cs1|2 does not supply terminal punctuation when |quote= is set</p> <p>end</p> <p>]]</p> <p>-- We check length of PostScript here because it will have been nuked by</p> <p>-- the quote parameters. We'd otherwise emit a message even if there wasn't</p> <p>-- a displayed postscript.</p> <p>-- @todo: Should the max size (1) be configurable?</p> <p>-- @todo: Should we check a specific pattern?</p> <p>if utilities.is_set(PostScript) and mw.ustring.len(PostScript) > 1 then</p> <p>utilities.set_message ('maint_postscript')</p> <p>end</p> <p>local Archived;</p> <p>if utilities.is_set (ArchiveURL) then</p> <p>if not utilities.is_set (ArchiveDate) then -- ArchiveURL set but ArchiveDate not set</p> <p>utilities.set_message ('err_archive_missing_date'); -- emit an error message</p> <p>ArchiveURL = ''; -- empty string for concatenation</p> <p>ArchiveDate = ''; -- empty string for concatenation</p> <p>end</p> <p>else</p> <p>if utilities.is_set (ArchiveDate) then -- ArchiveURL not set but ArchiveDate is set</p> <p>utilities.set_message ('err_archive_date_missing_url'); -- emit an error message</p> <p>ArchiveURL = ''; -- empty string for concatenation</p> <p>ArchiveDate = ''; -- empty string for concatenation</p> <p>end</p> <p>end</p> <p>if utilities.is_set (ArchiveURL) then</p> <p>local arch_text;</p> <p>if "live" == UrlStatus then</p> <p>arch_text = cfg.messages['archived'];</p> <p>if sepc ~= "." then arch_text = arch_text:lower() end</p> <p>if utilities.is_set (ArchiveDate) then</p> <p>Archived = sepc .. ' ' .. utilities.substitute ( cfg.messages['archived-live'],</p> <p>{external_link( ArchiveURL, arch_text, A:ORIGIN('ArchiveURL'), nil) .. ArchiveFormat, ArchiveDate } );</p> <p>else</p> <p>Archived = '';</p> <p>end</p> <p>if not utilities.is_set (OriginalURL) then</p> <p>utilities.set_message ('err_archive_missing_url');</p> <p>Archived = ''; -- empty string for concatenation</p> <p>end</p> <p>elseif utilities.is_set (OriginalURL) then -- UrlStatus is empty, 'dead', 'unfit', 'usurped', 'bot: unknown'</p> <p>if utilities.in_array (UrlStatus, {'unfit', 'usurped', 'bot: unknown'}) then</p> <p>arch_text = cfg.messages['archived-unfit'];</p> <p>if sepc ~= "." then arch_text = arch_text:lower() end</p> <p>Archived = sepc .. ' ' .. arch_text .. ArchiveDate; -- format already styled</p> <p>if 'bot: unknown' == UrlStatus then</p> <p>utilities.set_message ('maint_bot_unknown'); -- and add a category if not already added</p> <p>else</p> <p>-- utilities.set_message ('maint_unfit'); -- and add a category if not already added</p> <p>utilities.add_prop_cat ('unfit'); -- and add a category if not already added</p> <p>end</p> <p>else -- UrlStatus is empty, 'dead'</p> <p>arch_text = cfg.messages['archived-dead'];</p> <p>if sepc ~= "." then arch_text = arch_text:lower() end</p> <p>if utilities.is_set (ArchiveDate) then</p> <p>Archived = sepc .. " " .. utilities.substitute ( arch_text,</p> <p>{ external_link( OriginalURL, cfg.messages['original'], OriginalURL_origin, OriginalAccess ) .. OriginalFormat, ArchiveDate } ); -- format already styled</p> <p>else</p> <p>Archived = ''; -- unset for concatenation</p> <p>end</p> <p>end</p> <p>else -- OriginalUrl not set</p> <p>utilities.set_message ('err_archive_missing_url');</p> <p>Archived = ''; -- empty string for concatenation</p> <p>end</p> <p>elseif utilities.is_set (ArchiveFormat) then</p> <p>Archived = ArchiveFormat; -- if set and ArchiveURL not set ArchiveFormat has error message</p> <p>else</p> <p>Archived = '';</p> <p>end</p> <p>local TranscriptURL = A['TranscriptURL']</p> <p>local TranscriptFormat = A['TranscriptFormat'];</p> <p>TranscriptFormat = style_format (TranscriptFormat, TranscriptURL, 'transcript-format', 'transcripturl');</p> <p>local Transcript = A['Transcript'];</p> <p>local TranscriptURL_origin = A:ORIGIN('TranscriptURL'); -- get name of parameter that holds TranscriptURL</p> <p>if utilities.is_set (Transcript) then</p> <p>if utilities.is_set (TranscriptURL) then</p> <p>Transcript = external_link( TranscriptURL, Transcript, TranscriptURL_origin, nil );</p> <p>end</p> <p>Transcript = sepc .. ' ' .. Transcript .. TranscriptFormat;</p> <p>elseif utilities.is_set (TranscriptURL) then</p> <p>Transcript = external_link( TranscriptURL, nil, TranscriptURL_origin, nil );</p> <p>end</p> <p>local Publisher;</p> <p>if utilities.is_set (PublicationDate) then</p> <p>PublicationDate = wrap_msg ('published', PublicationDate);</p> <p>end</p> <p>if utilities.is_set (PublisherName) then</p> <p>if utilities.is_set (PublicationPlace) then</p> <p>Publisher = sepc .. " " .. PublicationPlace .. ": " .. PublisherName .. PublicationDate;</p> <p>else</p> <p>Publisher = sepc .. " " .. PublisherName .. PublicationDate;</p> <p>end</p> <p>elseif utilities.is_set (PublicationPlace) then</p> <p>Publisher= sepc .. " " .. PublicationPlace .. PublicationDate;</p> <p>else</p> <p>Publisher = PublicationDate;</p> <p>end</p> <p>-- Several of the above rely upon detecting this as nil, so do it last.</p> <p>if (utilities.is_set (Periodical) or utilities.is_set (ScriptPeriodical) or utilities.is_set (TransPeriodical)) then</p> <p>if utilities.is_set (Title) or utilities.is_set (TitleNote) then</p> <p>Periodical = sepc .. " " .. format_periodical (ScriptPeriodical, ScriptPeriodical_origin, Periodical, TransPeriodical, TransPeriodical_origin);</p> <p>else</p> <p>Periodical = format_periodical (ScriptPeriodical, ScriptPeriodical_origin, Periodical, TransPeriodical, TransPeriodical_origin);</p> <p>end</p> <p>end</p> <p>local Language = A['Language'];</p> <p>if utilities.is_set (Language) then</p> <p>Language = language_parameter (Language); -- format, categories, name from ISO639-1, etc.</p> <p>else</p> <p>Language=''; -- language not specified so make sure this is an empty string;</p> <p>--[[ @todo: need to extract the wrap_msg from language_parameter</p> <p>so that we can solve parentheses bunching problem with Format/Language/TitleType</p> <p>]]</p> <p>end</p> <p>--[[</p> <p>Handle the oddity that is cite speech. This code overrides whatever may be the value assigned to TitleNote (through |department=) and forces it to be " (Speech)" so that</p> <p>the annotation directly follows the |title= parameter value in the citation rather than the |event= parameter value (if provided).</p> <p>]]</p> <p>if "speech" == config.CitationClass then -- cite speech only</p> <p>TitleNote = TitleType; -- move TitleType to TitleNote so that it renders ahead of |event=</p> <p>TitleType = ''; -- and unset</p> <p>if utilities.is_set (Periodical) then -- if Periodical, perhaps because of an included |website= or |journal= parameter</p> <p>if utilities.is_set (Conference) then -- and if |event= is set</p> <p>Conference = Conference .. sepc .. " "; -- then add appropriate punctuation to the end of the Conference variable before rendering</p> <p>end</p> <p>end</p> <p>end</p> <p>-- Piece all bits together at last. Here, all should be non-nil.</p> <p>-- We build things this way because it is more efficient in LUA</p> <p>-- not to keep reassigning to the same string variable over and over.</p> <p>local tcommon;</p> <p>local tcommon2; -- used for book cite when |contributor= is set</p> <p>if utilities.in_array (config.CitationClass, {"book", "citation"}) and not utilities.is_set (Periodical) then -- special cases for book cites</p> <p>if utilities.is_set (Contributors) then -- when we are citing foreword, preface, introduction, etc.</p> <p>tcommon = safe_join ({Title, TitleNote}, sepc); -- author and other stuff will come after this and before tcommon2</p> <p>tcommon2 = safe_join ({TitleType, Series, Language, Volume, Others, Edition, Publisher}, sepc);</p> <p>else</p> <p>tcommon = safe_join ({Title, TitleNote, TitleType, Series, Language, Volume, Others, Edition, Publisher}, sepc);</p> <p>end</p> <p>elseif 'map' == config.CitationClass then -- special cases for cite map</p> <p>if utilities.is_set (Chapter) then -- map in a book; TitleType is part of Chapter</p> <p>tcommon = safe_join ({Title, Edition, Scale, Series, Language, Cartography, Others, Publisher, Volume}, sepc);</p> <p>elseif utilities.is_set (Periodical) then -- map in a periodical</p> <p>tcommon = safe_join ({Title, TitleType, Periodical, Scale, Series, Language, Cartography, Others, Publisher, Volume}, sepc);</p> <p>else -- a sheet or stand-alone map</p> <p>tcommon = safe_join ({Title, TitleType, Edition, Scale, Series, Language, Cartography, Others, Publisher}, sepc);</p> <p>end</p> <p>elseif 'episode' == config.CitationClass then -- special case for cite episode</p> <p>tcommon = safe_join ({Title, TitleNote, TitleType, Series, Language, Edition, Publisher}, sepc);</p> <p>else -- all other CS1 templates</p> <p>tcommon = safe_join ({Title, TitleNote, Conference, Periodical, TitleType, Series, Language, Volume, Others, Edition, Publisher, Agency}, sepc);</p> <p>end</p> <p>if #ID_list > 0 then</p> <p>ID_list = safe_join( { sepc .. " ", table.concat( ID_list, sepc .. " " ), ID }, sepc );</p> <p>else</p> <p>ID_list = ID;</p> <p>end</p> <p>local Via = A['Via'];</p> <p>Via = utilities.is_set (Via) and wrap_msg ('via', Via) or '';</p> <p>local idcommon;</p> <p>if 'audio-visual' == config.CitationClass or 'episode' == config.CitationClass then -- special case for cite AV media & cite episode position transcript</p> <p>idcommon = safe_join( { ID_list, URL, Archived, Transcript, AccessDate, Via, Quote }, sepc );</p> <p>else</p> <p>idcommon = safe_join( { ID_list, URL, Archived, AccessDate, Via, Quote }, sepc );</p> <p>end</p> <p>local text;</p> <p>local pgtext = Position .. Sheet .. Sheets .. Page .. Pages .. At;</p> <p>local OrigDate = A['OrigDate'];</p> <p>OrigDate = utilities.is_set (OrigDate) and wrap_msg ('origdate', OrigDate) or '';</p> <p>if utilities.is_set (Date) then</p> <p>if utilities.is_set (Authors) or utilities.is_set (Editors) then -- date follows authors or editors when authors not set</p> <p>Date = " (" .. Date .. ")" .. OrigDate .. sepc .. " "; -- in parentheses</p> <p>else -- neither of authors and editors set</p> <p>if (string.sub(tcommon, -1, -1) == sepc) then -- if the last character of tcommon is sepc</p> <p>Date = " " .. Date .. OrigDate; -- Date does not begin with sepc</p> <p>else</p> <p>Date = sepc .. " " .. Date .. OrigDate; -- Date begins with sepc</p> <p>end</p> <p>end</p> <p>end</p> <p>if utilities.is_set (Authors) then</p> <p>if (not utilities.is_set (Date)) then -- when date is set it's in parentheses; no Authors termination</p> <p>Authors = terminate_name_list (Authors, sepc); -- when no date, terminate with 0 or 1 sepc and a space</p> <p>end</p> <p>if utilities.is_set (Editors) then</p> <p>local in_text = '';</p> <p>local post_text = '';</p> <p>if utilities.is_set (Chapter) and 0 == #c then</p> <p>in_text = cfg.messages['in'] .. ' ';</p> <p>if (sepc ~= '.') then</p> <p>in_text = in_text:lower(); -- lowercase for cs2</p> <p>end</p> <p>end</p> <p>if EditorCount <= 1 then</p> <p>post_text = ' (' .. cfg.messages['editor'] .. ')'; -- be consistent with no-author, no-date case</p> <p>else</p> <p>post_text = ' (' .. cfg.messages['editors'] .. ')';</p> <p>end</p> <p>Editors = terminate_name_list (in_text .. Editors .. post_text, sepc); -- terminate with 0 or 1 sepc and a space</p> <p>end</p> <p>if utilities.is_set (Contributors) then -- book cite and we're citing the intro, preface, etc.</p> <p>local by_text = sepc .. ' ' .. cfg.messages['by'] .. ' ';</p> <p>if (sepc ~= '.') then by_text = by_text:lower() end -- lowercase for cs2</p> <p>Authors = by_text .. Authors; -- author follows title so tweak it here</p> <p>if utilities.is_set (Editors) and utilities.is_set (Date) then -- when Editors make sure that Authors gets terminated</p> <p>Authors = terminate_name_list (Authors, sepc); -- terminate with 0 or 1 sepc and a space</p> <p>end</p> <p>if (not utilities.is_set (Date)) then -- when date is set it's in parentheses; no Contributors termination</p> <p>Contributors = terminate_name_list (Contributors, sepc); -- terminate with 0 or 1 sepc and a space</p> <p>end</p> <p>text = safe_join( {Contributors, Date, Chapter, tcommon, Authors, Place, Editors, tcommon2, pgtext, idcommon }, sepc );</p> <p>else</p> <p>text = safe_join( {Authors, Date, Chapter, Place, Editors, tcommon, pgtext, idcommon }, sepc );</p> <p>end</p> <p>elseif utilities.is_set (Editors) then</p> <p>if utilities.is_set (Date) then</p> <p>if EditorCount <= 1 then</p> <p>Editors = Editors .. cfg.presentation['sep_name'] .. cfg.messages['editor'];</p> <p>else</p> <p>Editors = Editors .. cfg.presentation['sep_name'] .. cfg.messages['editors'];</p> <p>end</p> <p>else</p> <p>if EditorCount <= 1 then</p> <p>Editors = Editors .. " (" .. cfg.messages['editor'] .. ")" .. sepc .. " "</p> <p>else</p> <p>Editors = Editors .. " (" .. cfg.messages['editors'] .. ")" .. sepc .. " "</p> <p>end</p> <p>end</p> <p>text = safe_join( {Editors, Date, Chapter, Place, tcommon, pgtext, idcommon}, sepc );</p> <p>else</p> <p>if utilities.in_array (config.CitationClass, {"journal", "citation"}) and utilities.is_set (Periodical) then</p> <p>text = safe_join( {Chapter, Place, tcommon, pgtext, Date, idcommon}, sepc );</p> <p>else</p> <p>text = safe_join( {Chapter, Place, tcommon, Date, pgtext, idcommon}, sepc );</p> <p>end</p> <p>end</p> <p>if utilities.is_set (PostScript) and PostScript ~= sepc then</p> <p>text = safe_join( {text, sepc}, sepc ); -- Deals with italics, spaces, etc.</p> <p>if '.' == sepc then -- remove final seperator if present</p> <p>text = text:gsub ('%' .. sepc .. '$', ''); -- dot must be escaped here</p> <p>else</p> <p>text = mw.ustring.gsub (text, sepc .. '$', ''); -- using ustring for non-dot sepc (likely a non-Latin character)</p> <p>end</p> <p>end</p> <p>text = safe_join( {text, PostScript}, sepc );</p> <p>-- Now enclose the whole thing in a <cite> element</p> <p>local options_t = {};</p> <p>options_t.class = cite_class_attribute_make (config.CitationClass, Mode);</p> <p>local Ref = is_valid_parameter_value (A['Ref'], A:ORIGIN('Ref'), cfg.keywords_lists['ref'], nil, true); -- nil when |ref=harv; A['Ref'] else</p> <p>if 'none' ~= cfg.keywords_xlate[(Ref and Ref:lower()) or ''] then</p> <p>local namelist_t = {}; -- holds selected contributor, author, editor name list</p> <p>local year = first_set ({Year, anchor_year}, 2); -- Year first for legacy citations and for YMD dates that require disambiguation</p> <p>if #c > 0 then -- if there is a contributor list</p> <p>namelist_t = c; -- select it</p> <p>elseif #a > 0 then -- or an author list</p> <p>namelist_t = a;</p> <p>elseif #e > 0 then -- or an editor list</p> <p>namelist_t = e;</p> <p>end</p> <p>local citeref_id;</p> <p>if #namelist_t > 0 then -- if there are names in namelist_t</p> <p>citeref_id = make_citeref_id (namelist_t, year); -- go make the CITEREF anchor</p> <p>if mw.uri.anchorEncode (citeref_id) == ((Ref and mw.uri.anchorEncode (Ref)) or '') then -- Ref may already be encoded (by {{sfnref}}) so citeref_id must be encoded before comparison</p> <p>utilities.set_message ('maint_ref_duplicates_default');</p> <p>end</p> <p>else</p> <p>citeref_id = ''; -- unset</p> <p>end</p> <p>options_t.id = Ref or citeref_id;</p> <p>end</p> <p>if string.len (text:gsub('%b<>', '')) <= 2 then -- remove html and html-like tags; then get length of what remains;</p> <p>z.error_cats_t = {}; -- blank the categories list</p> <p>z.error_msgs_t = {}; -- blank the error messages list</p> <p>OCinSoutput = nil; -- blank the metadata string</p> <p>text = ''; -- blank the the citation</p> <p>utilities.set_message ('err_empty_citation'); -- set empty citation message and category</p> <p>end</p> <p>local render_t = {}; -- here we collect the final bits for concatenation into the rendered citation</p> <p>if utilities.is_set (options_t.id) then -- here we wrap the rendered citation in <cite ...>...</cite> tags</p> <p>table.insert (render_t, utilities.substitute (cfg.presentation['cite-id'], {mw.uri.anchorEncode(options_t.id), mw.text.nowiki(options_t.class), text})); -- when |ref= is set or when there is a namelist</p> <p>else</p> <p>table.insert (render_t, utilities.substitute (cfg.presentation['cite'], {mw.text.nowiki(options_t.class), text})); -- when |ref=none or when namelist_t empty and |ref= is missing or is empty</p> <p>end</p> <p>if OCinSoutput then -- blanked when citation is 'empty' so don't bother to add boilerplate metadata span</p> <p>table.insert (render_t, utilities.substitute (cfg.presentation['ocins'], OCinSoutput)); -- format and append metadata to the citation</p> <p>end</p> <p>local template_name = ('citation' == config.CitationClass) and 'citation' or 'cite ' .. (cfg.citation_class_map_t[config.CitationClass] or config.CitationClass);</p> <p>local template_link = '<a href='?title=Template%3A%27_.._template_name_.._%27'>' .. template_name .. '</a>';</p> <p>local msg_prefix = '<code class="cs1-code">{{' .. template_link .. '}}</code>: ';</p> <p>if 0 ~= #z.error_msgs_t then</p> <p>mw.addWarning (utilities.substitute (cfg.messages.warning_msg_e, template_link));</p> <p>table.insert (render_t, ' '); -- insert a space between citation and its error messages</p> <p>table.sort (z.error_msgs_t); -- sort the error messages list; sorting includes wrapping <span> and <code> tags; hidden-error sorts ahead of visible-error</p> <p>local hidden = true; -- presume that the only error messages emited by this template are hidden</p> <p>for _, v in ipairs (z.error_msgs_t) do -- spin through the list of error messages</p> <p>if v:find ('cs1-visible-error', 1, true) then -- look for the visible error class name</p> <p>hidden = false; -- found one; so don't hide the error message prefix</p> <p>break; -- and done because no need to look further</p> <p>end</p> <p>end</p> <p>z.error_msgs_t[1] = table.concat ({utilities.error_comment (msg_prefix, hidden), z.error_msgs_t[1]}); -- add error message prefix to first error message to prevent extraneous punctuation</p> <p>table.insert (render_t, table.concat (z.error_msgs_t, '; ')); -- make a big string of error messages and add it to the rendering</p> <p>end</p> <p>if 0 ~= #z.maint_cats_t then</p> <p>mw.addWarning (utilities.substitute (cfg.messages.warning_msg_m, template_link));</p> <p>table.sort (z.maint_cats_t); -- sort the maintenance messages list</p> <p>local maint_msgs_t = {}; -- here we collect all of the maint messages</p> <p>if 0 == #z.error_msgs_t then -- if no error messages</p> <p>table.insert (maint_msgs_t, msg_prefix); -- insert message prefix in maint message livery</p> <p>end</p> <p>for _, v in ipairs( z.maint_cats_t ) do -- append maintenance categories</p> <p>table.insert (maint_msgs_t, -- assemble new maint message and add it to the maint_msgs_t table</p> <p>table.concat ({v, ' (', utilities.substitute (cfg.messages[':cat wikilink'], v), ')'})</p> <p>);</p> <p>end</p> <p>table.insert (render_t, utilities.substitute (cfg.presentation['hidden-maint'], table.concat (maint_msgs_t, ' '))); -- wrap the group of maint messages with proper presentation and save</p> <p>end</p> <p>if not no_tracking_cats then</p> <p>local sort_key;</p> <p>local cat_wikilink = 'cat wikilink';</p> <p>if cfg.enable_sort_keys then -- when namespace sort keys enabled</p> <p>local namespace_number = mw.title.getCurrentTitle().namespace; -- get namespace number for this wikitext</p> <p>sort_key = (0 ~= namespace_number and (cfg.name_space_sort_keys[namespace_number] or cfg.name_space_sort_keys.other)) or nil; -- get sort key character; nil for mainspace</p> <p>cat_wikilink = (not sort_key and 'cat wikilink') or 'cat wikilink sk'; -- make <cfg.messages> key</p> <p>end</p> <p>for _, v in ipairs (z.error_cats_t) do -- append error categories</p> <p>table.insert (render_t, utilities.substitute (cfg.messages[cat_wikilink], {v, sort_key}));</p> <p>end</p> <p>if cfg.id_limits_data_load_fail then -- boolean true when load failed</p> <p>utilities.set_message ('maint_id_limit_load_fail'); -- done here because this maint cat emits no message</p> <p>end</p> <p>for _, v in ipairs (z.maint_cats_t) do -- append maintenance categories</p> <p>table.insert (render_t, utilities.substitute (cfg.messages[cat_wikilink], {v, sort_key}));</p> <p>end</p> <p>for _, v in ipairs (z.prop_cats_t) do -- append properties categories</p> <p>table.insert (render_t, utilities.substitute (cfg.messages['cat wikilink'], v)); -- no sort keys</p> <p>end</p> <p>end</p> <p>return table.concat (render_t); -- make a big string and done</p> <p>end</p> <p>--- Looks for a parameter's name in one of several whitelists.</p> <p>--</p> <p>-- Parameters in the whitelist can have three values:</p> <p>-- true - active, supported parameters</p> <p>-- false - deprecated, supported parameters</p> <p>-- nil - unsupported parameters</p> <p>--</p> <p>-- @param name name of parameter</p> <p>-- @param {table} cite_class type of citation</p> <p>-- @param {boolean} empty whether a parameter is empty and deprecated</p> <p>-- @return Whether the parameter is empty</p> <p>local function validate (name, cite_class, empty)</p> <p>local name = tostring (name);</p> <p>local enum_name; -- parameter name with enumerator (if any) replaced with '#'</p> <p>local state;</p> <p>local function state_test (state, name) -- local function to do testing of state values</p> <p>if true == state then return true; end -- valid actively supported parameter</p> <p>if false == state then</p> <p>if empty then return nil; end -- empty deprecated parameters are treated as unknowns</p> <p>deprecated_parameter (name); -- parameter is deprecated but still supported</p> <p>return true;</p> <p>end</p> <p>if 'tracked' == state then</p> <p>local base_name = name:gsub ('%d', ''); -- strip enumerators from parameter names that have them to get the base name</p> <p>utilities.add_prop_cat ('tracked-param', {base_name}, base_name); -- add a properties category; <base_name> modifies <key></p> <p>return true;</p> <p>end</p> <p>return nil;</p> <p>end</p> <p>if name:find ('#') then -- # is a cs1|2 reserved character so parameters with # not permitted</p> <p>return nil;</p> <p>end</p> <p>-- replace enumerator digit(s) with # (|last25= becomes |last#=) (mw.ustring because non-Western 'local' digits)</p> <p>enum_name = mw.ustring.gsub (name, '%d+$', '#'); -- where enumerator is last charaters in parameter name (these to protect |s2cid=)</p> <p>enum_name = mw.ustring.gsub (enum_name, '%d+([%-l])', '#%1'); -- where enumerator is in the middle of the parameter name; |author#link= is the oddity</p> <p>if 'document' == cite_class then -- special case for {{tl|cite document}}</p> <p>state = whitelist.document_parameters_t[enum_name]; -- this list holds enumerated and nonenumerated parameters</p> <p>if true == state_test (state, name) then return true; end</p> <p>return false;</p> <p>end</p> <p>if utilities.in_array (cite_class, whitelist.preprint_template_list_t) then -- limited parameter sets allowed for these templates</p> <p>state = whitelist.limited_parameters_t[enum_name]; -- this list holds enumerated and nonenumerated parameters</p> <p>if true == state_test (state, name) then return true; end</p> <p>state = whitelist.preprint_arguments_t[cite_class][name]; -- look in the parameter-list for the template identified by cite_class</p> <p>if true == state_test (state, name) then return true; end</p> <p>return false; -- not supported because not found or name is set to nil</p> <p>end -- end limited parameter-set templates</p> <p>if utilities.in_array (cite_class, whitelist.unique_param_template_list_t) then -- template-specific parameters for templates that accept parameters from the basic argument list</p> <p>state = whitelist.unique_arguments_t[cite_class][name]; -- look in the template-specific parameter-lists for the template identified by cite_class</p> <p>if true == state_test (state, name) then return true; end</p> <p>end -- if here, fall into general validation</p> <p>state = whitelist.common_parameters_t[enum_name]; -- all other templates; all normal parameters allowed; this list holds enumerated and nonenumerated parameters</p> <p>if true == state_test (state, name) then return true; end</p> <p>return false; -- not supported because not found or name is set to nil</p> <p>end</p> <p>--- check <value> for inter-language interwiki-link markup. <prefix> must be a MediaWiki-recognized language</p> <p>-- code. when these values have the form (without leading colon):</p> <p>-- <a href='?title=%3Cprefix%3E%3Alink'>label</a> return label as plain-text</p> <p>-- <a href='?title=%3Cprefix%3E%3Alink'><prefix>:link</a> return <prefix>:link as plain-text</p> <p>-- @param parameter prameter</p> <p>-- @param {string} value value as is</p> <p>--</p> <p>-- @return interwiki label</p> <p>local function inter_wiki_check (parameter, value)</p> <p>local prefix = value:match ('%[%[(%a+):'); -- get an interwiki prefix if one exists</p> <p>local _;</p> <p>if prefix and cfg.inter_wiki_map[prefix:lower()] then -- if prefix is in the map, needs preceding colon so</p> <p>utilities.set_message ('err_bad_paramlink', parameter); -- emit an error message</p> <p>_, value, _ = utilities.is_wikilink (value); -- extract label portion from wikilink</p> <p>end</p> <p>return value;</p> <p>end</p> <p>--- Look at the contents of a parameter. If the content has a string of characters and digits followed by an equal</p> <p>-- sign, compare the alphanumeric string to the list of cs1|2 parameters. If found, then the string is possibly a</p> <p>-- parameter that is missing its pipe. There are two tests made:</p> <p>-- {{tl|cite ... |title=Title access-date=2016-03-17}} -- the first parameter has a value and whitespace separates that value from the missing pipe parameter name</p> <p>-- {{tl|cite ... |title=access-date=2016-03-17}} -- the first parameter has no value (whitespace after the first = is trimmed by MediaWiki)</p> <p>-- cs1|2 shares some parameter names with XML/HTML attributes: class=, title=, etc. To prevent false positives XML/HTML</p> <p>-- tags are removed before the search.</p> <p>--</p> <p>-- If a missing pipe is detected, this function adds the missing pipe maintenance category.</p> <p>--</p> <p>-- @param parameter Parameter</p> <p>-- @param {string} value Value of parameter</p> <p>local function missing_pipe_check (parameter, value)</p> <p>local capture;</p> <p>value = value:gsub ('%b<>', ''); -- remove XML/HTML tags because attributes: class=, title=, etc.</p> <p>capture = value:match ('%s+(%a[%w%-]+)%s*=') or value:match ('^(%a[%w%-]+)%s*='); -- find and categorize parameters with possible missing pipes</p> <p>if capture and validate (capture) then -- if the capture is a valid parameter name</p> <p>utilities.set_message ('err_missing_pipe', parameter);</p> <p>end</p> <p>end</p> <p>--- look for extraneous terminal punctuation in most parameter values; parameters listed in skip table are not checked</p> <p>--</p> <p>-- @param param Parameter</p> <p>-- @param {string} value Value of parameter</p> <p>local function has_extraneous_punc (param, value)</p> <p>if 'number' == type (param) then</p> <p>return;</p> <p>end</p> <p>param = param:gsub ('%d+', '#'); -- enumerated name-list mask params allow terminal punct; normalize</p> <p>if cfg.punct_skip[param] then</p> <p>return; -- parameter name found in the skip table so done</p> <p>end</p> <p>if value:match ('[,;:]$') then</p> <p>utilities.set_message ('maint_extra_punct'); -- has extraneous punctuation; add maint cat</p> <p>end</p> <p>if value:match ('^=') then -- sometimes an extraneous '=' character appears ...</p> <p>utilities.set_message ('maint_extra_punct'); -- has extraneous punctuation; add maint cat</p> <p>end</p> <p>end</p> <p>--- look for The Wikipedia Library urls in url-holding parameters. TWL urls are accessible for readers who are not</p> <p>-- active extended confirmed Wikipedia editors. This function emits an error message when such urls are discovered.</p> <p>--</p> <p>-- looks for: '.wikipedialibrary.idm.oclc.org'</p> <p>-- @param {table} url_params_t table of URL params</p> <p>local function has_twl_url (url_params_t)</p> <p>local url_error_t = {}; -- sequence of url-holding parameters that have a TWL url</p> <p>for param, value in pairs (url_params_t) do</p> <p>if value:find ('%.wikipedialibrary%.idm%.oclc%.org') then -- has the TWL base url?</p> <p>table.insert (url_error_t, utilities.wrap_style ('parameter', param)); -- add parameter name to the list</p> <p>end</p> <p>end</p> <p>if 0 ~= #url_error_t then -- non-zero when there are errors</p> <p>table.sort (url_error_t);</p> <p>utilities.set_message ('err_param_has_twl_url', {utilities.make_sep_list (#url_error_t, url_error_t)}); -- add this error message</p> <p>return true;</p> <p>end</p> <p>end</p> <p>--- look for extraneous url parameter values; parameters listed in skip table are not checked</p> <p>--</p> <p>-- @param {table} non_url_param_t table of non-URL param values</p> <p>local function has_extraneous_url (non_url_param_t)</p> <p>local url_error_t = {};</p> <p>check_for_url (non_url_param_t, url_error_t); -- extraneous url check</p> <p>if 0 ~= #url_error_t then -- non-zero when there are errors</p> <p>table.sort (url_error_t);</p> <p>utilities.set_message ('err_param_has_ext_link', {utilities.make_sep_list (#url_error_t, url_error_t)}); -- add this error message</p> <p>end</p> <p>end</p> <p>--- Module entry point</p> <p>--</p> <p>-- @param {table} frame from template call (citation()); may be nil when called from another module</p> <p>-- @param {table} args table of all cs1|2 parameters in the template (the template frame)</p> <p>-- @param {table} config table of template-supplied parameter (the #invoke frame)</p> <p>-- @return Output of module</p> <p>local function _citation (frame, args, config) -- save a copy in case we need to display an error message in preview mode</p> <p>if not frame then</p> <p>frame = mw.getCurrentFrame(); -- if called from another module, get a frame for frame-provided functions</p> <p>end</p> <p>-- i18n: set the name that your wiki uses to identify sandbox subpages from sandbox template invoke (or can be set here)</p> <p>local sandbox = ((config.SandboxPath and '' ~= config.SandboxPath) and config.SandboxPath) or '/sandbox'; -- sandbox path from {{ml|#invoke:Citation/CS1/sandbox|citation|SandboxPath=/...}}</p> <p>is_sandbox = nil ~= string.find (frame:getTitle(), sandbox, 1, true); -- is this invoke the sandbox module?</p> <p>sandbox = is_sandbox and sandbox or ''; -- use i18n sandbox to load sandbox modules when this module is the sandox; live modules else</p> <p>cfg = mw.loadData ('Module:Citation/CS1/Configuration' .. sandbox); -- load sandbox versions of support modules when {{ml|#invoke:Citation/CS1/sandbox|...}}; live modules else</p> <p>whitelist = mw.loadData ('Module:Citation/CS1/Whitelist' .. sandbox);</p> <p>utilities = require ('Module:Citation/CS1/Utilities' .. sandbox);</p> <p>validation = require ('Module:Citation/CS1/Date_validation' .. sandbox);</p> <p>identifiers = require ('Module:Citation/CS1/Identifiers' .. sandbox);</p> <p>metadata = require ('Module:Citation/CS1/COinS' .. sandbox);</p> <p>utilities.set_selected_modules (cfg); -- so that functions in Utilities can see the selected cfg tables</p> <p>identifiers.set_selected_modules (cfg, utilities); -- so that functions in Identifiers can see the selected cfg tables and selected Utilities module</p> <p>validation.set_selected_modules (cfg, utilities); -- so that functions in Date validataion can see selected cfg tables and the selected Utilities module</p> <p>metadata.set_selected_modules (cfg, utilities); -- so that functions in COinS can see the selected cfg tables and selected Utilities module</p> <p>z = utilities.z; -- table of error and category tables in Module:Citation/CS1/Utilities</p> <p>is_preview_mode = not utilities.is_set (frame:preprocess ('{{REVISIONID}}'));</p> <p>-- table where we store all of the template's arguments</p> <p>local suggestions = {}; -- table where we store suggestions if we need to loadData them</p> <p>local error_text; -- used as a flag</p> <p>local capture; -- the single supported capture when matching unknown parameters using patterns</p> <p>local empty_unknowns = {}; -- sequence table to hold empty unknown params for error message listing</p> <p>for k, v in pairs( args ) do -- get parameters from the parent (template) frame</p> <p>v = mw.ustring.gsub (v, '^%s*(.-)%s*$', '%1'); -- trim leading/trailing whitespace; when v is only whitespace, becomes empty string</p> <p>if v ~= '' then</p> <p>if ('string' == type (k)) then</p> <p>k = mw.ustring.gsub (k, '%d', cfg.date_names.local_digits); -- for enumerated parameters, translate 'local' digits to Western 0-9</p> <p>end</p> <p>if not validate( k, config.CitationClass ) then</p> <p>if type (k) ~= 'string' then -- exclude empty numbered parameters</p> <p>if v:match("%S+") ~= nil then</p> <p>error_text = utilities.set_message ('err_text_ignored', {v});</p> <p>end</p> <p>elseif validate (k:lower(), config.CitationClass) then</p> <p>error_text = utilities.set_message ('err_parameter_ignored_suggest', {k, k:lower()}); -- suggest the lowercase version of the parameter</p> <p>else</p> <p>if nil == suggestions.suggestions then -- if this table is nil then we need to load it</p> <p>suggestions = mw.loadData ('Module:Citation/CS1/Suggestions' .. sandbox); --load sandbox version of suggestion module when {{ml|#invoke:Citation/CS1/sandbox|...}}; live module else</p> <p>end</p> <p>for pattern, param in pairs (suggestions.patterns) do -- loop through the patterns to see if we can suggest a proper parameter</p> <p>capture = k:match (pattern); -- the whole match if no capture in pattern else the capture if a match</p> <p>if capture then -- if the pattern matches</p> <p>param = utilities.substitute (param, capture); -- add the capture to the suggested parameter (typically the enumerator)</p> <p>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)</p> <p>error_text = utilities.set_message ('err_parameter_ignored_suggest', {k, param}); -- set the suggestion error message</p> <p>else</p> <p>error_text = utilities.set_message ('err_parameter_ignored', {k}); -- suggested param not supported by this template</p> <p>v = ''; -- unset</p> <p>end</p> <p>end</p> <p>end</p> <p>if not utilities.is_set (error_text) then -- couldn't match with a pattern, is there an explicit suggestion?</p> <p>if (suggestions.suggestions[ k:lower() ] ~= nil) and validate (suggestions.suggestions[ k:lower() ], config.CitationClass) then</p> <p>utilities.set_message ('err_parameter_ignored_suggest', {k, suggestions.suggestions[ k:lower() ]});</p> <p>else</p> <p>utilities.set_message ('err_parameter_ignored', {k});</p> <p>v = ''; -- unset value assigned to unrecognized parameters (this for the limited parameter lists)</p> <p>end</p> <p>end</p> <p>end</p> <p>end</p> <p>args[k] = v; -- save this parameter and its value</p> <p>elseif not utilities.is_set (v) then -- for empty parameters</p> <p>if not validate (k, config.CitationClass, true) then -- is this empty parameter a valid parameter</p> <p>k = ('' == k) and '(empty string)' or k; -- when k is empty string (or was space(s) trimmed to empty string), replace with descriptive text</p> <p>table.insert (empty_unknowns, utilities.wrap_style ('parameter', k)); -- format for error message and add to the list</p> <p>end</p> <p>-- crude debug support that allows us to render a citation from module {{ml|#invoke:}}</p> <p>-- @todo: keep?</p> <p>-- elseif args[k] ~= nil or (k == 'postscript') then -- when args[k] has a value from {{#invoke}} frame (we don't normally do that)</p> <p>-- args[k] = v; -- overwrite args[k] with empty string from pframe.args[k] (template frame); v is empty string here</p> <p>end -- not sure about the postscript bit; that gets handled in parameter validation; historical artifact?</p> <p>end</p> <p>if 0 ~= #empty_unknowns then -- create empty unknown error message</p> <p>utilities.set_message ('err_param_unknown_empty', {</p> <p>1 == #empty_unknowns and '' or 's',</p> <p>utilities.make_sep_list (#empty_unknowns, empty_unknowns)</p> <p>});</p> <p>end</p> <p>local non_url_param_t = {}; -- table of parameters and values that are not url-holding parameters</p> <p>local url_param_t = {}; -- table of url-holding paramters and their values</p> <p>for k, v in pairs( args ) do</p> <p>if 'string' == type (k) then -- don't evaluate positional parameters</p> <p>has_invisible_chars (k, v); -- look for invisible characters</p> <p>end</p> <p>has_extraneous_punc (k, v); -- look for extraneous terminal punctuation in parameter values</p> <p>missing_pipe_check (k, v); -- do we think that there is a parameter that is missing a pipe?</p> <p>args[k] = inter_wiki_check (k, v); -- when language interwiki-linked parameter missing leading colon replace with wiki-link label</p> <p>if 'string' == type (k) then -- when parameter k is not positional</p> <p>if not cfg.url_skip[k] then -- and not in url skip table</p> <p>non_url_param_t[k] = v; -- make a parameter/value list for extraneous url check</p> <p>else -- and is in url skip table (a url-holding parameter)</p> <p>url_param_t[k] = v; -- make a parameter/value list to check for values that are The Wikipedia Library url</p> <p>end</p> <p>end</p> <p>end</p> <p>has_extraneous_url (non_url_param_t); -- look for url in parameter values where a url does not belong</p> <p>if has_twl_url (url_param_t) then -- look for url-holding parameters that hold a The Wikipedia Library url</p> <p>args['url-access'] = 'subscription';</p> <p>end</p> <p>return table.concat ({</p> <p>frame:extensionTag ('templatestyles', '', {src='Module:Citation/CS1' .. sandbox .. '/styles.css'}),</p> <p>citation0( config, args)</p> <p>});</p> <p>end</p> <p>--- Template entry point</p> <p>--</p> <p>-- @param {table} Calling frame</p> <p>-- @return {string} Wikitext output</p> <p>local function citation (frame)</p> <p>local config_t = {}; -- table to store parameters from the module {{ml|#invoke:}}</p> <p>local args_t = frame:getParent().args; -- get template's preset parameters</p> <p>for k, v in pairs (frame.args) do -- get parameters from the {{#invoke}} frame</p> <p>config_t[k] = v;</p> <p>-- args_t[k] = v; -- crude debug support that allows us to render a citation from module {{ml|#invoke:}}; skips parameter validation</p> <p>-- @todo: keep?</p> <p>end</p> <p>return _citation (frame, args_t, config_t)</p> <p>end</p> <p>-- exports</p> <p>return {</p> <p>--- module entry point</p> <p>-- @param {table} Calling frame</p> <p>-- @return {string} Wikitext output</p> <p>citation = citation,</p> <p>--- template entry point</p> <p>-- @param {table} Calling frame</p> <p>-- @return {string} Wikitext output</p> <p>_citation = _citation,</p> <p>}</p> <p>-- </nowiki></p></div></section></div></main> <footer class="site-footer"> <div class="footer-container"> <div class="footer-links"> <a href="/about.php">About</a> <a href="/help.php">Help</a> <a href="/updates.php">Updates</a> <a href="/contact.php">Contact</a> <a href="/privacy.php">Privacy</a> <a href="/terms.php">Terms</a> <a href="https://github.com/yourusername/friendly-wiki" target="_blank" rel="noopener">GitHub</a> </div> <div class="footer-copy"> © 2025 Friendly Wiki. All rights reserved. </div> </div> </footer> <script> const toggle = document.getElementById('mobileMenuToggle'); const menu = document.getElementById('mobileMenu'); toggle.addEventListener('click', () => { menu.classList.toggle('active'); }); </script> <!-- Collapsible toggle --> <script> document.addEventListener("DOMContentLoaded", function () { const toggles = document.querySelectorAll('.section-toggle'); toggles.forEach(toggle => { toggle.addEventListener('click', function () { const section = toggle.closest('.collapsible'); const body = section.querySelector('.wiki-body'); body.classList.toggle('collapsed'); }); }); }); </script>