Va ô cuntinutu

Mòdulu:Sandbox/Dapal

Dâ Wikipedia, la nciclupidìa lìbbira.

La ducumintazzioni di stu mòdulu si pò criari nta Mòdulu:Sandbox/Dapal/doc

local p = {}

local getArgs = require('Module:Arguments').getArgs
local api = new mw.Api()

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	-- https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Germantown,_Tennessee&
	-- rvstartid=1254513101&rvlimit=1&format=json
	local ret = {}

	local query = {
		action = "query",
		prop = "revisions",
		rvprop = "content",
		rvstartid = args.id,
		rvlimit = 1,
		titles = args.page
	}

	api.get(query)
		.done (
			function (data)
				if (data ~= nil and data.query and data.query.pages) then
					page = Object.entries(data.query.pages)[0][1];
					if (page.revisions ~= nil ) then
						ret = {
							msg = "success",
							user = page.revisions[1].user,
							timestamp = pages.revisions[1].timestamp,
						}
						return ret;
					else
						statusText = "Error: Revisions not found!";
						ret = {
							msg = "revisions not found",
							user = nil,
							timestamp = nil,
						}
						return ret
					end
				end
				ret = {
					msg = "data not found",
					user = nil,
					timestamp = nil,
				}
			end
		)
		.fail (
			function (err)
				ret = {
					msg = err,
					user = nil,
					timestamp = nil,
				}
				return ret
			end
		);
end

return p