モジュール:MultiProtect

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

このモジュールはTemplate:MultiProtectの内部で使用されています。

require('strict')

local getArgs = require('モジュール:Arguments').getArgs
local yesno = require('モジュール:Yesno')
local makeList = require('モジュール:List').makeList

local function pagestatus(f_pagename, f_status, f_options)
	local frame = mw.getCurrentFrame()
	local m_title = mw.title.new(f_pagename)
	local m_historylink = '[' .. m_title:fullUrl('action=history') .. ' 履歴]'
	local m_loglink = '[' .. mw.title.new('Special:Log'):fullUrl({ page = m_title.prefixedText }) .. ' ログ]'
	local m_whatlinkshere = '[[Special:WhatLinksHere/' .. m_title.prefixedText .. '|リンク元]]'
	local m_pagelink = ''
	local m_pageinfo = ''
	local m_tlcount
	local m_status_display = ''
	local m_additional = {}
	
	-- 進捗判定
	if f_status then
		f_status = string.lower(f_status)
	elseif f_options.default_status then
		f_status = string.lower(f_options.default_status)
	end
	if f_status == '対処' or f_status == '済' or f_status == 'd' or f_status == 'done' then
		m_status_display = '[[File:Yes check.svg|20px|チェック]] '
	elseif f_status == '却下' or f_status == 'n' or f_status == 'nd' or f_status == 'not done' then
		m_status_display = '[[ファイル:X mark.svg|20px|×]] '
	end
	
	if not m_title.isTalkPage then
		-- ノート(会話)ページでない
		table.insert(
			m_additional,
			m_title.talkPageTitle and '[[' .. tostring(m_title.talkPageTitle) .. '|ノート]]'
			)
	end
		
	if m_title.exists then
		-- ページが存在する場合
		
		-- リダイレクト判定
		if m_title.isRedirect then
			m_pagelink = string.format(
				'<span class="plainlinks">[%s %s]</span>',
				m_title:fullUrl('redirect=no'),
				m_title.prefixedText
				)
		else
			m_pagelink = '[[:' .. m_title.prefixedText .. ']]'
		end
		
		if f_options.pageinfo then
			local m_editprotect = '無'
			local m_editprotect_expiry_display = '' -- 表示用
			local m_moveprotect = '無'
			local m_moveprotect_expiry_display = '' -- 表示用
			
			-- 編集保護レベル
			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 = '半'
			end
			-- 移動保護レベル(移動半保護はないものとして扱う)
			if m_title.protectionLevels.move[1] == 'sysop' then
				m_moveprotect = '全'
			elseif m_title.protectionLevels.move[1] == 'extendedconfirmed' then
				m_moveprotect = '拡'
			end
			-- 編集保護期間。編集保護が存在する場合
			if m_editprotect == '全' or m_editprotect == '拡' or m_editprotect == '半' then
				if frame:callParserFunction('PROTECTIONEXPIRY','edit',m_title.prefixedText) == '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.prefixedText) == 'infinity' then
					m_moveprotect_expiry_display = '<small>(無)</small>'
				else
					m_moveprotect_expiry_display = '<small>(有)</small>'
				end
			end
			-- 最終編集者
			local m_lastedituser = frame:callParserFunction('REVISIONUSER',m_title.prefixedText)
			
			m_pageinfo = string.format(
				'〈編:%s%s 移:%s%s 最終編集:[[Special:Contribs/%s|%s]]〉',
				m_editprotect,
				m_editprotect_expiry_display,
				m_moveprotect,
				m_moveprotect_expiry_display,
				m_lastedituser,
				m_lastedituser
				)
		end
		-- テンプレート呼び出し数
		if f_options.tlcount ~= false then
			-- f_options.tlcountがtrueもしくはnilの場合
			
			if f_options.tlcount or m_title.namespace == 10 or m_title.namespace == 828 then
				m_tlcount = string.format(
					'[https://templatecount.toolforge.org/index.php?lang=ja&namespace=%s&name=%s 呼び出し数]',
					m_title.namespace,
					m_title:partialUrl()
					)
			end
		end
		table.insert(m_additional, m_historylink)
		table.insert(m_additional, m_loglink)
		table.insert(m_additional, m_whatlinkshere)
		table.insert(m_additional, m_tlcount)
		
	else
		-- ページが存在しない場合
		
		-- ページリンク
		m_pagelink = '[[:' .. m_title.prefixedText .. ']]'
		
		-- pageinfo
		if f_options.pageinfo then
			local m_createprotect = '無'
			local m_createprotect_expiry_display = ''
			
			-- 作成保護レベル
			if m_title.protectionLevels.create then
				if m_title.protectionLevels.create[1] == 'sysop' then
					m_createprotect = '全'
				elseif m_title.protectionLevels.create[1] == 'extendedconfirmed' then
					m_createprotect = '拡'
				elseif m_title.protectionLevels.create[1] == 'autoconfirmed' then
					m_createprotect = '半'
				end
			end
			-- 作成保護期間
			if m_createprotect == '全' or m_createprotect == '拡' or m_createprotect == '半' then
				if frame:callParserFunction('PROTECTIONEXPIRY','create',m_title.prefixedText) == 'infinity' then
					m_createprotect_expiry_display = '<small>(無)</small>'
				else
					m_createprotect_expiry_display = '<small>(有)</small>'
				end
			end
			m_pageinfo = string.format(
				'〈作:%s%s〉',
				m_createprotect,
				m_createprotect_expiry_display
				)
		end
		table.insert(m_additional, m_loglink)
		table.insert(m_additional, m_whatlinkshere)
	end
	return string.format(
		'%s%s%s<span style="font-size:smaller" class="plainlinks">(%s)</span>',
		m_status_display,
		m_pageinfo,
		m_pagelink,
		table.concat(m_additional, ' / ')
		)
end

local p = {}

function p.Main(frame)
	-- 本体部分
	local args = getArgs(frame, { wrappers = 'Template:MultiProtect' })
	local list = {}
	local options = {
		pageinfo = yesno(args.pageinfo),
		tlcount = yesno(args.tlcount),
		default_status = args['status']
	}
	args[51] = nil	-- args[51]以降は無視する
	for i, v in ipairs(args) do
		table.insert(list, pagestatus(v, args['s' .. i], options))
	end
	return makeList('ordered', list)
end
return p