Jump to content

Module:URL to diff

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 15:35, 1 January 2015 (add some validation stuff). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This module converts Wikipedia diff URLs to the {{diff}} template format.

local p = {}

local validDiffValues = {
	cur = true,
	prev = true,
	['next'] = true
}

local function isValidId(s)
	local id = tonumber(s)
	return id and id > 0
end

local function isValidDiffParam(s)
	return s and (validDiffValues[s] or isValidId(s))
end

local function decodeUrl(url)
	if type(url) ~= 'string' then
		return nil
	end
	url = mw.uri.new(url)
	if not url or url.host ~= 'en.wikipedia.org' or not isValidDiffParam(url.query.diff) then
		return nil
	end
	local data = {}
	mw.logObject(data)
end

local function encodeDiffTemplate(data)
end

function p._url(args)
	local url = args[1]
	local data = decodeUrl(url)
	if data then
		return encodeDiffTemplate(data)
	else
		return nil
	end
end

function p.url(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:Make diff',
	})
	return p._url(args)
end

return p