Jump to content
Wikipedia The Free Encyclopedia

Module:Transclusion count

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
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.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
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

{{#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}}

Notices

  • 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.
Subpages of this module.

 localp={}

 functionp._fetch(args)
 localtemplate=nil
 localreturn_value=nil

 -- Use demo parameter if it exists, otherwise use current template name
 localnamespace=mw.title.getCurrentTitle().namespace
 ifargs["demo"]andargs["demo"]~=""then
 template=mw.ustring.gsub(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==nilandargs[1]~=nilthen
 localarg1=mw.ustring.match(args[1],'[%d,]+')
 ifarg1andarg1~=''then
 return_value=tonumber(mw.getCurrentFrame():callParserFunction('formatnum',arg1,'R'))
 end
 end

 returnreturn_value
 end

 functionp.fetch(frame)
 returnp._fetch(frame.args)
 end

 -- Tabulate this data for [[Wikipedia:Database reports/Templates transcluded on the most pages]]
 functionp.tabulate()
 locallist={}
 fori=65,91do
 localdata=mw.loadData('Module:Transclusion count/data/'..((i==91)and'other'orstring.char(i)))
 forname,countinpairs(data)do
 localtitle=mw.title.new(name,"Template")
 table.insert(list,{title,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
 localprotLevel=""
 localtitle=list[i][1]
 ifi<400then
 -- Stop at 400 to avoid breaching the expensive parser function call limit
 protLevel=title.protectionLevels.edit[1]or"(unprotected)"
 end
 list[i]=('|-\n| %d || [[%s]] || %s || %s \n'):format(i,title.fullText:gsub('_',' '),lang:formatNum(list[i][2]),protLevel)
 end
 returntable.concat(list)
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /