Module:Article history/config: Difference between revisions

Content deleted Content added
remove the status-unknown message, as there will always be an error message displayed for unknown currentstatus values
add comments for the helper functions
Line 10:
-------------------------------------------------------------------------------
 
-- Makes a link to a template page surrounded by double curly braces. A
-- workalike for the {{tl}} template.
local function makeTemplateLink(s)
local openb = mw.text.nowiki('{{')
Line 16 ⟶ 18:
end
 
-- Gets the Good Article topic for the given key. Uses
-- [[Module:Good article topics]].
local function getGoodArticleTopic(key)
if not key then
Line 23 ⟶ 27:
end
 
-- Returns the Good Article page link and display value for a given Good Article
-- key. If the key wasn't valid, the default Good Article page and display value
-- is returned instead.
local function getGoodArticleTopicLink(key)
local topic = getGoodArticleTopic(key)
Line 36 ⟶ 43:
end
 
-- Wrapper function for mw.language:formatDate, going through pcall to catch
-- invalid input errors.
local function getDate(format, date)
local success, result = pcall(lang.formatDate, lang, format, date)
Line 43 ⟶ 52:
end
 
-- Gets the date in the format YYYYMMDD, as a number. Months and dates are
-- zero-padded. Results from this function are intended to be used in date
-- calculations.
local function getYmdDate(date)
return tonumber(getDate('Ymd', date))
end
 
-- Gets the date in the format Month d, YYYY.
local function getLongDate(date)
return getDate('F j, Y', date)
end
 
-- Wrapper function for mw.title.new.
local function makeTitle(page)
local success, title = pcall(mw.title.new, page)
Line 58 ⟶ 72:
end
 
-- Returns a truthy value if a date parameter for the given prefix has been
-- provided by the user.
local function isActiveDatedObject(articleHistoryObj, prefix)
local args = articleHistoryObj.args
Line 64 ⟶ 80:
end
 
-- Returns a date as formatted by getLongDate. If the date is invalid, it raises
local function validateDate(key, date, articleHistoryObj)
-- an error using param as the parameter name containing the invalid date.
local function validateDate(keyparam, date, articleHistoryObj)
local longDate = getLongDate(date)
if longDate then
Line 73 ⟶ 91:
"invalid date '%s' detected in parameter '%s'",
tostring(date),
keyparam
),
'Template:Article history#Invalid date'
Line 80 ⟶ 98:
end
 
-- Generates a data table for a date-related notice such as DYK and ITN. prefix
-- is the parameter prefix for that notice type (e.g. "dyk"), and suffixes is
-- an array of parameter suffixes in addition to "date" that is used by that
-- notice type (e.g. "entry" for the "dykentry" and "dyk2entry" parameters).
local function makeDateData(articleHistoryObj, prefix, suffixes)
local args = articleHistoryObj.args
Line 153 ⟶ 175:
end
 
-- 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 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
Line 169 ⟶ 191:
end
 
-- Returns a deprecated parameters category if the data table passed to it has
-- a deprecated parameters flag set.
local function makeDeprecatedParamsCategory(data)
if data and data.hasDeprecatedParams then