Content deleted Content added
make the article name available to the featured topic categories function |
add ITN and OTD and generalise the isActive, data and text functions as helper functions |
||
Line 50:
return title
end
end
local function isActiveDatedObject(articleHistoryObj, prefix)
local args = articleHistoryObj.args
local prefixArgs = articleHistoryObj.prefixArgs
return args[prefix .. 'date'] or args[prefix .. 'date2'] or prefixArgs[prefix]
end
local function makeDateData(articleHistoryObj, prefix, suffixes)
local args = articleHistoryObj.args
local prefixArgs = articleHistoryObj.prefixArgs
-- Sanity checks
if prefixArgs[prefix] then
for _, t in ipairs(prefixArgs[prefix]) do
if not t.date then
articleHistoryObj:raiseError(
string.format(
"an argument starting with '%s%d' was detected, " ..
"but no '%s%ddate' parameter was specified",
prefix, t[1],
prefix, t[1]
),
'Template:Article history#Errors'
)
end
end
end
local function validateDate(key, date)
local longDate = getLongDate(date)
if longDate then
return longDate
else
articleHistoryObj:raiseError(
string.format(
"invalid date '%s' detected in parameter '%s'",
tostring(date),
key
),
'Template:Article history#Errors'
)
end
end
local data = {}
-- Organise the input
if args[prefix .. 'date'] then
local t = {}
do
local key = prefix .. 'date'
t.date = validateDate(key, args[key])
end
for _, suffix in ipairs(suffixes) do
local key = prefix .. suffix
t[suffix] = args[key]
end
data[#data + 1] = t
end
if args[prefix .. 'date2'] then
local t, oldKeys, newKeys = {}, {}, {}
do
local oldKey = prefix .. 'date2'
local newKey = prefix .. '2date'
t.date = validateDate(oldKey, args[oldKey])
table.insert(oldKeys, "'" .. oldKey .. "'")
table.insert(newKeys, "'" .. newKey .. "'")
end
for i, suffix in ipairs(suffixes) do
local oldKey = prefix .. suffix .. '2'
local newKey = prefix .. '2' .. suffix
table.insert(oldKeys, "'" .. oldKey .. "'")
table.insert(newKeys, "'" .. newKey .. "'")
t[suffix] = args[oldKey]
end
data[#data + 1] = t
articleHistoryObj:addWarning(
string.format(
"the %s parameters are deprecated; use %s instead",
mw.text.listToText(oldKeys),
mw.text.listToText(newKeys)
),
'Template:Article history#Errors'
)
end
if prefixArgs[prefix] then
for _, prefixData in ipairs(prefixArgs[prefix]) do
local t = {}
do
local key = prefix .. tostring(prefixData[1]) .. 'date'
t.date = validateDate(key, args[key])
end
for i, suffix in ipairs(suffixes) do
local key = prefix .. tostring(prefixData[1]) .. suffix
t[suffix] = args[key]
end
data[#data + 1] = t
end
end
if #data < 1 then
error(string.format(
"no data items found for prefix '%s' and parameter checks failed'",
tostring(prefix)
))
end
return data
end
local function makeDateText(dateData, blurb)
-- This makes the text for Main Page features such as DYKs and ITNs for the
-- dates contained in dateData (made with the makeDateData function).
-- The parameter $1 in the blurb will be replaced with the list of dates.
local dates = {}
for i, t in ipairs(dateData) do
if t.link then
dates[i] = string.format('on [[%s|%s]]', t.link, t.date)
else
dates[i] = string.format('on %s', t.date)
end
end
local dateList = mw.text.listToText(dates, ', ', ', and ')
return mw.message.newRawMessage(blurb, dateList):plain()
end
Line 1,479 ⟶ 1,603:
icon = 'DYK questionmark icon.svg',
iconCaption = 'Did You Know',
iconSmallSize = '15px',
isActive = function (articleHistoryObj)
return isActiveDatedObject(articleHistoryObj, 'dyk')
end,
makeData = function (articleHistoryObj)
return makeDateData(articleHistoryObj, 'dyk', {'entry'})
end,
text = function (articleHistoryObj, collapsibleNoticeObj)
local data = collapsibleNoticeObj:getData(articleHistoryObj)
local
.. getDate('Y/F#j F Y', data[1].date)
do
local raTitle = makeTitle(raPage)
if not raTitle or not raTitle.exists then
Line 1,567 ⟶ 1,620:
end
end
local blurb = string.format(
"A [[%s|'''fact from this article''']] appeared on " ..
"
"
"column on $1.",
raPage
)
return makeDateText(data, blurb)
end,
collapsibleText = function (articleHistoryObj, collapsibleNoticeObj)
Line 1,639 ⟶ 1,685:
return cats
end
},
-- ITN
{
id = 'ITN',
isActive = function (articleHistoryObj)
return isActiveDatedObject(articleHistoryObj, 'itn')
end,
makeData = function (articleHistoryObj)
return makeDateData(articleHistoryObj, 'itn', {'link'})
end,
icon = 'Globe current.svg',
iconCaption = 'In the news',
text = function (articleHistoryObj, collapsibleNoticeObj)
local data = collapsibleNoticeObj:getData(articleHistoryObj)
local blurb = "A news item involving this article was featured " ..
"on Wikipedia's [[Main Page]] in the " ..
"''\"[[Template:In the news|In the news]]\"'' column $1."
return makeDateText(data, blurb)
end,
categories = {'Wikipedia In the news articles'}
},
-- On this day
{
id = 'OTD',
isActive = function (articleHistoryObj)
return isActiveDatedObject(articleHistoryObj, 'otd')
end,
makeData = function (articleHistoryObj)
return makeDateData(articleHistoryObj, 'otd', {'link'})
end,
icon = 'Nuvola apps date.svg',
iconCaption = 'On this day...',
text = function (articleHistoryObj, collapsibleNoticeObj)
local data = collapsibleNoticeObj:getData(articleHistoryObj)
local blurb = "A fact from this article was featured " ..
"on Wikipedia's [[Main Page]] in the " ..
"''\"[[Wikipedia:Selected anniversaries|On this day...]]\"'' " ..
"column $1."
return makeDateText(data, blurb)
end,
categories = {'Selected anniversaries articles'}
}
},
Line 1,688 ⟶ 1,777:
-- The default size for collapsible status icons for small templates. The
-- default is 30px.
defaultSmallCollapsibleNoticeIconSize = '
-------------------------------------------------------------------------------
|