మాడ్యూల్:Citation/CS1: కూర్పుల మధ్య తేడాలు
Content deleted Content added
Arjunaraoc (చర్చ | రచనలు) చి Arjunaraoc (చర్చ) చేసిన మార్పులను Chaduvari చివరి కూర్పు వరకు తిప్పికొట్టారు. ట్యాగు: రోల్బ్యాక్ |
sync from sandbox; |
||
పంక్తి 22:
--[[--------------------------< P A G E S C O P E V A R I A B L E S >--------------------------------------
]]
Line 695 ⟶ 694:
]]
local function format_chapter_title (
local chapter_error = '';
Line 713 ⟶ 712:
end
chapter = script_concatenate (chapter,
if is_set (
chapter = external_link (
elseif ws_url then
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?
Line 722 ⟶ 721:
end
if is_set (
if is_set (chapter) then
chapter = chapter .. ' ' ..
else -- here when
chapter =
chapter_source = trans_chapter_source:match ('trans%-?(.+)'); -- when no chapter, get matching name from trans-<param>
chapter_error = ' ' .. set_error ('trans_missing_title', {chapter_source});
end
end
పంక్తి 882:
local function set_titletype (cite_class, title_type)
if is_set (title_type) then
if 'none' == cfg.keywords_xlate[title_type] then
title_type = ''; -- if |type=none then type parameter not displayed
end
return title_type; -- if |type= has been set to any other value use that value
Line 1,074 ⟶ 1,073:
]]
local function is_good_vanc_name (last, first, suffix)
if not suffix then
if first:find ('[,%s]') then -- when there is a space or comma, might be first name/initials + generational suffix
first = first:match ('(.-)[,%s]+'); -- get name/initials
suffix = first:match ('[,%s]+(.+)$'); -- get generational suffix
end
end
if is_set (suffix) then
if not is_suffix (suffix) then
Line 1,085 ⟶ 1,088:
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 (cfg.err_msg_supl['non-Latin
return false; -- not a string of latin characters; Vancouver requires Romanization
end;
Line 1,118 ⟶ 1,121:
return first; -- one or two initials and a valid suffix so nothing to do
else
add_vanc_error (cfg.err_msg_supl.suffix);
return first; -- and return first unmolested
end
Line 1,549 ⟶ 1,552:
add_prop_cat ('foreign_lang_source' .. code, {name, code}); -- categorize it; code appended to allow for multiple language categorization
else -- or is a recognized language (but has a three-character code)
add_prop_cat ('foreign_lang_source_2' .. code, {code}); -- categorize it differently TODO: support
end
elseif cfg.local_lang_cat_enable then -- when the language and this wiki's language are the same and categorization is enabled
Line 1,835 ⟶ 1,838:
for i, v_name in ipairs(v_name_table) do
first = ''; -- set to empty string for concatenation and because it may have been set for previous author/editor
if v_name:match ('^%(%(.+%)%)$') then -- corporate authors are wrapped in doubled parentheses to supress vanc formatting and error detection
last = v_name:match ('^%(%((.+)%)%)$') -- remove doubled parntheses
corporate = true; -- flag used in list_people()
Line 1,844 ⟶ 1,847:
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
if not mw.ustring.match (first, '^%u+$') then -- mw.ustring here so that later we will catch non-latin characters
suffix = first; -- not initials so assume that whatever we got is a generational suffix
first = table.remove(lastfirstTable); -- get what should be the initials from the table
end
last = table.concat(lastfirstTable,
if not is_set (last) then
first = ''; -- unset
last = v_name; -- last empty because something wrong with first
add_vanc_error (cfg.err_msg_supl.name);
end
if mw.ustring.match (last, '%a+%s+%u+%s+%a+') then
add_vanc_error (cfg.err_msg_supl['missing comma']);
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 (cfg.err_msg_supl.name);
end
else
last = v_name; -- last name or single corporate name? Doesn't support multiword corporate names? do we need this?
end
Line 1,864 ⟶ 1,872:
if is_set (first) then
if not mw.ustring.match (first, "^%u?%u$") then -- first shall contain one or two upper-case letters, nothing else
add_vanc_error (cfg.err_msg_supl.initials);
end
is_good_vanc_name (last, first, suffix);
if is_set (suffix) then
first = first .. ' ' .. suffix; -- if there was a suffix concatenate with the initials
Line 2,300 ⟶ 2,308:
local c = {}; -- contributors list from |contributor-lastn= / contributor-firstn= pairs
local Contributors; -- assembled contributors name list
local Chapter = A['Chapter']; -- done here so that we have access to |contribution= from |chapter= aliases
local Chapter_origin = A:ORIGIN ('Chapter');
local Contribution; -- because contribution is required for contributor(s)
if 'contribution' == A:ORIGIN ('Chapter') then
Contribution = A['Chapter']; -- get the name of the contribution
end
if in_array(config.CitationClass, {"book","citation"}) and not is_set(A['Periodical']) then -- |contributor= and |contribution= only supported in book cites
c = extract_names (args, 'ContributorList'); -- fetch contributor list from |contributorn= / |contributor-lastn=, -firstn=, -linkn=, -maskn=
Line 2,338 ⟶ 2,353:
local Conference = A['Conference'];
local TransTitle = A['TransTitle'];
local TransTitle_origin = A:ORIGIN ('TransTitle');
local TitleNote = A['TitleNote'];
local TitleLink = A['TitleLink'];
link_title_ok (TitleLink, A:ORIGIN ('TitleLink'), Title, 'title'); -- check for wikimarkup in |title-link= or wikimarkup in |title= when |title-link= is set
local
if 'map' == config.CitationClass and 'section' == A:ORIGIN ('Chapter') then
Section = A['Chapter']; -- get |section= from |chapter= alias list; |chapter= and the other aliases not supported in {{cite map}}
Chapter = ''; -- unset for now; will be reset later from |map= if present
end
local ScriptChapter = A['ScriptChapter'];
local
local ChapterLink -- = A['ChapterLink']; -- deprecated as a parameter but still used internally by cite episode
local TransChapter = A['TransChapter'];
local TransChapter_origin = A:ORIGIN ('TransChapter');
local TitleType = A['TitleType'];
local Degree = A['Degree'];
Line 2,361 ⟶ 2,383:
local URL = A['URL']
local
local ChapterURL = A['ChapterURL'];
local
local ConferenceFormat = A['ConferenceFormat'];
local ConferenceURL = A['ConferenceURL'];
local
local Periodical = A['Periodical'];
local Periodical_origin = '';
if is_set (Periodical) then
Line 2,379 ⟶ 2,400:
end
end
if 'mailinglist' == config.CitationClass then -- special case for {{cite mailing list}}
if is_set (Periodical) and is_set (A ['MailingList']) then -- both set emit an error
table.insert( z.message_tail, { set_error('redundant_parameters', {wrap_style ('parameter', Periodical_origin) .. ' and ' .. wrap_style ('parameter', 'mailinglist')}, true )});
end
Periodical = A ['MailingList']; -- error or no, set Periodical to |mailinglist= value because this template is {{cite mailing list}}
Periodical_origin = A:ORIGIN('MailingList');
end
local ScriptPeriodical = A['ScriptPeriodical'];
local ScriptPeriodical_origin = A:ORIGIN('ScriptPeriodical');
Line 2,393 ⟶ 2,426:
local TransPeriodical = A['TransPeriodical'];
local TransPeriodical_origin = A:ORIGIN ('TransPeriodical');
local Series = A['Series'];
Line 2,511 ⟶ 2,545:
local TranscriptFormat = A['TranscriptFormat'];
local TranscriptURL = A['TranscriptURL']
local
local LastAuthorAmp = is_valid_parameter_value (A['LastAuthorAmp'], A:ORIGIN('LastAuthorAmp'), cfg.keywords_lists['yes_true_y'], nil);
Line 2,585 ⟶ 2,619:
]]
local Encyclopedia = A['Encyclopedia']; -- used as a flag by this module and by ~/COinS
if 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
table.insert (z.message_tail, {set_error ('parameter_ignored', {A:ORIGIN ('Encyclopedia')}, true)});
Encyclopedia = nil; -- unset because not supported by this template
end
end
if ('encyclopaedia' == config.CitationClass) or ('citation' == config.CitationClass and is_set (Encyclopedia)) then
if is_set (Periodical) and is_set (Encyclopedia) then -- when both set emit an error
table.insert (z.message_tail, {set_error('redundant_parameters', {wrap_style ('parameter', A:ORIGIN ('Encyclopedia')) .. ' and ' .. wrap_style ('parameter', Periodical_origin)}, true )});
end
if is_set (Encyclopedia) then
Periodical = Encyclopedia; -- error or no, set Periodical to Encyclopedia; allow periodical without encyclopedia
Periodical_origin = A:ORIGIN ('Encyclopedia');
end
if is_set (Periodical) then -- Periodical is set when |encyclopedia is set
if is_set(Title) or is_set (ScriptTitle) then
Line 2,593 ⟶ 2,643:
Chapter = Title; -- |encyclopedia and |title are set so map |title to |article and |encyclopedia to |title
ScriptChapter = ScriptTitle;
TransChapter = TransTitle;
ChapterURL = URL;
ChapterUrlAccess = UrlAccess;
Line 2,628 ⟶ 2,678:
end
end
end
Line 2,641 ⟶ 2,684:
if is_set(BookTitle) then
Chapter = Title;
Chapter_origin = 'title';
-- ChapterLink = TitleLink; -- |chapterlink= is deprecated
ChapterURL = URL;
ChapterUrlAccess = UrlAccess;
ChapterFormat = Format;
TransChapter = TransTitle;
TransChapter_origin = TransTitle_origin;
Title = BookTitle;
Format = '';
Line 2,664 ⟶ 2,709:
local Sheets = A['Sheets'] or '';
if config.CitationClass == "map" then
if is_set (Chapter) then
table.insert( z.message_tail, { set_error( 'redundant_parameters', {wrap_style ('parameter', 'map') .. ' and ' .. wrap_style ('parameter', Chapter_origin)}, true ) } ); -- add error message
end
Chapter = A['Map'];
Chapter_origin = A:ORIGIN('Map');
ChapterURL = A['MapURL'];
TransChapter = A['TransMap'];
ScriptChapter = A['ScriptMap']
ChapterUrlAccess = MapUrlAccess;
Line 2,714 ⟶ 2,763:
Chapter = Title; -- promote title parameters to chapter
ScriptChapter = ScriptTitle;
ChapterLink = TitleLink; -- alias episodelink
TransChapter = TransTitle;
ChapterURL = URL;
ChapterUrlAccess = UrlAccess;
Title = Series; -- promote series to title
Line 2,859 ⟶ 2,908:
end -- end of do
--
-- Here we unset Embargo if PMC not embargoed (|embargo= not set in the citation) or if the embargo time has expired. Otherwise, holds embargo date
Embargo = is_embargoed (Embargo);
if config.CitationClass == "journal" and not is_set(URL) and not is_set(
if is_set(ID_list['PMC']) and not is_set (Embargo) then -- if not embargoed or embargo has expired
URL=cfg.id_handlers['PMC'].prefix .. ID_list['PMC']; -- set url to be the same as the PMC external link if not embargoed
elseif is_set(ID_list['DOI']) and ID_access_levels['DOI'] == "free" then
URL=cfg.id_handlers['DOI'].prefix .. ID_list['DOI'];
URL_origin = cfg.id_handlers['DOI'].parameters[1];
if is_set(URL) and is_set(AccessDate) then -- access date requires |url=; pmc or doi created url is not |url=
table.insert( z.message_tail, { set_error( 'accessdate_missing_url', {}, true ) } );
AccessDate = ''; -- unset
end
end
Line 2,877 ⟶ 2,928:
-- At this point fields may be nil if they weren't specified in the template use. We can use that fact.
-- Test if citation has no title
if not is_set(Title) and not is_set(TransTitle) and not is_set(ScriptTitle) then -- has special case for cite episode
table.insert( z.message_tail, { set_error( 'citation_missing_title', {'episode' == config.CitationClass and 'series' or 'title'}, true ) } );
end
Line 2,923 ⟶ 2,968:
local OCinSoutput = COinS({
['Periodical'] = strip_apostrophe_markup (Periodical), -- no markup in the metadata
['Encyclopedia'] =
['Chapter'] = make_coins_title (coins_chapter, ScriptChapter), -- Chapter and ScriptChapter stripped of bold / italic wikimarkup
['Degree'] = Degree; -- cite thesis only
Line 2,930 ⟶ 2,975:
['Date'] = COinS_date.rftdate, -- COinS_date has correctly formatted date if Date is valid;
['Season'] = COinS_date.rftssn,
['Quarter'] = COinS_date.rftquarter,
['Chron'] = COinS_date.rftchron or (not COinS_date.rftdate and Date) or '', -- chron but if not set and invalid date format use Date; keep this last bit?
['Series'] = Series,
Line 3,044 ⟶ 3,090:
end
local OriginalURL,
UrlStatus = UrlStatus:lower(); -- used later when assembling archived text
if is_set( ArchiveURL ) then
if is_set (ChapterURL) then -- if chapter-url is set apply archive url to it
OriginalURL = ChapterURL; -- save copy of source chapter's url for archive text
OriginalFormat = ChapterFormat; -- and original |chapter-format=
if 'live' ~= UrlStatus then
ChapterURL = ArchiveURL -- swap-in the archive's url
ChapterFormat = ArchiveFormat or ''; -- swap in archive's format
ChapterUrlAccess = nil; -- restricted access levels do not make sense for archived urls
Line 3,060 ⟶ 3,106:
elseif is_set (URL) then
OriginalURL = URL; -- save copy of original source URL
OriginalFormat = Format; -- and original |format=
OriginalAccess = UrlAccess;
Line 3,066 ⟶ 3,112:
if 'live' ~= UrlStatus then -- if URL set then archive-url applies to it
URL = ArchiveURL -- swap-in the archive's url
Format = ArchiveFormat or ''; -- swap in archive's format
UrlAccess = nil; -- restricted access levels do not make sense for archived urls
Line 3,083 ⟶ 3,129:
chap_param = A:ORIGIN ('ChapterURL')
elseif is_set (ScriptChapter) then
chap_param =
else is_set (ChapterFormat)
chap_param = A:ORIGIN ('ChapterFormat')
Line 3,104 ⟶ 3,150:
end
Chapter = format_chapter_title (ScriptChapter,
if is_set (Chapter) then
Chapter = Chapter .. ChapterFormat ;
Line 3,116 ⟶ 3,162:
end
-- Format main title
if is_set (ArchiveURL) and
(mw.ustring.match (mw.ustring.lower(Title), cfg.special_case_translation.archived_copy.en) or -- if title is 'Archived copy' (place holder added by bots that can't find proper title)
Line 3,160 ⟶ 3,206:
if is_set (Title) then -- TODO: is this the right place to be making wikisource urls?
if is_set (TitleLink) and is_set (URL) then
table.insert( z.message_tail, { set_error( 'wikilink_in_url', {}, true ) } ); -- set an error message because we can't have both
TitleLink = ''; -- unset
end
if not is_set (TitleLink) and is_set (URL) then
Title = external_link (URL, Title,
URL = ''; -- unset these because no longer needed
Format = "";
Line 3,196 ⟶ 3,247:
if is_set (Conference) then
if is_set (ConferenceURL) then
Conference = external_link( ConferenceURL, Conference,
end
Conference = sepc .. " " .. Conference .. ConferenceFormat;
elseif is_set(ConferenceURL) then
Conference = sepc .. " " .. external_link( ConferenceURL, nil,
end
Line 3,233 ⟶ 3,284:
At = is_set(At) and (sepc .. " " .. At) or "";
Position = is_set(Position) and (sepc .. " " .. Position) or "";
if config.CitationClass == 'map' then
local
local Inset = A['Inset'];
Line 3,307 ⟶ 3,357:
if is_set(URL) then
URL = " " .. external_link( URL, nil,
end
Line 3,346 ⟶ 3,396:
if sepc ~= "." then arch_text = arch_text:lower() end
Archived = sepc .. " " .. substitute( arch_text,
{ external_link( OriginalURL, cfg.messages['original'],
end
else -- OriginalUrl not set
Line 3,379 ⟶ 3,429:
if is_set(Transcript) then
if is_set(TranscriptURL) then
Transcript = external_link( TranscriptURL, Transcript,
end
Transcript = sepc .. ' ' .. Transcript .. TranscriptFormat;
elseif is_set(TranscriptURL) then
Transcript = external_link( TranscriptURL, nil,
end
Line 3,405 ⟶ 3,455:
if (is_set (Periodical) or is_set (ScriptPeriodical) or is_set (TransPeriodical)) then
if is_set(Title) or is_set(TitleNote) then
Periodical = sepc .. " " .. format_periodical (ScriptPeriodical, ScriptPeriodical_origin, Periodical, TransPeriodical, TransPeriodical_origin);
else
Periodical = format_periodical (ScriptPeriodical, ScriptPeriodical_origin, Periodical, TransPeriodical, TransPeriodical_origin);
end
end
Line 3,554 ⟶ 3,604:
if is_set(config.CitationClass) and config.CitationClass ~= "citation" then
options.class = string.format ('%s %s %s', 'citation', config.CitationClass, is_set (Mode) and Mode or 'cs1'); -- class=citation required for blue highlight when used with |ref=
else
options.class =
end
Line 3,703 ⟶ 3,752:
Look at the contents of a parameter. If the content has a string of characters and digits followed by an equal
sign, compare the alphanumeric string to the list of cs1|2 parameters. If found, then the string is possibly a
parameter that is missing its pipe. There are two tests made:
{{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
{{cite ... |title=access-date=2016-03-17}} -- the first parameter has no value (whitespace after the first = is trimmed by mediawiki)
cs1|2 shares some parameter names with xml/html atributes: class=, title=, etc. To prevent false positives xml/html
tags are removed before the search.
Line 3,718 ⟶ 3,767:
capture = value:match ('%s+(%a[%w%-]+)%s*=') or value:match ('^(%a[%w%-]+)%s*='); -- find and categorize parameters with possible missing pipes
if capture and validate (capture) then -- if the capture is a valid parameter name
table.insert( z.message_tail, {set_error ('missing_pipe', parameter)});
end
end
Line 3,731 ⟶ 3,780:
local function has_extraneous_punc (param, value)
if 'number' == type (param) then
return;
end
param = param:gsub ('%d+', '#'); -- enumerated name-list mask params allow terminal punct; normalize
if cfg.punct_skip[param] then
return; -- parameter name found in the skip table so done
Line 3,812 ⟶ 3,866:
local config = {}; -- table to store parameters from the module {{#invoke:}}
for k, v in pairs( frame.args ) do -- get parameters from the {{#invoke}} frame
config[k] = v;
--
end
local capture; -- the single supported capture when matching unknown parameters using patterns
for k, v in pairs( pframe.args ) do -- get parameters from the parent (template) frame
if v ~= '' then
if ('string' == type (k)) then
Line 3,865 ⟶ 3,919:
end
end
-- crude debug support that allows us to render a citation from module {{#invoke:}} TODO: keep?
--
-- args[k] = v; -- overwrite args[k] with empty string from pframe.args[k] (template frame); v is empty string here
end -- not sure about the postscript bit; that gets handled in parameter validation; historical artifact?
end
for k, v in pairs( args ) do
has_extraneous_punc (k, v); -- look for extraneous terminal punctuation in parameter values
end
|