Module:Sandbox/Grufo2
Jump to navigation
Jump to search
require[[strict]]
local iface = {}
iface.foobar = function (frame)
return foobar
end
iface.call_info_template = function (frame)
local rname
local tname
local srcpage
local opts = frame.args
if opts[1] ~= nil then tname = opts[1]:match'^%s*(.*%S)' end
if tname == nil then error('No template name was provided', 0) end
if opts[2] ~= nil then rname = opts[2]:match'^%s*(.*%S)' end
if rname == nil then srcpage = mw.title.getCurrentTitle()
else srcpage = mw.title.new(rname) end
local targetpage = srcpage.redirectTarget
if not targetpage then return '' end
local newargs = {}
for key, val in pairs(targetpage) do
if type(val) == 'string' then newargs[key] = val
elseif type(val) == 'number' or type(val) == 'boolean' then
newargs[key] = tostring(val)
end
end
for key, val in pairs(opts) do
if type(key) ~= 'number' or key < 1 then newargs[key] = val
elseif key > 2 then newargs[key - 2] = val end
end
return frame:getParent():expandTemplate{
title = tname,
args = newargs
}
end
iface.get_target_page = function (frame)
local tname
local srcpage
local opts = frame.args
if opts[1] ~= nil then tname = opts[1]:match'^%s*(.*%S)' end
if tname == nil then srcpage = mw.title.getCurrentTitle()
else srcpage = mw.title.new(tname) end
local targetpage = srcpage.redirectTarget
if targetpage then return targetpage.fullText end
return ''
end
iface.walk_through = function (frame)
local tname
local srcpage
local opts = frame.args
if opts[1] ~= nil then tname = opts[1]:match'^%s*(.*%S)' end
if tname == nil then srcpage = mw.title.getCurrentTitle()
else srcpage = mw.title.new(tname) end
local thiswikilink = ''
local targetpage = srcpage.redirectTarget
local nextwikilink
local walkedthrough = { srcpage.fullText }
while targetpage do
nextwikilink = targetpage.fullText
if (walkedthrough[nextwikilink]) then break end
thiswikilink = nextwikilink
walkedthrough[nextwikilink] = true
targetpage = targetpage.redirectTarget
end
return thiswikilink
end
iface.create_svg = function (frame)
local opts = frame.args
local icontent
if opts[1] ~= nil then icontent = opts[1]:match'^%s*(.*%S)' end
if icontent == nil then error('No SVG code was provided', 0) end
local img = mw.svg.new()
for key, val in pairs(opts) do
if type(key) == 'string' then
if key:sub(1, 1) == '#' then
img:setAttribute(key:sub(2), val)
else img:setImgAttribute(key, val) end
end
end
return img:setContent(icontent):toImage()
end
return iface