From ModelUSGov Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Page/doc

local callAssert = require('Module:CallAssert')

local function main(frame, field)
	local args, pargs = frame.args, ( frame:getParent() or {} ).args or {}
	local makeTitle=args.makeTitle or pargs.makeTitle
	local namespace=args.namespace or pargs.namespace or ""
	local fragment=args.fragment or pargs.fragment or ""
	local interwiki=args.interwiki or pargs.interwiki or ""
	local or args[1] or or pargs[1] or ""
	local id= tonumber( or )
	local pn = {}
	local title -- holds the result of the call

	for i = 1,9 do pn[i] = args['p'..i] or pargs['p'..i] end
	if not id and not mw.ustring.match( page, '%S' ) then page = nil end

	if id then
		title = callAssert(, '', id)
	elseif not page then
		title = callAssert(mw.title.getCurrentTitle, 'getCurrentTitle')
	elseif makeTitle then
		title = callAssert(mw.title.makeTitle, 'makeTitle', namespace, page, fragment, interwiki)
		title = callAssert(, '', page, namespace)

	local result = title[field]
	if type(result) == "function" then
		result = result(title, unpack(pn))

	return tostring(result or "")

-- 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)
setmetatable(p, meta)

function p.getContent(frame)
	local args, pargs = frame.args, ( frame:getParent() or {} ).args or {}
	local fmt = or 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{ "<pre>", text, "</pre>" }
		elseif how == "expand" then
			text = frame:preprocess(text)
		elseif how == "nowiki" then
			text = mw.text.nowiki(text)

	return text

return p