localp={}localspecialParams={['$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'}p['']=function(frame)ifnotframe:getParent()thenerror('{{#invoke:Unsubst-infobox|}} makes no sense without a parent frame')endifnotframe.args['$B']thenerror('{{#invoke:Unsubst-infobox|}} requires parameter $B (template content)')endifnotframe.args['$params']thenerror('{{#invoke:Unsubst-infobox|}} requires parameter $params (parameter list)')endifmw.isSubsting()then---- substing-- Combine passed args with passed defaultslocalargs={}ifstring.find(','..(frame.args['$flags']or'')..',',',%s*override%s*,')thenfork,vinpairs(frame:getParent().args)doargs[k]=vendfork,vinpairs(frame.args)doifnotspecialParams[k]thenifv=='__DATE__'thenv=mw.getContentLanguage():formatDate('F Y')endargs[k]=vendendelsefork,vinpairs(frame.args)doifnotspecialParams[k]thenifv=='__DATE__'thenv=mw.getContentLanguage():formatDate('F Y')endargs[k]=vendendfork,vinpairs(frame:getParent().args)doargs[k]=vendend-- Build an equivalent template invocation-- First, find the title to uselocaltitleobj=mw.title.new(frame:getParent():getTitle())localtitleiftitleobj.namespace==10then-- NS_TEMPLATEtitle=titleobj.textelseiftitleobj.namespace==0then-- NS_MAINtitle=':'..titleobj.textelsetitle=titleobj.prefixedTextend-- Remove empty fieldsfork,vinpairs(args)doifv==''thenargs[k]=nilendend-- Pull information from parameter aliaseslocalaliases={}ifframe.args['$aliases']thenlocallist=mw.text.split(frame.args['$aliases'],'%s*,%s*')fork,vinipairs(list)dolocaltmp=mw.text.split(v,'%s*>%s*')aliases[(tonumber(mw.ustring.match(tmp[1],'^[1-9][0-9]*$')))ortmp[1]]=((tonumber(mw.ustring.match(tmp[2],'^[1-9][0-9]*$')))ortmp[2])endendfork,vinpairs(aliases)doifargs[k]andnotargs[v]thenargs[v],args[k]=args[k],nilendend-- Build the invocation body with numbered args first, then namedlocalret='{{'..titlefork,vinipairs(args)doifmw.ustring.find(v,'=',1,true)then-- likely something like 1=foo=bar, we need to do it as a named argbreakendifnotaliases[k]thenret=ret..'|'..vargs[k]=nilendend-- Pull lists from special parameterslocalparams=mw.text.split(frame.args['$params'],'%s*,%s*')fork,vinipairs(params)doparams[k]=(tonumber(mw.ustring.match(v,'^[1-9][0-9]*$')))orvendlocalsets,setparams,extra={{},{},{}},{},{}fork=1,3dolocalv=frame.args['$set'..k]ifvthensetparams[k]=mw.text.split(v,'%s*,%s*')forx,yinipairs(setparams[k])dosetparams[k][x]=(tonumber(mw.ustring.match(y,'^[1-9][0-9]*$')))orysets[k][setparams[k][x]]=trueendendendifframe.args['$extra']thenlocaltmp=mw.text.split(frame.args['$extra'],'%s*,%s*')fork,vinipairs(tmp)doextra[(tonumber(mw.ustring.match(v,'^[1-9][0-9]*$')))orv]=trueendend-- Replace parameter list with short version if full version not necessarylocaltmp={}fork,vinipairs(sets)doifnext(v)then-- if table v is not emptyfor_,xinipairs(params)doifargs[x]andnotv[x]thentmp[k]=truebreakendendifnottmp[k]thenparams=setparams[k]endendend-- Align parameters correctly and remove extra oneslocalmaxlength=0localdiscard={}fork,vinipairs(params)doif(notextra[v])orargs[v]thenlocaltmp=mw.ustring.len(tostring(v))iftmp>maxlengththenmaxlength=tmpendelsetable.insert(discard,1,k)endendfork,vinipairs(discard)dotable.remove(params,v)endlocalindent=string.rep(' ',(tonumber(frame.args['$indent'])or0))localspace,newline=' ','\n'ifnotnext(params)thenspace,newline='',''endfork,vinipairs(params)dolocaltmp=spaceifmw.ustring.match(mw.ustring.sub((args[v]or'')..' ',1,1),'[%*:;#]')thentmp='\n'endret=ret..newline..indent..'|'..space..v..string.rep(' ',(maxlength-mw.ustring.len(v)))..space..'='..tmp..(args[v]or'')endret=ret..newline..'}}'ret=mw.ustring.gsub(ret,'%s+\n','\n')returnretelse-- Not substing-- Just return the "body"returnframe.args['$B']endendreturnp