Revision as of 18:44, 26 March 2020 by imported>CFCF(Stripped some of the formality and unnecessary verbiage that only takes space, decreasing the likelihood banners will actually be read)
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 pagesand changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages. Please discuss 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.
localp={}local_fetch=require('Module:Transclusion_count').fetchfunctionp.num(frame,count)ifcount==nilthencount=_fetch(frame)end-- Build output stringlocalreturn_value=""ifcount==nilthenifframe.args[1]=="risk"thenreturn_value="a very large number of"elsereturn_value="many"endelse-- Use 2 sigfigs 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 "apprxomimately" or "+" when appropriateif(frame.args[2]=="yes")or(mw.ustring.sub(frame.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 %s",mw.getContentLanguage():formatNum(math.floor((count/10^(f))+0.5)*(10^(f))))end-- Insert percent of pagesifframe.args["all-pages"]andframe.args["all-pages"]~=""thenlocalpercent=math.floor(((count/frame:callParserFunction('NUMBEROFPAGES','R'))*100)+0.5)return_value=string.format("%s pages, roughly %s%% of all",return_value,percent)endendreturnreturn_valueendfunctionp.risk(frame)localreturn_value=""ifframe.args[1]=="risk"thenreturn_value="risk"elselocalcount=_fetch(frame)ifcountandcount>=100000thenreturn_value="risk"endendreturnreturn_valueendfunctionp.text(frame,count)ifcount==nilthencount=_fetch(frame)endlocalreturn_value={}localtitle=mw.title.getCurrentTitle()iftitle.subpageText=="doc"ortitle.subpageText=="sandbox"thentitle=title.basePageTitleendlocaltemplatecount=string.format("https://tools.wmflabs.org/templatecount/index.php?lang=en&namespace=%s&name=%s",mw.title.getCurrentTitle().namespace,mw.uri.encode(title.text))localused_on_text=string.format("'''This %s is used on [%s %s pages]'''",(mw.title.getCurrentTitle().namespace==828and"Lua module"or"template"),templatecount,p.num(frame,count))localsandbox_text=string.format("%s's [[%s/sandbox|/sandbox]] or [[%s/testcases|/testcases]] subpages%s ",(mw.title.getCurrentTitle().namespace==828and"module"or"template"),title.fullText,title.fullText,(mw.title.getCurrentTitle().namespace==828and"."or", or in your own [[Wikipedia:Subpages#How to create user subpages|user subpage]]."))if(frame.args[1]=="risk"or(countandcount>=100000))thenlocalinfo=""ifframe.args["info"]andframe.args["info"]~=""theninfo="<br />"..frame.args["info"]endsandbox_text=string.format(".%s<br /> To avoid major disruption and server load, any changes should be tested in the %sThe tested changes can be added to this page in a single edit. ",info,sandbox_text)elsesandbox_text=string.format("and changes may be widely noticed. Test changes in the %s",sandbox_text)endlocaldiscussion_text="Please discuss changes "ifframe.args["2"]andframe.args["2"]~=""andframe.args["2"]~="yes"thendiscussion_text=string.format("%sat [[%s]]",discussion_text,frame.args["2"])elsediscussion_text=string.format("%son the [[%s|talk page]]",discussion_text,title.talkPageTitle.fullText)endreturntable.concat({used_on_text,sandbox_text,discussion_text," before implementing them."})endfunctionp.main(frame)localcount=_fetch(frame)localreturn_value=""localimage="[[File:Ambox warning yellow.svg|40px|alt=Warning|link=]]"localtype_param="style"if(frame.args[1]=="risk"or(countandcount>=100000))thenimage="[[File:Ambox warning orange.svg|40px|alt=Warning|link=]]"type_param="content"endifframe.args["form"]=="editnotice"thenreturn_value=frame:expandTemplate{title='editnotice',args={["image"]=image,["text"]=p.text(frame,count),["expiry"]=(frame.args["expiry"]or"")}}elsereturn_value=frame:expandTemplate{title='ombox',args={["type"]=type_param,["image"]=image,["text"]=p.text(frame,count),["expiry"]=(frame.args["expiry"]or"")}}endreturnreturn_valueendreturnp