Module:Transclusion count
Tools
Actions
General
Sister projects
Print/export
localp={}functionp.fetch(frame)localtemplate=nillocalreturn_value=nil-- Use demo parameter if it exists, otherswise use current template namelocalnamespace=mw.title.getCurrentTitle().namespaceifframe.args["demo"]andframe.args["demo"]~=""thentemplate=mw.ustring.gsub(frame.args["demo"],"^[Tt]emplate:","")elseifnamespace==10then-- Template namespacetemplate=mw.title.getCurrentTitle().textelseifnamespace==828then-- Module namespacetemplate=(mw.site.namespaces[828].name..":"..mw.title.getCurrentTitle().text)end-- If in template or module namespace, look up count in /dataiftemplate~=nilthennamespace=mw.title.new(template,"Template").namespaceifnamespace==10ornamespace==828thentemplate=mw.ustring.gsub(template,"/doc$","")-- strip /doc from endtemplate=mw.ustring.gsub(template,"/sandbox$","")-- strip /sandbox from endlocalindex=mw.ustring.sub(mw.title.new(template).text,1,1)localstatus,data=pcall(function()return(mw.loadData('Module:Transclusion_count/data/'..(mw.ustring.find(index,"%a")andindexor"other")))end)ifstatusthenreturn_value=tonumber(data[mw.ustring.gsub(template," ","_")])endendend-- If database value doesn't exist, use value passed to templateifreturn_value==nilandframe.args[1]~=nilthenlocalarg1=mw.ustring.match(frame.args[1],'[%d,]+')ifarg1andarg1~=''thenreturn_value=tonumber(frame:callParserFunction('formatnum',arg1,'R'))endendreturnreturn_valueend-- Tabulate this data for [[Wikipedia:Database reports/Templates transcluded on the most pages]]functionp.tabulate(frame)locallist={}fori=65,91dolocaldata=mw.loadData('Module:Transclusion count/data/'..((i==91)and'other'orstring.char(i)))forname,countinpairs(data)dotable.insert(list,{mw.title.new(name,"Template").fullText,count})endendtable.sort(list,function(a,b)return(a[2]==b[2])and(a[1]<b[1])or(a[2]>b[2])end)locallang=mw.getContentLanguage();fori=1,#listdolist[i]=('|-\n| %d || [[%s]] || %s\n'):format(i,list[i][1]:gsub('_',' '),lang:formatNum(list[i][2]))endreturntable.concat(list)endreturnp