Content deleted Content added
Undid revision 770371918 by Mr. Stradivarius (talk) test cases are odd after deploying; reverting until I can figure out what's up |
add maindate2 again - the first time was missing an isMulti flag in the FFA/GA definition |
||
Line 56:
-- calculations.
local function getYmdDate(date)
if date then
return tonumber(date)
else
return nil
end
end
Line 885 ⟶ 890:
local status = articleHistoryObj:getStatusId()
local data = {}
local function validateMainDate(argName, dataName, dataTimestampName)
data[dataName] = args[argName]
if data[dataName] then
data[dataTimestampName] = getYmdDate(data[dataName])
if not data[dataTimestampName] then
articleHistoryObj:raiseError(
string.format(
"invalid date '%s' detected in parameter '%s'",
data[dataName],
argName
),
'Template:Article history#Invalid date'
)
end
end
end
validateMainDate('maindate', 'mainDate', 'mainDateTimestamp')
if data.mainDate then
validateMainDate('maindate2', 'mainDate2', 'mainDate2Timestamp')
if data.mainDate2 and data.mainDateTimestamp >= data.mainDate2Timestamp then
articleHistoryObj:raiseError(
"the date in the 'maindate' parameter must be earlier than the date in the 'maindate2' parameter",
'Template:Article history#Main Page date order'
)
end
else
return data
end
data.currentTimestamp = getYmdDate()
-- The first Today's Featured List was on 13 June 2011.
data.isList = (status == 'FL' or status == 'FFL') and data.mainDateTimestamp >= 20110613
Line 916 ⟶ 932:
text = function (articleHistoryObj, noticeObj)
local data = noticeObj:getData(articleHistoryObj)
if not data or not data.
return nil
end
-- Build the blurb for all the possible combinations of past,
-- present and future appearances of maindate and maindate2.
local pagetype = data.isList and 'list' or 'article'
local mainDateLong = getLongDate(data.mainDate)
local mainDate2Long = data.mainDate2 and getLongDate(data.mainDate2)
local todaysFA = "Today's featured " .. pagetype
local function makeFeaturedLink(date, display)
return string.format(
"[[Wikipedia:Today's featured %s/%s|%s]]",
pagetype,
date,
display or date
)
end
local function isPast(timestamp)
return timestamp < data.currentTimestamp
end
local function isCurrent(timestamp)
return timestamp == data.currentTimestamp
end
local function isFuture(timestamp)
return timestamp > data.currentTimestamp
end
if data.mainDate2 then
if isPast(data.mainDateTimestamp) then
if isPast(data.mainDate2Timestamp) then
return string.format(
"This article appeared on Wikipedia's Main Page as %s on %s, and on %s.",
todaysFA,
makeFeaturedLink(mainDateLong),
makeFeaturedLink(mainDate2Long)
)
elseif isCurrent(data.mainDate2Timestamp) then
return string.format(
"This article is currently on Wikipedia's Main Page as %s. It also appeared previously on %s.",
makeFeaturedLink(mainDate2Long, todaysFA),
makeFeaturedLink(mainDateLong)
)
else
return string.format(
"This article appeared on Wikipedia's Main Page as %s on %s, and will appear again on %s.",
todaysFA,
makeFeaturedLink(mainDateLong),
makeFeaturedLink(mainDate2Long)
)
end
elseif isCurrent(data.mainDateTimestamp) then
if isFuture(data.mainDate2Timestamp) then
return string.format(
"This article is currently on Wikipedia's Main Page as %s, and will appear again on %s.",
makeFeaturedLink(mainDateLong, todaysFA),
makeFeaturedLink(mainDate2Long)
)
else
return nil
end
else
if isFuture(data.mainDate2Timestamp) then
return string.format(
"This article will appear on Wikipedia's Main Page as %s on %s, and again on %s.",
todaysFA,
makeFeaturedLink(mainDateLong),
makeFeaturedLink(mainDate2Long)
)
else
return nil
end
end
else
if isPast(data.mainDateTimestamp) then
return string.format(
"This article appeared on Wikipedia's Main Page as %s on %s.",
makeFeaturedLink(mainDateLong, todaysFA),
mainDateLong
)
elseif isCurrent(data.mainDateTimestamp) then
return string.format(
"This article is currently on Wikipedia's Main Page as %s.",
makeFeaturedLink(mainDateLong, todaysFA),
mainDateLong
)
else
return string.format(
"This article will appear on Wikipedia's Main Page as %s on %s.",
makeFeaturedLink(mainDateLong, todaysFA),
mainDateLong
)
end
end
end,
categories = function (articleHistoryObj, noticeObj)
Line 944 ⟶ 1,036:
return nil
end
local status = articleHistoryObj:getStatusId()
local cats = {}
local pagetype = data.isList and 'lists' or 'articles'
if data.mainDate and data.mainDateTimestamp < data.currentTimestamp then
cats[#cats + 1] = Category.new(string.format(
'Featured %s that have appeared on the main page',
pagetype
))
if data.mainDate2 and data.mainDate2Timestamp < data.currentTimestamp then
cats[#cats + 1] = Category.new(string.format(
'Featured %s that have appeared on the main page twice',
pagetype
))
else
cats[#cats + 1] = Category.new(string.format(
'Featured %s that have appeared on the main page once',
pagetype
))
end
elseif status == 'FA' or status == 'FL' or data.mainDate then
cats[#cats + 1] = Category.new(string.format(
'Featured %s that have not appeared on the main page',
pagetype
))
end
|