This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This Lua module is used on many 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.
This module depends on the following other modules:
number of transclusions: The first parameter is either a static number of times the template has been transcluded, or the word "risk" (without quotes) to display "a very large number of" instead of the actual value. This value will be ignored if transclusion data is available for the current page.
discussion page, or use + notation: The second parameter is overloaded. It will cause the number of transclusions to display as "#,###+" instead of "approximately #,###" when set equal to "yes" (without quotes). When used in this manner, values will be rounded down, instead of rounded to the nearest number with the appropriate number of significant figures. When set to any other non-blank value, it will replace the link to the template's talk page to the value of the parameter (for example, 2=WP:VPT will insert a link to WP:VPT),
|info=extra information: When set to non-blank, will insert extra information into the template text if the template has more than 10,000 transclusions or parameter 1 is set to "risk".
|form=: When set to "editnotice", will display the message using {{editnotice}} instead of {{ombox}}.
|expiry=: Sets the |expiry= parameter for {{editnotice}}.
|system=in system messages: if set, this module looks like {{Used in system}}. Use that template directly as it performs some checks.
|fetch=: if set to false, the module will not attempt to fetch transclusion counts using Module:Transclusion count
Other functions
num
Produces the text and and link to toolforge surrounding the amount of transclusions.
risk
With this function, if risk is passed into the first unnamed parameter, or there are more than 100k transclusions, this will return risk.
text
Returns the body text of this template, with nil or a number of transclusions.
require('strict')localp={}localgetArgs=require('Module:Arguments').getArgslocal_fetch=require('Module:Transclusion_count')._fetch-- _fetch looks at the 'demo' argumentlocalyesno=require('Module:Yesno')locallang_obj=mw.getContentLanguage()-- this here because the language object is used multiple places in the modulelocallarge_count_cutoff=100000localapprox_num_total_pages=63000000localuser_subpage_info_page='Wikipedia:User pages#SUB'localsandbox_module_page='Module:Sandbox'localsystem_messages_cat='Pages used in system messages needing protection'localsandbox_word='sandbox'localtestcases_word='testcases'localdoc_word='doc'localfunctioncount_from_args(args)iftonumber(args.count)then-- check if function has already been usedreturntonumber(args.count)-- early exit if soendlocalcountifyesno(args['fetch'])~=falsethencount=_fetch(args)-- fetch transclusion countend-- use explicitly-provided count when fetch failsifcount==nilandargs[1]~=nilandargs[1]~=''then-- convert local language number string to a number understandable by Luacount=mw.ustring.gsub(args[1],'+$','')count=lang_obj:parseFormattedNumber(args[1])end-- in case someone writes a non-positive numberifcountandcount>0thenreturncountendreturnnilend-- Actions if there is a large (greater than or equal to 100,000) transclusion countlocalfunctionrisk_boolean(args)ifargs.risk==trueorargs.risk==falsethenreturnargs.riskelseifargs[1]=='risk'thenreturntrueelselocalcount=count_from_args(args)ifcountandcount>=large_count_cutoffthenreturntrueendendreturnfalseend-- function retained for backwards compatibilityfunctionp._risk(args)returnrisk_boolean(args)and'risk'or''end-- function retained for backwards compatibilityfunctionp.risk(frame)returnp._risk(getArgs(frame))end-- count and no_percent arguments retained for backwards compatibilityfunctionp._num(args,count,no_percent)ifcount==nilthencount=count_from_args(args)endargs.count=countargs.risk=risk_boolean(args)-- Build output stringlocalreturn_value=''ifargs.count==nilandargs.riskthenreturn'a very large number of'elseifargs.count==nilthenreturn'many'else-- Use 2 significant figures for smaller numbers and 3 for larger oneslocalsigfig=2ifargs.count>=large_count_cutoffthensigfig=3end-- Prepare to round to appropriate number of sigfigslocalf=math.floor(math.log10(args.count))-sigfig+1-- Round and insert 'approximately' or '+' when appropriateifyesno(args[2])==trueor(type(args[1])=='string'and(mw.ustring.sub(args[1],-1)=='+'))then-- Round downreturn_value=string.format('%s+',lang_obj:formatNum(math.floor((args.count/10^(f)))*(10^(f))))else-- Round to nearestreturn_value=string.format('approximately %s',lang_obj:formatNum(math.floor((args.count/10^(f))+0.5)*(10^(f))))end-- Insert percentage of pages if that is likely to be >= 1% and when |no-percent= not set to yesno_percent=yesno(no_percentorargs['no-percent'])ifargs.countandargs.count>=approx_num_total_pages/100andnotno_percentthenlocalnum_total_pages=mw.getCurrentFrame():callParserFunction('NUMBEROFPAGES','R')localtotal_percent=math.floor(((args.count/num_total_pages)*100)+0.5)iftotal_percent>=1thenreturn_value=string.format('%s pages, or roughly %s%% of all',return_value,total_percent)endendendreturnreturn_valueend-- used by [[Template:Stub documentation]] and other pages-- count argument retained for backwards compatibilityfunctionp.num(frame,count)returnp._num(getArgs(frame),count)end-- count argument retained for backwards compatibilityfunctionp._text(args,count)--[=[ Only show the information about how this template gets updated if someone is actually editing the page and maybe trying to update the count. ]=]localbot_text=(mw.getCurrentFrame():preprocess('{{REVISIONID}}')=='')and("\n\n----\n'''Preview message''':"..' Transclusion count updated automatically ([[Template:High-use/doc#Technical details|see documentation]]).')or''ifcount==nilthencount=count_from_args(args)endargs.count=countargs.risk=risk_boolean(args)-- trim /doc, /sandbox and /testcaseslocaltitle=args.titleor(args.demoandargs.demo~=''andmw.title.new(args.demo,'Template'))ormw.title.getCurrentTitle()iftitle.subpageText==doc_wordortitle.subpageText==sandbox_wordortitle.subpageText==testcases_wordthentitle=title.basePageTitleend-- use /testcases of base templatelocaltestcases_page=mw.title.new(title.prefixedText..'/'..testcases_word)-- exists is expensivewhiletestcases_page.basePageTitle.isSubpageandnottestcases_page.existsdotestcases_page=mw.title.new(testcases_page.basePageTitle.basePageTitle.prefixedText..'/'..testcases_word)endlocalsystemMessages=(args['system']or'')~=''-- This retrieves the project URL automatically to simplify localization.localtemplateCount=('on [https://linkcount.toolforge.org/?project=%s&page=%s#transclusions %s pages]'):format(title:fullUrl():gsub('//(.-)/.*','%1'),mw.uri.encode(title.fullText),p._num(args))localused_on_text="'''This "..(title:inNamespace('Module')and'Lua module'or'template')..' is used 'ifsystemMessagesthenused_on_text=used_on_text..args['system']..((args.countandargs.count>2000)and("''', and "..templateCount)or("'''"))elseused_on_text=used_on_text..templateCount.."'''"endlocalsandbox_text=('%s\'s [[%s/sandbox|/sandbox]] or [[%s|/testcases]] subpages, or in your own [[%s]]. '):format(title:inNamespace('Module')and'module'or'template',title.fullText,testcases_page.fullText,title:inNamespace('Module')and(sandbox_module_page..'|module sandbox')or(user_subpage_info_page..'|user subpage'))localinfoArg=args['info']~=''andargs['info']if(systemMessagesorargs.risk)thenlocalinfo='.'ifsystemMessagestheninfo=info..'<br />Changes to it can cause immediate changes to the '..mw.site.namespaces.Project.name..' user interface.'endifinfoArgtheninfo=info..'<br />'..infoArgendsandbox_text=info..'<br /> To avoid major disruption'..(args.countandargs.count>=large_count_cutoffand' and server load'or'')..-- should this use args.risk?', any changes should be tested in the '..sandbox_text..'The tested changes can be added to this page in a single edit. 'elsesandbox_text=(infoArgand('.<br />'..infoArg..' C')or' and c')..'hanges may be widely noticed. Test changes in the '..sandbox_textendlocaldiscussion_text=systemMessagesand'Please discuss changes 'or'Consider discussing changes 'ifargs[2]~=nilandargs[2]~=''andyesno(args[2])==nilthendiscussion_text=string.format('%sat [[%s]]',discussion_text,args[2])elsediscussion_text=string.format('%son the [[%s|talk page]]',discussion_text,title.talkPageTitle.fullText)endreturnused_on_text..sandbox_text..discussion_text..' before implementing them.'..bot_textend-- used by [[Template:R from high-use template]]-- count argument retained for backwards compatibilityfunctionp.text(frame,count)returnp._text(getArgs(frame),count)end-- nocat argument retained for backwards compatibilityfunctionp._main(args,nocat)args.count=count_from_args(args)args.risk=risk_boolean(args)args.title=(args.demoandargs.demo~=''andmw.title.new(args.demo,'Template'))ormw.title.getCurrentTitle()localimage='Ambox warning yellow.svg'localtype_param='style'localepilogue=''ifargs['system']andargs['system']~=''thenimage='Ambox important.svg'type_param='content'ifyesno(nocatorargs['nocat'])~=trueandnotargs.title.isRedirectthenlocalprotection_action=(args.title:inNamespace('File')and'upload')or'edit'localprotection_level=require('Module:Effective protection level')._main(protection_action,args.title.fullText)ifprotection_level~='sysop'andprotection_level~='templateeditor'andprotection_level~='interfaceadmin'thenepilogue=mw.getCurrentFrame():expandTemplate{title='sandbox other',args={[2]='[[Category:'..system_messages_cat..']]'}}endendelseifargs.riskthenimage='Ambox warning orange.svg'type_param='content'endimage='[[File:'..image..'|40px|alt=Warning|link=]]'ifargs['form']=='editnotice'thenreturnmw.getCurrentFrame():expandTemplate{title='editnotice',args={['image']=image,['text']=p._text(args),['expiry']=(args['expiry']or'')}}..epilogueelsereturnrequire('Module:Message box').main('ombox',{type=type_param,image=image,text=p._text(args),expiry=(args['expiry']or'')})..epilogueendendfunctionp.main(frame)returnp._main(getArgs(frame))endreturnp