Module:Article history/config: Difference between revisions

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)
returndate = tonumber(getDate('Ymd', date))
if date then
return tonumber(date)
else
return nil
end
end
 
Line 885 ⟶ 890:
local status = articleHistoryObj:getStatusId()
local data = {}
data.mainDate = args.maindate
 
local function validateMainDate(argName, dataName, dataTimestampName)
if not data.mainDate then
data[dataName] = args[argName]
if status == 'FA' then
if data[dataName] then
data.categoryOnly = 'Featured articles that have not appeared on the main page'
data[dataTimestampName] = getYmdDate(data[dataName])
elseif status == 'FL' then
if not data[dataTimestampName] then
data.categoryOnly = 'Featured lists that have not appeared on the main page'
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.mainDateTimestamp = getYmdDate(data.mainDate)
data.currentTimestamp = getYmdDate()
 
if not data.mainDateTimestamp then
articleHistoryObj:raiseError(
string.format(
"invalid date '%s' detected in parameter 'maindate'",
data.mainDate
),
'Template:Article history#Invalid date'
)
end
-- 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.categoryOnlymainDate then
return nil
end
 
-- Build the blurb for all the possible combinations of past,
local blurb = "This article %s on Wikipedia's Main Page as " ..
-- present and future appearances of maindate and maindate2.
"[[Wikipedia:Today's featured %s/%s|Today's featured %s]]%s."
local longDate = getLongDate(data.mainDate)
local pagetype = data.isList and 'list' or 'article'
local mainDateLong = getLongDate(data.mainDate)
local tenseBlurb, dateBlurb
local mainDate2Long = data.mainDate2 and getLongDate(data.mainDate2)
if data.mainDateTimestamp < data.currentTimestamp then
local todaysFA = "Today's featured " .. pagetype
tenseBlurb = 'appeared'
 
dateBlurb = ' on ' .. longDate
local function makeFeaturedLink(date, display)
elseif data.mainDateTimestamp == data.currentTimestamp then
return string.format(
tenseBlurb = 'is currently'
"[[Wikipedia:Today's featured %s/%s|%s]]",
dateBlurb = ''
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
tenseBlurb = 'will appear'
return string.format(
dateBlurb = ' on ' .. longDate
"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
return string.format(
blurb, tenseBlurb, pagetype, longDate, pagetype, dateBlurb
)
end,
categories = function (articleHistoryObj, noticeObj)
Line 944 ⟶ 1,036:
return nil
end
local status = articleHistoryObj:getStatusId()
local cats = {}
 
if data.categoryOnly then
local pagetype = data.isList and 'lists' or 'articles'
cats[1] = Category.new(data.categoryOnly)
if data.mainDate and data.mainDateTimestamp < data.currentTimestamp then
else
cats[#cats + 1] = Category.new(string.format(
'Featured %s that have appeared on the main page',
pagetype
data.isList and 'lists' or 'articles'
))
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