Modul:Citation/CS1/peskovnik: Razlika med redakcijama

Izbrisana vsebina Dodana vsebina
mBrez povzetka urejanja
mBrez povzetka urejanja
Vrstica 5:
]]
 
local dates, year_date_check, reformat_dates, date_hyphen_to_dash -- functions in Modul:Citation/CS1/Date_validation
 
local is_set, in_array, substitute, error_comment, set_error, select_one, -- functions in Modul:Citation/CS1/Utilities
Vrstica 18:
local cfg = {}; -- table of configuration tables that are defined in Modul:Citation/CS1/Configuration
local whitelist = {}; -- table of tables listing valid template parameter names; defined in Modul:Citation/CS1/Whitelist
 
 
--[[--------------------------< P A G E S C O P E V A R I A B L E S >--------------------------------------
 
delare variables here that have page-wide scope
 
]]
 
local Preview_mode = false; -- flag indicating that we are rendering a preview page (Show preview button)
 
--[[--------------------------< F I R S T _ S E T >------------------------------------------------------------
Vrstica 71 ⟶ 62:
 
local added_vanc_errs; -- flag so we only emit one Vancouver error / category
local function add_vanc_error (source)
if not added_vanc_errs then
added_vanc_errs = true; -- note that we've added this category
table.insert( z.message_tail, { set_error( 'vancouver', {source}, true ) } );
end
end
Vrstica 484 ⟶ 475:
script_value = script_value:gsub ('^%l%l%s*:%s*', ''); -- strip prefix from script
-- is prefix one of these language codes?
if in_array (lang, {'am', 'ar', 'be', 'bg', 'bs', 'dv', 'el', 'fa', 'he', 'hy', 'ja', 'ka', 'ko', 'ku', 'mk', 'ml', 'ps', 'ru', 'sd', 'sr', 'th', 'uk', 'ug', 'yi', 'zh'}) then
if in_array (lang, cfg.script_lang_codes) then
add_prop_cat ('script_with_name', {name, lang})
else
Vrstica 850 ⟶ 841:
return str;
end
 
 
--[[--------------------------< I S _ S U F F I X >------------------------------------------------------------
 
returns true is suffix is properly formed Jr, Sr, or ordinal in the range 2–9. Puncutation not allowed.
 
]]
 
local function is_suffix (suffix)
if in_array (suffix, {'Jr', 'Sr', '2nd', '3rd'}) or suffix:match ('^%dth$') then
return true;
end
return false;
end
 
--[[--------------------------< I S _ G O O D _ V A N C _ N A M E >--------------------------------------------
Vrstica 881 ⟶ 858:
|firstn= also allowed to contain hyphens, spaces, apostrophes, and periods
 
At the time of this writing, I had to write the 'if nil == mw.ustring.find ...' test ouside of the code editor and paste it here
This original test:
because the code editor gets confused between character insertion point and cursor position.
if nil == mw.ustring.find (last, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%']*$") or nil == mw.ustring.find (first, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%'%.]+[2-6%a]*$") then
was written ouside of the code editor and pasted here because the code editor gets confused between character insertion point and cursor position.
The test has been rewritten to use decimal character escape sequence for the individual bytes of the unicode characters so that it is not necessary
to use an external editor to maintain this code.
 
\195\128-\195\150 – À-Ö
\195\152-\195\182 – Ø-ö
\195\184-\198\191 – ø-ƿ
\199\132-\201\143 – DŽ-ɏ%
 
]]
 
local function is_good_vanc_name (last, first)
if nil == mw.ustring.find (last, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%']*$") or nil == mw.ustring.find (first, "^[A-Za-zÀ-ÖØ-öø-ƿDŽ-ɏ%-%s%'%.]*$") then
local first, suffix = first:match ('(.-),?%s*([%dJS][%drndth]+)%.?$') or first; -- if first has something that looks like a generational suffix, get it
add_vanc_error ();
 
return false; -- not a string of latin characters; Vancouver required Romanization
if is_set (suffix) then
if not is_suffix (suffix) then
add_vanc_error ('suffix');
return false; -- not a name with an appropriate suffix
end
end
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%-%s%']*$") or
nil == mw.ustring.find (first, "^[A-Za-z\195\128-\195\150\195\152-\195\182\195\184-\198\191\199\132-\201\143%-%s%'%.]*$") then
add_vanc_error ('non-Latin character');
return false; -- not a string of latin characters; Vancouver requires Romanization
end;
return true;
Vrstica 917 ⟶ 877:
Names in |firstn= may be separated by spaces or hyphens, or for initials, a period. See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35062/.
 
Vancouver style requires family rank designations (Jr, II, III, etc) to be rendered as Jr, 2nd, 3rd, etc. SeeThis http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35085/.form is not
currently supported by this code so correctly formed names like Smith JL 2nd are converted to Smith J2. See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35085/.
This code only accepts and understands generational suffix in the Vancouver format because Roman numerals look like, and can be mistaken for, initials.
 
This function uses ustring functions because firstname initials may be any of the unicode Latin characters accepted by is_good_vanc_name ().
Vrstica 925 ⟶ 885:
 
local function reduce_to_initials(first)
local name, suffix =if mw.ustring.match(first, "^(%u+) ([%dJS][%drndth]+)u$") then return first end; -- when first contains just two upper-case letters, nothing to do
local initials = {}
 
iflocal noti name= then0; -- ifcounter notfor initialsnumber andof a suffixinitials
name for =word in mw.ustring.matchgmatch(first, "[^(%us%.%-]+)$"); do -- isnames itseparated by spaces, hyphens, justor intials?periods
table.insert(initials, mw.ustring.sub(word,1,1)) -- Vancouver format does not include full stops.
i = i + 1; -- bump the counter
if 2 <= i then break; end -- only two initials allowed in Vancouver system; if 2, quit
end
 
if name then -- if first is initials with or without suffix
if 3 > name:len() then -- if one or two initials
if suffix then -- if there is a suffix
if is_suffix (suffix) then -- is it legitimate?
return first; -- one or two initials and a valid suffix so nothing to do
else
add_vanc_error ('suffix'); -- one or two initials with invalid suffix so error message
return first; -- and return first unmolested
end
else
return first; -- one or two initials without suffix; nothing to do
end
end
end -- if here then name has 3 or more uppercase letters so treat them as a word
 
 
local initials, names = {}, {}; -- tables to hold name parts and initials
local i = 1; -- counter for number of initials
 
names = mw.text.split (first, '[%s,]+'); -- split into a table of names and possible suffix
 
while names[i] do -- loop through the table
if 1 < i and names[i]:match ('[%dJS][%drndth]+%.?$') then -- if not the first name, and looks like a suffix (may have trailing dot)
names[i] = names[i]:gsub ('%.', ''); -- remove terminal dot if present
if is_suffix (names[i]) then -- if a legitimate suffix
table.insert (initials, ' ' .. names[i]); -- add a separator space, insert at end of initials table
break; -- and done because suffix must fall at the end of a name
end -- no error message if not a suffix; possibly because of Romanization
end
if 3 > i then
table.insert (initials, mw.ustring.sub(names[i],1,1)); -- insert the intial at end of initials table
end
i = i+1; -- bump the counter
end
-- for word in mw.ustring.gmatch(first, "[^%s%.%-]+") do -- names separated by spaces, hyphens, or periods
-- table.insert(initials, mw.ustring.sub(word,1,1)) -- Vancouver format does not include full stops.
-- i = i + 1; -- bump the counter
-- if 2 <= i then break; end -- only two initials allowed in Vancouver system; if 2, quit
-- end
return table.concat(initials) -- Vancouver format does not include spaces.
end
Vrstica 1.143 ⟶ 1.065:
 
When an author or editor parameter contains some form of 'et al.', the 'et al.' is stripped from the parameter and a flag (etal) returned
that will cause list_people() to add the static 'et al.' text from ModuleModul:Citation/CS1/Configuration. This keeps 'et al.' out of the
template's metadata. When this occurs, the page is added to a maintenance category.
 
Vrstica 1.210 ⟶ 1.132:
and the associated code is not two or three characters, this function returns only the Wikimedia language name.
 
Adapted from code taken from lModul:Check ISO 639-1.
 
]]
Vrstica 1.453 ⟶ 1.375:
--[[--------------------------< E X T R A _ T E X T _ I N _ P A G E _ C H E C K >------------------------------
 
Adds page to Kategorija:CS1 vzdrževanjemaint: extra text if |page= or |pages= has what appears to be some form of p. or pp.
abbreviation in the first characters of the parameter content.
 
Vrstica 1.486 ⟶ 1.408:
may sometimes be required and because such names will often fail the is_good_vanc_name() and other format compliance
tests, are wrapped in doubled paranethese ((corporate name)) to suppress the format tests.
 
Supports generational suffixes Jr, 2nd, 3rd, 4th–6th.
 
This function sets the vancouver error when a reqired comma is missing and when there is a space between an author's initials.
 
TODO: check for names like Coon V JS (Coon JS 5th at PMID 25205766, John S. Coon V at doi:10.1093/humupd/dmu048)?
 
]]
Vrstica 1.497 ⟶ 1.419:
local v_name_table = {};
local etal = false; -- return value set to true when we find some form of et al. vauthors parameter
local last, first, link, mask, suffix;
local corporate = false;
 
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)
if vparam:find ('%[%[') or vparam:find ('%]%]') then -- no wikilinking vauthors names
add_vanc_error ('wikilink');
end
v_name_table = mw.text.split(vparam, "%s*,%s*") -- names are separated by commas
 
