Module:Transclusion count/sandbox
Appearance
From Wikipedia, the free encyclopedia
This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected.
Warning This Lua module is used on approximately 62,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
Fetches usage data for highly-transcluded templates. Uses bot-updated values from subpages of Module:Transclusion_count/data/ when available.
Usage
[edit ]{{#invoke:Transclusion count|fetch|number of transclusions|use + notation|all-pages=|demo=}}
number of transclusions: is a static number of times the template has been transcluded, to use when values cannot be read from the database. This value will be ignored if transclusion data is available for the current page.demo=Template_name: will use the transclusion count for the template at Template:Template_name instead of detecting what template it is being used on. Capitalization must exactly match the value used in Special:PrefixIndex/Module:Transclusion_count/data/.
{{#invoke:Transclusion count|tabulate}}
- Used to generate Wikipedia:Database reports/Templates transcluded on the most pages.
Notices
[edit ]- The number of transclusion count is generated via subpages of Module:Transclusion count/data when is available and is automatically updated via a bot.
The above documentation is transcluded from Module:Transclusion count/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
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