モジュール:サンドボックス/Q8j/MultiProtect

モジュールの解説[作成]
local p = {}
function p.Main( frame )
	function m_pagestatus(f_pagename,f_pageinfo,f_tlcount,f_status_i,f_status_a)
		local m_argtitle = mw.uri.decode(f_pagename,'WIKI')
		local m_title = mw.title.new(m_argtitle)
		local m_talklink = '[[' .. mw.allToString(m_title.talkPageTitle) .. '|ノート]]'
		local m_historylink = '[//ja.wikipedia.org/w/index.php?title=' .. mw.uri.encode(m_title.fullText,"WIKI") .. '&action=history 履歴]'
		local m_loglink = '[//ja.wikipedia.org/w/index.php?title=%E7%89%B9%E5%88%A5:Log&page=' .. mw.uri.encode(m_title.fullText,"WIKI") .. ' ログ]'
		local m_whatlinkshere = '[[Special:WhatLinksHere/' .. m_title.fullText .. '|リンク元]]'

		local m_ifexist = ''
		local m_pagelink = ''
		local m_pageinfo = ''
		local m_editprotect = ''
		local m_editprotect_expiry_display = '' -- 表示用
		local m_moveprotect = ''
		local m_moveprotect_expiry_display = '' -- 表示用
		local m_lasteditby -- 最終編集者
		local m_createprotect = ''
		local m_createprotect_expiry_display = ''
		local m_tlcount = ''
		local m_type = ''
		local f_status_2 = ''
		local m_status = ''
		local m_status_display = ''
		
		-- 進捗判定
		if f_status_i == nil then
			f_status_2 = string.lower(mw.allToString(f_status_a))
		else
			f_status_2 = string.lower(mw.allToString(f_status_i))
		end
		if f_status_2 == '対処' or f_status_2 == '済' or f_status_2 == 'd' or f_status_2 == 'done' then
			m_status = false
			m_status_display = '[[File:Yes check.svg|20px|チェック]] '
		elseif f_status_2 == '却下' or f_status_2 == 'n' or f_status_2 == 'nd' or f_status_2 == 'not done' then
			m_status = false
			m_status_display = '[[ファイル:X mark.svg|20px|×]] '
		else
			m_status = true
		end
			
		-- exist判定
		m_ifexist = m_title.exists
		-- existここまで

		--存在する場合
		if m_ifexist then
			-- トーク系?
			if m_title.isTalkPage then
				m_type = 2
			else
				m_type = 1
			end
			-- リダイレクト判定
			if m_title.isRedirect then
				m_pagelink = '<span class="plainlinks">[' .. mw.allToString(mw.uri.fullUrl(m_title.fullText,'redirect=no')) .. ' ' .. m_title.fullText .. ']</span>'
			else
				m_pagelink = '[[' .. m_title.fullText .. ']]'
			end
			-- pageinfo がyesの場合
			if f_pageinfo == 'yes' then
				-- 編集保護レベル
				if m_title.protectionLevels.edit[1] == 'sysop' then
					m_editprotect = '全'
				elseif m_title.protectionLevels.edit[1] == 'extendedconfirmed' then
					m_editprotect = '拡'
				elseif m_title.protectionLevels.edit[1] == 'autoconfirmed' then
					m_editprotect = '半'
				else
					m_editprotect = '無'
				end
				-- 移動保護レベル
				if m_title.protectionLevels.move[1] == 'sysop' then
					m_moveprotect = '全'
				elseif m_title.protectionLevels.move[1] == 'extendedconfirmed' then
					m_moveprotect = '拡'
				else
					m_moveprotect = '無' -- 移動半保護はないものとして扱う
				end
				-- 編集保護期間。編集保護が存在する場合
				if m_editprotect == '全' or m_editprotect == '拡' or m_editprotect == '半' then
					if frame:callParserFunction('PROTECTIONEXPIRY','edit',m_title.fullText) == 'infinity' then
						m_editprotect_expiry_display = '<small>(無)</small>'
					else
						m_editprotect_expiry_display = '<small>(有)</small>'
					end
				end
				-- 移動保護期間
				if m_moveprotect == '全' or m_moveprotect == '拡' then
					if frame:callParserFunction('PROTECTIONEXPIRY','move',m_title.fullText) == 'infinity' then
						m_moveprotect_expiry_display = '<small>(無)</small>'
					else
						m_moveprotect_expiry_display = '<small>(有)</small>'
					end
				end
				-- 最終編集者
				m_lasteditby = '<span class="plainlinks">[' .. mw.allToString(mw.uri.fullUrl('利用者:' .. frame:callParserFunction('REVISIONUSER',m_title.fullText))) .. ' ' .. frame:callParserFunction('REVISIONUSER',m_title.fullText) .. ']</span>'
				-- pageinfo
				m_pageinfo = '〈編:' .. m_editprotect .. m_editprotect_expiry_display .. ' 移:' .. m_moveprotect .. m_moveprotect_expiry_display .. ' 最終編集:' .. m_lasteditby .. '〉'
			end
			-- テンプレート呼び出し数
			if f_tlcount == 'no' then
			elseif f_tlcount == 'yes' or m_title.namespace == 4 or m_title.namespace == 828 then
				m_tlcount = ' / [https://templatecount.toolforge.org/index.php?lang=ja&namespace=' .. m_title.namespace .. '&name=' .. mw.uri.encode( m_title.text, 'WIKI' ) .. ' 呼び出し数]'
			end
		-- 存在しない場合
		else
			-- ページリンク
			m_pagelink = '[[' .. m_title.fullText .. ']]'
			-- トーク?
			if m_title.isTalkPage then
				m_type = 4
			else
				m_type = 3
			end
			-- pageinfo
			if f_pageinfo == 'yes' then
				-- 作成保護レベル
				if frame:callParserFunction('PROTECTIONLEVEL','create',m_title.fullText) == 'sysop' then
					m_createprotect = '全'
				elseif frame:callParserFunction('PROTECTIONLEVEL','create',m_title.fullText) == 'extendedconfirmed' then
					m_createprotect = '拡'
				elseif frame:callParserFunction('PROTECTIONLEVEL','create',m_title.fullText) == 'autoconfirmed' then
					m_createprotect = '半'
				else
					m_createprotect = '無'
				end
				-- 作成保護期間
				if m_createprotect == '全' or m_createprotect == '拡' or m_createprotect == '半' then
					if frame:callParserFunction('PROTECTIONEXPIRY','create',m_title.fullText) == 'infinity' then
						m_createprotect_expiry_display = '<small>(無)</small>'
					else
						m_createprotect_expiry_display = '<small>(有)</small>'
					end
				end
				m_pageinfo = '〈作:' .. m_createprotect .. m_createprotect_expiry_display .. '〉'
			end
		end
		if m_type == 1 then -- 存在する、メイン系
			return m_status_display .. m_pageinfo .. m_pagelink .. '<span style="font-size:smaller" class="plainlinks">(' .. m_talklink .. ' / ' .. m_historylink .. ' / ' .. m_loglink .. ' / ' .. m_whatlinkshere .. m_tlcount .. ')</span>'
		elseif m_type == 2 then -- 存在する、トーク系
			return m_status_display .. m_pageinfo .. m_pagelink .. '<span style="font-size:smaller" class="plainlinks">(' .. m_historylink .. ' / ' .. m_loglink .. ' / ' .. m_whatlinkshere .. m_tlcount .. ')</span>'
		elseif m_type == 3 then -- 存在しない、メイン系
			return m_status_display .. m_pageinfo .. m_pagelink .. '<span style="font-size:smaller" class="plainlinks">(' .. m_talklink .. ' / ' .. m_loglink .. ' / ' .. m_whatlinkshere .. ')</span>'
		else -- 存在しない、トーク系
			return m_status_display .. m_pageinfo .. m_pagelink .. '<span style="font-size:smaller" class="plainlinks">(' .. m_loglink .. ' / ' .. m_whatlinkshere .. ')</span>'
		end
	end
	-- 本体部分
	m_body = '#' .. m_pagestatus(mw.getCurrentFrame():getParent().args[1],string.lower(mw.getCurrentFrame():getParent().args['pageinfo']),string.lower(mw.getCurrentFrame():getParent().args['tlcount']),mw.getCurrentFrame():getParent().args['s1'],mw.getCurrentFrame():getParent().args['status'])
	m_i = 2
	while (mw.getCurrentFrame():getParent().args[m_i] ~= nil and m_i <= 50) do
		m_body = m_body .. '\n#' .. m_pagestatus(mw.getCurrentFrame():getParent().args[m_i],string.lower(mw.getCurrentFrame():getParent().args['pageinfo']),string.lower(mw.getCurrentFrame():getParent().args['tlcount']),mw.getCurrentFrame():getParent().args['s' .. m_i],mw.getCurrentFrame():getParent().args['status'])
		m_i = m_i + 1
	end
	return m_body
end
return p