Jump to content
Wikipedia The Free Encyclopedia

Module:NUMBEROF/sandbox

From Wikipedia, the free encyclopedia
This is the module sandbox page for Module:NUMBEROF (diff).
Module documentation[view] [edit] [history] [purge]
[画像:Warning] This Lua module is used in MediaWiki:Statistics-files-desc .
Changes to it can cause immediate changes to the Wikipedia user interface.
To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them.
This module depends on the following other modules:
The above documentation is transcluded from Module:NUMBEROF/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
 localaliases={
 commons='commons.wikimedia.org',
 donate='donate.wikimedia.org',
 foundation='foundation.wikimedia.org',
 incubator='incubator.wikimedia.org',
 meta='meta.wikimedia.org',
 species='species.wikimedia.org',
 wikidata='www.wikidata.org',
 wikifunctions='www.wikifunctions.org',
 wikimania='wikimania.wikimedia.org',
 wikitech='wikitech.wikimedia.org',
 }

 localfunctiontrimArg(arg,i)
 arg=mw.text.trim(argor'')
 ifarg==''then
 ifithen
 error('Parameter '..i..' is missing. See template documentation')
 end
 returnnil
 end
 returnmw.ustring.lower(arg)
 end

 localfunctiongetValue(stats,action,map)
 ifaction=='depth'then
 -- https://meta.wikimedia.org/wiki/Wikipedia_article_depth
 -- This gives silly results if, for example, the number of articles is small.
 localn={'articles','edits','pages'}
 ifmapthen
 fori,vinipairs(n)do
 n[i]=map[v]
 end
 end
 fori,vinipairs(n)do
 n[i]=stats[v]or0
 end
 localarticles,edits,pages=n[1],n[2],n[3]
 ifpages==0orarticles==0then
 return0
 end
 returnmath.floor((edits/pages)*((pages-articles)/articles)^2)
 end
 ifmapthen
 action=map[action]
 end
 returnstats[action]
 end

 localfunctiongetIfLocal(site,action)
 -- If wanted site is the local site where module is running,
 -- return numberof result for given action, or nil.
 -- This is faster than reading the cached table, and gives the current value.
 ifsite==localSitethen
 ifaction=='activeusers'then
 action='activeUsers'
 end
 returngetValue(mw.site.stats,action)
 end
 end

 localfunctionmain(frame)
 localmetaWords={active=true,closed=true,languages=true,}
 localargs=frame:getParent().args
 localaction=trimArg(args[1],1)-- activeusers, admins, articles, edits, files, pages, users, depth, active, closed, languages
 ifaction:sub(1,8)=='numberof'then-- numberofX is an alias for X
 action=trimArg(action:sub(9),1)
 end
 localwantMeta=metaWords[action]
 localsite=trimArg(args[2],2)
 site=aliases[site]orsite
 ifnotwantMetaandnotsite:find('.',1,true)then
 -- site is like "af" or "af.wikipedia" or "af.wikiquote" etc., including "total"
 site=site..'.wikipedia'
 end
 localwantComma=trimArg(args[3])-- nil for no commas in output; "N" or anything nonblank inserts commas
 localresult
 ifwantMetathen
 localdata=mw.loadData('Module:NUMBEROF/meta')
 localnrActive=data.nrActive[site]
 localnrClosed=data.nrClosed[site]
 ifnrActiveornrClosedthen
 -- If either is set, site is valid but there may not be an entry for both active and closed.
 nrActive=nrActiveor0
 nrClosed=nrClosedor0
 ifaction=='active'then
 result=nrActive
 elseifaction=='closed'then
 result=nrClosed
 elseifaction=='languages'then
 result=nrActive+nrClosed
 end
 end
 else
 result=getIfLocal(site,action)
 ifnotresultthen
 localdata=mw.loadData('Module:NUMBEROF/data')
 localmap=data.map
 data=data.data
 result=data[site]
 ifresultthen
 result=getValue(result,action,map)
 end
 end
 end
 ifresultthen
 ifwantCommathen
 result=mw.language.getContentLanguage():formatNum(result)
 end
 returnresult-- number or formatted string
 end
 return-1
 end

 localfunctionrank(frame)
 -- Rank sites in a specified sister project by their number of articles.
 localargs=frame:getParent().args
 localparm=trimArg(args[1],1)-- a number like 12 or a site name like "af" (not "af.wikipedia")
 localbase=trimArg(args[2])or'wikipedia'-- base of full site name like "wikipedia" or "wikiquote"
 localwantComma=trimArg(args[3])
 localdata=mw.loadData('Module:NUMBEROF/'..(base=='wikipedia'and'rank'or'other'))
 data=data[base]
 ifdatathen
 localresult
 parm=tonumber(parm)orparm
 iftype(parm)=='number'then
 result=data.rankByIndex[parm]
 else
 result=data.rankBySite[parm]
 ifresultandwantCommathen
 result=mw.language.getContentLanguage():formatNum(result)
 end
 end
 ifresultthen
 returnresult-- number or string
 end
 end
 return-1
 end

 return{
 main=main,
 rank=rank,
 }

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