Module:Transclusion count/testcases
Appearance
From Meta, a Wikimedia project coordination wiki
localp={} functionp.fetch(frame) localtemplate=nil localreturn_value=nil -- Use demo parameter if it exists, otherswise use current template name localnamespace=mw.title.getCurrentTitle().namespace ifframe.args["demo"]andframe.args["demo"]~=""then template=mw.ustring.gsub(frame.args["demo"],"^[Tt]emplate:","") elseifnamespace==10then-- Template namespace template=mw.title.getCurrentTitle().text elseifnamespace==828then-- Module namespace template=(mw.site.namespaces[828].name..":"..mw.title.getCurrentTitle().text) end -- If in template or module namespace, look up count in /data iftemplate~=nilthen namespace=mw.title.new(template,"Template").namespace ifnamespace==10ornamespace==828then template=mw.ustring.gsub(template,"/doc$","")-- strip /doc from end template=mw.ustring.gsub(template,"/sandbox$","")-- strip /sandbox from end localindex=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) ifstatusthen return_value=tonumber(data[mw.ustring.gsub(template," ","_")]) end end end -- If database value doesn't exist, use value passed to template ifreturn_value==nilandframe.args[1]~=nilthen localarg1=mw.ustring.match(frame.args[1],'[%d,]+') ifarg1andarg1~=''then return_value=tonumber(frame:callParserFunction('formatnum',arg1,'R')) end end returnreturn_value end -- Tabulate this data for [[Wikipedia:Database reports/Templates transcluded on the most pages]] functionp.tabulate(frame) locallist={} fori=65,91do localdata=mw.loadData('Module:Transclusion count/data/'..((i==91)and'other'orstring.char(i))) forname,countinpairs(data)do table.insert(list,{mw.title.new(name,"Template").fullText,count}) end end table.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,#listdo list[i]=('|-\n| %d || [[%s]] || %s\n'):format(i,list[i][1]:gsub('_',' '),lang:formatNum(list[i][2])) end returntable.concat(list) end returnp