for i, v_name in ipairs(v_name_table) do
if v_name:match ('^%(%(.+%)%)$') then -- corporate authors are wrapped in doubled parenthesesparenthese to supress vanc formatting and error detection
first = ''; -- set to empty string for concatenation and because it may have been set for previous author/editor
last = v_name:match ('^%(%((.+)%)%)$') -- remove doubled parntheses
corporate = true; -- flag used in list_people()
elseif string.find(v_name, "%s") then
if v_name:find('[;%.]') then -- look for commonly occurring punctuation characters;
add_vanc_error ('punctuation');
end
local lastfirstTable = {}
lastfirstTable = mw.text.split(v_name, "%s")
first = table.remove(lastfirstTable); -- removes and returns value of last element in table which should be author intials
last = table.concat(lastfirstTable, " ") -- returns a string that is the concatenation of all other names that are not initials
if is_suffix (first) then -- if a valid suffix
if mw.ustring.match (last, '%a+%s+%u+%s+%a+') or mw.ustring.match (v_name, ' %u %u$') then
suffix = first -- save it as a suffix and
add_vanc_error (); -- matches last II last; the case when a comma is missing or a space between two intiials
first = table.remove(lastfirstTable); -- get what should be the initials from the table
end -- no suffix error message here because letter combination may be result of Romanization; check for digits?
last = table.concat(lastfirstTable, " ") -- returns a string that is the concatenation of all other names that are not initials
if mw.ustring.match (last, '%a+%s+%u+%s+%a+') then
add_vanc_error ('missing comma'); -- matches last II last; the case when a comma is missing
end
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
add_vanc_error ('name'); -- matches a space between two intiials
end
else
Vrstica 1.534 ⟶ 1.446:
end
if is_set (first) and not mw.ustring.match (first, "^%u?%u$") then -- first shall contain one or two upper-case letters, nothing else
if is_set (first) then
add_vanc_error ();
if not mw.ustring.match (first, "^%u?%u$") then -- first shall contain one or two upper-case letters, nothing else
add_vanc_error ('initials'); -- too many initials; mixed case initials (which may be ok Romanization); hyphenated initials
end
is_good_vanc_name (last, first); -- check first and last before restoring the suffix which may have a non-Latin digit
if is_set (suffix) then
first = first .. ' ' .. suffix; -- if there was a suffix concatenate with the initials
suffix = ''; -- unset so we don't add this suffix to all subsequent names
end
else
is_good_vanc_name (last, '');
end
-- this from extract_names ()
link = select_one( args, cfg.aliases[list_name .. '-Link'], 'redundant_parameters', i );
Vrstica 1.756 ⟶ 1.657:
 
