Module:Page: Difference between revisions

Content deleted Content added
pcall encapsulation is now provided by Module:Protect
Add support for tables
 
(5 intermediate revisions by 3 users not shown)
Line 1:
local function callAssert(func, funcName,= ...require('Module:CallAssert')
local result = { func(...) }
if not result[1] then
local message = mw.ustring.format(
'%s(%s) failed',
funcName,
table.concat({...}, ', ')
)
error(message, 2)
end
return unpack(result)
end
 
local function main(frame, field)
local args, pargs = frame.args, ( frame:getParent() or {} ).args or {}
local makeTitle=args.makeTitle or pargs.makeTitle or ""
local namespace=args.namespace or pargs.namespace or ""
local fragment=args.fragment or pargs.fragment or ""
Line 39 ⟶ 28:
if type(result) == "function" then
result = result(title, unpack(pn))
elseif type(result) == "table" then
result = mw.text.listToText(result)
end
 
Line 60 ⟶ 51:
function p.getContent(frame)
local args, pargs = frame.args, ( frame:getParent() or {} ).args or {}
local fmt = args.as or pargs.as or false"pre"
local text = main(frame, "getContent")
 
if not fmt then
return frame:preprocess( "<pre>" .. text .. "</pre>" )
end
 
fmt = mw.text.split( fmt, ", ?" )