--------------------------------------------------------------------------------- Configuration data for -------------------------------------------------------------------------------
local lang = mw.language.getContentLanguagelocal Category = require('Module:Article history/Category')
--------------------------------------------------------------------------------- Helper functions-------------------------------------------------------------------------------
-- Makes a link to a template page surrounded by double curly braces. A-- workalike for the template.local function makeTemplateLink(s) local openb = mw.text.nowiki('') return string.format('%s%s%s', openb, s, s, closeb)end
-- Gets the Good Article topic for the given key. Uses-- .local function getGoodArticleTopic(key) if not key then return nil end return require('Module:Good article topics')._main(key)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) local link, display if topic then link = 'Wikipedia:Good articles/' .. topic display = topic .. ' good articles' else link = 'Wikipedia:Good articles' display = 'good articles' end return link, displayend
-- 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) if success then return result endend
-- 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) date = getDate('Ymd', date) if date then return tonumber(date) else return nil endend
-- Gets the date in the format Month d, YYYY.local function getLongDate(date) return getDate('F j, Y', date)end
-- Returns true if the given page is an existing title, and false or nil-- otherwiselocal function titleExists(page) local success, title = pcall(mw.title.new, page) return success and title.existsend
-- 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 local prefixArgs = articleHistoryObj.prefixArgs return args[prefix .. 'date'] or prefixArgs[prefix]end
-- Returns a date as formatted by getLongDate. If the date is invalid, it raises-- an error using param as the parameter name containing the invalid date.local function validateDate(param, date, articleHistoryObj) local longDate = getLongDate(date) if longDate then return longDate else articleHistoryObj:raiseError(string.format("invalid date '%s' detected in parameter '%s'", tostring(date), param ), 'Template:Article history#Invalid date' ) endend
-- 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 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#No date parameter' ) end end end
local data =
-- Organise the input local function addData(sep) local t = local argPrefix = prefix .. sep do local key = argPrefix .. 'date' t.date = validateDate(key, args[key], articleHistoryObj) t.month, t.day, t.year = t.date:match('(%a+) (%d+), (%d+)') t.day = tonumber(t.day) t.year = tonumber(t.year) t.ymdDate = getYmdDate(t.date) end for _, suffix in ipairs(suffixes) do local key = argPrefix .. suffix t[suffix] = args[key] end t.argPrefix = argPrefix data[#data + 1] = t end if args[prefix .. 'date'] then addData() end if prefixArgs[prefix] then for _, prefixData in ipairs(prefixArgs[prefix]) do addData(tostring(prefixData[1])) end end if #data < 1 then error(string.format("no data items found for prefix '%s' and parameter checks failed'", tostring(prefix) )) end
return dataend
-- 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, wantBold) local bold = wantBold and "" or "" local dates, doneLinks =, for i, t in ipairs(dateData) do local date if t.link and not doneLinks[t.link] then date = string.format('%s', t.link, t.date) doneLinks[t.link] = true else date = t.date end dates[i] = bold .. date .. bold end local dateList = mw.text.listToText(dates, ', ', ', and ') return mw.message.newRawMessage(blurb, dateList):plainend
return