モジュール:SockInfo/sandbox

モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

{{SockInfo}}の内部モジュール。

使用法[編集]

{{#invoke:SockInfo|main}}

関連項目[編集]

require('strict')

local getArgs = require('モジュール:Arguments').getArgs
local Error

-- {{LineBox}}の代用
local function lineBox(logpages)
	return '<div style="border: 1px solid #00f; margin: 5px; padding: 5px;'
		.. 'float: right; font-size: 80%; width:15em">[[Wikipedia:管理者伝言板/'
		.. '投稿ブロック/ソックパペット#List|■リストへ戻る]]<hr>\n'
		.. logpages
		.. '\n</div>'
end

-- {{Main}}の簡易版
local function makeMain(pages)
	local endpos = table.maxn(pages)
	if endpos == 0 then
		return ''
	end
	local obj = {
		'<div class="rellink" style="margin-bottom: 0.5em; ',
		'padding-left: 2em; font-style: italic;">詳細は'
	}
	if endpos == 1 then
		table.insert(obj, mw.ustring.format('「[[:%s]]」', pages[1]))
	else
		local obj2 = {}
		for i = 1, endpos - 1 do
			if pages[i] then
				table.insert(obj2, mw.ustring.format('「[[:%s]]」', pages[i]))
			end
		end
		table.insert(obj, table.concat(obj2, '、'))
		table.insert(obj, mw.ustring.format('および「[[:%s]]」', pages[endpos]))
	end
	table.insert(obj, 'を参照</div>')
	return table.concat(obj)
end

local p = {}

-- {{系統活動記録}}
function p._sockLog(lastdate, username, showtype)
	if not lastdate then
		Error = Error or require('モジュール:Error')
		Error.error('最終確認年月の入力がありません。')
	end
	local str = ''
	if showtype == '1' then
		str = '最終確認:' .. lastdate
	elseif showtype == '2' then
		str = lastdate
	else
		str = lastdate .. 'に活動記録あり'
	end
	if username then
		local logurl = mw.uri.fullUrl(
			'特別:ログ',
			'page=User:' .. mw.uri.encode(username)
		)
		str = mw.ustring.format('%s([%s 参考])', str, tostring(logurl))
	end
	return str
end

function p._active_main(args)
	local main_args = {}
	for k, v in pairs(args) do
		if k == 'main' or k == 'Main' then
			main_args[1] = v
		else
			local m = string.match(k, 'main([1-9]%d-)')
			if m then
				main_args[tostring(m) + 1] = v
			end
		end
	end
	
	local obj = { 
		'<div class="sockinfo_active" '
		.. (args['name'] and mw.ustring.format('id="SockInfo_%s"', args['name']) or '')
		.. '>'
		}
	if args['過去ログ'] then
		table.insert(obj, lineBox(args['過去ログ']))
	end
	table.insert(obj, '<div class="sock_status"></div>')
	table.insert(obj, makeMain(main_args))
	if args['分類'] then
		table.insert(
			obj, 
			"* '''[[Wikipedia:進行中の荒らし行為/長期/分類方法"
				.. "|分類理由]]''':"
				.. args['分類']
			 )
	end
	if args['最終確認年月'] or args['最終ブロックアカウント'] then
		table.insert(obj, '*' .. p._sockLog(args['最終確認年月'], args['最終ブロックアカウント'], ''))
	end
	if args['備考'] then
		table.insert(obj, args['備考'])
	end
	table.insert(obj, '<hr style="clear: both;"><div class="sock_report">')
	
	return table.concat(obj, '\n')
end

function p._inactive_main(args)
	local main_args = {}
	for k, v in pairs(args) do
		if k == 'main' or k == 'Main' then
			main_args[1] = v
		else
			local m = string.match(k, 'main([1-9]%d-)')
			if m then
				main_args[tostring(m) + 1] = v
			end
		end
	end
	
	local obj = { 
		'<div class="sockinfo_inactive" '
		.. (args['name'] and mw.ustring.format('id="SockInfo_%s"', args['name']) or '')
		.. '>'
		}
	if args['過去ログ'] then
		table.insert(obj, lineBox(args['過去ログ']))
	end
	table.insert(obj, makeMain(main_args))
	if args['分類'] then
		table.insert(
			obj, 
			"* '''[[Wikipedia:進行中の荒らし行為/長期/分類方法"
				.. "|分類理由]]''':"
				.. args['分類']
			 )
	end
	if args['最終確認年月'] or args['最終ブロックアカウント'] then
		table.insert(obj, '*' .. p._sockLog(args['最終確認年月'], args['最終ブロックアカウント'], ''))
	end
	if args['備考'] then
		table.insert(obj, args['備考'])
	end
	table.insert(obj, '<hr style="clear: both;">')

	return table.concat(obj, '\n') .. '</div>'
end

function p.sockLog(frame)
	return p._sockLog(getArgs(frame, { wrappers = 'Template:系統活動記録' }))
end

function p.active_main(frame)
	return p._active_main(getArgs(frame, { wrappers = 'Template:SockInfo' }))
end

function p.inactive_main(frame)
	return p._inactive_main(getArgs(frame, { wrappers = 'Template:SockInfo/inactive' }))
end

return p