Check archive.org urls to make sure they at least look like they are pointing at valid archives and not to the
save snapshot url or to calendar pages. When the archive url is 'https://web.archive.org/save/' (or http://...) archive.org saves a snapshot
archive.org saves a snapshot of the target page in the url. That is something that Wikipedia should not allow unwitting readers to do.
unwitting readers to do.
 
When the archive.org url does not have a complete timestamp, archive.org chooses a snapshot according to its own
algorithm or provides a calendar 'search' result. [[WP:ELNO]] discourages links to search results.
 
This function looks at the value assigned to |archive-url= and returns empty strings for |archive-url= and
|archive-date= and an error message when:
|archive-url= holds an archive.org save command url
|archive-url= is an archive.org url that does not have a complete timestamp (YYYYMMDDhhmmss 14 digits) in the correct place
correct place
otherwise returns |archive-url= and |archive-date=
 
Vrstica 1.777 ⟶ 1.676:
('id_', 'js_', 'cs_', 'im_') but since archive.org ignores others following the same form (two letters and an underscore)
we don't check for these specific flags but we do check the form.
 
This function supports a preview mode. When the article is rendered in preview mode, this funct may return a modified
archive url:
for save command errors, return undated wildcard (/*/)
for timestamp errors when the timestamp has a wildcard, return the url unmodified
for timestamp errors when the timestamp does not have a wildcard, return with timestamp limited to six digits plus wildcard (/yyyymm*/)
 
]=]
Vrstica 1.791 ⟶ 1.684:
if not url:match('//web%.archive%.org/') then
return url, date; -- not an archive.org archive, return ArchiveURLarchiveURL and ArchiveDate
end
 
