Modul:Vandal-m

This is [[MediaWiki:Tagline]]. Set to <code>display:none</code> by chameleon skin.
Version vom 9. August 2015, 09:56 Uhr von Maintenance script (Diskussion | Beiträge) (Schützte „Modul:Vandal-m“ ([Bearbeiten=Nur Administratoren erlauben] (unbeschränkt) [Verschieben=Nur Administratoren erlauben] (unbeschränkt)))
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu:Navigation, Suche
Documentation icon Module documentation[view] [edit] [history] [purge]

This module implements the {{vandal-m}} template.

Usage from wikitext

This module cannot be used directly from wikitext. It can only be used through a template, usually the {{vandal-m}} template. Please see the template page for documentation.

Usage from Lua modules

To use this module from other Lua modules, first load the module.

local mVandalM = require('Module:Vandal-m')

You can then generate the vandal-m links by using the _main function.

mVandalM._main(args)

The args variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the {{vandal-m}} template documentation.

-- This module implements {{vandal-m}}.

local p = {}

local su = require('Module:Su')._main

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._main(args)
end

function p._main(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 log and autoblocks
	do
		local blockLogLink = makeFullUrlLink(
			'Special:Log/block',
			{page = 'User:' .. username},
			'<span title="Blocklog: '
				.. username
				.. '" style="color:#002bb8">block&nbsp;log</span>'
		)
		local autoblocksLink = makeUrlLink(
			{
				host = 'tools.wmflabs.org',
				path = '/xtools/autoblock/',
				query = {user = username}
			},
			'<sup title="Autoblock: '
				.. username
				.. '" style="color:#002bb8">auto</sup>'
		)
		links[#links + 1] = blockLogLink .. autoblocksLink
	end

	-- 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'
	)

	-- Sockpuppet investigations
	links[#links + 1] = getLinkIfExists(
		'Wikipedia:Sockpuppet investigations/',
		username,
		'spi'
	)

	-- Suspected sockpuppets
	links[#links + 1] = getLinkIfExists(
		'Wikipedia:Suspected sock puppets/',
		username,
		'ssp'
	)

	-- Sockpuppet categories
	-- There isn't a seperator between these and the suspected sockpuppets link,
	-- so we will add them later instead of adding them to the links table.
	local sockCategoryLinks
	do
		local confirmed = getTitle(
			'Category:Wikipedia sockpuppets of ' .. username
		)
		local suspected = getTitle(
			'Category:Suspected Wikipedia sockpuppets of ' .. username
		)
		if confirmed and confirmed.exists or suspected and suspected.exists then
			local sup, sub
			if confirmed and confirmed.exists then
				sup = '&ensp;' .. makeWikilink(
					':' .. confirmed.prefixedText,
					'confirmed&nbsp;socks'
				)
			end
			if suspected and suspected.exists then
				sub = '&ensp;' .. makeWikilink(
					':' .. suspected.prefixedText,
					'suspected&nbsp;socks'
				)
			end
			sockCategoryLinks = su(sup, sub)
		end
	end

	-- Add the user link and the outer span tags.
	return string.format(
		'<span id="%s" class="plainlinks">%s (%s%s)</span>',
		username,
		makeWikilink('User:' .. username, username),
		table.concat(links, ' &bull; '),
		sockCategoryLinks or ''
	)
end

return p