Módulo:Frase do dia

A documentação para este módulo pode ser criada na página Módulo:Frase do dia/doc

local months = {'january','february','march','april','may long','june','july','august','september','october','november','december'}
local base = 'Frase do dia/'
local lang = mw.language.getContentLanguage()
local p = {}

-- detect the index of a month (1-12) from its localized name
function monthNumber(monthName)
	for i,x in pairs(months) do
		if lang:ucfirst(mw.message.new(x):plain())==lang:ucfirst(monthName) then
			return i
		end
	end
end

-- show a list of "Quotes of the day" for the given month
function p.mes(frame)
	local month = frame.args[1]
	if month==nil or month=='' then
		month = mw.title.getCurrentTitle().subpageText
	end
	if month~=nil then
		local mn = monthNumber(month)
		if mn~=nil then
			local output = {}
			local ns = mw.site.namespaces[4].name
			for i,x in pairs(months) do
				table.insert(output,'[['..ns..':'..base..lang:ucfirst(mw.message.new(x):plain())..'|'..frame:preprocess('{{ucfirst:{{int:'..x..'}}}}')..']]')
			end
			table.insert(output,'\n<table border="0">')
			for x = 1,tonumber(lang:formatDate('t','2012-'..mn..'-01')) do
				local t = '<tr><td><strong>'..x..'</strong></td><td>'
				local tt = base..x..' de '..month
				-- use pcall to catch errors
				local ok,result = pcall( frame.expandTemplate, frame, { title=tt } )
				if ok then
					-- show the actual quote
					t = t..result
				else
					-- show a link if the template was not found
					t = t..'[['..mw.site.namespaces[10].name..':'..tt..']]'
				end
				table.insert(output,t..'</td></tr>')
			end
			table.insert(output,'</table>\n\n[['..mw.site.namespaces[14].name..':!Predefinições de Frase do dia|Frase da semana]]')
			return table.concat(output,'\n')
		end
	end
end

return p