跳转到内容

模組:Carousel

维基百科,自由的百科全书

这是本页的一个历史版本,由PhiLiP留言 | 贡献2017年3月4日 (六) 22:08编辑。这可能和当前版本存在着巨大的差异。

local p = {}
local lang = mw.language.new('zh')

function getCandidateList(args)
	local page = mw.title.new(args.pageName)
	local candidates =
		mw.text.jsonDecode(page:getContent(), mw.text.JSON_TRY_FIXING)

	-- change mw timestamp to unix timestamp
	for _, item in pairs(candidates) do
		for i in pairs(item.displayTimeRanges) do
			item.displayTimeRanges[i][1] =
				lang:formatDate('U', tostring(item.displayTimeRanges[i][1]))
			if item.displayTimeRanges[i][2] ~= null then
				item.displayTimeRanges[i][2] =
					lang:formatDate('U', tostring(item.displayTimeRanges[i][2]))
			end
		end
	end
	return candidates
end

function p.main(frame)
	local candidateList = getCandidateList{pageName = frame.args.candidateList}
	local currentTime = lang:formatDate('U', frame.args.currentTime)
	local timeStart = lang:formatDate(
		"U", frame.args.timeStart or '19700101000000')
	local timeInterval = tonumber(frame.args.timeInterval) or 86400
	--local index0 = math.floor((os.time() - timeStart) / 86400) % #candidateList
	--local currentPage = candidateList[index0 + 1]
	--return mw.getCurrentFrame():expandTemplate { title = currentPage }
end

return p