Moduuli:Viikon kilpailu navigaatio

Wikipediasta
Siirry navigaatioon Siirry hakuun



local vk = {}
vk.lang = mw.getContentLanguage()
vk.currentYear = tonumber(vk.lang:formatDate("o", "now", true))

function vk.main(frame)
	local year = tonumber(frame.args[1] or vk.currentYear)
	local vk_list = {}
	table.insert(vk_list, vk.entry(year -1, vk.lang:formatDate("W", year.."W01 -1 week"), "<<", 1))
	repeat
		table.insert(vk_list, vk.entry(year, #vk_list))
		local year2 = tonumber(vk.lang:formatDate("o", year.."W01 +"..(#vk_list -1).." weeks"))
	until year ~= year2
	table.insert(vk_list, vk.entry(year +1, 1, ">>", #vk_list +1))
	return last and table.concat(vk_list, "  ", first, last) or ""
end

function vk.entry(year, week, text, length)
	week = tonumber(week)
	local topic = mw.title.new("Module:Viikon kilpailu luettelo "..year).exists and require("Module:Viikon kilpailu luettelo "..year)[week] or ""
	local page = string.format("Wikipedia:Viikon kilpailu/Viikon kilpailu %04d-%02d", year, week)
	if topic == "" then
		topic = "—"
	else
		_G.first = first or length or (week +1)
		_G.last  = length or (week +1)
		if year < vk.currentYear or mw.title.new(page).exists then
			if text then
				text = "[["..page.."|<span title='Viikko "..week..": "..topic.."'>"..text.."</span>]]"
			else
				topic = "[["..page.."|"..topic.."]]"
			end
		else
			if text then
				text = "<span class='explain' title='Viikko "..week..": "..topic.."'>"..text.."</span>"
			else
				topic = topic..vk.createLink(string.format("%04dW%02d", year, week))
			end
		end
	end
	return text or "<b>"..week.."</b>&nbsp;"..topic
end

function vk.createLink(id)
	local startDate = vk.lang:formatDate("j.n.Y", id.."1")
	local endDate = vk.lang:formatDate("j.n.Y", id.."7")
	local page = "Wikipedia:Viikon kilpailu/Viikon kilpailu "..vk.lang:formatDate("o-W", id)
	local url = tostring(mw.uri.fullUrl(page, "action=edit&preload=Malline:VK kilpailusivu preload&preloadparams[]="..startDate.."&preloadparams[]="..endDate))
	return " <small class='plainlinks'>(["..url.." Luo sivu])</small>"
end

return vk