پودمان:Checkuser

از ویکی‌پدیا، دانشنامهٔ آزاد
توضیحات پودمان[ایجاد] [پاکسازی]
local yesno = require('Module:Yesno')

local p = {}

local getArgs = function(fr)
	return require('Module:Arguments').getArgs(fr, {
		trim = true,
		removeBlanks = true
	})
end
local noping = function(name)
	return require('Module:No ping')._main({name})
end

local middot = '&nbsp;<b>&middot;</b>&#32;'
local spi = 'ویکی‌پدیا:درخواست بازرسی کاربر'
local extlink = function(url, text)
	return '[' .. tostring(url) .. (text and ' ' .. text or '') .. ']'
end
local link = function(page, param, text)
	return extlink(mw.uri.fullUrl(page, param), text)
end

function p.user(frame)
	local args = getArgs(frame)
	return p._user(args['User'] or args[1] or args['کاربر'], args['master name'] or args['حساب اصلی'], args['master'] or args['اصلی'])
end

function p._user(sock, mastername, master)
	if not sock then
		return (
			'<strong class="error">نام کاربری وارد نشده است.</strong>' ..
			'[[رده:الگوی بازرسی کاربر فاقد نام کاربری]]'
		)
	end
	local span = mw.html.create('span'):attr('class', 'plainlinks cuEntry')
	local curtitle = mw.title.getCurrentTitle()
	local links = {
		'[[بحث کاربر:' .. sock .. '|بحث]]' ..
			'<sup><span style="font-size: 120%;">' ..
				link('بحث کاربر:' .. sock, {
					action = 'edit',
					section = 'new'
				}, '<span style="color: grey;">+</span>') ..
			'</span></sup>',
		link('کاربر:' .. sock, (function()
			local param = {
				action = 'edit',
				preload = 'الگو:بازرسی کاربر/پیش‌بارگذاری' .. (yesno(master) and ' اصلی' or '')
			}
			if master ~= 'yes' or not yesno(master) then
				param['preloadparams[]'] = (
					mastername and
					mastername or
					'<!-- زاپاس‌دار در اینجا -->'
				)
			end
			return param
		end)(), 'برچسب'),
		'[[ویژه:مشارکت‌ها/' .. sock .. '|مشارکت‌ها]]' ..
			'<span class="sysop-show">',
		'[[ویژه:مشارکت‌های حذف شده/' .. sock .. '|مشارکت‌های حذف‌شده]]' ..
			'</span>',
		link('ویژه:سیاهه‌ها', {
			user = sock
		}, 'سیاهه‌ها'),
		link('ویژه:سیاههٔ_خرابکاری', {
			wpSearchUser = sock
		}, 'سیاههٔ پالایه') ..
			'<span class="sysop-show">',
		'[[ویژه:بستن نشانی آی‌پی/' .. sock .. '|قطع دسترسی]]' ..
		(function()
			if curtitle:isSubpageOf(mw.title.new(spi)) then
				return (
					middot .. link('ویژه:بستن نشانی آی‌پی', {
						wpBlockAddress = sock,
						wpExpiry = 'indefinite',
						wpReason = 'سوءاستفاده از [[وپ:زاپاس|چند حساب کاربری]]',
						['wpReason-other'] = 'لطفاً: [[:w:fa:' .. spi .. '/' ..
							mw.text.split(curtitle.text, '/')[2] ..
						']] را ببینید'
					}, 'قطع دسترسی بازرسی کاربر')
				)
			else
				return ''
			end
		end)() ..
			'</span>',
		link('ویژه:سیاهه‌ها/block', {
			page = 'کاربر:' .. sock
		}, 'سیاههٔ بسته‌شدن'),
		'[[:m:Special:CentralAuth/' .. sock .. '|ورود متمرکز]]' ..
			'<span class="cuLink checkuser-show">',
		link('ویژه:بازرسی_کاربر', (function()
			local param = {
				user = sock
			}
			if mw.text.split(curtitle.prefixedText, '/')[1] == spi then
				param['reason'] = sock .. ' از [[' .. curtitle.prefixedText .. ']]'
			end
			return param
		end)(), 'بازرسی') ..
		'(' .. link('ویژه:سیاهه_بازرسی_کاربر', {
			cuSearch = sock
		}, 'سیاهه') .. ')',
		link('ویژه:بررسی', (function()
			local param = {
				targets = sock
			}
			if curtitle.prefixedText == spi .. '/' .. table.concat({
				mw.text.split(curtitle.prefixedText, '/')[2],
				mw.text.split(curtitle.prefixedText, '/')[3]
			}, '/') then
				param['reason'] = sock .. ' از [[' .. curtitle.prefixedText .. ']]'
			end
			return param
		end)(), 'بررسی'),
		extlink(
			tostring(mw.uri.new('https://checkuser.wikimedia.org/w/index.php'):extend({
				title = 'Special:Search',
				search = sock,
				ns0 = 1,
				ns2 = 1,
				ns14 = 1
			})),
			'ویکی‌بازرسی'
		) ..
			'</span>'
	}
	span = span:wikitext(table.concat({
		noping(sock),
		'(' .. table.concat(links, middot) .. ')'
	}, ' '))
	return tostring(span) .. '__NOINDEX__'