if url:match('//web%.archive%.org/save/') then -- if a save command url, we don't want to allow saving of the target page
table.insert( z.message_tail, { set_error( 'archive_url', {'save command'}, true ) } ); -- add error message
return '', ''; -- return empty strings for archiveURL and ArchiveDate
if Preview_mode then
return url:gsub ('(//web%.archive%.org)/save/', '%1/*/', 1), date; -- preview mode: modify and return ArchiveURL and ArchiveDate
else
return '', ''; -- return empty strings for archiveURL and ArchiveDate
end
end
 
-- if url:match('//web%.archive%.org/web/%*/') or url:match('//web%.archive%.org/%*/') then -- wildcard with or without 'web/' path element
-- table.insert( z.message_tail, { set_error( 'archive_url', {'wildcard'}, true ) } ); -- add error message and
-- return '', ''; -- return empty strings for archiveURL and ArchiveDate
-- end
path, timestamp, flag = url:match('//web%.archive%.org/([^%d]*)(%d+)([^/]*)/'); -- split out some of the url parts for evaluation
 
if not is_set(timestamp) or 14 ~= timestamp:len() then -- path and flag optional, must have 14-digit timestamp here
err_msg = 'timestamp';
if '*' ~= flag then
url=url:gsub ('(//web%.archive%.org/[^%d]*%d?%d?%d?%d?%d?%d?)[^/]*', '%1*', 1) -- for preview, modify ts to be yearmo* max (0-6 digits plus splat)
end
elseif is_set(path) and 'web/' ~= path then -- older archive urls do not have the extra 'web/' path element
err_msg = 'path';
Vrstica 1.826 ⟶ 1.712:
-- if here something not right so
table.insert( z.message_tail, { set_error( 'archive_url', {err_msg}, true ) } ); -- add error message and
return '', ''; -- return empty strings for archiveURL and ArchiveDate
if Preview_mode then
return url, date; -- preview mode so return archiveURL and ArchiveDate
else
return '', ''; -- return empty strings for archiveURL and ArchiveDate
end
end
 
Vrstica 1.975 ⟶ 1.857:
ArchiveURL, ArchiveDate = archive_url_check (A['ArchiveURL'], A['ArchiveDate'])
-- local ArchiveDate = A['ArchiveDate'];
-- local ArchiveURL = A['ArchiveURL'];
-- if ArchiveURL:match('//web%.archive%.org/save/') then -- if an archive.org save command url, we don't want to save target page ...
-- ArchiveURL = ''; -- every time a reader clicks the link so
-- ArchiveDate = ''; -- unset these
-- table.insert( z.message_tail, { set_error( 'archive_save', {}, true ) } ); -- and add error message
-- end
local DeadURL = A['DeadURL']
if not is_valid_parameter_value (DeadURL, 'dead-url', cfg.keywords ['deadurl']) then -- set in config.defaults to 'yes'
Vrstica 2.391 ⟶ 2.280:
local error_message = '';
-- AirDate has been promoted to Date so not necessary to check it
-- local date_parameters_list = {['access-date']=AccessDate, ['archive-date']=ArchiveDate, ['date']=Date, ['doi-broken-date']=DoiBroken,
-- ['embargo']=Embargo, ['lay-date']=LayDate, ['publication-date']=PublicationDate, ['year']=Year};
-- anchor_year, Embargo, error_message = dates(date_parameters_list, COinS_date);
anchor_year, error_message = dates({['access-date']=AccessDate, ['archive-date']=ArchiveDate, ['date']=Date, ['doi-broken-date']=DoiBroken,
['embargo']=Embargo, ['lay-date']=LayDate, ['publication-date']=PublicationDate, ['year']=Year}, COinS_date);
 
