Module:was wotd

Hello, you have come here looking for the meaning of the word Module:was wotd. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:was wotd, but we will also tell you about its etymology, its characteristics and you will know how to say Module:was wotd in singular and plural. Everything you need to know about the word Module:was wotd you have here. The definition of the word Module:was wotd will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:was wotd, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

local languages_module = "Module:languages"
local debug_track_module = "Module:debug/track"

local function get_code(...)
	get_code = require(languages_module).getByCode
	return get_code(...)
end

local function debug_track(...)
	debug_track = require(debug_track_module)
	return debug_track(...)
end

local function track(page)
	debug_track("was wotd/" .. page)
	return true
end

local function render_entry(date, prefix, link_base)
	if date == nil then
		return "date error"
	end

	local page = link_base .. date.year .. "/" .. date.month
	local title = mw.title.makeTitle("Wiktionary", page, date.day)
	local display = prefix .. date.day .. " " .. date.month .. " " .. date.year

	if title.exists then
		return "]"
	else
		return display
	end
end

local function canonicalize_date(year, month, day)
	local lang = mw.language.getContentLanguage()
	local time

	local ok = pcall(function()
		time = lang:formatDate("U", day .. "-" .. month .. "-" .. year, false)
	end)

	if not ok then
		return
	end

	return {
		month = lang:formatDate("F", "@" .. time, false),
		day   = lang:formatDate("j", "@" .. time, false),
		year  = lang:formatDate("Y", "@" .. time, false),
		unix  = tonumber(time)
	}
end

local function render_categories(categories)
	local output = ""

	for category in pairs(categories) do
		output = output .. "]"
	end

	return output
end

local function render(args, categorize, category_bases, prefix, link_base)
	if #args % 3 ~= 0 or canonicalize_date(args, args, args) == nil then
		if categorize then
			-- ]
			track("date error")
		end
		return "]"
	end

	local categories = {}
	local output = ""
	local dates = {}

	local today_midnight = tonumber(mw.language.getContentLanguage():formatDate("U", "today", false))
	local tomorrow_midnight = today_midnight + 86400
	
	for i = 1, #args / 3 do
		dates = canonicalize_date(args, args, args)
	end

	table.sort(dates, function(a, b)
		if a == nil then
			return true
		elseif b == nil then
			return false
		else
			return a.unix < b.unix
		end
	end)

	for i, date in ipairs(dates) do
		local sep = (i == 1 and "" or ", ")
		local first = (i == 1)
		local future = (date.unix >= tomorrow_midnight)
		local entry_prefix = ""
		if future then
			entry_prefix = entry_prefix .. "Upcoming "
		end
		if first then
			entry_prefix = entry_prefix .. prefix .. " –&#32;"
		end
		output = output .. sep .. render_entry(date, entry_prefix, link_base)
		if date ~= nil then
			for category_idx, category_base in ipairs(category_bases) do
				if category_base.should_year then
					categories = true
				end
				if category_base.should_month then
					categories = true
				end
			end
		end
	end

	for category_idx, category_base in ipairs(category_bases) do
		categories = true
	end

	return output .. (categorize and render_categories(categories) or "")
end

function export.was_wotd(frame)
	local args = {}
	local parent = frame:getParent()

	for i, v in ipairs(parent.args) do
		args = v
	end

	local title = mw.title.getCurrentTitle()

	return "<div class=\"was-wotd floatright\" style=\"padding-right: 1em\">"
		.. "<span title=\"This was a Wiktionary Word of the Day\">"
		.. "<small>''"
		..
		render(args, title.isContentPage,
			{ { name = "Word of the day archive", should_month = true, should_year = true } }, "WOTD",
			"Word of the day/Archive/")
		.. "''</small></span></div>"
end

function export.was_fwotd(frame)
	local args = {}
	local parent = frame:getParent()

	for i, v in ipairs(parent.args) do
		args = v
	end

	local lang = args
	table.remove(args, 1)

	local title = mw.title.getCurrentTitle()

	return "<div class=\"was-wotd floatright\" style=\"padding-right: 1em\">"
		.. "<span title=\"This was a Wiktionary foreign word of the day\">"
		.. "<small>''"
		.. render(args, title.isContentPage,
			{
				{ name = "Foreign word of the day archive",                                   should_month = true,  should_year = true },
				{ name = "Foreign words of the day in " .. get_code(lang):getCanonicalName(), should_month = false, should_year = true }
			},
			"FWOTD", "Foreign Word of the Day/")
		.. "''</small></span></div>"
end

return export