Module:User type
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module depends on the following other modules: |
| Description | This module gets the user type for a given username. |
|---|---|
| Status | Release |
| Updated | September 29, 2026 (11 hours ago) |
| Dependencies | Module:IPAddress |
This module gets the user type for a given username.
Documentation
Package items
user_type._isUser( s )(function)- Detects whether the user is an account or not.
- Parameter:
sUsername (string) - Returns: The user type or an empty string if the user is an IP address.
user_type._isTempUser( s )(function)- Detects whether the user is a temporary user or not.
- Parameter:
sUsername (string) - Returns: Whether the user is likely a permanent account.
user_type._isPermUser( s )(function)- Detects whether the user is a registered user or not.
- Parameter:
sUsername (string) - Returns: Whether the user is likely a permanent account.
user_type._main( s )(function)- Gets the user type.
- Parameter:
sUsername (string) - Returns: User type "ip", "range", "temp", or "perm".
user_type.isTempUser( frame )(function)- Entrypoint for templates to detect whether a user is a temporary account.
- Parameters:
- Returns: Whether the user is likely a temporary account.
user_type.isPermUser( frame )(function)- Entrypoint for templates to detect whether a user is a registered account.
- Parameters:
- Returns: Whether the user is likely a registered account.
user_type.isUser( frame )(function)- Entrypoint for templates to detect the type of user account.
- Parameters:
- Returns: Whether the user is likely an account.
user_type.main( frame )(function)- Entrypoint for {{user type}}.
- Parameters:
- Returns: Whether the user is likely an account.
Documentation above is auto generated
--- This module gets the user type for a given username.
--
-- @require Module:IPAddress
-- @release stable
local p = {}
p._ipMod = require("Module:IPAddress")
for k,v in pairs(p._ipMod) do
p[k] = v
end
--- Detects whether the user is an account or not.
--
-- @param {string} s Username
-- @return The user type or an empty string if the user is an IP address.
function p._isUser(s)
if p._isIpOrRange(s) ~= '' then return '' end
local isTempUser = p._isTempUser(s)
if isTempUser then return 'temp'
else return 'perm' end
end
--- Detects whether the user is a temporary user or not.
--
-- @param {string} s Username
-- @return Whether the user is likely a permanent account.
function p._isTempUser(s)
if p._isIpOrRange(s) ~= '' then return false end
for k,v in ipairs( mw.text.split(s, '') ) do
if ( k == 1 ) then
if v ~= '~' then return false end
elseif k == 6 or ( k > 6 and math.fmod( k, 6 ) == 0 ) then
if v ~= '-' then return false end
else
if not v:match('%d') then return false end
end
end
return true
end
--- Detects whether the user is a registered user or not.
--
-- @param {string} s Username
-- @return Whether the user is likely a permanent account.
function p._isPermUser(s)
if p._isIpOrRange(s) ~= '' then return false end
return not p._isTempUser(s)
end
--- Gets the user type.
--
-- @param {string} s Username
-- @return User type "ip", "range", "temp", or "perm".
function p._main(s)
local isIpOrRange = p._isIpOrRange(s)
local isUser = p._isUser(s)
return isIpOrRange ~= '' and isIpOrRange or isUser
end
--- Adapted from [[Module:IPAddress]]
-- @see [[Module:IPAddress#L-54]]
local function input(args)
-- Return input parameter after replacing any of following directional markers.
-- LRM : LEFT-TO-RIGHT MARK (U+200E) : hex e2 80 8e = 226 128 142
-- LRE : LEFT-TO-RIGHT EMBEDDING (U+202A) : hex e2 80 aa = 226 128 170
-- PDF : POP DIRECTIONAL FORMATTING (U+202C) : hex e2 80 ac = 226 128 172
-- This is required for MediaWiki:Blockedtext message.
return (args[1] or ''):gsub('\226\128[\142\170\172]', ' ') -- replace LRM, LRE, PDF with space delimiter
end
--- Entrypoint for templates to detect whether a user is a temporary account.
--
-- @param {Frame} frame Calling frame
-- @param {table} frame.args Calling arguments
-- @param {string} frame.args[1] String to test
-- @return Whether the user is likely a temporary account.
function p.isTempUser(frame) return p._isTempUser(input(frame)) and "1" or "0" end
--- Entrypoint for templates to detect whether a user is a registered account.
--
-- @param {Frame} frame Calling frame
-- @param {table} frame.args Calling arguments
-- @param {string} frame.args[1] String to test
-- @return Whether the user is likely a registered account.
function p.isPermUser(frame) return p._isPermUser(input(frame)) and "1" or "0" end
--- Entrypoint for templates to detect the type of user account.
--
-- @param {Frame} frame Calling frame
-- @param {table} frame.args Calling arguments
-- @param {string} frame.args[1] String to test
-- @return Whether the user is likely an account.
function p.isUser(frame) return p._isUser(input(frame)) or "" end
--- Entrypoint for {{tl|user type}}.
--
-- @param {Frame} frame Calling frame
-- @param {table} frame.args Calling arguments
-- @param {string} frame.args[1] String to test
-- @return Whether the user is likely an account.
function p.main(frame)
local args = require("Module:Arguments").getArgs(frame)
local sanitizeInput = input(args)
if sanitizeInput == '' then return args['#default'] or '' end
local result = p._main(sanitizeInput)
if args[result] ~= nil then
return args[result]
elseif args['#default'] then
return args['#default']
else
return result
end
end
return p