มอดูล:Article history/config

-------------------------------------------------------------------------------
--              Configuration data for Module:Article history
-------------------------------------------------------------------------------
local lang = mw.language.getContentLanguage()
local Category = require('มอดูล: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
-- Module:Good article topics.
local function getGoodArticleTopic(key)
	if not key then
		return nil
	end
	return require('มอดูล: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 = 'วิกิพีเดีย:บทความคุณภาพ/' .. topic
		display = topic .. ' บทความคุณภาพ'
	else
		link = 'วิกิพีเดีย:บทความคุณภาพ'
		display = 'บทความคุณภาพ'
	end
	return link, display
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)
	if success then
		return result
	end
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)
	date = getDate('Ymd', date)
	if date then
		return tonumber(date)
	else
		return nil
	end
end
-- 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
-- otherwise
local function titleExists(page)
	local success, title = pcall(mw.title.new, page)
	return success and title.exists
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
	local prefixArgs = articleHistoryObj.prefixArgs
	return argsprefix .. 'date' or prefixArgsprefix
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
			),
			'แม่แบบ:Article history#Invalid date'
		)
	end
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
	local prefixArgs = articleHistoryObj.prefixArgs
	-- Sanity checks
	if prefixArgsprefix then
		for _, t in ipairs(prefixArgsprefix) 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, t1,
						prefix, t1
					),
					'แม่แบบ: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, argskey, 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
			tsuffix = argskey
		end
		t.argPrefix = argPrefix
		data#data + 1 = t
	end
	if argsprefix .. 'date' then
		addData()
	end
	if prefixArgsprefix then
		for _, prefixData in ipairs(prefixArgsprefix) do
			addData(tostring(prefixData1))
		end
	end
	if #data แต่หากไม่เข้าเกณฑ์อีกต่อไป คุณสามารถ" ..
				"ประเมินซ้ำได้"
			return string.format(text, articlePage, link, display)
		end,
		categories = function (articleHistoryObj)
			local ret = {}
			local title = articleHistoryObj.currentTitle
			if title.namespace == 1 then
				ret#ret + 1 = Category.new('Wikipedia good articles')
				ret#ret + 1 = Category.new('Wikipedia CD Selection-GAs')
				local topic = getGoodArticleTopic(articleHistoryObj.args.topic)
				if topic then
					ret#ret + 1 = Category.new(
						topic .. ' good articles',
						title.text
					)
				else
					ret#ret + 1 = Category.new(
						'Good articles without topic parameter',
						title.text
					)
				end
			end
			return ret
		end
	},
	FGAN = {
		id = 'FGAN',
		name = 'Former good article nominee',
		aliases = {'FAILEDGA'},
		icon = 'Symbol unsupport vote.svg',
		text = function (articleHistoryObj)
			local articlePage = articleHistoryObj.currentTitle.subjectPageTitle.prefixedText
			local link, display = getGoodArticleTopicLink(articleHistoryObj.args.topic)
			local text = "%s was a %s nominee, " ..
				"but did not meet the good article criteria " ..
				"at the time. There are suggestions below for improving the article. " ..
				"Once these issues have been addressed, the article can be " ..
				"renominated. " ..
				"Editors may also seek a reassessment " ..
				"of the decision if they believe there was a mistake."
			return string.format(text, articlePage, link, display)
		end,
		categories = {'Former good article nominees'}
	},
	DGA = {
		id = 'DGA',
		name = 'Delisted good article',
		aliases = {'DELISTEDGA'},
		icon = 'Symbol unsupport vote.svg',
		iconCaption = 'Former good article',
		text = function (articleHistoryObj)
			local articlePage = articleHistoryObj.currentTitle.subjectPageTitle.prefixedText
			local link, display = getGoodArticleTopicLink(articleHistoryObj.args.topic)
			local text = "%s was one of the %s, " ..
				"but it has been removed from the list. " ..
				"There are suggestions below for improving the article to meet the " ..
				"good article criteria. " ..
				"Once these issues have been addressed, the article can be " ..
				"renominated. " ..
				"Editors may also seek a reassessment " ..
				"of the decision if they believe there was a mistake."
			return string.format(text, articlePage, link, display)
		end,
		categories = {'Delisted good articles'}
	},
	FFT = {
		id = 'FFT',
		name = 'Part of former featured topic',
		icon = 'Cscr-featured-strike.svg',
		iconCaption = 'Former featured topic',
		text = "This article is part of a " ..
			"former featured topic series. " ..
			"If it has improved again to " ..
			"featured topic standard, " ..
			"you may renominate " ..
			"the topic to become a featured topic."
	},
	FFTC = {
		id = 'FFTC',
		name = 'Former featured topic candidate',
		icon = 'Cscr-former.svg',
		text = "This article is part of a former " ..
			"featured topic candidate. " ..
			"Please view the links under Article milestones below to see why " ..
			"the nomination failed."
	},
	FPO = {
		id = 'FPO',
		name = 'Featured portal',
		icon = 'Cscr-featured.svg',
		text = "The $2 Portal is a featured portal, " ..
			"which means it has been " ..
			"identified " ..
			"as one of the best portals on Wikipedia. " ..
			"If you see a way this portal can be updated or improved without " ..
			"compromising previous work, please feel free to contribute.",
		categories = function (articleHistoryObj)
			return {Category.new(
				'Wikipedia featured portals',
				articleHistoryObj.currentTitle.text
			)}
		end
	},
	FFPO = {
		id = 'FFPO',
		name = 'Former featured portal',
		icon = 'Featured article star - cross.svg',
		text = "This portal is a former featured portal. " ..
			"Please see the links under Portal milestones below for its " ..
			"original nomination page and why it was removed.",
		categories = function (articleHistoryObj)
			return {Category.new(
				'Wikipedia former featured portals',
				articleHistoryObj.currentTitle.text
			)}
		end
	},
	FFPOC = {
		id = 'FFPOC',
		name = 'Former featured portal candidate',
		icon = 'Cscr-former.svg',
		text = "This portal is a former " ..
			"featured portal candidate. " ..
			"Please see the links under Portal milestones below for its " ..
			"original nomination page and why the nomination failed.",
		categories = function (articleHistoryObj)
			return {Category.new(
				'Wikipedia featured portal candidates (contested)',
				articleHistoryObj.currentTitle.text
			)}
		end
	},
	PR = {
		-- Peer review is a valid current status, but it doesn't trigger a
		-- header row.
		id = 'PR',
		name = 'Peer reviewed',
		noticeBarIcon = 'Nuvola apps kedit.svg'
	},
	NA = {
		-- A valid current status, but doesn't trigger a header row.
		id = 'NA',
		noticeBarIcon = 'Nuvola apps kedit.svg'
	},
	-- The following are invalid statuses.
	FAC = {
		id = 'FAC',
		text = function (articleHistoryObj)
			articleHistoryObj:raiseError(
				string.format(
					'use the template %s to nominate an article for Featured article status',
					makeTemplateLink('fac')
				),
				'แม่แบบ:Article history#Featured article candidates'
			)
		end
	},
	FAR = {
		id = 'FAR',
		text = function (articleHistoryObj)
			articleHistoryObj:raiseError(
				string.format(
					'use the template %s to nominate an article for Featured article review',
					makeTemplateLink('FAR')
				),
				'แม่แบบ:Article history#Featured article review'
			)
		end
	},
	STUB = {
		id = 'STUB',
		aliases = {'START', 'B', 'A'},
		text = function (articleHistoryObj)
			local currentStatusParam = articleHistoryObj.cfg.currentStatusParam
			articleHistoryObj:raiseError(
				string.format(
					"do not use '%s' as value of the '%s' parameter; these " ..
						'assessments are the responsibility of individual ' ..
						'WikiProjects',
					articleHistoryObj.argscurrentStatusParam,
					currentStatusParam
				),
				'แม่แบบ:Article history#WikiProject assessments'
			)
		end
	},
},
-- This function allows the generation of custom status ID. It takes an
-- articleHistory object as the first parameter, and should output the status
-- ID.
getStatusIdFunction = function (articleHistoryObj)
	-- Get the status ID. The status code is the code passed in from the
	-- arguments, and the ID is the value contained in the config.
	local statuses = articleHistoryObj.cfg.statuses
	local statusCode = articleHistoryObj.argsarticleHistoryObj.cfg.currentStatusParam
	local statusId = articleHistoryObj:getStatusIdForCode(statusCode)
	-- Check for former featured articles.
	if statusId ~= 'FA'
		and statusId ~= 'FL'
		and statusId ~= 'FFA'
		and statusId ~= 'FFL'
		and statusId ~= 'FFA/GA'
	then
		local ffaObj
		local actions = articleHistoryObj:getActionObjects()
		for i = #actions, 1, -1 do
			local actionObj = actionsi
			if actionObj.id == 'FAR' and actionObj.resultId == 'demoted' then
				ffaObj = actionObj
				break
			end
		end
		if ffaObj then
			if not statusId then
				articleHistoryObj:raiseError(
					'former featured articles should have a current status',
					'แม่แบบ:Article history#Former featured articles'
				)
			elseif statusId == 'GA' then
				statusId = 'FFA/GA'
			elseif statusId == 'DGA' then
				statusId = 'FFA'
			else
				articleHistoryObj:raiseError(
					string.format(
						"'%s' is not a valid current status for former featured articles",
						tostring(statusCode)
					),
					'แม่แบบ:Article history#Former featured articles'
				)
			end
		end
	end
	return statusId
