Module:Vandal-m
Appearance
-- This module implements {{vandal-m}}.
local p = {}
local function makeWikilink(link, display)
if display then
return string.format('[[%s|%s]]', link, display)
else
return string.format('[[%s]]', link)
end
end
local function makeUrlLink(data, display)
local url = mw.uri.new(data)
url = tostring(url)
return string.format('[%s %s]', url, display)
end
local function makeFullUrlLink(page, query, display)
local url = mw.uri.fullUrl(page, query)
url = tostring(url)
return string.format('[%s %s]', url, display)
end
local function getTitle(page)
local success, title = pcall(mw.title.new, page)
if success then
return title
else
return nil
end
end
local function getLinkIfExists(pagePrefix, username, display)
local title = getTitle(pagePrefix .. username)
if title and title.exists then
return makeWikilink(title.prefixedText, display)
end
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {parentOnly = true})
return p.luaMain(args)
end
function p.luaMain(args)
local username, usernameEncoded
do
local lang = mw.language.getContentLanguage()
username = args.User or args[1] or 'Example'
username = lang:ucfirst(username)
usernameEncoded = mw.uri.encode(username)
end
local links = {}
-- Talk
links[#links + 1] = makeWikilink('User talk:' .. username, 'talk')
-- Contribs
links[#links + 1] = makeWikilink(
'Special:Contributions/' .. username,
'<span title="Contributions: ' .. username .. '">contribs</span>'
)
-- Block
links[#links + 1] = makeFullUrlLink(
'Special:Log/block',
{page = 'User:' .. username},
'<span title="Blocklog: '
.. username
.. '" style="color:#002bb8">block log</span>'
)
-- Autoblocks
links[#links + 1] = makeUrlLink(
{
host = 'tools.wmflabs.org',
path = '/xtools/autoblock/',
query = {user = username}
},
'<sup title="Autoblock: '
.. username
.. '" style="color:#002bb8">auto</sup>'
)
-- Ban listing
if args.ban then
links[#links + 1] = makeWikilink(
mw.site.namespaces[4].name .. 'List of banned users#' .. username,
'ban'
)
end
-- Arbitration requests
links[#links + 1] = getLinkIfExists(
'Wikipedia:Requests for arbitration/',
username,
'rfarb'
)
-- Requests for comment
links[#links + 1] = getLinkIfExists(
'Wikipedia:Requests for comment/',
username,
'rfcuser'
)
-- Long-term abuse
links[#links + 1] = getLinkIfExists(
'Wikipedia:Long term abuse/',
username,
'lta'
)
-- Requests for checkuser
links[#links + 1] = getLinkIfExists(
'Wikipedia:Requests for checkuser/Case/',
username,
'rfcu'
)
-- Requests for checkuser
links[#links + 1] = getLinkIfExists(
'Wikipedia:Sockpuppet investigations/',
username,
'spi'
)
-- Suspected sockpuppets
links[#links + 1] = getLinkIfExists(
'Wikipedia:Suspected sock puppets/',
username,
'ssp'
)
-- Sockpuppet categories
do
local confirmed = getTitle(
'Category:Wikipedia sockpuppets of ' .. username
)
local suspected = getTitle(
'Category:Suspected Wikipedia sockpuppets of ' .. username
)
if confirmed and suspected then
local confirmedLink = makeWikilink(
':' .. confirmed.prefixedText,
'confirmed socks'
)
local suspectedLink = makeWikilink(
':' .. suspected.prefixedText,
'suspected socks'
)
if confirmed.exists and suspected.exists then
-- Put the two links on top of each other.
local span = mw.html.create('span')
span
:css{
display = 'inline-block',
['margin-bottom'] = '-0.3em',
['vertical-align'] = '-0.4em',
['line-height'] = '1.2em',
['font-size'] = '85%',
['text-align'] = 'left'
}
:wikitext(confirmedLink)
:tag('br', {selfClosing = true}):done()
:wikitext(suspectedLink)
links[#links + 1] = tostring(span)
elseif confirmed.exists then
links[#links + 1] = confirmedLink
elseif suspected.exists then
links[#links + 1] = suspectedLink
end
end
end
return table.concat(links, ' • ')
end
return p