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 updatedif 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