Jump to content

Module:QoD

Hali sa Wikiquote

This module is used by {{QoDList}} to automatically show a list of all "Quotes of the Day" for a given month and year.


local dayBase = 'Wikisambit:Sambit kan aldaw/' 
local lang = mw.language.getContentLanguage()
local p = {}

-- Function to map Bikol month names to English month abbreviations (or numbers)
local monthMap = {
    ['Enero'] = 'Jan',
    ['Pebrero'] = 'Feb',
    ['Marso'] = 'Mar',
    ['Abril'] = 'Apr',
    ['Mayo'] = 'May',
    ['Hunyo'] = 'Jun',
    ['Hulyo'] = 'Jul',
    ['Agosto'] = 'Aug',
    ['Setyembre'] = 'Sep',
    ['Oktubre'] = 'Oct',
    ['Nobyembre'] = 'Nov',
    ['Disyembre'] = 'Dec'
}

function msg(monthName)
	if string.len(monthName)<=3 then
		return monthName..' long'
	end
	return monthName
end

function p.list(frame)
	local s = frame.args[1]
	if s==nil or s=='' then
		s = mw.title.getCurrentTitle().subpageText
	end
	local month, year = string.match(s,'^(%w+) (%d+)$')
	if month==nil or year==nil then
		s = mw.title.new(frame:getTitle()).subpageText
	end
	month, year = string.match(s,'^(%w+) (%d+)$')

	if month~=nil and year~=nil then
		-- Convert Bikol month to English abbreviation for formatDate
		local englishMonth = monthMap[month]
		if not englishMonth then
			englishMonth = month
		end

		local output = {}
       
		local viw = 'Hilingon'
		local tlk = 'Urulay'
		local his = 'Mga Pagbabago' 

		for x = 1,tonumber(lang:formatDate('t','1 '..englishMonth..' '..year)) do
			local page = mw.title.new(dayBase..month..' '..x..', '..year)
			local t = ';[['..month..' '..x..']]\n'
			if page.exists then
				t = t..frame:preprocess(page:getContent())
			else
				t = t..'[['..page.fullText..']]'
			end
			t = t..' <br clear="all">\n'
			t = t..'[['..page.fullText..'|'..viw..']] - [['..page.talkPageTitle.fullText..'|'
			t = t..tlk..']] - ['..page:fullUrl{action = 'history'}..' '..his..']'
			table.insert(output,t)
		end
		output = table.concat(output,'\n----\n')
		output = output..'\n[[tr:Vikisöz:Günün sözü/Arşiv/'..mw.message.new(msg(englishMonth)):inLanguage('tr'):plain()..' '..year..']]'
		return output
	end
end

return p