Module:Page

local getArgs = require('Module:Arguments').getArgs

local callAssert = require('CallAssert')

local function main(frame, field, pPage) local args = getArgs(frame) local makeTitle = args.makeTitle local namespace = args.namespace or '' local fragment = args.fragment or '' local interwiki = args.interwiki or '' local page = pPage or args.page or args[1] or '' local id = tonumber( args.id ) local pn = {} local title -- holds the result of the mw.title.xxx call for i = 1, 9 do pn[i] = args['p'..i] end if not id and not mw.ustring.match( page, '%S' ) then page = nil end if id then title = callAssert(mw.title.new, 'mw.title.new', id) elseif not page then title = callAssert(mw.title.getCurrentTitle, 'getCurrentTitle') elseif makeTitle then title = callAssert(mw.title.makeTitle, 'makeTitle', namespace, page, fragment, interwiki) else title = callAssert(mw.title.new, 'mw.title.new', page, namespace) end local result = title[field] if type(result) == 'function' then result = result(title, unpack(pn)) end return tostring(result or '') end

-- handle all errors in main main = require('Module:Protect')(main)

local p = {}

-- -- main function does all the work -- local meta = {} -- function meta.__index(self, key) -- 	return function(frame) -- 		return main(frame, key) -- 	end -- end -- setmetatable(p, meta)

function p.data(frame) local args = getArgs(frame) local field = args[1] or '' local page = args.page or args[2] or '' return main(frame, field, page) end

function p.getContent(frame) local args = getArgs(frame) local fmt = args.as or 'pre' local text = main(frame, 'getContent') fmt = mw.text.split( fmt, ', ?' ) for _, how in ipairs( fmt ) do		if how == 'pre' then text = table.concat{ ' ', text, ' ' } elseif how == 'expand' then text = frame:preprocess(text) elseif how == 'nowiki' then text = mw.text.nowiki(text) end end return text end

return p