Module:URL to diff
Documentation for this module may be created at Module:URL to diff/doc
Documentation for this module may be created at Module:URL to diff/doc
-- This module converts Wikipedia diff URLs to the {{diff}} template format.
local newBuffer = require('Module:OutputBuffer')
local p = {}
local function decodeUrl(url)
if type(url) ~= 'string' then
return nil
end
url = mw.uri.new(url)
if not url or url.host ~= 'simple.wikipedia.org' then
return nil
end
local data = {}
data.title = url.query.title and mw.uri.decode(url.query.title, 'WIKI')
data.diff = url.query.diff
data.oldid = url.query.oldid
data.diffonly = url.query.diffonly
return data
end
local function encodeDiffTemplate(data)
if not data.title and not data.diff and not data.oldid then
return nil
end
local isNamed = false -- Track whether we need to use named parameters
for k, v in pairs(data) do
if string.find(v, '=') then
isNamed = true
break
end
end
local getBuffer, print, printf = newBuffer()
print('diff')
printf('%s%s', isNamed and 'page=' or '', data.title or '')
printf('%s%s', isNamed and 'diff=' or '', data.diff or '')
printf('%s%s', isNamed and 'oldid=' or '', data.oldid or '')
if data.label then
printf('%s%s', isNamed and 'label=' or '', data.label)
end
if data.diffonly then
printf('diffonly=%s', data.diffonly)
end
local ret = getBuffer('|')
ret = '{{' .. ret .. '}}'
return ret
end
function p._url(args)
local data = decodeUrl(args.url)
if data then
data.label = args.label
return encodeDiffTemplate(data)
else
return nil
end
end
function p.url(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:URL to diff',
})
return p._url(args)
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.