Module:Unsubst-infobox

local p = {}

local specialParams = { ['$params'] = 'all parameters', ['$extra'] = 'extra parameters', ['$set1'] = 'parameter set 1', ['$set2'] = 'parameter set 2', ['$set3'] = 'parameter set 3', ['$aliases'] = 'parameter aliases', ['$indent'] = 'indent', ['$flags'] = 'flags', ['$B'] = 'template content', ['$template-name'] = 'template invocation name override' }

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['$params'] then error( ' requires parameter $params (parameter list)' ) end

if mw.isSubsting then substing -- Combine passed args with passed defaults local args = {} if string.find( ','..(frame.args['$flags'] 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

if frame.args['$template-name'] and '' ~= frame.args['$template-name'] then title = frame.args['$template-name'] -- override whatever the template name is with this name 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['$aliases'] then local list = mw.text.split( frame.args['$aliases'], '%s*,%s*' ) for k, v in ipairs( list ) do				local tmp = mw.text.split( v, '%s*>%s*' ) aliases[(tonumber(mw.ustring.match(tmp[1], '^[1-9][0-9]*$'))) or tmp[1]] = ((tonumber(mw.ustring.match(tmp[2], '^[1-9][0-9]*$'))) or 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