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:13, 1 January 2015 (make a start at a URL to {{diff}} converter). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

local function decodeUrl(url)
	if type(url) ~= 'string' then
		error('no URL provided', 2)
	end
	url = mw.uri.new(url)
	if not url then
		error('invalid URL provided', 2)
	end
	if url.host ~= 'en.wikipedia.org' then
		error(string.format(
			"invalid host '%s'; this template only accepts diff URLs from en.wikipedia.org",
			tostring(url.host)
		), 2)
	end
	mw.logObject(url.host)
end

local function encodeDiffTemplate(data)
end

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

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

return p