Module:Citation/CS1: Difference between revisions
Try to fix year handling for CITEREF
m>Dragons flight (Treat PublicationDate as Date is Date is absent) |
m>Dragons flight (Try to fix year handling for CITEREF) |
||
Line 79: | Line 79: | ||
function safeforurl( str ) | function safeforurl( str ) | ||
return str:gsub('%[','['):gsub('%]',']'):gsub("\n", " "); | return str:gsub('%[','['):gsub('%]',']'):gsub("\n", " "); | ||
end | |||
function selectyear( str ) | |||
local lang = mw.getContentLanguage(); | |||
local good, result; | |||
good, result = pcall( lang.formatDate, lang, 'Y', str ) | |||
if good then | |||
return result; | |||
else | |||
return ''; | |||
end | |||
end | end | ||
Line 905: | Line 916: | ||
-- Now enclose the whole thing in a <span/> element | -- Now enclose the whole thing in a <span/> element | ||
if ( Year == nil ) then | if ( Year == nil ) then | ||
if (DateIn | if ( DateIn ~= nil and DateIn ~= "" ) then | ||
Year = selectyear( DateIn ) | |||
elseif( PublicationDate ~= nil and PublicationDate ~= "" ) then | |||
end | Year = selectyear( PublicationDate ) | ||
else | |||
Year = "" | |||
end | |||
end | end | ||
local classname = "citation" | local classname = "citation" |