Moduł:Sandbox/Magwac
Z Nonsensopedii, polskiej encyklopedii humoru
local p = {}
local function matchtodeath(text, pattern, trimby)
local prev = text
local m = string.match(prev, pattern)
if m == nil then
return nil
end
repeat
prev = m
if #m > trimby then
m = string.sub(m, 1, -1-trimby)
else
break
end
m = string.match(m, pattern)
until m == nil
return prev
end
local function getparam(text, param)
local m = matchtodeath(text, '|%s*' .. param .. '%s*=.*\n|', 1)
if m == nil then
m = matchtodeath(text, '|%s*' .. param .. '%s*=.*}}', 2)
if m == nil then
return ''
end
local s = string.find(m, '=')
return mw.text.trim(string.sub(m, s+1, #m-2))
end
local s = string.find(m, '=')
return mw.text.trim(string.sub(m, s+1, #m-1))
end
function p.pliktest(frame)
local content = mw.title.new(frame.args[1], 'Plik'):getContent()
local s =
'[[Plik:' .. frame.args[1] .. '|thumb|center|300px|' ..
getparam(content, 'Description') .. ", ''autor: " .. getparam(content, 'Author') .. "'']]"
return s
end
return p