Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Cytat dnia/opis

local months = {'january','february','march','april','may long','june','july','august','september','october','november','december'}
-- locative forms of Polish month names
local monthsLoc = {'styczniu','lutym','marcu','kwietniu','maju','czerwcu','lipcu','sierpniu','wrześniu','październiku','listopadzie','grudniu'}
local base = 'Cytat dnia'
local lang = mw.language.getContentLanguage()
local p = {}

local msgvals = {}
function intmsg(code)
	if msgvals[code]==nil then
		msgvals[code] = mw.getCurrentFrame():preprocess('{{lcfirst:{{int:'..code..'}}}}')
	end
	return msgvals[code]
end

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

function index(monthGen,totalDays)
	local days = {}
	for x = 1,totalDays do
		table.insert(days,'[[#'..x..' '..monthGen..'|'..x..']]')
	end
	return '{| id="toc"\n|Dzień:\n|'..table.concat(days,' ')..'\n|}'
end

function day(title,after)
	local page = mw.title.new(base..'/'..title,10)
	local res = ''
	if page.exists then
		-- try to show the quote, ...
		res = res..mw.getCurrentFrame():preprocess(page:getContent())
	else
		-- ...otherwise display a link
		res = res..'[['..page.fullText..']]'
	end
	res = res..'\n<div class="plainlinks"><small>\n[['..page.fullText..'|zobacz]]\n'
	res = res..'[['..page.talkPageTitle.fullText..'|'..intmsg('talk')..']]\n'
	res = res..'['..page:fullUrl{action = 'history'}..' '..intmsg('history short')..']\n'
	res = res..'['..page:fullUrl{action = 'edit'}..' '..intmsg('edit')..']\n'
	if after~=nil then
		res = res..after
	end
	res = res..'</small></div>'
	return res
end

function p.day(frame)
	return day(lang:formatDate('d xg',frame.args[1]))
end

function p.miesiace()
	local res = {}
	for i,x in pairs(months) do
		table.insert(res,'[['..mw.site.namespaces[4].name..':'..base..'/'..mw.message.new(x):plain()..'|'..monthsLoc[i]..']]')
	end
	return table.concat(res,'\n')
end

function p.miesiac(frame)
	local month = frame.args[1]
	if month==nil or month=='' then
		-- if no month is specified, try to autodetect it via the page title
		month = mw.title.getCurrentTitle().subpageText
	end
	if month==nil then
		return nil
	end
	local mn = monthNumber(month)
	if mn==nil then
		month = lang:formatDate('F')
		mn = monthNumber(month)
	end
	if mn==nil then
		return nil
	end
	-- genitive form of the month name
	local monthGen = mw.message.new(string.gsub(months[mn],'[_ ]long$','')..'-gen'):plain()
	local monthLoc = monthsLoc[mn]
	local totalDays = tonumber(lang:formatDate('t','1 '..mw.message.new(months[mn]):inLanguage('en'):plain()))
	local idx = index(monthGen,totalDays)
	local output = {'\'\'\''..frame:expandTemplate{title='Dzisiaj'}..'\'\'\''}
	local cydn = frame:expandTemplate{title='Cytaty dnia'}
	table.insert(output,'----\n'..cydn..'\n<br clear=all>\n==Cytaty dnia w '..monthLoc..'==')
	-- hide 'edit section' links and Table Of Contents
	table.insert(output,'__NOEDITSECTION__\n__NOTOC__\n'..idx..'\n')
	for x = 1,totalDays do
		local tt = x..' '..monthGen
		local t = '=='..tt..'==\n'..day(tt,'[[#Cytaty dnia w '..monthLoc..'|wróć]]\n')
		table.insert(output,t)
	end
	table.insert(output,'----\n'..idx..'\n'..cydn)
	-- categorization by month
	table.insert(output,'[['..mw.site.namespaces[14].name..':Cytaty dnia|'..month..']]') 
	return table.concat(output,'\n')
end

return p