Module:Unsubst-infobox

local p = {}

local specialParams = { ['$P'] = 'parameters', ['$E'] = 'extra parameters', ['$S1'] = 'parameter set 1', ['$S2'] = 'parameter set 2', ['$S3'] = 'parameter set 3', ['$A'] = 'aliases', ['$I'] = 'indent', ['$L'] = 'lists', -- usually not necessary; should be automatically detected ['$B'] = 'template content', ['$X'] = 'flags' }

p[''] = function ( frame ) if not frame:getParent then error( ' makes no sense without a parent frame' ) end if not frame.args['$B'] then error( ' requires parameter $B (template content)' ) end if not frame.args['$P'] then error( ' requires parameter $P (parameter list)' ) end

if mw.isSubsting then substing -- Combine passed args with passed defaults local args = {} if string.find( ','..(frame.args['$X'] or '')..',', ',%s*override%s*,' ) then for k, v in pairs( frame:getParent.args ) do				args[k] = v			end for k, v in pairs( frame.args ) do				if not specialParams[k] then if v == '__DATE__' then v = mw.getContentLanguage:formatDate( 'F Y' ) end args[k] = v				end end else for k, v in pairs( frame.args ) do				if not specialParams[k] then if v == '__DATE__' then v = mw.getContentLanguage:formatDate( 'F Y' ) end args[k] = v				end end for k, v in pairs( frame:getParent.args ) do				args[k] = v			end end

-- Build an equivalent template invocation -- First, find the title to use local titleobj = mw.title.new(frame:getParent:getTitle) local title if titleobj.namespace == 10 then -- NS_TEMPLATE title = titleobj.text elseif titleobj.namespace == 0 then -- NS_MAIN title = ':' .. titleobj.text else title = titleobj.prefixedText end

-- Remove empty fields for k, v in pairs( args ) do			if v == '' then args[k] = nil end end

-- Pull information from parameter aliases local aliases = {} if frame.args['$A'] then local list = mw.text.split( frame.args['$A'], '%s*,%s*' ) for k, v in ipairs( list ) do				local tmp = mw.text.split( v, '%s*>%s*' ) aliases[tmp[1]] = tmp[2] end end for k, v in pairs( aliases ) do			if args[k] and not args[v] then args[v], args[k] = args[k], nil end end

-- Build the invocation body with numbered args first, then named local ret = ''

ret = mw.ustring.gsub(ret, '%s+\n', '\n')

return ret else -- Not substing -- Just return the "body" return frame.args['$B'] end end

return p