Module:Citation/CS1:修订间差异
IdleTap-bot(留言 | 贡献) 导入自求闻百科 |
zhwiki>Shizhao test,缓解phab:T437056 |
||
| 第152行: | 第152行: | ||
]] | ]] | ||
local function validate_date (AccessDate, Date, DoiBroken, Embargo, LayDate, PublicationDate, Year, COinS_date, origin) | local function validate_date (AccessDate, ArchiveDate, Date, DoiBroken, Embargo, LayDate, PublicationDate, Year, COinS_date, origin) | ||
local error_message = ''; | local error_message = ''; | ||
-- AirDate has been promoted to Date so not necessary to check it | -- AirDate has been promoted to Date so not necessary to check it | ||
anchor_year, error_message = dates ({['access-date']=AccessDate, ['date']=Date, ['doi-broken-date']=DoiBroken, | 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); | ['embargo']=Embargo, ['lay-date']=LayDate, ['publication-date']=PublicationDate, ['year']=Year}, COinS_date); | ||
| 第263行: | 第263行: | ||
]] | ]] | ||
local function set_cs1_style (ps) | local function set_cs1_style (ps, ref) | ||
if not is_set (ps) then -- unless explicitely set to something | if not is_set (ps) then -- unless explicitely set to something | ||
ps = '.'; -- terminate the rendered citation with a period | ps = '.'; -- terminate the rendered citation with a period | ||
end | end | ||
return '.', ps; -- separator is a full stop | if not is_set(ref) then -- if |ref= is not set | ||
ref = 'harv'; -- set default |ref=harv | |||
end | |||
return '.', ps, ref; -- separator is a full stop | |||
end | end | ||
| 第298行: | 第301行: | ||
sep, ps, ref = set_cs2_style (ps, ref); | sep, ps, ref = set_cs2_style (ps, ref); | ||
else -- not a citation template so CS1 | else -- not a citation template so CS1 | ||
sep, ps = set_cs1_style (ps); | sep, ps, ref = set_cs1_style (ps, ref); | ||
end | end | ||
| 第317行: | 第320行: | ||
sep, ps, ref = set_cs2_style (ps, ref); | sep, ps, ref = set_cs2_style (ps, ref); | ||
elseif 'cs1' == mode then -- if this template is to be rendered in CS1 (cite xxx) style | elseif 'cs1' == mode then -- if this template is to be rendered in CS1 (cite xxx) style | ||
sep, ps = set_cs1_style (ps); | sep, ps, ref = set_cs1_style (ps, ref); | ||
else -- anything but cs1 or cs2 | else -- anything but cs1 or cs2 | ||
sep, ps, ref = get_settings_from_cite_class (ps, ref, cite_class); -- get settings based on the template's CitationClass | sep, ps, ref = get_settings_from_cite_class (ps, ref, cite_class); -- get settings based on the template's CitationClass | ||
| 第326行: | 第329行: | ||
return sep, ps, ref | return sep, ps, ref | ||
end | |||
--[[--------------------------< S W A P _ U R L S >-------------------------------------------------------------- | |||
]] | |||
local function swap_urls (url_object, chapter_url_object, archive_url_object, dead_url) | |||
local original_url_object = create_url_object (); | |||
local is_dead = in_array (dead_url, cfg.keywords['deadurl-live']); -- used later when assembling archived text | |||
if is_set (archive_url_object['url']) then | |||
if is_set (url_object['url']) then | |||
original_url_object = url_object; | |||
if not is_dead then | |||
url_object = archive_url_object; | |||
end | |||
elseif is_set (chapter_url_object['url']) then -- URL not set so if chapter-url is set apply archive url to it | |||
original_url_object = chapter_url_object; | |||
if not is_dead then | |||
chapter_url_object = archive_url_object; | |||
end | |||
end | |||
end | |||
return original_url_object, url_object, chapter_url_object; | |||
end | end | ||
| 第706行: | 第733行: | ||
end | end | ||
return ''; | return ''; | ||
end | |||
--[[--------------------------< F O R M A T _ A R C H I V E >------------------------------------------ | |||
]] | |||
local function format_archive (archive_url_object, original_url_object, archive_date, dead_url, sepc, lower) | |||
local archived = ''; | |||
if is_set (archive_url_object['url']) then | |||
if not is_set (archive_date) then | |||
archive_date = set_error ('archive_missing_date'); | |||
end | |||
if in_array (dead_url, cfg.keywords['deadurl-live']) then | |||
local arch_text = cfg.messages['archived']; | |||
if (lower) then arch_text = arch_text:lower(); end; | |||
archived = pend_separator (wrap_msg ('archived-not-dead', {make_external_link (archive_url_object['url'], arch_text, archive_url_object['origin']) .. archive_url_object['format'], archive_date }, lower), sepc, true); | |||
if not is_set (original_url_object['url']) then | |||
archived = archived .. ' ' .. set_error ('archive_missing_url'); | |||
end | |||
elseif is_set (original_url_object['url']) then -- dead_url is not live, so it should be empty, dead or unfit | |||
if in_array (dead_url, cfg.keywords['deadurl-unfit']) then | |||
archived = pend_separator (wrap_msg('archived-unfit', archive_date, lower), sepc, true); | |||
-- format already styled | |||
else -- dead_url is empty or dead | |||
archived = pend_separator (wrap_msg ('archived-dead', | |||
{make_external_link (original_url_object['url'], cfg.messages['original'], original_url_object['origin']) .. original_url_object['access-text'] .. original_url_object['format'], archive_date }, lower), sepc, true); | |||
-- format already styled | |||
end | |||
else | |||
archived = pend_separator (wrap_msg ('archived-missing', | |||
{set_error ('archive_missing_url'), archive_date }, lower), sepc, true); | |||
end | |||
elseif is_set (original_url_object['format']) then | |||
archived = original_url_object['format']; -- if set and archive_url not set archive_format has error message | |||
end | |||
return archived; | |||
end | end | ||
| 第940行: | 第1,003行: | ||
local ConferenceURLobject = create_url_object (A['ConferenceURL'], A:ORIGIN ('ConferenceURL'), A['ConferenceFormat'], A:ORIGIN ('ConferenceFormat')); | local ConferenceURLobject = create_url_object (A['ConferenceURL'], A:ORIGIN ('ConferenceURL'), A['ConferenceFormat'], A:ORIGIN ('ConferenceFormat')); | ||
local ArchiveURLobject = create_url_object (A['ArchiveURL'], A:ORIGIN ('ArchiveURL'), A['ArchiveFormat'], A:ORIGIN ('ArchiveFormat')); | |||
local URLobject = create_url_object (A['URL'], A:ORIGIN ('URL'), A['Format'], A:ORIGIN ('Format'),A['UrlAccess'], A:ORIGIN ('UrlAccess')); | local URLobject = create_url_object (A['URL'], A:ORIGIN ('URL'), A['Format'], A:ORIGIN ('Format'),A['UrlAccess'], A:ORIGIN ('UrlAccess')); | ||
local TranscriptURLobject = create_url_object (A['TranscriptURL'], A:ORIGIN ('TranscriptURL'), A['TranscriptFormat'], A:ORIGIN ('TranscriptFormat')); | local TranscriptURLobject = create_url_object (A['TranscriptURL'], A:ORIGIN ('TranscriptURL'), A['TranscriptFormat'], A:ORIGIN ('TranscriptFormat')); | ||
| 第1,033行: | 第1,097行: | ||
local Via = A['Via']; | local Via = A['Via']; | ||
local AccessDate = A['AccessDate']; | local AccessDate = A['AccessDate']; | ||
local ArchiveDate = A['ArchiveDate']; | |||
local Agency = A['Agency']; | local Agency = A['Agency']; | ||
local DeadURL = sanitized_parameter_value (A['DeadURL'], A:ORIGIN ('DeadURL'), 'deadurl', ''); | |||
local Language = A['Language']; | local Language = A['Language']; | ||
| 第1,403行: | 第1,469行: | ||
local COinS_date = {}; -- holds date info extracted from |date= for the COinS metadata by Module:Date verification | local COinS_date = {}; -- holds date info extracted from |date= for the COinS metadata by Module:Date verification | ||
local anchor_year = validate_date (AccessDate, Date, DoiBroken, Embargo, LayDate, PublicationDate, Year, COinS_date, Dateorigin); | local anchor_year = validate_date (AccessDate, ArchiveDate, Date, DoiBroken, Embargo, LayDate, PublicationDate, Year, COinS_date, Dateorigin); | ||
-- used in the CITEREF identifier | -- used in the CITEREF identifier | ||
| 第1,511行: | 第1,577行: | ||
-- apply |[xx-]format= styling; at the end, these parameters hold correctly styled format annotation, | -- apply |[xx-]format= styling; at the end, these parameters hold correctly styled format annotation, | ||
-- an error message if the associated url is not set, or an empty string for concatenation | -- an error message if the associated url is not set, or an empty string for concatenation | ||
format_format ({ConferenceURLobject, URLobject, LayURLobject, TranscriptURLobject, ChapterURLobject}); | format_format ({ArchiveURLobject, ConferenceURLobject, URLobject, LayURLobject, TranscriptURLobject, ChapterURLobject}); | ||
-- special case for chapter format so no error message or cat when chapter not supported | -- special case for chapter format so no error message or cat when chapter not supported | ||
| 第1,519行: | 第1,585行: | ||
format_url_access_text (ChapterURLobject, nil, nil); | format_url_access_text (ChapterURLobject, nil, nil); | ||
local OriginalURLobject; -- TODO: swap chapter and title here so that archive applies to most specific if both are set? | |||
OriginalURLobject, URLobject, ChapterURLobject = | |||
swap_urls (URLobject, ChapterURLobject, ArchiveURLobject, DeadURL); | |||
local chapter_no_quotes = false; -- default assume that we will be quoting the chapter parameter value | local chapter_no_quotes = false; -- default assume that we will be quoting the chapter parameter value | ||
if is_set (Contribution) and has_contributors then -- if this is a contribution with contributor(s) | if is_set (Contribution) and has_contributors then -- if this is a contribution with contributor(s) | ||
| 第1,561行: | 第1,631行: | ||
local Format = URLobject['format']; | local Format = URLobject['format']; | ||
Quote = format_quote (Quote, sepc); | Quote = format_quote (Quote, sepc); | ||
local Archived = format_archive (ArchiveURLobject, OriginalURLobject, ArchiveDate, DeadURL, sepc, use_lowercase); | |||
local Lay = format_lay (LayURLobject, LayDate, LaySource, sepc, use_lowercase); | local Lay = format_lay (LayURLobject, LayDate, LaySource, sepc, use_lowercase); | ||
Transcript = format_external_link (Transcript, TranscriptURLobject, sepc); | Transcript = format_external_link (Transcript, TranscriptURLobject, sepc); | ||
| 第1,627行: | 第1,698行: | ||
-- END LOCAL | -- END LOCAL | ||
local idcommon = safe_join ({URL, xDate, ID_list, Via, Lay, Language, Quote}, sepc); | local idcommon = safe_join ({URL, xDate, ID_list, Archived, Via, Lay, Language, Quote}, sepc); | ||
local text; | local text; | ||
if is_set (Authors) then | if is_set (Authors) then | ||
| 第1,689行: | 第1,760行: | ||
]] | ]] | ||
function citation (frame) | local function citation (frame) | ||
local pframe = frame:getParent(); | local pframe = frame:getParent(); | ||
local module_path = 'Module:Citation/CS1/' | local module_path = 'Module:Citation/CS1/' | ||
| 第1,759行: | 第1,830行: | ||
end | end | ||
end | end | ||
return do_citation (config, args) | return table.concat ({ | ||
frame:extensionTag ('templatestyles', '', {src='Module:Citation/CS1/styles.css'}), | |||
do_citation (config, args) | |||
}); | |||
end | end | ||