if is_set (Year) and is_set (Date) then -- both |date= and |year= not normally needed;
Vrstica 2.409 ⟶ 2.294:
end
end
-- if not is_set(error_message) then -- error free dates only
-- local modified = false; -- flag
-- if is_set (DF) then -- if we need to reformat dates
-- modified = reformat_dates (date_parameters_list, DF, false); -- reformat to DF format, use long month names if appropriate
-- end
--
-- if true == date_hyphen_to_dash (date_parameters_list) then -- convert hyphens to dashes where appropriate
-- modified = true;
-- add_maint_cat ('date_format'); -- hyphens were converted so add maint category
-- end
--
-- if modified then -- if the date_parameters_list values were modified
-- AccessDate = date_parameters_list['access-date']; -- overwrite date holding parameters with modified values
-- ArchiveDate = date_parameters_list['archive-date'];
-- Date = date_parameters_list['date'];
-- DoiBroken = date_parameters_list['doi-broken-date'];
-- LayDate = date_parameters_list['lay-date'];
-- PublicationDate = date_parameters_list['publication-date'];
-- end
-- else
-- table.insert( z.message_tail, { set_error( 'bad_date', {error_message}, true ) } ); -- add this error message
-- end
 
if is_set(error_message) then
Vrstica 2.827 ⟶ 2.689:
if is_set (Translators) then
-- Others = sepc .. ' PrevedelTranslated by ' .. Translators .. Others;
Others = sepc .. ' ' .. wrap_msg ('translated', Translators, use_lowercase) .. Others;
end
 
Vrstica 3.133 ⟶ 2.994:
text = safe_join( {Editors, Date, Chapter, Place, tcommon, pgtext, idcommon}, sepc );
else
if in_array(config.CitationClass, {=="journal","citation"}) and is_set(Periodical) then
text = safe_join( {Chapter, Place, tcommon, pgtext, Date, idcommon}, sepc );
else
Vrstica 3.170 ⟶ 3.031:
namelist = e;
end
ifid #namelist= >anchor_id 0(namelist, then year); -- ifgo theremake arethe namesCITEREF in namelistanchor
id = anchor_id (namelist, year); -- go make the CITEREF anchor
else
id = ''; -- unset
end
end
options.id = id;
Vrstica 3.240 ⟶ 3.097:
local validation, utilities, identifiers, metadata;
if nil ~= string.find (frame:getTitle(), 'peskovnik', 1, true) then -- did the {{#invoke:}} use sandboxpeskovnik version?
cfg = mw.loadData ('Modul:Citation/CS1/Configuration/peskovnik'); -- load sandboxpeskovnik versions of support modules
whitelist = mw.loadData ('Modul:Citation/CS1/Whitelist/peskovnik');
utilities = require ('Modul:Citation/CS1/Utilities/peskovnik');
Vrstica 3.265 ⟶ 3.122:
year_date_check = validation.year_date_check;
reformat_dates = validation.reformat_dates;
date_hyphen_to_dash = validation.date_hyphen_to_dash;
is_set = utilities.is_set; -- imported functions from Modul:Citation/CS1/Utilities
Vrstica 3.288 ⟶ 3.144:
COinS = metadata.COinS;
 
Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id
if is_set (Preview_mode) then -- if there is a value then this is not a preiview
Preview_mode = false;
else
Preview_mode = true; -- no value (nil or empty string) so this is a preview
end
local args = {};
Vrstica 3.320 ⟶ 3.169:
else
if nil == suggestions.suggestions then -- if this table is nil then we need to load it
if nil ~= string.find (frame:getTitle(), 'peskovnik', 1, true) then -- did the {{#invoke:}} use sandboxpeskovnik version?
suggestions = mw.loadData( 'Modul:Citation/CS1/Suggestions/peskovnik' ); -- use the sandboxpeskovnik version
else
suggestions = mw.loadData( 'Modul:Citation/CS1/Suggestions' ); -- use the live version