CargoAdmin, Bureaucrats, Moderators (CommentStreams), fileuploaders, Interface administrators, newuser, Push subscription managers, Suppressors, Administrators
14,662
edits
>Trappist the monk (sync from sandbox;) |
m (1 revision imported) |
||
Line 1,039: | Line 1,039: | ||
end | end | ||
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 | 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 | 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 (cfg.err_msg_supl['non-Latin char'], position); | add_vanc_error (cfg.err_msg_supl['non-Latin char'], position); | ||
return false; -- not a string of Latin characters; Vancouver requires Romanization | return false; -- not a string of Latin characters; Vancouver requires Romanization | ||
Line 1,065: | Line 1,065: | ||
]] | ]] | ||
local function reduce_to_initials (first, position) | local function reduce_to_initials(first, position) | ||
local name, suffix = mw.ustring.match(first, "^(%u+) ([%dJS][%drndth]+)$"); | |||
local name, suffix = mw.ustring.match (first, "^(%u+) ([%dJS][%drndth]+)$"); | |||
if not name then -- if not initials and a suffix | if not name then -- if not initials and a suffix | ||
name = mw.ustring.match (first, "^(%u+)$"); -- is it just initials? | name = mw.ustring.match(first, "^(%u+)$"); -- is it just initials? | ||
end | end | ||
Line 1,091: | Line 1,087: | ||
end -- if here then name has 3 or more uppercase letters so treat them as a word | end -- if here then name has 3 or more uppercase letters so treat them as a word | ||
local | local initials, names = {}, {}; -- tables to hold name parts and initials | ||
local i = 1; -- counter for number of 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 | while names[i] do -- loop through the table | ||
if 1 < i and | 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 ( | if is_suffix (names[i]) then -- if a legitimate suffix | ||
table.insert ( | 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 | 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 -- no error message if not a suffix; possibly because of Romanization | ||
end | end | ||
if 3 > i then | if 3 > i then | ||
table.insert ( | table.insert (initials, mw.ustring.sub(names[i], 1, 1)); -- insert the initial at end of initials table | ||
end | end | ||
i = i + 1; -- bump the counter | i = i + 1; -- bump the counter | ||
end | end | ||
return table.concat ( | return table.concat(initials) -- Vancouver format does not include spaces. | ||
end | end | ||
Line 1,251: | Line 1,247: | ||
if one then -- if <one> has a value (name, mdash replacement, or mask text replacement) | if one then -- if <one> has a value (name, mdash replacement, or mask text replacement) | ||
local proj, tag = interwiki_prefixen_get (one, true); -- get the interwiki prefixen if present | local proj, tag = interwiki_prefixen_get (one, true); -- get the interwiki prefixen if present | ||
if 'w' == proj and ('Wikipedia' == mw.site.namespaces.Project['name']) then | if 'w' == proj and ('Wikipedia' == mw.site.namespaces.Project['name']) then | ||
proj = nil; -- for stuff like :w:de:<article>, :w is unnecessary TODO: maint cat? | proj = nil; -- for stuff like :w:de:<article>, :w is unnecessary TODO: maint cat? | ||
end | end | ||
if proj then | if proj then | ||
proj = ({['d'] = 'Wikidata', ['s'] = 'Wikisource', ['w'] = 'Wikipedia'})[proj]; -- :w (wikipedia) for linking from a non-wikipedia project | |||
if | if proj then | ||
one = one .. utilities.wrap_style ('interproj', | one = one .. utilities.wrap_style ('interproj', proj); -- add resized leading space, brackets, static text, language name | ||
tag = nil; -- unset; don't do both project and language | tag = nil; -- unset; don't do both project and language | ||
end | end | ||
Line 1,269: | Line 1,265: | ||
if lang then -- error messaging done in extract_names() where we know parameter names | if lang then -- error messaging done in extract_names() where we know parameter names | ||
one = one .. utilities.wrap_style ('interwiki', lang); -- add resized leading space, brackets, static text, language name | one = one .. utilities.wrap_style ('interwiki', lang); -- add resized leading space, brackets, static text, language name | ||
end | end | ||
end | end | ||
Line 1,852: | Line 1,847: | ||
-- emit a maintenance message if user postscript is the default cs2 postscript | -- emit a maintenance message if user postscript is the default cs2 postscript | ||
-- we catch the opposite case for cs1 in set_cs_style | -- we catch the opposite case for cs1 in set_cs_style | ||
if 'cs2' == mode or | if 'cs2' == mode or 'citation' == cite_class then | ||
utilities.set_message ('maint_postscript'); | utilities.set_message ('maint_postscript'); | ||
end | end | ||
Line 1,978: | Line 1,973: | ||
--[[--------------------------< E X T R A _ T E X T _ I N _ V O L _ I S S _ C H E C K >------------------------ | --[[--------------------------< E X T R A _ T E X T _ I N _ V O L _ I S S _ C H E C K >------------------------ | ||
Adds error if |volume= or |issue= has what appears to be some form of redundant 'type' indicator | Adds error if |volume= or |issue= has what appears to be some form of redundant 'type' indicator. | ||
For |volume=: | For |volume=: | ||
Line 1,989: | Line 1,982: | ||
For |issue=: | For |issue=: | ||
'No.', 'I.', 'Iss.' (with or without the dot) abbreviations, or 'Issue' in the first characters of the | 'No.', 'I.', 'Iss.' (with or without the dot) abbreviations, or 'Issue' in the first characters of the | ||
parameter content (all case insensitive) | parameter content (all case insensitive). | ||
Single character values ('v', 'i', 'n') allowed when not followed by separator character ('.', ':', '=', or | Single character values ('v', 'i', 'n') allowed when not followed by separator character ('.', ':', '=', or | ||
Line 2,008: | Line 2,000: | ||
end | end | ||
local patterns = 'v' == selector and cfg.vol_iss_pg_patterns.vpatterns or cfg.vol_iss_pg_patterns.ipatterns; | |||
local handler = 'v' == selector and 'err_extra_text_volume' or 'err_extra_text_issue'; | local handler = 'v' == selector and 'err_extra_text_volume' or 'err_extra_text_issue'; | ||
val = val:lower(); -- force parameter value to lower case | val = val:lower(); -- force parameter value to lower case | ||
for _, pattern in ipairs (patterns) do -- spin through the selected sequence table of patterns | |||
for _, pattern in ipairs ( | |||
if val:match (pattern) then -- when a match, error so | if val:match (pattern) then -- when a match, error so | ||
utilities.set_message (handler, name); -- add error message | utilities.set_message (handler, name); -- add error message | ||
Line 2,472: | Line 2,465: | ||
local path, timestamp, flag; -- portions of the archive.org URL | local path, timestamp, flag; -- portions of the archive.org URL | ||
timestamp = url:match ('//archive.today/(%d%d%d%d%d%d%d%d%d%d%d%d%d%d)/') | timestamp = url:match ('//archive.today/(%d%d%d%d%d%d%d%d%d%d%d%d%d%d)/'); -- get timestamp from archive.today urls | ||
if timestamp then -- if this was an archive.today url ... | if timestamp then -- if this was an archive.today url ... | ||
return url, date, timestamp | return url, date, timestamp; -- return ArchiveURL, ArchiveDate, and timestamp from |archive-url=, and done | ||
end | end | ||
-- here for archive.org urls | -- here for archive.org urls | ||
Line 2,926: | Line 2,918: | ||
local Encyclopedia = A['Encyclopedia']; -- used as a flag by this module and by ~/COinS | local Encyclopedia = A['Encyclopedia']; -- used as a flag by this module and by ~/COinS | ||
if utilities.is_set (Encyclopedia | if utilities.is_set (Encyclopedia) then -- emit error message when Encyclopedia set but template is other than {{cite encyclopedia}} or {{citation}} | ||
if 'encyclopaedia' ~= config.CitationClass and 'citation' ~= config.CitationClass then | if 'encyclopaedia' ~= config.CitationClass and 'citation' ~= config.CitationClass then | ||
utilities.set_message ('err_parameter_ignored', {A:ORIGIN ('Encyclopedia')}); | |||
Encyclopedia = nil; -- unset because not supported by this template | |||
Encyclopedia = nil; -- unset | |||
end | end | ||
end | end | ||
Line 2,949: | Line 2,931: | ||
end | end | ||
if utilities.is_set (Encyclopedia | if utilities.is_set (Encyclopedia) then | ||
Periodical = Encyclopedia; -- error or no, set Periodical to Encyclopedia for rendering; {{citation}} could (not legitimately) have both; use Encyclopedia | Periodical = Encyclopedia; -- error or no, set Periodical to Encyclopedia for rendering; {{citation}} could (not legitimately) have both; use Encyclopedia | ||
Periodical_origin = A:ORIGIN ('Encyclopedia'); | Periodical_origin = A:ORIGIN ('Encyclopedia'); | ||
if utilities.is_set (Title) or utilities.is_set (ScriptTitle) then | if utilities.is_set (Title) or utilities.is_set (ScriptTitle) then | ||
if not utilities.is_set (Chapter) then | if not utilities.is_set (Chapter) then | ||
Chapter = Title; -- |encyclopedia= and |title= are set so map |title= | Chapter = Title; -- |encyclopedia= and |title= are set so map |title= to |article= and |encyclopedia= to |title= for rendering | ||
ScriptChapter = ScriptTitle; | ScriptChapter = ScriptTitle; | ||
ScriptChapter_origin = A:ORIGIN('ScriptTitle') | ScriptChapter_origin = A:ORIGIN('ScriptTitle') | ||
Line 2,963: | Line 2,943: | ||
ChapterURL = URL; | ChapterURL = URL; | ||
ChapterURL_origin = URL_origin; | ChapterURL_origin = URL_origin; | ||
ChapterUrlAccess = UrlAccess; | ChapterUrlAccess = UrlAccess; | ||
if not utilities.is_set (ChapterURL) and utilities.is_set (TitleLink) then | if not utilities.is_set (ChapterURL) and utilities.is_set (TitleLink) then | ||
Chapter = utilities.make_wikilink (TitleLink, Chapter); | Chapter = utilities.make_wikilink (TitleLink, Chapter); | ||
end | end | ||
Title = Periodical | Title = Periodical; | ||
ChapterFormat = Format; | |||
Periodical = ''; -- redundant so unset | Periodical = ''; -- redundant so unset | ||
TransTitle = ''; | |||
URL = ''; | URL = ''; | ||
Format = ''; | Format = ''; | ||
TitleLink = ''; | TitleLink = ''; | ||
ScriptTitle = ''; | |||
end | end | ||
elseif utilities.is_set (Chapter) or utilities.is_set (ScriptChapter) then -- |title= not set | elseif utilities.is_set (Chapter) or utilities.is_set (ScriptChapter) then -- |title= not set | ||
Title = Periodical; -- |encyclopedia= set and |article= set so map |encyclopedia= to |title= for rendering | Title = Periodical; -- |encyclopedia= set and |article= set so map |encyclopedia= to |title= for rendering | ||
Periodical = ''; -- redundant so unset | Periodical = ''; -- redundant so unset | ||
end | end | ||
end | end | ||
Line 3,159: | Line 3,136: | ||
local Year = A['Year']; | local Year = A['Year']; | ||
if not utilities.is_set (Date) then | if not utilities.is_set (Date) then | ||
Date = Year; -- promote Year to Date | Date = Year; -- promote Year to Date | ||
Line 3,221: | Line 3,194: | ||
local error_list = {}; | local error_list = {}; | ||
anchor_year, Embargo = validation.dates(date_parameters_list, COinS_date, error_list); | anchor_year, Embargo = validation.dates(date_parameters_list, COinS_date, error_list); | ||
-- start temporary Julian / Gregorian calendar uncertainty categorization | |||
if COinS_date.inter_cal_cat then | |||
utilities.add_prop_cat ('jul-greg-uncertainty'); | |||
end | |||
-- end temporary Julian / Gregorian calendar uncertainty categorization | |||
if utilities.is_set (Year) and utilities.is_set (Date) then -- both |date= and |year= not normally needed; | if utilities.is_set (Year) and utilities.is_set (Date) then -- both |date= and |year= not normally needed; | ||
validation.year_date_check (Year, A:ORIGIN ('Year'), Date, A:ORIGIN ('Date'), error_list); | validation.year_date_check (Year, A:ORIGIN ('Year'), Date, A:ORIGIN ('Date'), error_list); | ||
end | end | ||
if 0 == #error_list then -- error free dates only; 0 when error_list is empty | if 0 == #error_list then -- error free dates only; 0 when error_list is empty | ||
local modified = false; -- flag | local modified = false; -- flag | ||
Line 3,752: | Line 3,731: | ||
Series = utilities.is_set (Series) and wrap_msg ('series', {sepc, Series}) or ""; -- not the same as SeriesNum | Series = utilities.is_set (Series) and wrap_msg ('series', {sepc, Series}) or ""; -- not the same as SeriesNum | ||
local Agency = A['Agency'] | local Agency = A['Agency']; | ||
Agency = utilities.is_set (Agency) and wrap_msg ('agency', {sepc, Agency}) or ""; | |||
Volume = format_volume_issue (Volume, Issue, ArticleNumber, config.CitationClass, Periodical_origin, sepc, use_lowercase); | Volume = format_volume_issue (Volume, Issue, ArticleNumber, config.CitationClass, Periodical_origin, sepc, use_lowercase); | ||
Line 3,981: | Line 3,952: | ||
local tcommon2; -- used for book cite when |contributor= is set | local tcommon2; -- used for book cite when |contributor= is set | ||
if utilities.in_array (config.CitationClass, {"book", "citation"}) and not utilities.is_set (Periodical) then -- special cases for book cites | if utilities.in_array (config.CitationClass, {"journal", "citation"}) and utilities.is_set (Periodical) then | ||
if not (utilities.is_set (Authors) or utilities.is_set (Editors)) then | |||
Others = Others:gsub ('^' .. sepc .. ' ', ''); -- when no authors and no editors, strip leading sepc and space | |||
end | |||
if utilities.is_set (Others) then Others = safe_join ({Others, sepc .. " "}, sepc) end -- add terminal punctuation & space; check for dup sepc; TODO why do we need to do this here? | |||
tcommon = safe_join( {Others, Title, TitleNote, Conference, Periodical, Format, TitleType, Series, Language, Edition, Publisher, Agency, Volume}, sepc ); | |||
elseif utilities.in_array (config.CitationClass, {"book", "citation"}) and not utilities.is_set (Periodical) then -- special cases for book cites | |||
if utilities.is_set (Contributors) then -- when we are citing foreword, preface, introduction, etc. | if utilities.is_set (Contributors) then -- when we are citing foreword, preface, introduction, etc. | ||
tcommon = safe_join ({Title, TitleNote}, sepc); | tcommon = safe_join( {Title, TitleNote}, sepc ); -- author and other stuff will come after this and before tcommon2 | ||
tcommon2 = safe_join ({TitleType, Series, Language, Volume, Others, Edition, Publisher}, sepc); | tcommon2 = safe_join( {Conference, Periodical, Format, TitleType, Series, Language, Volume, Others, Edition, Publisher, Agency}, sepc ); | ||
else | else | ||
tcommon = safe_join ({Title, TitleNote, TitleType, Series, Language, Volume, Others, Edition, Publisher}, sepc); | tcommon = safe_join( {Title, TitleNote, Conference, Periodical, Format, TitleType, Series, Language, Volume, Others, Edition, Publisher, Agency}, sepc ); | ||
end | end | ||
elseif 'map' == config.CitationClass then -- special cases for cite map | elseif 'map' == config.CitationClass then -- special cases for cite map | ||
if utilities.is_set (Chapter) then -- map in a book; TitleType is part of Chapter | if utilities.is_set (Chapter) then -- map in a book; TitleType is part of Chapter | ||
tcommon = safe_join ({Title, Edition, Scale, Series, Language, Cartography, Others, Publisher, Volume}, sepc); | tcommon = safe_join( {Title, Format, Edition, Scale, Series, Language, Cartography, Others, Publisher, Volume}, sepc ); | ||
elseif utilities.is_set (Periodical) then -- map in a periodical | elseif utilities.is_set (Periodical) then -- map in a periodical | ||
tcommon = safe_join ({Title, TitleType, Periodical, Scale, Series, Language, Cartography, Others, Publisher, Volume}, sepc); | tcommon = safe_join( {Title, TitleType, Format, Periodical, Scale, Series, Language, Cartography, Others, Publisher, Volume}, sepc ); | ||
else -- a sheet or stand-alone map | else -- a sheet or stand-alone map | ||
tcommon = safe_join ({Title, TitleType, Edition, Scale, Series, Language, Cartography, Others, Publisher}, sepc); | tcommon = safe_join( {Title, TitleType, Format, Edition, Scale, Series, Language, Cartography, Others, Publisher}, sepc ); | ||
end | end | ||
elseif 'episode' == config.CitationClass then -- special case for cite episode | elseif 'episode' == config.CitationClass then -- special case for cite episode | ||
tcommon = safe_join ({Title, TitleNote, TitleType, Series, Language, Edition, Publisher}, sepc); | tcommon = safe_join( {Title, TitleNote, TitleType, Series, Language, Edition, Publisher}, sepc ); | ||
else -- all other CS1 templates | else -- all other CS1 templates | ||
tcommon = safe_join ({Title, TitleNote, Conference, Periodical, TitleType, Series, Language, Volume, Others, Edition, Publisher, Agency}, sepc); | tcommon = safe_join( {Title, TitleNote, Conference, Periodical, Format, TitleType, Series, Language, | ||
Volume, Others, Edition, Publisher, Agency}, sepc ); | |||
end | end | ||
Line 4,092: | Line 4,070: | ||
end | end | ||
end | end | ||
if utilities.is_set (PostScript) and PostScript ~= sepc then | if utilities.is_set (PostScript) and PostScript ~= sepc then | ||
text = safe_join( {text, sepc}, sepc ); -- Deals with italics, spaces, etc. | text = safe_join( {text, sepc}, sepc ); -- Deals with italics, spaces, etc. | ||
text = text:sub(1, -sepc:len() - 1); | |||
end | end | ||
Line 4,252: | Line 4,226: | ||
return nil; | return nil; | ||
end | end | ||
-- replace | -- replace wnumerator digit(s) with # (|last25= becomes |last#=) (mw.ustring because non-Western 'local' digits) | ||
enum_name = mw.ustring.gsub (name, '%d+$', '#'); -- where enumerator is last charaters in parameter name (these to protect |s2cid=) | enum_name = mw.ustring.gsub (name, '%d+$', '#'); -- where enumerator is last charaters in parameter name (these to protect |s2cid=) | ||
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 | 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 |
edits