end,
-------------------------------------------------------------------------------
-- Notices
-------------------------------------------------------------------------------
-- The notices table contains configuration tables for notices about the article
-- that are unrelated to its current status.
-- Each configuration table can have the following fields:
--
-- id: the main ID for the notice. This should be the same as the configuration
--    table key.
-- isActive: a function that should return a truthy value if the notice should
--    be displayed, and a falsy value if not. (Falsy values are false and nil,
--    and truthy values are everything else.) The function takes an article
--    history object as its first parameter.
-- makeData: a function that should return a table of data to be used by other
--    functions in this notice configuration table. It can be accessed using
--    noticeObj:getData().
-- icon: the filename of the notice icon, minus the "File:" prefix.
-- iconCaption: the icon caption.
-- iconSize: The icon size, including "px" suffix. The default is defined in
--    defaultIconSize.
-- iconSmallSize: The icon size if we are outputting a small template. The
--    default is defined in defaultSmallIconSize.
-- text: The notice text. This may be a string or a function. If it is a
--    function, it takes an article history object as the first parameter, and
--    the current notice object as the second parameter, and should return the
--    text string.
-- categories: The categories set by the notice. This may be an array of
--    category names, or a function. If it is a function, it takes an article
--    history object as the first parameter, and the current notice object as
--    the second parameter, and should return an array of category objects.
-- noticeBarIcon: the icon to use for the notice bar. This can be a string, or
--    a function, or true. If it is a function it takes an article history
--    object as the first parameter, and should output the icon filename. If it
--    is true, it uses the value of icon. If it is nil then no notice bar icon
--    will be displayed.
-- noticeBarIconCaption: the caption to use for the notice bar icon. This can be
--    a string or a function. If it is a function, it takes an article history
--    object as its first parameter, and should return the caption text. If this
--    is absent, the icon caption is used instead.
-- noticeBarIconSize: the size of the notice bar icon, including "px" suffix.
--    The default is set by defaultNoticeBarIconSize.
notices = {
	{
		id = 'FT',
		isActive = function (articleHistoryObj)
			local args = articleHistoryObj.args
			local prefixArgs = articleHistoryObj.prefixArgs
			-- ftmain is included here because it leads to better error
			-- messages than leaving it out, even though ftmain by itself is
			-- invalid.
			return args.ftname or args.ftmain or prefixArgs.ft
		end,
		makeData = function (articleHistoryObj)
			local args = articleHistoryObj.args
			local prefixArgs = articleHistoryObj.prefixArgs
			local data = {}
			local getTopicStatus = require('มอดูล:FeaturedTopicSum').status
			local yesno = require('มอดูล:Yesno')
			local function makeTopicData(name, isMain, paramNum)
				if name then
					return {
						name = name,
						isMain = yesno(isMain) or false,
						status = getTopicStatus(name),
						paramNum = paramNum
					}
				elseif isMain then
					local num = paramNum and tostring(paramNum) or 
					articleHistoryObj:raiseError(
						string.format(
							"parameter 'ft%smain' is set, but no featured " ..
								"topic name is set in parameter 'ft%sname'",
							num, num
						),
						'แม่แบบ:Article history#Featured topic names'
					)
				else
					return nil
				end
			end
			data#data + 1 = makeTopicData(args.ftname, args.ftmain)
			if prefixArgs.ft then
				for i, t in ipairs(prefixArgs.ft) do
					if t1 > 1 then -- we use args.ftname instead of args.ft1name
						data#data + 1 = makeTopicData(t.name, t.main, t1)
					end
				end
			end
			-- Check for rogue ft.. parameters
			if #data  1
				text#text + 1 = string.format(
					finalBlurb,
					isPlural and thisPlural or thisSingular,
					isPlural and itPlural or itSingular
				)
			end
			return table.concat(text, ' ')
		end,
		categories = function (articleHistoryObj, noticeObj)
			local data = noticeObj:getData(articleHistoryObj)
			if not data then
				return nil
			end
			local status = articleHistoryObj:getStatusId()
			local article = articleHistoryObj.currentTitle.subjectPageTitle.prefixedText
			local cats = {}
			local function addCat(cat, sort)
				cats#cats + 1 = Category.new(cat, sort)
			end
			-- Page-wide status categories
			if status == 'FA' then
				addCat('FA-Class Featured topics articles')
			elseif status == 'FL' then
				addCat('FL-Class Featured topics articles')
			elseif status == 'FFA/GA' or status == 'GA' then
				addCat('GA-Class Featured topics articles')
			else
				addCat('Unassessed Featured topics articles')
			end
			-- Topic-specific status categories
			local function addTopicCats(catFormat)
				for i, topic in ipairs(data) do
					addCat(string.format(catFormat, topic.name))
				end
			end
			if status == 'FA' or status == 'FL' then
				addTopicCats('Wikipedia featured topics %s featured content')
			elseif status == 'FFA/GA' or 'GA' then
				addTopicCats('Wikipedia featured topics %s good content')
			else
				addTopicCats('Wikipedia featured topics %s')
			end
			-- Importance categories
			local hasTop, hasHigh, hasMid, hasLow -- These check for dupes
			for i, topic in ipairs(data) do
				local cat, sort
				if topic.status == 'FT' then
					if topic.isMain and not hasTop then
						cat = 'Top-importance Featured topics articles'
						sort = topic.name .. ' ' .. article
						hasTop = true
					elseif not topic.isMain and not hasHigh then
						cat = 'High-importance Featured topics articles'
						hasHigh = true
					end
				else
					if topic.isMain and not hasMid then
						cat = 'Mid-importance Featured topics articles'
						sort = topic.name .. ' ' .. article
						hasMid = true
					elseif not topic.isMain and not hasLow then
						cat = 'Low-importance Featured topics articles'
						hasLow = true
					end
				end
				if cat then
					addCat(cat, sort)
				end
			end
			return cats
		end
	},
	-- Main page date
	{
		id = 'MAINDATE',
		isActive = function (articleHistoryObj)
			local args = articleHistoryObj.args
			local status = articleHistoryObj:getStatusId()
			return args.maindate or status == 'FA' or status == 'FL'
		end,
		makeData = function (articleHistoryObj)
			local args = articleHistoryObj.args
			local status = articleHistoryObj:getStatusId()
			local data = {}
			local function validateMainDate(argName, dataName, dataTimestampName)
				datadataName = argsargName
				if datadataName then
					datadataTimestampName = getYmdDate(datadataName)
					if not datadataTimestampName then
						articleHistoryObj:raiseError(
							string.format(
								"invalid date '%s' detected in parameter '%s'",
								datadataName,
								argName
							),
							'แม่แบบ: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",
						'แม่แบบ:Article history#Main Page date order'
					)
				end
			end
			data.currentTimestamp = getYmdDate()
			
			-- Whether the page is a list or not for the purposes of the Main
			-- Page. The first Today's Featured List was on 13 June 2011, so
			-- lists that were featured before then count as articles.
			data.isList = (status == 'FL' or status == 'FFL')
				and (not data.mainDate or data.mainDateTimestamp >= 20110613)
			return data
		end,
		icon = 'Wikipedia-logo-v2.svg',
		iconCaption = 'Main Page trophy',
		text = function (articleHistoryObj, noticeObj)
			local data = noticeObj:getData(articleHistoryObj)
			if not data or not data.mainDate then
				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(
					"%s",
					pagetype,
					date,
					display or date
				)
			end
			local function isPast(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)
			local data = noticeObj:getData(articleHistoryObj)
			if not data then
				return nil
			end
			local status = articleHistoryObj:getStatusId()
			local cats = {}
			local pagetype = data.isList and 'lists' or 'articles'
			if data.mainDate and data.mainDateTimestamp  1 then
					ctext#ctext + 1 = 'The text of the entries was:\n'
					local list = mw.html.create('ul')
					for i, t in ipairs(data) do
						if t.entry then
							list:tag('li'):wikitext(string.format(
								"%s: Did you know %s",
								t.date, t.entry
							))
						end
					end
					ctext#ctext + 1 = tostring(list)
				end
			end
			if #ctext > 0 then
				return table.concat(ctext)
			else
				return nil
			end
		end,
		categories = function (articleHistoryObj, collapsibleNoticeObj)
			local cats = {}
			local status = articleHistoryObj:getStatusId()
			local cat
			if status == 'FA' then
				cat = 'Wikipedia Did you know articles that are featured articles'
			elseif status == 'FL' then
				cat = 'Wikipedia Did you know articles that are featured lists'
			elseif status == 'GA' or status == 'FFA/GA' then
				cat = 'Wikipedia Did you know articles that are good articles'
			else
				cat = 'Wikipedia Did you know articles'
			end
			cats1 = Category.new(cat)
			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',
		noticeBarIcon = true,
		noticeBarIconSize = '20px',
		text = function (articleHistoryObj, collapsibleNoticeObj)
			local data = collapsibleNoticeObj:getData(articleHistoryObj)
			if not data then
				return nil
			end
			local dates = {}
			for i, t in ipairs(data) do
				local date = {}
				if t.link then
					date.link = t.link
				elseif t.ymdDate >= 20090101 then
					date.link = string.format(
						'Wikipedia:ITN archives/%d/%s',
						t.year,
						t.month
					)
				elseif t.ymdDate >= 20050101 then
					date.link = string.format(
						'Portal:Current events/%d %s %d',
						t.year,
						t.month,
						t.day
					)
				end
				date.date = t.date
				dates#dates + 1 = date
			end
			local intro
			if #data > 1 then
				intro = 'News items involving this article were'
			else
				intro = 'A news item involving this article was'
			end
			local blurb = intro ..
				" featured on Wikipedia's Main Page in the " ..
				"\"In the news\" column on $1."
			return makeDateText(dates, blurb)
		end,
		categories = function (articleHistoryObj, collapsibleNoticeObj)
			local cats = {}
			cats1 = Category.new('Wikipedia In the news articles')
			return cats
		end
	},
	-- On This Day
	{
		id = 'OTD',
		isActive = function (articleHistoryObj)
			return isActiveDatedObject(articleHistoryObj, 'otd')
		end,
		makeData = function (articleHistoryObj)
			return makeDateData(articleHistoryObj, 'otd', {'link', 'oldid'})
			-- TODO: remove 'link' after it is no longer needed for tracking
		end,
		icon = 'Nuvola apps date.svg',
		iconCaption = 'On this day...',
		noticeBarIcon = true,
		noticeBarIconSize = '20px',
		text = function (articleHistoryObj, collapsibleNoticeObj)
			local data = collapsibleNoticeObj:getData(articleHistoryObj)
			if not data then
				return nil
			end
			local dates = {}
			for i, t in ipairs(data) do
				local date = {}
				date.date = t.date
				date.link = t.link
				if t.oldid then
					-- TODO: Move this inside the main module
					local oldid = tonumber(t.oldid)
					if oldid and 
						math.floor(oldid) == oldid and
						oldid > 0 and
						oldid  1 then
				intro = 'Facts from this article were'
			else
				intro = 'A fact from this article was'
			end
			local blurb = intro ..
				" featured on Wikipedia's Main Page in the " ..
				"\"On this day...\" " ..
				"column on $1."
			return makeDateText(dates, blurb)
		end,
		categories = function (articleHistoryObj, collapsibleNoticeObj)
			local cats = {}
			cats1 = Category.new('Selected anniversaries articles')
			local data = collapsibleNoticeObj:getData(articleHistoryObj)
			if data then
				for i, t in ipairs(data) do
					if t.link then
						cats#cats + 1 = Category.new(
							'Article history templates with linked otd dates'
						)
						break
					end
				end
			end
			return cats
		end
	},
	-- Article Collaboration and Improvement Drive
	{
		id = 'ACID',
		isActive = function (articleHistoryObj)
			return articleHistoryObj.args.aciddate
		end,
		icon = 'Article Collaboration and Improvement Drive.svg',
		iconCaption = 'Article Collaboration and Improvement Drive',
		noticeBarIcon = true,
		noticeBarIconSize = '20px',
		text = function (articleHistoryObj)
			local args = articleHistoryObj.args
			local blurb = 'This article was on the ' ..
				'Article Collaboration and Improvement Drive ' ..
				'for the week of %s.'
			local date = validateDate('aciddate', args.aciddate)
			return string.format(blurb, date)
		end
	},
	-- League of Copy Editors
	{
		id = 'LOCE',
		isActive = function (articleHistoryObj)
			return articleHistoryObj.args.loceNotAnActiveOption
		end,
		icon = 'LoCiconRevised.png',
		iconCaption = 'League of Copyeditors',
		iconSize = '25px',
		noticeBarIcon = true,
		text = 'This article, or a portion of it, was copyedited by the ' ..
			'League of Copyeditors.'
	}
},
-------------------------------------------------------------------------------
-- Notice bar icons
-------------------------------------------------------------------------------
-- This table holds configuration tables for notice bar icons that don't appear
-- as part of a row. Other notice bar icons are handled in the statuses,
-- notices, actions, and collapsibleNotices tables.
-- It accepts the following fields:
-- isActive: a function that should return a truthy value if the notice should
--    be displayed, and a falsy value if not. (Falsy values are false and nil,
--    and truthy values are everything else.) The function takes an article
--    history object as its first parameter.
-- icon: the filename of the notice bar icon, minus the "File:" prefix.
noticeBarIcons = {
	-- Peer review, or NA status
	{
		isActive = function (articleHistoryObj)
			local status = articleHistoryObj:getStatusId()
			-- @XXX: This is what the template does, but we should take into
			-- account peer review actions as well.
			return not status or status == 'PR' or status == 'NA'
		end,
		icon = 'Nuvola apps kedit.svg'
	},
	-- Wikipedia 1.0
	{
		isActive = function (articleHistoryObj)
			return articleHistoryObj.args'v1.0NotAnActiveOption'
		end,
		icon = 'WP1 0 Icon.svg'
	}
},
-------------------------------------------------------------------------------
-- Extra categories
-------------------------------------------------------------------------------
-- This table contains categories that don't appear as part of a row. It is an
-- array of functions; each function takes an article history object as input
-- and must return an array of category objects as output.
extraCategories = {
	-- Four award
	function (articleHistoryObj)
		local yesno = require('มอดูล:Yesno')
		local ret = {}
		local isFour = yesno(articleHistoryObj.args.four)
		if isFour then
			ret#ret + 1 = Category.new('Wikipedia four award articles')
		elseif isFour == false then
			ret#ret + 1 = Category.new('Wikipedia articles rejected for Four awards')
		elseif articleHistoryObj:getStatusId() == 'FA' then
			local isDYK = false
			for i, obj in ipairs(articleHistoryObj:getCollapsibleNoticeObjects()) do
				if obj.id == 'DYK' then
					isDYK = true
					break
				end
			end
			if isDYK then
				for i, obj in ipairs(articleHistoryObj:getActionObjects()) do
					if obj.id == 'GAN' and obj.resultId == 'listed' then
						ret#ret + 1 = Category.new('Possible Wikipedia four award articles')
						break
					end
				end
			end
		end
		return ret
	end,
	-- Deletion to Quality award
	function (articleHistoryObj)
		local ret = {}
		local status = articleHistoryObj:getStatusId()
		if status == 'FA' or status == 'FL' or status == 'GA' then
			local iAfd = 0
			local hasAfd = false
			local actionObjects = articleHistoryObj:getActionObjects()
			for i, obj in ipairs(actionObjects) do
				if obj.id == 'AFD' then
					iAfd = i
					hasAfd = true
					break
				end
			end
			if hasAfd then
				local function hasNomination(id, result)
					for i = iAfd + 1, #actionObjects do
						local obj = actionObjectsi
						if obj.id == id and obj.resultId == result then
							return true
						end
					end
					return false
				end
				if status == 'GA' and hasNomination('GAN', 'listed') or
					status == 'FL' and hasNomination('FLC', 'promoted') or
					status == 'FA' and hasNomination('FAC', 'promoted')
				then
					ret#ret + 1 = Category.new('Deletion to Quality Award candidates')
				end
			end
		end
		return ret
	end,
	-- Track small banners
	function (articleHistoryObj)
		local ret = {}
		if articleHistoryObj.isSmall then
			table.insert(ret, Category.new('Small article history templates'))
		end
		return ret
	end,
},
-------------------------------------------------------------------------------
-- Parameters
-------------------------------------------------------------------------------
-- The parameter values used to generate the page actions. These are used as
-- Lua patterns, so any of the magic characters *+-.^$% should be escaped
-- with a preceding % symbol.
actionParamPrefix = 'action',
actionParamSuffixes = {
	 = 'code',
	date = 'date',
	link = 'link',
	result = 'resultCode',
	oldid = 'oldid'
},
-- The parameter used to set the current status.
currentStatusParam = 'currentstatus',
-------------------------------------------------------------------------------
-- Other settings
-------------------------------------------------------------------------------
-- If this number or fewer of collapsible rows are present (including actions
-- and collapsible notices) they will not be collapsed. If this is set to the
-- string "all", all rows will always be visible. Otherwise, the input must be
-- a number. The default is three rows.
uncollapsedRows = 3,
-- The default size for icons. The default is 30px.
defaultIconSize = '30px',
-- The default size for icons for small templates. The default is 15px.
defaultSmallIconSize = '15px',
-- The default size for status icons. The default is 50px.
defaultStatusIconSize = '50px',
-- The default size for status icons for small templates. The default is 30px.
defaultSmallStatusIconSize = '30px',
-- The default size for notice bar icons. The default is 15px.
defaultNoticeBarIconSize = '15px',
-- The default size for collapsible status icons. The default is 50px.
defaultCollapsibleNoticeIconSize = '20px',
-- The default size for collapsible status icons for small templates. The
-- default is 30px.
defaultSmallCollapsibleNoticeIconSize = '20px',
-------------------------------------------------------------------------------
-- Messages
-------------------------------------------------------------------------------
msg = {
-- The heading for the collapsible table of actions if we are in the main
-- namespace or the talk namespace.
'milestones-header' = 'หลักไมล์บทความ',
-- The heading for the collapsible table of actions if we are in a different
-- namespace.
-- $1 - the subject namespace name.
'milestones-header-other-ns' = '$1 milestones',
-- The milestones date header.
'milestones-date-header' = 'วันที่',
-- The milestones process header.
'milestones-process-header' = 'กระบวนการ',
-- The milestones result header.
'milestones-result-header' = 'ผลลัพธ์',
-- The format to display the action dates in. The syntax is the same as the
-- #time parser function.
'action-date-format' = 'j F Y',
-- The category to use if any errors are detected.
'error-category' = 'Article history templates with errors',
-- Define boilerplate text for error messages and warnings, both with and
-- without help links.
-- $1 - the error message
-- $2 - a link to a help page and section for the error
'error-message-help' = 'Error: $1 (help).',
'error-message-nohelp' = 'Error: $1.',
'warning-help' = 'Warning: $1 (help).',
'warning-nohelp' = 'Warning: $1.',
-- Error for row objects that should output notice bar icons but for which no
-- icon values could be found.
'row-error-missing-icon' = "notice bar icon config set to 'true' but no " ..
	'image could be found',
-- A help link for row-error-missing-icon
'row-error-missing-icon-help' = 'แม่แบบ:Article history#Missing icon',
-- Error for action objects that aren't passed a code.
-- $1 - the parameter name for the code
'action-error-no-code' = "no action code found in the '$1' parameter; " ..
	"please add a code or remove other parameters starting with '$1'",
-- A help link for action-error-no-code
'action-error-no-code-help' = 'แม่แบบ:Article history#Action codes',
-- Error for action objects that are passed an invalid code.
-- $1 - the code that the user input
-- $2 - the parameter name for the code
'action-error-invalid-code' = "invalid action code '$1' passed to the '$2' parameter",
-- A help link for action-error-invalid-code
'action-error-invalid-code-help' = 'แม่แบบ:Article history#Action codes',
-- Error for action objects with blank result parameters, where result
-- parameters are required for the action's ID.
-- $1 - the action ID
-- $2 - the result parameter name
'action-error-blank-result' = "the '$1' action requires a result code; " ..
	"please add a result code to parameter '$2'",
-- A help link for action-error-blank-result
'action-error-blank-result-help' = 'แม่แบบ:Article history#Action results',
-- Error for action objects with invalid result parameters.
-- $1 - the result code that the user input
-- $2 - the action ID
-- $3 - the result parameter name
'action-error-invalid-result' = "invalid result '$1' for action '$2' " ..
	"detected in parameter '$3'",
-- A help link for action-error-invalid-result
'action-error-invalid-result-help' = 'แม่แบบ:Article history#Action results',
-- Warning for action objects with invalid dates.
-- $1 - the date input by the user
-- $2 - the date parameter name
'action-warning-invalid-date' = "invalid date '$1' detected in parameter '$2'",
-- A help link for action-warning-invalid-date
'action-warning-invalid-date-help' = 'แม่แบบ:Article history#Invalid date',
-- Error for action objects with no dates.
-- $1 - the parameter number
-- $2 - the date parameter name
-- $3 - the action parameter name
'action-warning-no-date' = "no date specified for action $1; " ..
	"please add a date to parameter '$2' or remove the other parameters " ..
	"beginning with '$3'",
-- A help link for action-warning-no-date
'action-warning-no-date-help' = 'แม่แบบ:Article history#No date',
-- The text to display in place of the action date if it is missing.
'action-date-missing' = '?',
-- Error for action objects with invalid oldids.
-- $1 - the oldid input by the user
-- $2 - the oldid parameter name
'action-warning-invalid-oldid' = "invalid oldid '$1' detected in parameter '$2'; " ..
	"if an oldid is specified it must be a positive integer",
-- A help link for action-warning-invalid-oldid
'action-warning-invalid-oldid-help' = 'แม่แบบ:Article history#Invalid oldid',
-- Error for invalid current status codes.
-- $1 - the code input by the user
'articlehistory-warning-invalid-status' = "'$1' is not a valid status code",
-- A help link for articlehistory-warning-invalid-status
'articlehistory-warning-invalid-status-help' = 'แม่แบบ:Article history#Invalid status',
-- Warning for invocations that specify a current status without specifying any
-- actions.
'articlehistory-warning-status-no-actions' = "a current status was supplied " ..
	'without any actions',
-- A help link for articlehistory-warning-status-no-actions
'articlehistory-warning-status-no-actions-help' = 'แม่แบบ:Article history#No actions',
-- The text to display the current status at the bottom of the collapsible
-- table.
-- $1 - the current status name
'status-blurb' = "สถานะปัจจุบัน: $1",
-- The text to display at the bottom of the collapsible table if the current
-- status is unknown.
'status-unknown' = '?',
}
-------------------------------------------------------------------------------
--                              CONFIG TABLE END
-------------------------------------------------------------------------------
}