Module:User contrib
Appearance
![]() | This Lua module is used on approximately 5,200 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 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 module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Usage
Implements {{User contrib}}
local p = {}
local Userbox = require('Module:Userbox')
local getArgs = require('Module:Arguments').getArgs
local function urlencode(text)
-- Return equivalent of {{urlencode:text}}.
local function byte(char)
return string.format('%%%02X', string.byte(char))
end
return text:gsub('[^ %w%-._]', byte):gsub(' ', '+')
end
local function formatNumber(number)
return mw.getContentLanguage():formatNum( tonumber(number) )
end
function p.contrib(frame, args)
if not args then
args = getArgs(frame)
end
local count = tonumber(args[1])
local id_fc, id_c, info_fc, info_c
if count < 1000 then id_fc = '#ffffff'; id_c = '#186A3B'; info_fc = '#000000'; info_c = '#1D8348'
elseif count < 2000 then id_fc = '#ffffff'; id_c = '#1D8348'; info_fc = '#000000'; info_c = '#239B56'
elseif count < 3000 then id_fc = '#ffffff'; id_c = '#1D8348'; info_fc = '#000000'; info_c = '#239B56'
elseif count < 4000 then id_fc = '#ffffff'; id_c = '#1D8348'; info_fc = '#000000'; info_c = '#239B56'
elseif count < 5000 then id_fc = '#ffffff'; id_c = '#1D8348'; info_fc = '#000000'; info_c = '#239B56'
elseif count < 7500 then id_fc = '#ffffff'; id_c = '#1D8348'; info_fc = '#000000'; info_c = '#239B56'
elseif count < 10000 then id_fc = '#ffffff'; id_c = '#1D8348'; info_fc = '#000000'; info_c = '#239B56'
elseif count < 15000 then id_fc = '#ffffff'; id_c = '#239B56'; info_fc = '#000000'; info_c = '#28B463'
elseif count < 20000 then id_fc = '#000000'; id_c = '#28B463'; info_fc = '#000000'; info_c = '#2ECC71'
elseif count < 25000 then id_fc = '#000000'; id_c = '#2ECC71'; info_fc = '#ffffff'; info_c = '#58D68D'
elseif count < 30000 then id_fc = '#ffffff'; id_c = '#1B4F72'; info_fc = '#000000'; info_c = '#2874A6'
elseif count < 35000 then id_fc = '#ffffff'; id_c = '#2874A6'; info_fc = '#000000'; info_c = '#3498DB'
elseif count < 40000 then id_fc = '#ffffff'; id_c = '#3498DB'; info_fc = '#000000'; info_c = '#85C1E9'
elseif count < 45000 then id_fc = '#000000'; id_c = '#85C1E9'; info_fc = '#000000'; info_c = '#D6EAF8'
elseif count < 50000 then id_fc = '#000000'; id_c = '#D6EAF8'; info_fc = '#ffffff'; info_c = '#1B4F72'
-- https://htmlcolorcodes.com/
elseif count < 55000 then id_fc = '#ffffff'; id_c = '#4A235A'; info_fc = '#000000'; info_c = '#6C3483'
elseif count < 60000 then id_fc = '#ffffff'; id_c = '#6C3483'; info_fc = '#000000'; info_c = '#8E44AD'
elseif count < 65000 then id_fc = '#ffffff'; id_c = '#8E44AD'; info_fc = '#000000'; info_c = '#BB8FCE'
elseif count < 70000 then id_fc = '#000000'; id_c = '#BB8FCE'; info_fc = '#000000'; info_c = '#E8DAEF'
elseif count < 75000 then id_fc = '#000000'; id_c = '#E8DAEF'; info_fc = '#ffffff'; info_c = '#4A235A'
elseif count < 80000 then id_fc = '#000000'; id_c = '#dddddd'; info_fc = '#000000'; info_c = '#eeeeee'
elseif count < 85000 then id_fc = '#000000'; id_c = '#dddddd'; info_fc = '#000000'; info_c = '#eeeeee'
elseif count < 90000 then id_fc = '#ffffff'; id_c = '#000000'; info_fc = '#000000'; info_c = '#eeeeee'
elseif count < 95000 then id_fc = '#000000'; id_c = '#dddddd'; info_fc = '#000000'; info_c = '#eeeeee'
elseif count < 100000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 105000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 110000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 115000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 120000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 125000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 130000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 135000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 140000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 145000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 150000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 155000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 160000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 165000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 170000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 175000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 180000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 185000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 190000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 195000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
elseif count < 200000 then id_fc = '#000000'; id_c = '#33FFFF'; info_fc = '#000000'; info_c = '#99FFFF'
else id_fc = '#000000'; id_c = '#dddddd'; info_fc = '#000000'; info_c = '#eeeeee'
end
local user_args = {}
local language = ''
if args['lang'] then language = 'the '.. args['lang'] ..' ' end
local project = args['project'] or 'Wikipedia'
local project_site = args['projsite'] or 'en.wikipedia.org'
local user = 'user'
local username = args[2] or mw.title.getCurrentTitle().baseText
local url = 'https://xtools.wmflabs.org/ec/'.. project_site .. '/' ..urlencode(username)
local formated_count = mw.getContentLanguage():formatNum( count )
local deleted, articles, automated, distinct, unique, images, insane = '','','', '', '', '', ''
if args['deleted'] then deleted = ', over <b>' ..formatNumber(args['deleted'])..'</b> of which were to pages that are now deleted' end
if args['articles'] then articles = ', over <b>' ..formatNumber(args['articles'])..'</b> of which were to articles' end
if args['automated'] then automated = ', over <b>' ..formatNumber(args['automated'])..'</b> of which were automated' end
if args['distinct'] then distinct = ', on over <b>' ..formatNumber(args['distinct'])..'</b> distinct pages' end
if args['unique'] then unique = ', on over <b>' ..formatNumber(args['unique'])..'</b> unique pages' end
if args['images'] then images = ', including over <b>' ..formatNumber(args['images'])..'</b> uploaded images' end
if args['insane'] then insane = ' and, as a result, may be slightly insane' end
if args['bot'] then user = 'bot' end
user_args['id-s'] = 12
user_args['info-c'] = info_c
user_args['id-c'] = id_c
user_args['info-fc'] = info_fc
user_args['id-fc'] = id_fc
user_args['id'] = formated_count .. '+'
user_args['info'] = '<span class="plainlinks neverexpand">This '
.. user .. ' has made ['
..url
..' <span style="color: '..info_fc
..'"> more than '
.. '<b>'..formated_count..'</b>'
.. ' contributions] to '.. language.. project
.. automated
.. deleted
.. articles
.. distinct
.. unique
.. images
.. insane
.. '.</span>'
return Userbox.main('_userbox', user_args)
end
return p