Jump to content

Module:High-use

Permanently protected module
From Wikipedia, the free encyclopedia

localp={}localgetArgs=require('Module:Arguments').getArgs-- _fetch looks at the "demo" argument.local_fetch=require('Module:Transclusion_count')._fetchlocalyesno=require('Module:Yesno')functionp._num(args,count,no_percent)ifcount==nilthenifyesno(args['fetch'])==falsethenif(args[1]or'')~=''thencount=tonumber(args[1])endelsecount=_fetch(args)endend-- Build output stringlocalreturn_value=""ifcount==nilthenifargs[1]=="risk"thenreturn"a very large number of"elsereturn"many"endelse-- Use 2 significant figures for smaller numbers and 3 for larger oneslocalsigfig=2ifcount>=100000thensigfig=3end-- Prepare to round to appropriate number of sigfigslocalf=math.floor(math.log10(count))-sigfig+1-- Round and insert "approximately" or "+" when appropriateif(args[2]=="yes")or(type(args[1])=='string'and(mw.ustring.sub(args[1],-1)=="+"))then-- Round downreturn_value=string.format("%s+",mw.getContentLanguage():formatNum(math.floor((count/10^(f)))*(10^(f))))else-- Round to nearestreturn_value=string.format("approximately&#x20;%s",mw.getContentLanguage():formatNum(math.floor((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=no_percentorargs['no-percent']ifcountandcount>250000andnotyesno(no_percent)thenlocalnumpages=mw.getCurrentFrame():callParserFunction('NUMBEROFPAGES','R')localpercent=math.floor(((count/numpages)*100)+0.5)ifpercent>=1thenreturn_value=string.format("%s&#x20;pages, or roughly %s%% of all",return_value,percent)endendendreturnreturn_valueendfunctionp.num(frame,count)returnp._num(getArgs(frame),count)end-- Actions if there is a large (greater than or equal to 100,000) transclusion countfunctionp._risk(args)ifargs[1]=="risk"thenreturn"risk"elselocalcount=_fetch(args)ifcountandcount>=100000thenreturn"risk"endendreturn""endfunctionp.risk(frame)returnp._risk(getArgs(frame))endfunctionp._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==nilthenifyesno(args['fetch'])==falsethenif(args[1]or'')~=''thencount=tonumber(args[1])endelsecount=_fetch(args)endendlocaltitle=mw.title.getCurrentTitle()if((args.demoor''~='')andmw.title.new(args.demo,10))thentitle=mw.title.new(args.demo,10)endiftitle.subpageText=="doc"ortitle.subpageText=="sandbox"thentitle=title.basePageTitleendlocalsystemMessages=(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,count))localused_on_text="'''This "..(title.namespace==828and"Lua module"or"template")..' is used ';ifsystemMessagesthenused_on_text=used_on_text..args['system']..((countandcount>2000)and("''', and "..templateCount)or("'''"))elseused_on_text=used_on_text..templateCount.."'''"endlocalsandbox_text=("%s's [[%s/sandbox|/sandbox]] or [[%s/testcases|/testcases]] subpages, or in your own [[%s]]. "):format((title.namespace==828and"module"or"template"),title.fullText,title.fullText,title.namespace==828and"Module:Sandbox|module sandbox"or"Wikipedia:User pages#SUB|user subpage")localinfoArg=args["info"]~=""andargs["info"]if(systemMessagesorargs[1]=="risk"or(countandcount>=100000))thenlocalinfo=systemMessagesand'.<br/>Changes to it can cause immediate changes to the Wikipedia user interface.'or'.'ifinfoArgtheninfo=info.."<br />"..infoArgendsandbox_text=info..'<br /> To avoid major disruption'..(countandcount>=100000and' and server load'or'')..', 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"]andargs["2"]~=""andargs["2"]~="yes"thendiscussion_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_textendfunctionp.text(frame,count)returnp._text(getArgs(frame),count)endfunctionp._main(args,nocat)localcount=nilifyesno(args['fetch'])==falsethenif(args[1]or'')~=''thencount=tonumber(args[1])endelsecount=_fetch(args)endlocalimage="[[File:Ambox warning yellow.svg|40px|alt=Warning|link=]]"localtype_param="style"localepilogue=''ifargs['system']andargs['system']~=''thenimage="[[File:Ambox important.svg|40px|alt=Warning|link=]]"type_param="content"nocat=nocatorargs['nocat']localcategorise=(nocat==''ornotyesno(nocat))ifcategoriseandnotmw.title.getCurrentTitle().isRedirectthenepilogue=mw.getCurrentFrame():preprocess('{{Sandbox other||{{#switch:{{#invoke:Effective protection level|{{#switch:{{NAMESPACE}}|File=upload|#default=edit}}|{{FULLPAGENAME}}}}|sysop|templateeditor|interfaceadmin=|#default=[[Category:Pages used in system messages needing protection]]}}}}')endelseif(args[1]=="risk"or(countandcount>=100000))thenimage="[[File:Ambox warning orange.svg|40px|alt=Warning|link=]]"type_param="content"endifargs["form"]=="editnotice"thenreturnmw.getCurrentFrame():expandTemplate{title='editnotice',args={["image"]=image,["text"]=p._text(args,count),["expiry"]=(args["expiry"]or"")}}..epilogueelsereturnrequire('Module:Message box').main('ombox',{type=type_param,image=image,text=p._text(args,count),expiry=(args["expiry"]or"")})..epilogueendendfunctionp.main(frame)returnp._main(getArgs(frame))endreturnp
close