end

function p.ip(frame)
	local args = getArgs(frame)
	return p._ip(args['User'] or args[1] or args['کاربر'], args['master name'] or args['حساب اصلی'])
end

function p._ip(ip, mastername)
	if not ip then
		return (
			'<strong class="error">نام کاربری وارد نشده است.</strong>' ..
			'[[رده:الگوی بازرسی آی‌پی فاقد آی‌پی]]'
		)
	end
	local span = mw.html.create('span'):attr('class', 'plainlinks neverexpand cuEntry')
	local curtitle = mw.title.getCurrentTitle()
	local links = {
		'[[بحث کاربر:' .. ip .. '|بحث]]' ..
			'<sup><span style="font-size: 120%;">' ..
				link('بحث کاربر:' .. ip, {
					action = 'edit',
					section = 'new'
				}, '<span style="color: grey">+</span>') ..
			'</span></sup>',
		link('کاربر:' .. ip, {
			action = 'edit',
			preload = 'Template:Checkip/Preload',
			['preloadparams[]'] = (
				mastername and
				mastername or
				'<!-- نام زاپاس‌دار در اینجا -->'
			)
		}, 'برچسب'),
		'[[ویژه:مشارکت‌ها/' .. ip .. '|مشارکت‌ها]]',
		link('ویژه:سیاههٔ_خرابکاری', {
			wpSearchUser = ip
		}, 'سیاههٔ پالایه'),
		extlink(
			tostring(mw.uri.new('https://tools.wmflabs.org/whois/gateway.py'):extend({
				lookup = 'true',
				ip = ip
			})),
			'هوئیز'
		),
		extlink(
			tostring(mw.uri.new('https://www.robtex.com/rbls/' .. ip .. '.html')),
			'RBLs'
		),
		extlink(
			tostring(mw.uri.new('https://ipcheck.toolforge.org/index.php'):extend({
				ip = ip
			})),
			'بررسی پروکسی'
		) ..
			'<span class="sysop-show">',
		'[[ویژه:بستن نشانی آی‌پی/' .. ip .. '|قطع دسترسی]]' .. (function()
			if curtitle:isSubpageOf(mw.title.new(spi)) then
				return (
					middot .. link('ویژه:بستن نشانی آی‌پی', {
						wpTarget = ip,
						wpReason = 'سوءاستفاده از [[وپ:زاپاس|چند حساب کاربری]]',
						['wpReason-other'] = 'لطفاً [[:w:fa:' .. spi .. '/' ..
							mw.text.split(curtitle.text, '/')[2] ..
						']]'
					}, 'قطع دسترسی بازرسی کاربر')
				)
			else
				return ''
			end
		end)() ..
			'</span>',
		link('ویژه:سیاهه‌ها/block', {
			page = 'کاربر:' .. ip
		}, 'سیاههٔ بسته‌شدن'),
		extlink(
			tostring(mw.uri.new('https://guc.toolforge.org/'):extend({
				by = 'date',
				user = ip
			})),
			'مشارکت‌های بیناویکی'
		) ..
			'<span class="cuLink checkuser-show">',
		link('ویژه:بازرسی کاربر', (function()
			local param = {
				ip = ip
			}
			if curtitle.prefixedText == spi .. '/' .. table.concat({
				mw.text.split(curtitle.prefixedText, '/')[2],
				mw.text.split(curtitle.prefixedText, '/')[3]
			}, '/') then
				param['reason'] = '[[' .. curtitle.prefixedText .. ']]'
			end
			return param
		end)(), 'بازرسی') .. ' ' ..
		'(' .. link('ویژه:سیاهه بازرسی کاربر', {
			cuSearch = ip
		}, 'سیاهه') .. ')' ..
			'</span>'
	}
	span = span:wikitext(table.concat({
		noping(ip),
		'(' .. table.concat(links, middot) .. ')'
	}, ' '))
	return tostring(span)
end

return p