モジュール:保護

出典: 謎の百科事典もどき『エンペディア(Enpedia)』
ナビゲーションに移動 検索に移動

この説明文は 『 モジュール:保護/doc 』 から呼び出されています。
{{保護}}の内部モジュール。

--[[
Copyright (c) 2016 rxy <https://rxy.jp/>
License: The MIT License (MIT)
License detail: https://opensource.org/licenses/MIT
]]

local p = {}
local config ={
	category = {
		sysop = "保護されているページ",
		autoconfirmed =  "半保護されているページ",
	}
}

function p.main(frame)
	local pageName = frame.args[1]
	local reason = frame.args[2]
	local currentProtection = GetProtectionTypes(pageName)
	if currentProtection['message'] ~= "未保護" then
		return frame:preprocess(
			"{{保護/module|"
			..reason
			.."|"
			..currentProtection['message']
			.."|"
			..currentProtection['category']
			.."}}"
		)
	end
end

function GetProtectionTypes(pageName)
	local page = mw.title.new( pageName )
	mw.log(mw.dumpObject(page.protectionLevels))
	local returnProtectionLevels = ""
	local retTbl = {
		message = '',
		category = ''
	}
	for action, level in pairs( page.protectionLevels ) do
		if level[1] ~= nil then
			local actionMsg = mw.message.new( "restriction-"..action):plain()
			if action == "edit" then
				retTbl['category'] = config['category'][level[1]]
			end
			if action == "create" then
				if level[1] == "editprotected" then 
					level[1] = "sysop"
				elseif level[1] == "editsemiprotected" then 
					level[1] = "autoconfirmed"
				end
			end
			local levelMsg = mw.message.new( "restriction-level-"..level[1] ):plain()
			local suffix = ""
			if returnProtectionLevels ~= "" then
				suffix = "、"
			end
			if action == "move" and page.protectionLevels['edit'][1] == level[1] then
				--nil
			else
				returnProtectionLevels = actionMsg .. levelMsg .. suffix .. returnProtectionLevels
			end
			mw.log(mw.dumpObject( returnProtectionLevels ))
		end
	end
	returnProtectionLevels = returnProtectionLevels ~= "" and returnProtectionLevels or "未保護"
	retTbl['message'] = returnProtectionLevels
	return retTbl
end

return p