依存関係
 
ミス
 
1行目: 1行目:
-- This module provides configuration data for [[Module:Protection banner]].
-- This module implements {{pp-meta}} and its daughter templates such as
-- {{pp-dispute}}, {{pp-vandalism}} and {{pp-sock}}.


return {
-- Initialise necessary modules.
require('strict')
local makeFileLink = require('Module:File link')._main
local effectiveProtectionLevel = require('Module:Effective protection level')._main
local effectiveProtectionExpiry = require('Module:Effective protection expiry')._main
local yesno = require('Module:Yesno')
 
-- Lazily initialise modules and objects we don't always need.
local getArgs, makeMessageBox, lang
 
-- Set constants.
local CONFIG_MODULE = 'モジュール:Protection banner/config'
 
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
 
local function makeCategoryLink(cat, sort)
if cat then
return string.format(
'[[%s:%s|%s]]',
mw.site.namespaces[14].name,
cat,
sort
)
end
end
 
-- Validation function for the expiry and the protection date
local function validateDate(dateString, dateType)
if not lang then
lang = mw.language.getContentLanguage()
end
local success, result = pcall(lang.formatDate, lang, 'U', dateString)
if success then
result = tonumber(result)
if result then
return result
end
end
error(string.format(
'invalid %s: %s',
dateType,
tostring(dateString)
), 4)
end
 
local function makeFullUrl(page, query, display)
return string.format(
'[%s %s]',
tostring(mw.uri.fullUrl(page, query)),
display
)
end
 
-- Given a directed graph formatted as node -> table of direct successors,
-- get a table of all nodes reachable from a given node (though always
-- including the given node).
local function getReachableNodes(graph, start)
local toWalk, retval = {[start] = true}, {}
while true do
-- Can't use pairs() since we're adding and removing things as we're iterating
local k = next(toWalk) -- This always gets the "first" key
if k == nil then
return retval
end
toWalk[k] = nil
retval[k] = true
for _,v in ipairs(graph[k]) do
if not retval[v] then
toWalk[v] = true
end
end
end
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- Protection class
--                                BANNER DATA
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


--[[
local Protection = {}
-- Banner data consists of six fields:
Protection.__index = Protection
-- * text - the main protection text that appears at the top of protection
 
--  banners.
Protection.supportedActions = {
-- * explanation - the text that appears below the main protection text, used
edit = true,
--  to explain the details of the protection.
move = true,
-- * tooltip - the tooltip text you see when you move the mouse over a small
autoreview = true,
--  padlock icon.
upload = true
-- * link - the page that the small padlock icon links to.
}
-- * alt - the alt text for the small padlock icon. This is also used as tooltip
 
--  text for the large protection banners.
Protection.bannerConfigFields = {
-- * image - the padlock image used in both protection banners and small padlock
'text',
--  icons.
'explanation',
--
'tooltip',
-- The module checks in three separate tables to find a value for each field.
'alt',
-- First it checks the banners table, which has values specific to the reason
'link',
-- for the page being protected. Then the module checks the defaultBanners
'image'
-- table, which has values specific to each protection level. Finally, the
}
-- module checks the masterBanner table, which holds data for protection
 
-- templates to use if no data has been found in the previous two tables.
function Protection.new(args, cfg, title)
--
local obj = {}
-- The values in the banner data can take parameters. These are specified
obj._cfg = cfg
-- using ${TEXTLIKETHIS} (a dollar sign preceding a parameter name
obj.title = title or mw.title.getCurrentTitle()
-- enclosed in curly braces).
 
--
-- Set action
--                          Available parameters:
if not args.action then
--
obj.action = 'edit'
-- ${CURRENTVERSION} - a link to the page history or the move log, with the
elseif Protection.supportedActions[args.action] then
-- display message "current-version-edit-display" or
obj.action = args.action
-- "current-version-move-display".
else
--
error(string.format(
-- ${EDITREQUEST} - a link to create an edit request for the current page.
'invalid action: %s',
--
tostring(args.action)
-- ${EXPLANATIONBLURB} - an explanation blurb, e.g. "Please discuss any changes
), 3)
-- on the talk page; you may submit a request to ask an administrator to make
end
-- an edit if it is minor or supported by consensus."
--
-- ${IMAGELINK} - a link to set the image to, depending on the protection
-- action and protection level.
--
-- ${INTROBLURB} - the PROTECTIONBLURB parameter, plus the expiry if an expiry
-- is set. E.g. "Editing of this page by new or unregistered users is currently
-- disabled until dd Month YYYY."
--
-- ${INTROFRAGMENT} - the same as ${INTROBLURB}, but without final punctuation
-- so that it can be used in run-on sentences.
--
-- ${PAGETYPE} - the type of the page, e.g. "article" or "template".
-- Defined in the cfg.pagetypes table.
--
-- ${PROTECTIONBLURB} - a blurb explaining the protection level of the page, e.g.
-- "Editing of this page by new or unregistered users is currently disabled"
--
-- ${PROTECTIONDATE} - the protection date, if it has been supplied to the
-- template.
--
-- ${PROTECTIONLEVEL} - the protection level, e.g. "fully protected" or
-- "semi-protected".
--
-- ${PROTECTIONLOG} - a link to the protection log or the pending changes log,
-- depending on the protection action.
--
-- ${TALKPAGE} - a link to the talk page. If a section is specified, links
-- straight to that talk page section.
--
-- ${TOOLTIPBLURB} - uses the PAGETYPE, PROTECTIONTYPE and EXPIRY parameters to
-- create a blurb like "This template is semi-protected", or "This article is
-- move-protected until DD Month YYYY".
--
-- ${VANDAL} - links for the specified username (or the root page name)
-- using Module:Vandal-m.
--
--                                 Functions
--
-- For advanced users, it is possible to use Lua functions instead of strings
-- in the banner config tables. Using functions gives flexibility that is not
-- possible just by using parameters. Functions take two arguments, the
-- protection object and the template arguments, and they must output a string.
--
-- For example:
--
-- text = function (protectionObj, args)
--    if protectionObj.level == 'autoconfirmed' then
--        return 'foo'
--    else
--        return 'bar'
--    end
-- end
--
-- Some protection object properties and methods that may be useful:
-- protectionObj.action - the protection action
-- protectionObj.level - the protection level
-- protectionObj.reason - the protection reason
-- protectionObj.expiry - the expiry. Nil if unset, the string "indef" if set
--    to indefinite, and the protection time in unix time if temporary.
-- protectionObj.protectionDate - the protection date in unix time, or nil if
--    unspecified.
-- protectionObj.bannerConfig - the banner config found by the module. Beware
--    of editing the config field used by the function, as it could create an
--    infinite loop.
-- protectionObj:isProtected - returns a boolean showing whether the page is
--    protected.
-- protectionObj:isTemporary - returns a boolean showing whether the expiry is
--    temporary.
-- protectionObj:isIncorrect - returns a boolean showing whether the protection
--    template is incorrect.
--]]


-- The master banner data, used if no values have been found in banners or
-- Set level
-- defaultBanners.
obj.level = args.demolevel or effectiveProtectionLevel(obj.action, obj.title)
masterBanner = {
if not obj.level or (obj.action == 'move' and obj.level == 'autoconfirmed') then
text = '${INTROBLURB}',
-- Users need to be autoconfirmed to move pages anyway, so treat
explanation = '${EXPLANATIONBLURB}',
-- semi-move-protected pages as unprotected.
tooltip = '${TOOLTIPBLURB}',
obj.level = '*'
link = '${IMAGELINK}',
end
alt = '${PROTECTIONLEVEL}されたページ'
},


-- The default banner data. This holds banner data for different protection
-- Set expiry
-- levels.
local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title)
-- *required* - this table needs edit, move, autoreview and upload subtables.
if effectiveExpiry == 'infinity' then
defaultBanners = {
obj.expiry = 'indef'
edit = {},
elseif effectiveExpiry ~= 'unknown' then
move = {},
obj.expiry = validateDate(effectiveExpiry, 'expiry date')
autoreview = {
end
default = {
alt = 'Page protected with pending changes',
tooltip = 'All edits by unregistered and new users are subject to review prior to becoming visible to unregistered users',
image = 'Pending-protection-shackle.svg'
}
},
upload = {}
},


-- The banner data. This holds banner data for different protection reasons.
-- Set reason
-- In fact, the reasons specified in this table control which reasons are
if args[1] then
-- valid inputs to the first positional parameter.
obj.reason = mw.ustring.lower(args[1])
--
if obj.reason:find('|') then
-- There is also a non-standard "description" field that can be used for items
error('reasons cannot contain the pipe character ("|")', 3)
-- in this table. This is a description of the protection reason for use in the
end
-- module documentation.
end
--
 
-- *required* - this table needs edit, move, autoreview and upload subtables.
-- Set protection date
banners = {
if args.date then
edit = {
obj.protectionDate = validateDate(args.date, 'protection date')
--blp = {
end
-- description = 'For pages protected to promote compliance with the'
-- .. ' [[Wikipedia:Biographies of living persons'
-- Set banner config
-- .. '|biographies of living persons]] policy',
do
-- text = '${INTROFRAGMENT} to promote compliance with'
obj.bannerConfig = {}
-- .. ' [[Wikipedia:Biographies of living persons'
local configTables = {}
-- .. "|Wikipedia's policy on the biographies"
if cfg.banners[obj.action] then
-- .. ' of living people]].',
configTables[#configTables + 1] = cfg.banners[obj.action][obj.reason]
-- tooltip = '${TOOLTIPFRAGMENT} to promote compliance with the policy on'
end
-- .. ' biographies of living persons',
if cfg.defaultBanners[obj.action] then
--},
configTables[#configTables + 1] = cfg.defaultBanners[obj.action][obj.level]
dmca = {
configTables[#configTables + 1] = cfg.defaultBanners[obj.action].default
description = '[[デジタルミレニアム著作権法]]に基づく削除要求があったため、'
end
.. '保護されたページ',
configTables[#configTables + 1] = cfg.masterBanner
explanation = function (protectionObj, args)
for i, field in ipairs(Protection.bannerConfigFields) do
local ret = 'この${PAGETYPE}の内容に関して、[[デジタルミレニアム著作権法]]'
for j, t in ipairs(configTables) do
.. '(DMCA)に基づく権利所有者への通知があったため、'
if t[field] then
.. 'ウィキメディア財団は問題となった個所を削除した上で、'
obj.bannerConfig[field] = t[field]
.. 'このページの編集を制限しました。'
break
if args.notice then
ret = ret .. '財団が受理した通知のコピーは '
.. args.notice .. ' にあります。'
end
end
ret = ret .. '異議申し立て方法など詳細な情報については'
end
.. '[[Wikipedia:事務局行動]]および${TALKPAGE}をご覧ください。<br />'
end
.. "'''編集制限が解除されるまで、"
end
.. "このお知らせを除去しないでください。'''"
return setmetatable(obj, Protection)
return ret
end
end,
 
image = 'Office-protection-shackle-WMFlogo.svg',
function Protection:isProtected()
},
return self.level ~= '*'
dispute = {
end
description = '[[Wikipedia:編集合戦|編集合戦]]により保護されたページ',
 
text = '[[Wikipedia:編集合戦|編集合戦]]が発生したため、${INTROBLURB}',
function Protection:isTemporary()
explanation = "${CURRENTVERSION}の内容が'''適切とは限りません'''。"
return type(self.expiry) == 'number'
.. '詳しくは[[Wikipedia:保護の方針|保護の方針]]および'
end
.. '${PROTECTIONLOG}をご覧ください。'
 
.. '問題となった個所について意見がある場合は、'
function Protection:makeProtectionCategory()
.. '${TALKPAGE}で議論するよう心がけてください。'
local cfg = self._cfg
.. '[[Wikipedia:合意形成|合意が形成]]され、保護を解除できる状態になった場合は'
local title = self.title
.. '[[Wikipedia:保護解除依頼|保護の解除を依頼]]してください。',
tooltip = '編集合戦が発生したため、${TOOLTIPBLURB}',
-- Exit if the page is not protected.
},
if not self:isProtected() then
--ecp = {
return ''
-- description = 'For articles in topic areas authorized by'
end
-- .. ' [[Wikipedia:Arbitration Committee|ArbCom]] or'
-- .. ' meets the criteria for community use',
-- Get the expiry key fragment.
-- tooltip = 'This ${PAGETYPE} is extended-confirmed protected',
local expiryFragment
-- alt = 'Extended-protected ${PAGETYPE}',
if self.expiry == 'indef' then
--},
expiryFragment = self.expiry
--mainpage = {
elseif type(self.expiry) == 'number' then
-- description = 'For pages protected for being displayed on the [[Main Page]]',
expiryFragment = 'temp'
-- text = 'This file is currently'
end
-- .. ' [[Wikipedia:This page is protected|protected]] from'
 
-- .. ' editing because it is currently or will soon be displayed'
-- Get the namespace key fragment.
-- .. ' on the [[Main Page]].',
local namespaceFragment = cfg.categoryNamespaceKeys[title.namespace]
-- explanation = 'Images on the Main Page are protected due to their high'
if not namespaceFragment and title.namespace % 2 == 1 then
-- .. ' visibility. Please discuss any necessary changes on the ${TALKPAGE}.'
namespaceFragment = 'talk'
-- .. '<br /><span style="font-size:90%;">'
end
-- .. "'''Administrators:''' Once this image is definitely off the Main Page,"
-- .. ' please unprotect this file, or reduce to semi-protection,'
-- Define the order that key fragments are tested in. This is done with an
-- .. ' as appropriate.</span>',
-- array of tables containing the value to be tested, along with its
--},
-- position in the cfg.protectionCategories table.
office = {
local order = {
description = '[[Wikipedia:事務局行動|事務局行動]]により保護されたページ',
{val = expiryFragment,    keypos = 1},
text = function (protectionObj, args)
{val = namespaceFragment, keypos = 2},
local ret = '現在この${PAGETYPE}は[[Wikipedia:事務局行動|'
{val = self.reason,      keypos = 3},
.. 'ウィキメディア財団事務局]]の監視下にあり、'
{val = self.level,        keypos = 4},
if protectionObj.protectionDate then
{val = self.action,      keypos = 5}
ret = ret .. '${PROTECTIONDATE}以降、'
}
end
 
return ret .. '保護されています。'
--[[
end,
-- The old protection templates used an ad-hoc protection category system,
explanation = "もしあなたがこのページを編集できたとしても、加筆・修正を行う前に"
-- with some templates prioritising namespaces in their categories, and
.. "${TALKPAGE}で議論するよう心がけてください。<br />"
-- others prioritising the protection reason. To emulate this in this module
.. "'''ウィキメディア財団の許可があるまで、このページの保護を"
-- we use the config table cfg.reasonsWithNamespacePriority to set the
.. "解除しないでください。'''",
-- reasons for which namespaces have priority over protection reason.
image = 'Office-protection-shackle-WMFlogo.svg',
-- If we are dealing with one of those reasons, move the namespace table to
},
-- the end of the order table, i.e. give it highest priority. If not, the
permanent = {
-- reason should have highest priority, so move that to the end of the table
description = '半永久的に保護されているページ',
-- instead.
text = function (protectionObj, args)
--]]
if protectionObj.level == 'sysop' then
table.insert(order, table.remove(order, self.reason and cfg.reasonsWithNamespacePriority[self.reason] and 2 or 3))
return 'この${PAGETYPE}は、半永久的に編集[[Wikipedia:保護|保護]]されています。'
elseif protectionObj.level == 'extendedconfirmed' then
--[[
return 'この${PAGETYPE}は、[[Wikipedia:利用者#拡張承認された利用者|'
-- Define the attempt order. Inactive subtables (subtables with nil "value"
.. '拡張承認された利用者]]以外の編集を半永久的に[[Wikipedia:保護|禁止]]しています。'
-- fields) are moved to the end, where they will later be given the key
-- "all". This is to cut down on the number of table lookups in
-- cfg.protectionCategories, which grows exponentially with the number of
-- non-nil keys. We keep track of the number of active subtables with the
-- noActive parameter.
--]]
local noActive, attemptOrder
do
local active, inactive = {}, {}
for i, t in ipairs(order) do
if t.val then
active[#active + 1] = t
else
inactive[#inactive + 1] = t
end
end
noActive = #active
attemptOrder = active
for i, t in ipairs(inactive) do
attemptOrder[#attemptOrder + 1] = t
end
end
--[[
-- Check increasingly generic key combinations until we find a match. If a
-- specific category exists for the combination of key fragments we are
-- given, that match will be found first. If not, we keep trying different
-- key fragment combinations until we match using the key
-- "all-all-all-all-all".
--
-- To generate the keys, we index the key subtables using a binary matrix
-- with indexes i and j. j is only calculated up to the number of active
-- subtables. For example, if there were three active subtables, the matrix
-- would look like this, with 0 corresponding to the key fragment "all", and
-- 1 corresponding to other key fragments.
--
--  j 1  2  3
-- i 
-- 1  1  1  1
-- 2  0  1  1
-- 3  1  0  1
-- 4  0  0  1
-- 5  1  1  0
-- 6  0  1  0
-- 7  1  0  0
-- 8  0  0  0
--
-- Values of j higher than the number of active subtables are set
-- to the string "all".
--
-- A key for cfg.protectionCategories is constructed for each value of i.
-- The position of the value in the key is determined by the keypos field in
-- each subtable.
--]]
local cats = cfg.protectionCategories
for i = 1, 2^noActive do
local key = {}
for j, t in ipairs(attemptOrder) do
if j > noActive then
key[t.keypos] = 'all'
else
local quotient = i / 2 ^ (j - 1)
quotient = math.ceil(quotient)
if quotient % 2 == 1 then
key[t.keypos] = t.val
else
else
return 'この${PAGETYPE}は、[[Wikipedia:利用者#新規利用者|新規利用者]]'
key[t.keypos] = 'all'
.. 'および[[Wikipedia:利用者#IP利用者|未登録利用者]]からの編集を'
.. '半永久的に[[Wikipedia:保護|禁止]]しています。'
end
end
end,
end
explanation = function (protectionObj, args)
end
if protectionObj.level == 'sysop' then
key = table.concat(key, '|')
return '詳しくは[[Wikipedia:保護の方針#半永久的な保護|保護の方針]]および'
local attempt = cats[key]
.. '${PROTECTIONLOG}をご覧ください。'
if attempt then
.. '変更が必要なときは${TALKPAGE}で議論し、[[Wikipedia:合意形成|合意形成]]後に'
return makeCategoryLink(attempt, title.text)
.. '[[Wikipedia:管理者伝言板/保護ページ編集|保護編集依頼]]を行ってください。'
end
elseif protectionObj.level == 'extendedconfirmed' then
end
return '詳しくは[[Wikipedia:拡張半保護の方針#半永久的な拡張半保護|拡張半保護の方針]]および'
return ''
.. '${PROTECTIONLOG}をご覧ください。'
end
.. 'この${PAGETYPE}を編集することができない場合、${TALKPAGE}にて'
 
.. '<code class="nowrap">{{[[Template:拡張半保護編集依頼|拡張半保護編集依頼]]}}</code>'
function Protection:isIncorrect()
.. 'を用いて[[Wikipedia:拡張半保護の方針#拡張半保護されたページの編集|編集を依頼]]するか、'
local expiry = self.expiry
.. '[[Wikipedia:管理者伝言板/拡張承認の申請|拡張承認の申請]]をしてください。'
return not self:isProtected()
else
or type(expiry) == 'number' and expiry < os.time()
return '詳しくは[[Wikipedia:半保護の方針#半永久的な半保護|半保護の方針]]および'
end
.. '${PROTECTIONLOG}をご覧ください。'
 
.. 'この${PAGETYPE}を編集することができない場合、${TALKPAGE}にて'
-- 日本語版独自
.. '<code class="nowrap">{{[[Template:半保護編集依頼|半保護編集依頼]]}}</code>'
function Protection:isMismatched()
.. 'を用いて[[Wikipedia:半保護の方針#半保護されたページの編集|編集を依頼]]してください。'
return self.reason == 'dispute' and self.level ~= 'sysop'
end
end
end,
 
tooltip = '半永久的に${PROTECTIONLEVEL}されている${PAGETYPE}',
function Protection:isTemplateProtectedNonTemplate()
alt = '半永久的に${PROTECTIONLEVEL}されている${PAGETYPE}',
local action, namespace = self.action, self.title.namespace
image = function (protectionObj)
return self.level == 'templateeditor'
if protectionObj.level == 'sysop' then
and (
return 'Edit Semi-permanent Protection.svg'
(action ~= 'edit' and action ~= 'move')
elseif protectionObj.level == 'extendedconfirmed' then
or (namespace ~= 10 and namespace ~= 828)
return 'Edit Semi-permanent Extended Semi-protection.svg'
)
else
end
return 'Edit Semi-permanent Semi-protection.svg'
end
end,
},
reset = {
description = '[[Wikipedia:事務局行動|事務局行動]]により、内容が'
.. '縮小された上で保護されたページ',
text = function (protectionObj, args)
local ret = '現在この${PAGETYPE}は[[Wikipedia:事務局行動|'
.. 'ウィキメディア財団事務局]]の監視下にあり、'
if protectionObj.protectionDate then
ret = ret .. '${PROTECTIONDATE}以降、'
end
return ret .. '保護されています。'
end,
explanation = 'この${PAGETYPE}には最小限の内容しかないため、'
.. '[[WP:NPOV|中立的な観点]]や[[WP:V|検証可能性]]といった方針に'
.. '適合する形で、全面的に改稿されることが望まれています。'
.. "もしあなたがこのページを編集できたとしても、加筆・修正を行う前に"
.. "${TALKPAGE}で議論するよう心がけてください。<br />"
.. 'この${PAGETYPE}が保護される以前の版に書かれていた内容は'
.. '復帰させないでください。'
.. 'ノートページで議論を行う際も同様です。<br />'
.. "'''ウィキメディア財団の許可があるまで、このページの保護を"
.. "解除したり、このお知らせを除去しないでください。'''",
image = 'Office-protection-shackle-WMFlogo.svg',
},
--sock = {
-- description = 'For pages protected due to'
-- .. ' [[Wikipedia:Sock puppetry|sock puppetry]]',
-- text = '${INTROFRAGMENT} to prevent [[Wikipedia:Sock puppetry|sock puppets]] of'
-- .. ' [[Wikipedia:Blocking policy|blocked]] or'
-- .. ' [[Wikipedia:Banning policy|banned users]]'
-- .. ' from editing it.',
-- tooltip = '${TOOLTIPFRAGMENT} to prevent sock puppets of blocked or banned users from'
-- .. ' editing it',
--},
template = {
description = '[[Wikipedia:影響が特に大きいテンプレート|'
.. '影響が特に大きいテンプレート・モジュール]]',
text = 'この[[Wikipedia:影響が特に大きいテンプレート|'
.. '影響が特に大きい${PAGETYPE}]]は、[[Wikipedia:荒らし|荒らし]]を予防するために'
.. '${PROTECTIONLEVEL}されています。',
explanation = function (protectionObj, args)
if protectionObj.level == 'sysop' then
return '詳しくは[[Wikipedia:保護の方針#半永久的な保護|保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. '変更が必要なときは${TALKPAGE}で議論し、[[Wikipedia:合意形成|合意形成]]後に'
.. '[[Wikipedia:管理者伝言板/保護ページ編集|保護編集依頼]]を行ってください。'
elseif protectionObj.level == 'extendedconfirmed' then
return '詳しくは[[Wikipedia:拡張半保護の方針#半永久的な拡張半保護|拡張半保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. 'この${PAGETYPE}を編集することができない場合、${TALKPAGE}にて'
.. '<code class="nowrap">{{[[Template:拡張半保護編集依頼|拡張半保護編集依頼]]}}</code>'
.. 'を用いて[[Wikipedia:拡張半保護の方針#拡張半保護されたページの編集|編集を依頼]]するか、'
.. '[[Wikipedia:管理者伝言板/拡張承認の申請|拡張承認の申請]]をしてください。'
else
return '詳しくは[[Wikipedia:半保護の方針#半永久的な半保護|半保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. 'この${PAGETYPE}を編集することができない場合、${TALKPAGE}にて'
.. '<code class="nowrap">{{[[Template:半保護編集依頼|半保護編集依頼]]}}</code>'
.. 'を用いて[[Wikipedia:半保護の方針#半保護されたページの編集|編集を依頼]]してください。'
end
end,
tooltip = 'この影響が特に大きい${PAGETYPE}は、'
.. '荒らしを予防するために${PROTECTIONLEVEL}されています。',
alt = '半永久的に${PROTECTIONLEVEL}されている${PAGETYPE}',
image = function (protectionObj)
if protectionObj.level == 'sysop' then
return 'Edit Semi-permanent Protection.svg'
elseif protectionObj.level == 'extendedconfirmed' then
return 'Edit Semi-permanent Extended Semi-protection.svg'
else
return 'Edit Semi-permanent Semi-protection.svg'
end
end,
},
--usertalk = {
-- description = 'For pages protected against disruptive edits by a'
-- .. ' particular user',
-- text = '${INTROFRAGMENT} to prevent ${VANDAL} from using it to make disruptive edits,'
-- .. ' such as abusing the'
-- .. ' &#123;&#123;[[Template:unblock|unblock]]&#125;&#125; template.',
-- explanation = 'If you cannot edit this user talk page and you need to'
-- .. ' make a change or leave a message, you can'
-- .. ' [[Wikipedia:Requests for page protection'
-- .. '#Current requests for edits to a protected page'
-- .. '|request an edit]],'
-- .. ' [[Wikipedia:Requests for page protection'
-- .. '#Current requests for reduction in protection level'
-- .. '|request unprotection]],'
-- .. ' [[Special:Userlogin|log in]],'
-- .. ' or [[Special:UserLogin/signup|create an account]].',
--},
vandalism = {
description = '[[Wikipedia:荒らし|荒らし]]行為により保護されたページ',
text = '度重なる[[Wikipedia:荒らし|荒らし]]行為のため、${INTROBLURB}',
tooltip = '度重なる荒らし行為のため、${TOOLTIPBLURB}'
}
},
move = {
dispute = {
description = '[[Wikipedia:編集合戦#移動合戦|移動合戦]]により保護されたページ',
text = '[[Wikipedia:編集合戦#移動合戦|移動合戦]]が発生したため、${INTROFRAGMENT}',
explanation = "${CURRENTVERSION}が'''適切とは限りません'''。"
.. '詳しくは[[Wikipedia:保護の方針|保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. 'ページ名について意見がある場合は${TALKPAGE}で議論し、'
.. '必要に応じて[[Wikipedia:ページの改名]]に従い、'
.. '[[Wikipedia:改名提案|改名の提案]]をしてください。'
.. '[[Wikipedia:合意形成|合意が形成]]され、保護を解除できる状態になった場合は'
.. '[[Wikipedia:保護解除依頼|保護の解除を依頼]]してください。',
tooltip = '移動合戦が発生したため、${TOOLTIPBLURB}',
},
vandalism = {
description = '[[Wikipedia:荒らし#移動荒らし|移動荒らし]]行為により保護されたページ',
text = '度重なる[[Wikipedia:荒らし#移動荒らし|移動荒らし]]行為のため、${INTROFRAGMENT}',
tooltip = '度重なる移動荒らし行為のため、${TOOLTIPBLURB}'
}
},
autoreview = {},
upload = {}
},


--------------------------------------------------------------------------------
function Protection:makeCategoryLinks()
--
local msg = self._cfg.msg
--                            GENERAL DATA TABLES
local ret = { self:makeProtectionCategory() }
--
if self:isIncorrect() then
--------------------------------------------------------------------------------
ret[#ret + 1] = makeCategoryLink(
msg['tracking-category-incorrect'],
self.title.text
)
elseif self:isMismatched() then
ret[#ret + 1] = makeCategoryLink(
msg['tracking-category-mismatch'],
self.title.text
)
end
if self:isTemplateProtectedNonTemplate() then
ret[#ret + 1] = makeCategoryLink(
msg['tracking-category-template'],
self.title.text
)
end
return table.concat(ret)
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Protection blurbs
-- Blurb class
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- This table produces the protection blurbs available with the
local Blurb = {}
-- ${PROTECTIONBLURB} parameter. It is sorted by protection action and
Blurb.__index = Blurb
-- protection level, and is checked by the module in the following order:
-- 1. page's protection action, page's protection level
-- 2. page's protection action, default protection level
-- 3. "edit" protection action, default protection level
--
-- It is possible to use banner parameters inside this table.
-- *required* - this table needs edit, move, autoreview and upload subtables.
protectionBlurbs = {
edit = {
default = 'この${PAGETYPE}は編集[[Wikipedia:保護|保護]]されています',
autoconfirmed = 'この${PAGETYPE}は[[Wikipedia:利用者#新規利用者|新規利用者]]'
.. 'および[[Wikipedia:利用者#IP利用者|未登録利用者]]からの編集を[[Wikipedia:保護|禁止]]しています',
extendedconfirmed = 'この${PAGETYPE}は[[Wikipedia:利用者#拡張承認された利用者|'
.. '拡張承認された利用者]]以外の編集を[[Wikipedia:保護|禁止]]しています',
},
move = {
default = 'この${PAGETYPE}は[[Help:ページの移動|移動]][[Wikipedia:保護|保護]]されています',
extendedconfirmed = 'この${PAGETYPE}は[[Wikipedia:利用者#拡張承認された利用者|'
.. '拡張承認された利用者]]以外の[[Help:ページの移動|移動]]を[[Wikipedia:保護|禁止]]しています',
},
autoreview = {
default = 'All edits made to this ${PAGETYPE} by'
.. ' [[Wikipedia:User access levels#New users|new]] or'
.. ' [[Wikipedia:User access levels#Unregistered users|unregistered]]'
.. ' users are currently'
.. ' [[Wikipedia:Pending changes|subject to review]]'
},
upload = {
default = 'この${PAGETYPE}は[[Wikipedia:ファイルのアップロード|アップロード]]'
.. '[[Wikipedia:保護|保護]]されています',
extendedconfirmed = 'この${PAGETYPE}は[[Wikipedia:利用者#拡張承認された利用者|'
.. '拡張承認された利用者]]以外の[[Wikipedia:ファイルのアップロード|アップロード]]を'
.. '[[Wikipedia:保護|禁止]]しています',
}
},


Blurb.bannerTextFields = {
text = true,
explanation = true,
tooltip = true,
alt = true,
link = true
}


--------------------------------------------------------------------------------
function Blurb.new(protectionObj, args, cfg)
-- Explanation blurbs
return setmetatable({
--------------------------------------------------------------------------------
_cfg = cfg,
_protectionObj = protectionObj,
_args = args
}, Blurb)
end


-- This table produces the explanation blurbs available with the
-- Private methods --
-- ${EXPLANATIONBLURB} parameter. It is sorted by protection action,
-- protection level, and whether the page is a talk page or not. If the page is
-- a talk page it will have a talk key of "talk"; otherwise it will have a talk
-- key of "subject". The table is checked in the following order:
-- 1. page's protection action, page's protection level, page's talk key
-- 2. page's protection action, page's protection level, default talk key
-- 3. page's protection action, default protection level, page's talk key
-- 4. page's protection action, default protection level, default talk key
--
-- It is possible to use banner parameters inside this table.
-- *required* - this table needs edit, move, autoreview and upload subtables.
explanationBlurbs = {
edit = {
autoconfirmed = {
subject = '詳しくは[[Wikipedia:半保護の方針|半保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。この${PAGETYPE}を編集することができない場合、${TALKPAGE}'
.. 'にて<code class="nowrap">{{[[Template:半保護編集依頼|半保護編集依頼]]}}</code>'
.. 'を用いて[[Wikipedia:半保護の方針#半保護されたページの編集|編集を依頼]]してください。'
.. '半保護を解除しても問題ない状態になった場合、'
.. '[[Wikipedia:保護解除依頼|半保護の解除を依頼]]してください。',
default = '詳しくは[[Wikipedia:半保護の方針|半保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. '半保護を解除しても問題ない状態になった場合、'
.. '[[Wikipedia:保護解除依頼|半保護の解除を依頼]]してください。',
},
extendedconfirmed = {
subject = '詳しくは[[Wikipedia:拡張半保護の方針|拡張半保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。この${PAGETYPE}を編集することができない場合、${TALKPAGE}'
.. 'にて<code class="nowrap">{{[[Template:拡張半保護編集依頼|拡張半保護編集依頼]]}}</code>'
.. 'を用いて[[Wikipedia:拡張半保護の方針#拡張半保護されたページの編集|編集を依頼]]するか、'
.. '[[Wikipedia:管理者伝言板/拡張承認の申請|拡張承認の申請]]を'
.. 'してください。拡張半保護を解除しても問題ない状態になった場合、'
.. '[[Wikipedia:保護解除依頼|拡張半保護の解除を依頼]]してください。',
default = '詳しくは[[Wikipedia:拡張半保護の方針|拡張半保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. '拡張半保護を解除しても問題ない状態になった場合、'
.. '[[Wikipedia:保護解除依頼|拡張半保護の解除を依頼]]してください。'
},
default = {
subject = '詳しくは[[Wikipedia:保護の方針|保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. '変更が必要なときは${TALKPAGE}で議論し、[[Wikipedia:合意形成|合意形成]]後に'
.. '[[Wikipedia:管理者伝言板/保護ページ編集|保護編集依頼]]を行ってください。'
.. '合意が形成されるなど、保護を解除できる状態になった場合は'
.. '[[Wikipedia:保護解除依頼|保護の解除を依頼]]してください。',
default = '詳しくは[[Wikipedia:保護の方針|保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. '合意が形成されるなど、保護を解除できる状態になった場合は'
.. '[[Wikipedia:保護解除依頼|保護の解除を依頼]]してください。'
}
},
move = {
extendedconfirmed = {
subject = '詳しくは[[Wikipedia:拡張半保護の方針|拡張半保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. 'ページを移動できない場合は、${TALKPAGE}にて'
.. '<code class="nowrap">{{[[Template:拡張半保護編集依頼|拡張半保護編集依頼]]}}</code>'
.. 'を用いて[[Wikipedia:拡張半保護の方針#拡張半保護されたページの編集|移動を依頼]]するか、'
.. '[[Wikipedia:管理者伝言板/拡張承認の申請|拡張承認の申請]]を'
.. 'してください。移動拡張半保護を解除しても問題ない状態になった場合、'
.. '[[Wikipedia:保護解除依頼|移動拡張半保護の解除を依頼]]してください。',
default = '詳しくは[[Wikipedia:拡張半保護の方針|拡張半保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. '移動拡張半保護を解除しても問題ない状態になった場合、'
.. '[[Wikipedia:保護解除依頼|移動拡張半保護の解除を依頼]]してください。'
},
default = {
subject = '詳しくは[[Wikipedia:保護の方針|保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. '移動が必要なときは${TALKPAGE}で議論し、'
.. '[[Wikipedia:合意形成|合意形成]]後に'
.. '[[Wikipedia:移動依頼|移動依頼]]で依頼してください。'
.. '合意が形成されるなど、移動保護を解除できる状態になった場合は'
.. '[[Wikipedia:保護解除依頼|移動保護の解除を依頼]]してください。',
default = '詳しくは[[Wikipedia:保護の方針|保護の方針]]および'
.. '${PROTECTIONLOG}をご覧ください。'
.. '合意が形成されるなど、移動保護を解除できる状態になった場合は'
.. '[[Wikipedia:保護解除依頼|移動保護の解除を依頼]]してください。'
}
},
autoreview = {
default = {
default = 'See the [[Wikipedia:Protection policy|'
.. 'protection policy]] and ${PROTECTIONLOG} for more details.'
.. ' Edits to this ${PAGETYPE} by new and unregistered users'
.. ' will not be visible to readers until they are accepted by'
.. ' a reviewer. To avoid the need for your edits to be'
.. ' reviewed, you may'
.. ' [[Wikipedia:Requests for page protection'
.. '#Current requests for reduction in protection level'
.. '|request unprotection]], [[Special:Userlogin|log in]], or'
.. ' [[Special:UserLogin/signup|create an account]].'
},
},
upload = {
default = {
default = '詳しくは${PROTECTIONLOG}をご覧ください。'
.. '編集保護されていない場合は、'
.. 'ファイルの説明を編集することができます。'
.. 'アップロード保護を解除しても問題ない状態になった場合、'
.. '[[Wikipedia:保護解除依頼|アップロード保護の解除を依頼]]してください。'
}
}
},


--------------------------------------------------------------------------------
function Blurb:_formatDate(num)
-- Protection levels
-- Formats a Unix timestamp into dd Month, YYYY format.
--------------------------------------------------------------------------------
lang = lang or mw.language.getContentLanguage()
local success, date = pcall(
lang.formatDate,
lang,
self._cfg.msg['expiry-date-format'] or 'j F Y',
'@' .. tostring(num)
)
if success then
return date
end
end


-- This table provides the data for the ${PROTECTIONLEVEL} parameter, which
function Blurb:_getExpandedMessage(msgKey)
-- produces a short label for different protection levels. It is sorted by
return self:_substituteParameters(self._cfg.msg[msgKey])
-- protection action and protection level, and is checked in the following
end
-- order:
-- 1. page's protection action, page's protection level
-- 2. page's protection action, default protection level
-- 3. "edit" protection action, default protection level
--
-- It is possible to use banner parameters inside this table.
-- *required* - this table needs edit, move, autoreview and upload subtables.
protectionLevels = {
edit = {
default = '保護',
templateeditor = 'template-protected',
extendedconfirmed = '拡張半保護',
autoconfirmed = '半保護',
},
move = {
default = '移動保護',
extendedconfirmed = '移動拡張半保護'
},
autoreview = {
},
upload = {
default = 'アップロード保護',
extendedconfirmed = 'アップロード拡張半保護'
}
},


--------------------------------------------------------------------------------
function Blurb:_substituteParameters(msg)
-- Images
if not self._params then
--------------------------------------------------------------------------------
local parameterFuncs = {}


-- This table lists different padlock images for each protection action and
parameterFuncs.CURRENTVERSION    = self._makeCurrentVersionParameter
-- protection level. It is used if an image is not specified in any of the
parameterFuncs.EDITREQUEST        = self._makeEditRequestParameter
-- banner data tables, and if the page does not satisfy the conditions for using
parameterFuncs.EXPIRY            = self._makeExpiryParameter
-- the ['image-filename-indef'] image. It is checked in the following order:
parameterFuncs.EXPLANATIONBLURB  = self._makeExplanationBlurbParameter
-- 1. page's protection action, page's protection level
parameterFuncs.IMAGELINK          = self._makeImageLinkParameter
-- 2. page's protection action, default protection level
parameterFuncs.INTROBLURB        = self._makeIntroBlurbParameter
images = {
parameterFuncs.INTROFRAGMENT      = self._makeIntroFragmentParameter
edit = {
parameterFuncs.PAGETYPE          = self._makePagetypeParameter
default = 'Edit Protection.svg',
parameterFuncs.PROTECTIONBLURB    = self._makeProtectionBlurbParameter
templateeditor = 'Template-protection-shackle.svg',
parameterFuncs.PROTECTIONDATE    = self._makeProtectionDateParameter
extendedconfirmed = 'Edit Extended Semi-protection.svg',
parameterFuncs.PROTECTIONLEVEL    = self._makeProtectionLevelParameter
autoconfirmed = 'Edit Semi-protection.svg'
parameterFuncs.PROTECTIONLOG      = self._makeProtectionLogParameter
},
parameterFuncs.TALKPAGE          = self._makeTalkPageParameter
move = {
parameterFuncs.TOOLTIPBLURB      = self._makeTooltipBlurbParameter
default = 'Move-protection-shackle.svg',
parameterFuncs.TOOLTIPFRAGMENT    = self._makeTooltipFragmentParameter
extendedconfirmed = 'Move Extended Semi-protection.svg',
parameterFuncs.VANDAL            = self._makeVandalTemplateParameter
},
autoreview = {
self._params = setmetatable({}, {
default = 'Pending-protection-shackle.svg'
__index = function (t, k)
},
local param
upload = {
if parameterFuncs[k] then
default = 'Upload Protection.svg',
param = parameterFuncs[k](self)
extendedconfirmed = 'Upload Extended Semi-protection.svg',
end
}
param = param or ''
},
t[k] = param
return param
end
})
end
msg = msg:gsub('${(%u+)}', self._params)
return msg
end


-- Pages with a reason specified in this table will show the special "indef"
function Blurb:_makeCurrentVersionParameter()
-- padlock, defined in the 'image-filename-indef' message, if no expiry is set.
-- A link to the page history or the move log, depending on the kind of
indefImageReasons = {
-- protection.
template = true
local pagename = self._protectionObj.title.prefixedText
},
if self._protectionObj.action == 'move' then
-- We need the move log link.
return makeFullUrl(
'Special:Log',
{type = 'move', page = pagename},
self:_getExpandedMessage('current-version-move-display')
)
else
-- We need the history link.
return makeFullUrl(
pagename,
{action = 'history'},
self:_getExpandedMessage('current-version-edit-display')
)
end
end


--------------------------------------------------------------------------------
function Blurb:_makeEditRequestParameter()
-- Image links
local mEditRequest = require('Module:Submit an edit request')
--------------------------------------------------------------------------------
local action = self._protectionObj.action
local level = self._protectionObj.level
-- Get the edit request type.
local requestType
if action == 'edit' then
if level == 'autoconfirmed' then
requestType = 'semi'
elseif level == 'extendedconfirmed' then
requestType = 'extended'
elseif level == 'templateeditor' then
requestType = 'template'
end
end
requestType = requestType or 'full'
-- Get the display value.
local display = self:_getExpandedMessage('edit-request-display')


-- This table provides the data for the ${IMAGELINK} parameter, which gets
return mEditRequest._link{type = requestType, display = display}
-- the image link for small padlock icons based on the page's protection action
end
-- and protection level. It is checked in the following order:
-- 1. page's protection action, page's protection level
-- 2. page's protection action, default protection level
-- 3. "edit" protection action, default protection level
--
-- It is possible to use banner parameters inside this table.
-- *required* - this table needs edit, move, autoreview and upload subtables.
imageLinks = {
edit = {
default = 'Wikipedia:保護の方針',
templateeditor = 'Wikipedia:Protection policy#template',
extendedconfirmed = 'Wikipedia:拡張半保護の方針',
autoconfirmed = 'Wikipedia:半保護の方針'
},
move = {
default = 'Wikipedia:保護の方針',
extendedconfirmed = 'Wikipedia:拡張半保護の方針'
},
autoreview = {
default = 'Wikipedia:Protection policy#pending'
},
upload = {
default = ''
}
},


--------------------------------------------------------------------------------
function Blurb:_makeExpiryParameter()
-- Padlock indicator names
local expiry = self._protectionObj.expiry
--------------------------------------------------------------------------------
if type(expiry) == 'number' then
return self:_formatDate(expiry)
else
return expiry
end
end


-- This table provides the "name" attribute for the <indicator> extension tag
function Blurb:_makeExplanationBlurbParameter()
-- with which small padlock icons are generated. All indicator tags on a page
-- Cover special cases first.
-- are displayed in alphabetical order based on this attribute, and with
if self._protectionObj.title.namespace == 8 then
-- indicator tags with duplicate names, the last tag on the page wins.
-- MediaWiki namespace
-- The attribute is chosen based on the protection action; table keys must be a
return self:_getExpandedMessage('explanation-blurb-nounprotect')
-- protection action name or the string "default".
end
padlockIndicatorNames = {
move = 'pp-move',
autoreview = 'pp-autoreview',
upload = 'pp-upload',
default = 'pp-default'
},


--------------------------------------------------------------------------------
-- Get explanation blurb table keys
-- Protection categories
local action = self._protectionObj.action
--------------------------------------------------------------------------------
local level = self._protectionObj.level
local talkKey = self._protectionObj.title.isTalkPage and 'talk' or 'subject'


--[[
-- Find the message in the explanation blurb table and substitute any
-- The protection categories are stored in the protectionCategories table.
-- parameters.
-- Keys to this table are made up of the following strings:
local explanations = self._cfg.explanationBlurbs
--
local msg
-- 1. the expiry date
if explanations[action][level] and explanations[action][level][talkKey] then
-- 2. the namespace
msg = explanations[action][level][talkKey]
-- 3. the protection reason (e.g. "dispute" or "vandalism")
elseif explanations[action][level] and explanations[action][level].default then
-- 4. the protection level (e.g. "sysop" or "autoconfirmed")
msg = explanations[action][level].default
-- 5. the action (e.g. "edit" or "move")
elseif explanations[action].default and explanations[action].default[talkKey] then
--
msg = explanations[action].default[talkKey]
-- When the module looks up a category in the table, first it will will check to
elseif explanations[action].default and explanations[action].default.default then
-- see a key exists that corresponds to all five parameters. For example, a
msg = explanations[action].default.default
-- user page semi-protected from vandalism for two weeks would have the key
else
-- "temp-user-vandalism-autoconfirmed-edit". If no match is found, the module
error(string.format(
-- changes the first part of the key to "all" and checks the table again. It
'could not find explanation blurb for action "%s", level "%s" and talk key "%s"',
-- keeps checking increasingly generic key combinations until it finds the
action,
-- field, or until it reaches the key "all-all-all-all-all".
level,
--
talkKey
-- The module uses a binary matrix to determine the order in which to search.
), 8)
-- This is best demonstrated by a table. In this table, the "0" values
end
-- represent "all", and the "1" values represent the original data (e.g.
return self:_substituteParameters(msg)
-- "indef" or "file" or "vandalism").
end
--
--        expiry    namespace reason  level     action
-- order
-- 1      1        1        1        1        1
-- 2      0        1        1        1        1
-- 3      1        0        1        1        1
-- 4      0        0        1        1        1
-- 5      1        1        0        1        1
-- 6      0        1        0        1        1
-- 7      1        0        0        1        1
-- 8      0        0        0        1        1
-- 9      1        1        1        0        1
-- 10    0        1        1        0        1
-- 11    1        0        1        0        1
-- 12    0        0        1        0        1
-- 13    1        1        0        0        1
-- 14    0        1        0        0        1
-- 15    1        0        0        0        1
-- 16    0        0        0        0        1
-- 17    1        1        1        1        0
-- 18    0        1        1        1        0
-- 19    1        0        1        1        0
-- 20    0        0        1        1        0
-- 21    1        1        0        1        0
-- 22    0        1        0        1        0
-- 23    1        0        0        1        0
-- 24    0        0        0        1        0
-- 25    1        1        1        0        0
-- 26    0        1        1        0        0
-- 27    1        0        1        0        0
-- 28    0        0        1        0        0
-- 29    1        1        0        0        0
-- 30    0        1        0        0        0
-- 31    1        0        0        0        0
-- 32    0        0        0        0        0
--
-- In this scheme the action has the highest priority, as it is the last
-- to change, and the expiry has the least priority, as it changes the most.
-- The priorities of the expiry, the protection level and the action are
-- fixed, but the priorities of the reason and the namespace can be swapped
-- through the use of the cfg.bannerDataNamespaceHasPriority table.
--]]


-- If the reason specified to the template is listed in this table,
function Blurb:_makeImageLinkParameter()
-- namespace data will take priority over reason data in the protectionCategories
local imageLinks = self._cfg.imageLinks
-- table.
local action = self._protectionObj.action
reasonsWithNamespacePriority = {
local level = self._protectionObj.level
vandalism = true,
local msg
},
if imageLinks[action][level] then
msg = imageLinks[action][level]
elseif imageLinks[action].default then
msg = imageLinks[action].default
else
msg = imageLinks.edit.default
end
return self:_substituteParameters(msg)
end


-- The string to use as a namespace key for the protectionCategories table for each
function Blurb:_makeIntroBlurbParameter()
-- namespace number.
if self._protectionObj:isTemporary() then
categoryNamespaceKeys = {
return self:_getExpandedMessage('intro-blurb-expiry')
[  2] = 'user',
else
[  3] = 'user',
return self:_getExpandedMessage('intro-blurb-noexpiry')
[  4] = 'project',
end
[  6] = 'file',
end
[  8] = 'mediawiki',
[ 10] = 'template',
[ 12] = 'project',
[ 14] = 'category',
[100] = 'portal',
[828] = 'module',
},


protectionCategories = {
function Blurb:_makeIntroFragmentParameter()
['all|all|all|all|all']                  = '編集保護中のページ',
if self._protectionObj:isTemporary() then
--['all|all|office|all|all']              = 'Wikipedia Office-protected pages',
return self:_getExpandedMessage('intro-fragment-expiry')
--['all|all|reset|all|all']                = 'Wikipedia Office-protected pages',
else
--['all|all|dmca|all|all']                = 'Wikipedia Office-protected pages',
return self:_getExpandedMessage('intro-fragment-noexpiry')
['all|all|permanent|all|all']            = '保護運用中のページ',
end
--['all|all|mainpage|all|all']            = 'Wikipedia fully-protected main page files',
end
--['all|all|ecp|extendedconfirmed|all']    = '編集拡張半保護中のページ',
['all|all|all|extendedconfirmed|edit']    = '編集拡張半保護中のページ',
['all|all|all|autoconfirmed|edit']      = '編集半保護中のページ',
--['indef|all|all|autoconfirmed|edit']    = 'Wikipedia indefinitely semi-protected pages',
--['all|all|blp|autoconfirmed|edit']      = 'Wikipedia indefinitely semi-protected biographies of living people',
--['temp|all|blp|autoconfirmed|edit']      = 'Wikipedia temporarily semi-protected biographies of living people',
--['all|all|dispute|autoconfirmed|edit']  = 'Wikipedia pages semi-protected due to dispute',
--['all|all|sock|autoconfirmed|edit']      = 'Wikipedia pages semi-protected from banned users',
--['all|all|vandalism|autoconfirmed|edit'] = 'Wikipedia pages semi-protected against vandalism',
--['all|category|all|autoconfirmed|edit']  = 'Wikipedia semi-protected categories',
--['all|file|all|autoconfirmed|edit']      = 'Wikipedia semi-protected files',
--['all|portal|all|autoconfirmed|edit']    = 'Wikipedia semi-protected portals',
--['all|project|all|autoconfirmed|edit']  = 'Wikipedia semi-protected project pages',
--['all|talk|all|autoconfirmed|edit']      = 'Wikipedia semi-protected talk pages',
['all|template|all|sysop|edit']          = '編集保護中のテンプレート',
['all|template|all|autoconfirmed|edit']  = '編集半保護中のテンプレート',
--['all|user|all|autoconfirmed|edit']      = 'Wikipedia semi-protected user and user talk pages',
--['all|template|all|templateeditor|edit'] = 'Wikipedia template-protected templates',
--['all|all|blp|sysop|edit']              = 'Wikipedia indefinitely protected biographies of living people',
--['temp|all|blp|sysop|edit']              = 'Wikipedia temporarily protected biographies of living people',
--['all|all|dispute|sysop|edit']          = 'Wikipedia pages protected due to dispute',
--['all|all|sock|sysop|edit']              = 'Wikipedia pages protected from banned users',
--['all|all|vandalism|sysop|edit']        = 'Wikipedia pages protected against vandalism',
--['all|category|all|sysop|edit']          = 'Wikipedia fully protected categories',
--['all|file|all|sysop|edit']              = 'Wikipedia fully-protected files',
--['all|project|all|sysop|edit']          = 'Wikipedia fully-protected project pages',
--['all|talk|all|sysop|edit']              = 'Wikipedia fully-protected talk pages',
--['all|user|all|sysop|edit']              = 'Wikipedia fully protected user and user talk pages',
['all|module|all|sysop|edit']            = '編集保護中のモジュール',
--['all|module|all|templateeditor|edit']  = 'Wikipedia template-protected modules',
['all|module|all|autoconfirmed|edit']    = '編集半保護中のモジュール',
['all|all|all|sysop|move']              = '移動保護中のページ',
['all|all|all|extendedconfirmed|move']  = '移動拡張半保護中のページ',
--['indef|all|all|sysop|move']            = 'Wikipedia indefinitely move-protected pages',
--['all|all|dispute|sysop|move']          = 'Wikipedia pages move-protected due to dispute',
--['all|all|vandalism|sysop|move']        = 'Wikipedia pages move-protected due to vandalism',
--['all|portal|all|sysop|move']            = 'Wikipedia move-protected portals',
--['all|portal|all|sysop|move']            = 'Wikipedia move-protected portals',
--['all|project|all|sysop|move']          = 'Wikipedia move-protected project pages',
--['all|talk|all|sysop|move']              = 'Wikipedia move-protected talk pages',
['all|template|all|sysop|move']          = '移動保護中のテンプレート',
--['all|user|all|sysop|move']              = 'Wikipedia move-protected user and user talk pages',
--['all|all|all|autoconfirmed|autoreview'] = 'Wikipedia pending changes protected pages',
['all|file|all|all|upload']              = 'アップロード保護中のファイル',
['all|file|all|extendedconfirmed|upload']= 'アップロード拡張半保護中のファイル',
},


--------------------------------------------------------------------------------
function Blurb:_makePagetypeParameter()
-- Expiry category config
local pagetypes = self._cfg.pagetypes
--------------------------------------------------------------------------------
return pagetypes[self._protectionObj.title.namespace]
or pagetypes.default
or error('no default pagetype defined', 8)
end


-- This table configures the expiry category behaviour for each protection
function Blurb:_makeProtectionBlurbParameter()
-- action.
local protectionBlurbs = self._cfg.protectionBlurbs
-- * If set to true, setting that action will always categorise the page if
local action = self._protectionObj.action
--  an expiry parameter is not set.
local level = self._protectionObj.level
-- * If set to false, setting that action will never categorise the page.
local msg
-- * If set to nil, the module will categorise the page if:
if protectionBlurbs[action][level] then
--  1) an expiry parameter is not set, and
msg = protectionBlurbs[action][level]
--  2) a reason is provided, and
elseif protectionBlurbs[action].default then
--  3) the specified reason is not blacklisted in the reasonsWithoutExpiryCheck
msg = protectionBlurbs[action].default
--      table.
elseif protectionBlurbs.edit.default then
msg = protectionBlurbs.edit.default
else
error('no protection blurb defined for protectionBlurbs.edit.default', 8)
end
return self:_substituteParameters(msg)
end


expiryCheckActions = {
function Blurb:_makeProtectionDateParameter()
edit = nil,
local protectionDate = self._protectionObj.protectionDate
move = false,
if type(protectionDate) == 'number' then
autoreview = true,
return self:_formatDate(protectionDate)
upload = false
else
},
return protectionDate
end
end


reasonsWithoutExpiryCheck = {
function Blurb:_makeProtectionLevelParameter()
blp = true,
local protectionLevels = self._cfg.protectionLevels
template = true,
local action = self._protectionObj.action
},
local level = self._protectionObj.level
local msg
if protectionLevels[action][level] then
msg = protectionLevels[action][level]
elseif protectionLevels[action].default then
msg = protectionLevels[action].default
elseif protectionLevels.edit.default then
msg = protectionLevels.edit.default
else
error('no protection level defined for protectionLevels.edit.default', 8)
end
return self:_substituteParameters(msg)
end


--------------------------------------------------------------------------------
function Blurb:_makeProtectionLogParameter()
-- Pagetypes
local pagename = self._protectionObj.title.prefixedText
--------------------------------------------------------------------------------
if self._protectionObj.action == 'autoreview' then
-- We need the pending changes log.
return makeFullUrl(
'Special:Log',
{type = 'stable', page = pagename},
self:_getExpandedMessage('pc-log-display')
)
else
-- We need the protection log.
return makeFullUrl(
'Special:Log',
{type = 'protect', page = pagename},
self:_getExpandedMessage('protection-log-display')
)
end
end


-- This table produces the page types available with the ${PAGETYPE} parameter.
function Blurb:_makeTalkPageParameter()
-- Keys are namespace numbers, or the string "default" for the default value.
return string.format(
pagetypes = {
'[[%s:%s#%s|%s]]',
-- [0] = '記事',
mw.site.namespaces[self._protectionObj.title.namespace].talk.name,
[6] = 'ファイル',
self._protectionObj.title.text,
[10] = 'テンプレート',
self._args.section or 'top',
[14] = 'カテゴリ',
self:_getExpandedMessage('talk-page-link-display')
[828] = 'モジュール',
)
[1] = 'ノートページ',
end
[3] = '会話ページ',
[5] = 'ノートページ',
[7] = 'ノートページ',
[9] = 'ノートページ',
[11] = 'ノートページ',
[13] = 'ノートページ',
[15] = 'ノートページ',
[101] = 'ノートページ',
[103] = 'ノートページ',
[829] = 'ノートページ',
[2301] = 'ノートページ',
[2303] = 'ノートページ',
default = 'ページ'
},


--------------------------------------------------------------------------------
function Blurb:_makeTooltipBlurbParameter()
-- Strings marking indefinite protection
if self._protectionObj:isTemporary() then
--------------------------------------------------------------------------------
return self:_getExpandedMessage('tooltip-blurb-expiry')
else
return self:_getExpandedMessage('tooltip-blurb-noexpiry')
end
end


-- This table contains values passed to the expiry parameter that mean the page
function Blurb:_makeTooltipFragmentParameter()
-- is protected indefinitely.
if self._protectionObj:isTemporary() then
indefStrings = {
return self:_getExpandedMessage('tooltip-fragment-expiry')
['indef'] = true,
else
['indefinite'] = true,
return self:_getExpandedMessage('tooltip-fragment-noexpiry')
['indefinitely'] = true,
end
['infinite'] = true,
end
},


--------------------------------------------------------------------------------
function Blurb:_makeVandalTemplateParameter()
-- Group hierarchy
return require('Module:Vandal-m')._main{
--------------------------------------------------------------------------------
self._args.user or self._protectionObj.title.baseText
}
end


-- This table maps each group to all groups that have a superset of the original
-- Public methods --
-- group's page editing permissions.
hierarchy = {
sysop = {},
eliminator = {'sysop'},
reviewer = {'sysop'},
filemover = {'sysop'},
templateeditor = {'sysop'},
extendedconfirmed = {'sysop'},
autoconfirmed = {'eliminator', 'reviewer', 'filemover', 'templateeditor', 'extendedconfirmed'},
user = {'autoconfirmed'},
['*'] = {'user'}
},


--------------------------------------------------------------------------------
function Blurb:makeBannerText(key)
-- Wrapper templates and their default arguments
-- Validate input.
--------------------------------------------------------------------------------
if not key or not Blurb.bannerTextFields[key] then
error(string.format(
'"%s" is not a valid banner config field',
tostring(key)
), 2)
end


-- This table contains wrapper templates used with the module, and their
-- Generate the text.
-- default arguments. Templates specified in this table should contain the
local msg = self._protectionObj.bannerConfig[key]
-- following invocation, and no other template content:
if type(msg) == 'string' then
--
return self:_substituteParameters(msg)
-- {{#invoke:Protection banner|main}}
elseif type(msg) == 'function' then
--
msg = msg(self._protectionObj, self._args)
-- If other content is desired, it can be added between
if type(msg) ~= 'string' then
-- <noinclude>...</noinclude> tags.
error(string.format(
--
'bad output from banner config function with key "%s"'
-- When a user calls one of these wrapper templates, they will use the
.. ' (expected string, got %s)',
-- default arguments automatically. However, users can override any of the
tostring(key),
-- arguments.
type(msg)
wrappers = {
), 4)
['Template:Pp']                         = {},
end
['Template:Pp-extended']                = {'ecp'},
return self:_substituteParameters(msg)
['Template:Pp-blp']                    = {'blp'},
end
-- we don't need Template:Pp-create
end
['Template:Pp-dispute']                = {'dispute'},
['Template:Pp-main-page']              = {'mainpage'},
['Template:Pp-move']                    = {action = 'move'},
['Template:Pp-move-dispute']            = {'dispute', action = 'move'},
-- we don't need Template:Pp-move-indef
['Template:Pp-move-vandalism']          = {'vandalism', action = 'move'},
['Template:Pp-office']                  = {'office'},
['Template:Pp-office-dmca']            = {'dmca'},
['Template:Pp-pc']                      = {action = 'autoreview', small = true},
['Template:Pp-pc1']                    = {action = 'autoreview', small = true},
['Template:保護運用']                  = {'permanent', small = true},
['Template:Pp-reset']                  = {'reset'},
['Template:Pp-semi-indef']              = {small = true},
['Template:Pp-sock']                    = {'sock'},
['Template:Pp-template']                = {'template', small = true},
['Template:Pp-upload']                  = {action = 'upload'},
['Template:Pp-usertalk']                = {'usertalk'},
['Template:Pp-vandalism']              = {'vandalism'},
},


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--  
-- BannerTemplate class
--                                MESSAGES
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


msg = {
local BannerTemplate = {}
BannerTemplate.__index = BannerTemplate
 
function BannerTemplate.new(protectionObj, cfg)
local obj = {}
obj._cfg = cfg


--------------------------------------------------------------------------------
-- Set the image filename.
-- Intro blurb and intro fragment
local imageFilename = protectionObj.bannerConfig.image
--------------------------------------------------------------------------------
if imageFilename then
-- 日本語版独自の条件分岐
if type(imageFilename) == 'string' then
obj._imageFilename = imageFilename
elseif type(imageFilename) == 'function' then
obj._imageFilename = imageFilename(protectionObj)
end
else
-- If an image filename isn't specified explicitly in the banner config,
-- generate it from the protection status and the namespace.
local action = protectionObj.action
local level = protectionObj.level
local namespace = protectionObj.title.namespace
local reason = protectionObj.reason
-- Deal with special cases first.
if (
namespace == 10
or namespace == 828
or reason and obj._cfg.indefImageReasons[reason]
)
and action == 'edit'
and level == 'sysop'
and not protectionObj:isTemporary()
then
-- Fully protected modules and templates get the special red "indef"
-- padlock.
obj._imageFilename = obj._cfg.msg['image-filename-indef']
else
-- Deal with regular protection types.
local images = obj._cfg.images
if images[action] then
if images[action][level] then
obj._imageFilename = images[action][level]
elseif images[action].default then
obj._imageFilename = images[action].default
end
end
end
end
return setmetatable(obj, BannerTemplate)
end


-- These messages specify what is produced by the ${INTROBLURB} and
function BannerTemplate:renderImage()
-- ${INTROFRAGMENT} parameters. If the protection is temporary they use the
local filename = self._imageFilename
-- intro-blurb-expiry or intro-fragment-expiry, and if not they use
or self._cfg.msg['image-filename-default']
-- intro-blurb-noexpiry or intro-fragment-noexpiry.
or 'Transparent.gif'
-- It is possible to use banner parameters in these messages.
return makeFileLink{
['intro-blurb-expiry'] = '${PROTECTIONBLURB}(${EXPIRY}まで)。',
file = filename,
['intro-blurb-noexpiry'] = '${PROTECTIONBLURB}。',
size = (self.imageSize or 'x20') .. 'px', -- 日本語版独自の変更
['intro-fragment-expiry'] = '${PROTECTIONBLURB}(${EXPIRY}まで)。',
alt = self._imageAlt,
['intro-fragment-noexpiry'] = '${PROTECTIONBLURB}。',
link = self._imageLink,
caption = self.imageCaption
}
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Tooltip blurb
-- Banner class
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- These messages specify what is produced by the ${TOOLTIPBLURB} parameter.
local Banner = setmetatable({}, BannerTemplate)
-- If the protection is temporary the tooltip-blurb-expiry message is used, and
Banner.__index = Banner
-- if not the tooltip-blurb-noexpiry message is used.
-- It is possible to use banner parameters in these messages.
['tooltip-blurb-expiry'] = 'この${PAGETYPE}は${EXPIRY}まで${PROTECTIONLEVEL}されています。',
['tooltip-blurb-noexpiry'] = 'この${PAGETYPE}は${PROTECTIONLEVEL}されています。',
['tooltip-fragment-expiry'] = 'この${PAGETYPE}は${EXPIRY}まで${PROTECTIONLEVEL}されており、',
['tooltip-fragment-noexpiry'] = 'この${PAGETYPE}は${PROTECTIONLEVEL}されており、',


--------------------------------------------------------------------------------
function Banner.new(protectionObj, blurbObj, cfg)
-- Special explanation blurb
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
--------------------------------------------------------------------------------
obj.imageSize = 40 -- 日本語版独自の変更: フィールド名
obj.imageCaption = blurbObj:makeBannerText('alt') -- Large banners use the alt text for the tooltip.
obj._reasonText = blurbObj:makeBannerText('text')
obj._explanationText = blurbObj:makeBannerText('explanation')
obj._page = protectionObj.title.prefixedText -- Only makes a difference in testing.
return setmetatable(obj, Banner)
end


-- An explanation blurb for pages that cannot be unprotected, e.g. for pages
function Banner:__tostring()
-- in the MediaWiki namespace.
-- Renders the banner.
-- It is possible to use banner parameters in this message.
makeMessageBox = makeMessageBox or require('Module:Message box').main
['explanation-blurb-nounprotect'] = 'See the [[Wikipedia:Protection policy|'
local reasonText = self._reasonText or error('no reason text set', 2)
.. 'protection policy]] and ${PROTECTIONLOG} for more details.'
local explanationText = self._explanationText
.. ' Please discuss any changes on the ${TALKPAGE}; you'
local mbargs = {
.. ' may ${EDITREQUEST} to ask an'
page = self._page,
.. ' [[Wikipedia:Administrators|administrator]] to make an edit if it'
type = 'protection',
.. ' is [[Help:Minor edit#When to mark an edit as a minor edit'
image = self:renderImage(),
.. '|uncontroversial]] or supported by [[Wikipedia:Consensus'
text = string.format(
.. '|consensus]].',
"'''%s'''%s",
reasonText,
explanationText and '<br />' .. explanationText or ''
)
}
return makeMessageBox('mbox', mbargs)
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Protection log display values
-- Padlock class
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- These messages determine the display values for the protection log link
local Padlock = setmetatable({}, BannerTemplate)
-- or the pending changes log link produced by the ${PROTECTIONLOG} parameter.
Padlock.__index = Padlock
-- It is possible to use banner parameters in these messages.
['protection-log-display'] = '保護記録',
['pc-log-display'] = 'pending changes log',


--------------------------------------------------------------------------------
function Padlock.new(protectionObj, blurbObj, cfg)
-- Current version display values
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
--------------------------------------------------------------------------------
obj.imageSize = 'x20' -- 日本語版独自の変更: フィールド名、高さのみ指定
obj.imageCaption = blurbObj:makeBannerText('tooltip')
obj._imageAlt = blurbObj:makeBannerText('alt')
obj._imageLink = blurbObj:makeBannerText('link')
obj._indicatorName = cfg.padlockIndicatorNames[protectionObj.action]
or cfg.padlockIndicatorNames.default
or 'pp-default'
return setmetatable(obj, Padlock)
end


-- These messages determine the display values for the page history link
function Padlock:__tostring()
-- or the move log link produced by the ${CURRENTVERSION} parameter.
local frame = mw.getCurrentFrame()
-- It is possible to use banner parameters in these messages.
-- The nowiki tag helps prevent whitespace at the top of articles.
['current-version-move-display'] = '現在のページ名',
return frame:extensionTag{name = 'nowiki'} .. frame:extensionTag{
['current-version-edit-display'] = '現行版',
name = 'indicator',
args = {name = self._indicatorName},
content = self:renderImage()
}
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Talk page
-- Exports
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- This message determines the display value of the talk page link produced
local p = {}
-- with the ${TALKPAGE} parameter.
 
-- It is possible to use banner parameters in this message.
function p._exportClasses()
['talk-page-link-display'] = 'ノートページ',
-- This is used for testing purposes.
return {
Protection = Protection,
Blurb = Blurb,
BannerTemplate = BannerTemplate,
Banner = Banner,
Padlock = Padlock,
}
end


--------------------------------------------------------------------------------
function p._main(args, cfg, title)
-- Edit requests
args = args or {}
--------------------------------------------------------------------------------
cfg = cfg or require(CONFIG_MODULE)


-- This message determines the display value of the edit request link produced
local protectionObj = Protection.new(args, cfg, title)
-- with the ${EDITREQUEST} parameter.
-- It is possible to use banner parameters in this message.
['edit-request-display'] = 'submit an edit request',


--------------------------------------------------------------------------------
local ret = {}
-- Expiry date format
--------------------------------------------------------------------------------


-- This is the format for the blurb expiry date. It should be valid input for
-- If a page's edit protection is equally or more restrictive than its
-- the first parameter of the #time parser function.
-- protection from some other action, then don't bother displaying anything
['expiry-date-format'] = 'Y年Fj日" ("D") "H:i" ("e")"',
-- for the other action (except categories).
if protectionObj.action == 'edit' or
args.demolevel or
not getReachableNodes(
cfg.hierarchy,
protectionObj.level
)[effectiveProtectionLevel('edit', protectionObj.title)]
then
-- Initialise the blurb object
local blurbObj = Blurb.new(protectionObj, args, cfg)
-- Render the banner
if protectionObj:isProtected() then
ret[#ret + 1] = tostring(
(yesno(args.small) and Padlock or Banner)
.new(protectionObj, blurbObj, cfg)
)
end
end


--------------------------------------------------------------------------------
-- Render the categories
-- Tracking categories
if yesno(args.category) ~= false then
--------------------------------------------------------------------------------
ret[#ret + 1] = protectionObj:makeCategoryLinks()
end
return table.concat(ret)
end


-- These messages determine which tracking categories the module outputs.
function p.main(frame, cfg)
['tracking-category-incorrect'] = '不適切な保護テンプレートのあるページ',
cfg = cfg or require(CONFIG_MODULE)
['tracking-category-mismatch'] = '保護理由と保護レベルが合致していないページ', -- 日本語版独自
['tracking-category-template'] = 'Wikipedia template-protected pages other than templates and modules',


--------------------------------------------------------------------------------
-- Find default args, if any.
-- Images
local parent = frame.getParent and frame:getParent()
--------------------------------------------------------------------------------
local defaultArgs = parent and cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')]


-- These are images that are not defined by their protection action and protection level.
-- Find user args, and use the parent frame if we are being called from a
['image-filename-indef'] = 'Edit Protection.svg',
-- wrapper template.
['image-filename-default'] = 'Transparent.gif',
getArgs = getArgs or require('Module:Arguments').getArgs
local userArgs = getArgs(frame, {
parentOnly = defaultArgs,
frameOnly = not defaultArgs
})


--------------------------------------------------------------------------------
-- Build the args table. User-specified args overwrite default args.
-- End messages
local args = {}
--------------------------------------------------------------------------------
for k, v in pairs(defaultArgs or {}) do
}
args[k] = v
end
for k, v in pairs(userArgs) do
args[k] = v
end
return p._main(args, cfg)
end


--------------------------------------------------------------------------------
return p
-- End configuration
--------------------------------------------------------------------------------
}

2024年7月22日 (月) 12:59時点における最新版

このモジュールについての説明文ページを モジュール:Protection banner/doc に作成できます

-- This module implements {{pp-meta}} and its daughter templates such as
-- {{pp-dispute}}, {{pp-vandalism}} and {{pp-sock}}.

-- Initialise necessary modules.
require('strict')
local makeFileLink = require('Module:File link')._main
local effectiveProtectionLevel = require('Module:Effective protection level')._main
local effectiveProtectionExpiry = require('Module:Effective protection expiry')._main
local yesno = require('Module:Yesno')

-- Lazily initialise modules and objects we don't always need.
local getArgs, makeMessageBox, lang

-- Set constants.
local CONFIG_MODULE = 'モジュール:Protection banner/config'

--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------

local function makeCategoryLink(cat, sort)
	if cat then
		return string.format(
			'[[%s:%s|%s]]',
			mw.site.namespaces[14].name,
			cat,
			sort
		)
	end
end

-- Validation function for the expiry and the protection date
local function validateDate(dateString, dateType)
	if not lang then
		lang = mw.language.getContentLanguage()
	end
	local success, result = pcall(lang.formatDate, lang, 'U', dateString)
	if success then
		result = tonumber(result)
		if result then
			return result
		end
	end
	error(string.format(
		'invalid %s: %s',
		dateType,
		tostring(dateString)
	), 4)
end

local function makeFullUrl(page, query, display)
	return string.format(
		'[%s %s]',
		tostring(mw.uri.fullUrl(page, query)),
		display
	)
end

-- Given a directed graph formatted as node -> table of direct successors,
-- get a table of all nodes reachable from a given node (though always
-- including the given node).
local function getReachableNodes(graph, start)
	local toWalk, retval = {[start] = true}, {}
	while true do
		-- Can't use pairs() since we're adding and removing things as we're iterating
		local k = next(toWalk) -- This always gets the "first" key
		if k == nil then
			return retval
		end
		toWalk[k] = nil
		retval[k] = true
		for _,v in ipairs(graph[k]) do
			if not retval[v] then
				toWalk[v] = true
			end
		end
	end
end

--------------------------------------------------------------------------------
-- Protection class
--------------------------------------------------------------------------------

local Protection = {}
Protection.__index = Protection

Protection.supportedActions = {
	edit = true,
	move = true,
	autoreview = true,
	upload = true
}

Protection.bannerConfigFields = {
	'text',
	'explanation',
	'tooltip',
	'alt',
	'link',
	'image'
}

function Protection.new(args, cfg, title)
	local obj = {}
	obj._cfg = cfg
	obj.title = title or mw.title.getCurrentTitle()

	-- Set action
	if not args.action then
		obj.action = 'edit'
	elseif Protection.supportedActions[args.action] then
		obj.action = args.action
	else
		error(string.format(
			'invalid action: %s',
			tostring(args.action)
		), 3)
	end

	-- Set level
	obj.level = args.demolevel or effectiveProtectionLevel(obj.action, obj.title)
	if not obj.level or (obj.action == 'move' and obj.level == 'autoconfirmed') then
		-- Users need to be autoconfirmed to move pages anyway, so treat
		-- semi-move-protected pages as unprotected.
		obj.level = '*'
	end

	-- Set expiry
	local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title)
	if effectiveExpiry == 'infinity' then
		obj.expiry = 'indef'
	elseif effectiveExpiry ~= 'unknown' then
		obj.expiry = validateDate(effectiveExpiry, 'expiry date')
	end

	-- Set reason
	if args[1] then
		obj.reason = mw.ustring.lower(args[1])
		if obj.reason:find('|') then
			error('reasons cannot contain the pipe character ("|")', 3)
		end
	end

	-- Set protection date
	if args.date then
		obj.protectionDate = validateDate(args.date, 'protection date')
	end
	
	-- Set banner config
	do
		obj.bannerConfig = {}
		local configTables = {}
		if cfg.banners[obj.action] then
			configTables[#configTables + 1] = cfg.banners[obj.action][obj.reason]
		end
		if cfg.defaultBanners[obj.action] then
			configTables[#configTables + 1] = cfg.defaultBanners[obj.action][obj.level]
			configTables[#configTables + 1] = cfg.defaultBanners[obj.action].default
		end
		configTables[#configTables + 1] = cfg.masterBanner
		for i, field in ipairs(Protection.bannerConfigFields) do
			for j, t in ipairs(configTables) do
				if t[field] then
					obj.bannerConfig[field] = t[field]
					break
				end
			end
		end
	end
	return setmetatable(obj, Protection)
end

function Protection:isProtected()
	return self.level ~= '*'
end

function Protection:isTemporary()
	return type(self.expiry) == 'number'
end

function Protection:makeProtectionCategory()
	local cfg = self._cfg
	local title = self.title
	
	-- Exit if the page is not protected.
	if not self:isProtected() then
		return ''
	end
	
	-- Get the expiry key fragment.
	local expiryFragment
	if self.expiry == 'indef' then
		expiryFragment = self.expiry
	elseif type(self.expiry) == 'number' then
		expiryFragment = 'temp'
	end

	-- Get the namespace key fragment.
	local namespaceFragment = cfg.categoryNamespaceKeys[title.namespace]
	if not namespaceFragment and title.namespace % 2 == 1 then
			namespaceFragment = 'talk'
	end
 
	-- Define the order that key fragments are tested in. This is done with an
	-- array of tables containing the value to be tested, along with its
	-- position in the cfg.protectionCategories table.
	local order = {
		{val = expiryFragment,    keypos = 1},
		{val = namespaceFragment, keypos = 2},
		{val = self.reason,       keypos = 3},
		{val = self.level,        keypos = 4},
		{val = self.action,       keypos = 5}
	}

	--[[
	-- The old protection templates used an ad-hoc protection category system,
	-- with some templates prioritising namespaces in their categories, and
	-- others prioritising the protection reason. To emulate this in this module
	-- we use the config table cfg.reasonsWithNamespacePriority to set the
	-- reasons for which namespaces have priority over protection reason.
	-- If we are dealing with one of those reasons, move the namespace table to
	-- the end of the order table, i.e. give it highest priority. If not, the
	-- reason should have highest priority, so move that to the end of the table
	-- instead.
	--]]
	table.insert(order, table.remove(order, self.reason and cfg.reasonsWithNamespacePriority[self.reason] and 2 or 3))
 
	--[[
	-- Define the attempt order. Inactive subtables (subtables with nil "value"
	-- fields) are moved to the end, where they will later be given the key
	-- "all". This is to cut down on the number of table lookups in
	-- cfg.protectionCategories, which grows exponentially with the number of
	-- non-nil keys. We keep track of the number of active subtables with the
	-- noActive parameter.
	--]]
	local noActive, attemptOrder
	do
		local active, inactive = {}, {}
		for i, t in ipairs(order) do
			if t.val then
				active[#active + 1] = t
			else
				inactive[#inactive + 1] = t
			end
		end
		noActive = #active
		attemptOrder = active
		for i, t in ipairs(inactive) do
			attemptOrder[#attemptOrder + 1] = t
		end
	end
 
	--[[
	-- Check increasingly generic key combinations until we find a match. If a
	-- specific category exists for the combination of key fragments we are
	-- given, that match will be found first. If not, we keep trying different
	-- key fragment combinations until we match using the key
	-- "all-all-all-all-all".
	--
	-- To generate the keys, we index the key subtables using a binary matrix
	-- with indexes i and j. j is only calculated up to the number of active
	-- subtables. For example, if there were three active subtables, the matrix
	-- would look like this, with 0 corresponding to the key fragment "all", and
	-- 1 corresponding to other key fragments.
	-- 
	--   j 1  2  3
	-- i  
	-- 1   1  1  1
	-- 2   0  1  1
	-- 3   1  0  1
	-- 4   0  0  1
	-- 5   1  1  0
	-- 6   0  1  0
	-- 7   1  0  0
	-- 8   0  0  0
	-- 
	-- Values of j higher than the number of active subtables are set
	-- to the string "all".
	--
	-- A key for cfg.protectionCategories is constructed for each value of i.
	-- The position of the value in the key is determined by the keypos field in
	-- each subtable.
	--]]
	local cats = cfg.protectionCategories
	for i = 1, 2^noActive do
		local key = {}
		for j, t in ipairs(attemptOrder) do
			if j > noActive then
				key[t.keypos] = 'all'
			else
				local quotient = i / 2 ^ (j - 1)
				quotient = math.ceil(quotient)
				if quotient % 2 == 1 then
					key[t.keypos] = t.val
				else
					key[t.keypos] = 'all'
				end
			end
		end
		key = table.concat(key, '|')
		local attempt = cats[key]
		if attempt then
			return makeCategoryLink(attempt, title.text)
		end
	end
	return ''
end

function Protection:isIncorrect()
	local expiry = self.expiry
	return not self:isProtected()
		or type(expiry) == 'number' and expiry < os.time()
end

-- 日本語版独自
function Protection:isMismatched()
	return self.reason == 'dispute' and self.level ~= 'sysop'
end

function Protection:isTemplateProtectedNonTemplate()
	local action, namespace = self.action, self.title.namespace
	return self.level == 'templateeditor'
		and (
			(action ~= 'edit' and action ~= 'move')
			or (namespace ~= 10 and namespace ~= 828)
		)
end

function Protection:makeCategoryLinks()
	local msg = self._cfg.msg
	local ret = { self:makeProtectionCategory() }
	if self:isIncorrect() then
		ret[#ret + 1] = makeCategoryLink(
			msg['tracking-category-incorrect'],
			self.title.text
		)
	elseif self:isMismatched() then
		ret[#ret + 1] = makeCategoryLink(
			msg['tracking-category-mismatch'],
			self.title.text
		)
	end
	if self:isTemplateProtectedNonTemplate() then
		ret[#ret + 1] = makeCategoryLink(
			msg['tracking-category-template'],
			self.title.text
		)
	end
	return table.concat(ret)
end

--------------------------------------------------------------------------------
-- Blurb class
--------------------------------------------------------------------------------

local Blurb = {}
Blurb.__index = Blurb

Blurb.bannerTextFields = {
	text = true,
	explanation = true,
	tooltip = true,
	alt = true,
	link = true
}

function Blurb.new(protectionObj, args, cfg)
	return setmetatable({
		_cfg = cfg,
		_protectionObj = protectionObj,
		_args = args
	}, Blurb)
end

-- Private methods --

function Blurb:_formatDate(num)
	-- Formats a Unix timestamp into dd Month, YYYY format.
	lang = lang or mw.language.getContentLanguage()
	local success, date = pcall(
		lang.formatDate,
		lang,
		self._cfg.msg['expiry-date-format'] or 'j F Y',
		'@' .. tostring(num)
	)
	if success then
		return date
	end
end

function Blurb:_getExpandedMessage(msgKey)
	return self:_substituteParameters(self._cfg.msg[msgKey])
end

function Blurb:_substituteParameters(msg)
	if not self._params then
		local parameterFuncs = {}

		parameterFuncs.CURRENTVERSION     = self._makeCurrentVersionParameter
		parameterFuncs.EDITREQUEST        = self._makeEditRequestParameter
		parameterFuncs.EXPIRY             = self._makeExpiryParameter
		parameterFuncs.EXPLANATIONBLURB   = self._makeExplanationBlurbParameter
		parameterFuncs.IMAGELINK          = self._makeImageLinkParameter
		parameterFuncs.INTROBLURB         = self._makeIntroBlurbParameter
		parameterFuncs.INTROFRAGMENT      = self._makeIntroFragmentParameter
		parameterFuncs.PAGETYPE           = self._makePagetypeParameter
		parameterFuncs.PROTECTIONBLURB    = self._makeProtectionBlurbParameter
		parameterFuncs.PROTECTIONDATE     = self._makeProtectionDateParameter
		parameterFuncs.PROTECTIONLEVEL    = self._makeProtectionLevelParameter
		parameterFuncs.PROTECTIONLOG      = self._makeProtectionLogParameter
		parameterFuncs.TALKPAGE           = self._makeTalkPageParameter
		parameterFuncs.TOOLTIPBLURB       = self._makeTooltipBlurbParameter
		parameterFuncs.TOOLTIPFRAGMENT    = self._makeTooltipFragmentParameter
		parameterFuncs.VANDAL             = self._makeVandalTemplateParameter
		
		self._params = setmetatable({}, {
			__index = function (t, k)
				local param
				if parameterFuncs[k] then
					param = parameterFuncs[k](self)
				end
				param = param or ''
				t[k] = param
				return param
			end
		})
	end
	
	msg = msg:gsub('${(%u+)}', self._params)
	return msg
end

function Blurb:_makeCurrentVersionParameter()
	-- A link to the page history or the move log, depending on the kind of
	-- protection.
	local pagename = self._protectionObj.title.prefixedText
	if self._protectionObj.action == 'move' then
		-- We need the move log link.
		return makeFullUrl(
			'Special:Log',
			{type = 'move', page = pagename},
			self:_getExpandedMessage('current-version-move-display')
		)
	else
		-- We need the history link.
		return makeFullUrl(
			pagename,
			{action = 'history'},
			self:_getExpandedMessage('current-version-edit-display')
		)
	end
end

function Blurb:_makeEditRequestParameter()
	local mEditRequest = require('Module:Submit an edit request')
	local action = self._protectionObj.action
	local level = self._protectionObj.level
	
	-- Get the edit request type.
	local requestType
	if action == 'edit' then
		if level == 'autoconfirmed' then
			requestType = 'semi'
		elseif level == 'extendedconfirmed' then
			requestType = 'extended'
		elseif level == 'templateeditor' then
			requestType = 'template'
		end
	end
	requestType = requestType or 'full'
	
	-- Get the display value.
	local display = self:_getExpandedMessage('edit-request-display')

	return mEditRequest._link{type = requestType, display = display}
end

function Blurb:_makeExpiryParameter()
	local expiry = self._protectionObj.expiry
	if type(expiry) == 'number' then
		return self:_formatDate(expiry)
	else
		return expiry
	end
end

function Blurb:_makeExplanationBlurbParameter()
	-- Cover special cases first.
	if self._protectionObj.title.namespace == 8 then
		-- MediaWiki namespace
		return self:_getExpandedMessage('explanation-blurb-nounprotect')
	end

	-- Get explanation blurb table keys
	local action = self._protectionObj.action
	local level = self._protectionObj.level
	local talkKey = self._protectionObj.title.isTalkPage and 'talk' or 'subject'

	-- Find the message in the explanation blurb table and substitute any
	-- parameters.
	local explanations = self._cfg.explanationBlurbs
	local msg
	if explanations[action][level] and explanations[action][level][talkKey] then
		msg = explanations[action][level][talkKey]
	elseif explanations[action][level] and explanations[action][level].default then
		msg = explanations[action][level].default
	elseif explanations[action].default and explanations[action].default[talkKey] then
		msg = explanations[action].default[talkKey]
	elseif explanations[action].default and explanations[action].default.default then
		msg = explanations[action].default.default
	else
		error(string.format(
			'could not find explanation blurb for action "%s", level "%s" and talk key "%s"',
			action,
			level,
			talkKey
		), 8)
	end
	return self:_substituteParameters(msg)
end

function Blurb:_makeImageLinkParameter()
	local imageLinks = self._cfg.imageLinks
	local action = self._protectionObj.action
	local level = self._protectionObj.level
	local msg
	if imageLinks[action][level] then
		msg = imageLinks[action][level]
	elseif imageLinks[action].default then
		msg = imageLinks[action].default
	else
		msg = imageLinks.edit.default
	end
	return self:_substituteParameters(msg)
end

function Blurb:_makeIntroBlurbParameter()
	if self._protectionObj:isTemporary() then
		return self:_getExpandedMessage('intro-blurb-expiry')
	else
		return self:_getExpandedMessage('intro-blurb-noexpiry')
	end
end

function Blurb:_makeIntroFragmentParameter()
	if self._protectionObj:isTemporary() then
		return self:_getExpandedMessage('intro-fragment-expiry')
	else
		return self:_getExpandedMessage('intro-fragment-noexpiry')
	end
end

function Blurb:_makePagetypeParameter()
	local pagetypes = self._cfg.pagetypes
	return pagetypes[self._protectionObj.title.namespace]
		or pagetypes.default
		or error('no default pagetype defined', 8)
end

function Blurb:_makeProtectionBlurbParameter()
	local protectionBlurbs = self._cfg.protectionBlurbs
	local action = self._protectionObj.action
	local level = self._protectionObj.level
	local msg
	if protectionBlurbs[action][level] then
		msg = protectionBlurbs[action][level]
	elseif protectionBlurbs[action].default then
		msg = protectionBlurbs[action].default
	elseif protectionBlurbs.edit.default then
		msg = protectionBlurbs.edit.default
	else
		error('no protection blurb defined for protectionBlurbs.edit.default', 8)
	end
	return self:_substituteParameters(msg)
end

function Blurb:_makeProtectionDateParameter()
	local protectionDate = self._protectionObj.protectionDate
	if type(protectionDate) == 'number' then
		return self:_formatDate(protectionDate)
	else
		return protectionDate
	end
end

function Blurb:_makeProtectionLevelParameter()
	local protectionLevels = self._cfg.protectionLevels
	local action = self._protectionObj.action
	local level = self._protectionObj.level
	local msg
	if protectionLevels[action][level] then
		msg = protectionLevels[action][level]
	elseif protectionLevels[action].default then
		msg = protectionLevels[action].default
	elseif protectionLevels.edit.default then
		msg = protectionLevels.edit.default
	else
		error('no protection level defined for protectionLevels.edit.default', 8)
	end
	return self:_substituteParameters(msg)
end

function Blurb:_makeProtectionLogParameter()
	local pagename = self._protectionObj.title.prefixedText
	if self._protectionObj.action == 'autoreview' then
		-- We need the pending changes log.
		return makeFullUrl(
			'Special:Log',
			{type = 'stable', page = pagename},
			self:_getExpandedMessage('pc-log-display')
		)
	else
		-- We need the protection log.
		return makeFullUrl(
			'Special:Log',
			{type = 'protect', page = pagename},
			self:_getExpandedMessage('protection-log-display')
		)
	end
end

function Blurb:_makeTalkPageParameter()
	return string.format(
		'[[%s:%s#%s|%s]]',
		mw.site.namespaces[self._protectionObj.title.namespace].talk.name,
		self._protectionObj.title.text,
		self._args.section or 'top',
		self:_getExpandedMessage('talk-page-link-display')
	)
end

function Blurb:_makeTooltipBlurbParameter()
	if self._protectionObj:isTemporary() then
		return self:_getExpandedMessage('tooltip-blurb-expiry')
	else
		return self:_getExpandedMessage('tooltip-blurb-noexpiry')
	end
end

function Blurb:_makeTooltipFragmentParameter()
	if self._protectionObj:isTemporary() then
		return self:_getExpandedMessage('tooltip-fragment-expiry')
	else
		return self:_getExpandedMessage('tooltip-fragment-noexpiry')
	end
end

function Blurb:_makeVandalTemplateParameter()
	return require('Module:Vandal-m')._main{
		self._args.user or self._protectionObj.title.baseText
	}
end

-- Public methods --

function Blurb:makeBannerText(key)
	-- Validate input.
	if not key or not Blurb.bannerTextFields[key] then
		error(string.format(
			'"%s" is not a valid banner config field',
			tostring(key)
		), 2)
	end

	-- Generate the text.
	local msg = self._protectionObj.bannerConfig[key]
	if type(msg) == 'string' then
		return self:_substituteParameters(msg)
	elseif type(msg) == 'function' then
		msg = msg(self._protectionObj, self._args)
		if type(msg) ~= 'string' then
			error(string.format(
				'bad output from banner config function with key "%s"'
					.. ' (expected string, got %s)',
				tostring(key),
				type(msg)
			), 4)
		end
		return self:_substituteParameters(msg)
	end
end

--------------------------------------------------------------------------------
-- BannerTemplate class
--------------------------------------------------------------------------------

local BannerTemplate = {}
BannerTemplate.__index = BannerTemplate

function BannerTemplate.new(protectionObj, cfg)
	local obj = {}
	obj._cfg = cfg

	-- Set the image filename.
	local imageFilename = protectionObj.bannerConfig.image
	if imageFilename then
		
		-- 日本語版独自の条件分岐
		if type(imageFilename) == 'string' then
			obj._imageFilename = imageFilename
		elseif type(imageFilename) == 'function' then
			obj._imageFilename = imageFilename(protectionObj)
		end
	else
		-- If an image filename isn't specified explicitly in the banner config,
		-- generate it from the protection status and the namespace.
		local action = protectionObj.action
		local level = protectionObj.level
		local namespace = protectionObj.title.namespace
		local reason = protectionObj.reason
		
		-- Deal with special cases first.
		if (
			namespace == 10
			or namespace == 828
			or reason and obj._cfg.indefImageReasons[reason]
			)
			and action == 'edit'
			and level == 'sysop'
			and not protectionObj:isTemporary()
		then
			-- Fully protected modules and templates get the special red "indef"
			-- padlock.
			obj._imageFilename = obj._cfg.msg['image-filename-indef']
		else
			-- Deal with regular protection types.
			local images = obj._cfg.images
			if images[action] then
				if images[action][level] then
					obj._imageFilename = images[action][level]
				elseif images[action].default then
					obj._imageFilename = images[action].default
				end
			end
		end
	end
	return setmetatable(obj, BannerTemplate)
end

function BannerTemplate:renderImage()
	local filename = self._imageFilename
		or self._cfg.msg['image-filename-default']
		or 'Transparent.gif'
	return makeFileLink{
		file = filename,
		size = (self.imageSize or 'x20') .. 'px',	-- 日本語版独自の変更
		alt = self._imageAlt,
		link = self._imageLink,
		caption = self.imageCaption
	}
end

--------------------------------------------------------------------------------
-- Banner class
--------------------------------------------------------------------------------

local Banner = setmetatable({}, BannerTemplate)
Banner.__index = Banner

function Banner.new(protectionObj, blurbObj, cfg)
	local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
	obj.imageSize = 40	-- 日本語版独自の変更: フィールド名
	obj.imageCaption = blurbObj:makeBannerText('alt') -- Large banners use the alt text for the tooltip.
	obj._reasonText = blurbObj:makeBannerText('text')
	obj._explanationText = blurbObj:makeBannerText('explanation')
	obj._page = protectionObj.title.prefixedText -- Only makes a difference in testing.
	return setmetatable(obj, Banner)
end

function Banner:__tostring()
	-- Renders the banner.
	makeMessageBox = makeMessageBox or require('Module:Message box').main
	local reasonText = self._reasonText or error('no reason text set', 2)
	local explanationText = self._explanationText
	local mbargs = {
		page = self._page,
		type = 'protection',
		image = self:renderImage(),
		text = string.format(
			"'''%s'''%s",
			reasonText,
			explanationText and '<br />' .. explanationText or ''
		)
	}
	return makeMessageBox('mbox', mbargs)
end

--------------------------------------------------------------------------------
-- Padlock class
--------------------------------------------------------------------------------

local Padlock = setmetatable({}, BannerTemplate)
Padlock.__index = Padlock

function Padlock.new(protectionObj, blurbObj, cfg)
	local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
	obj.imageSize = 'x20'	-- 日本語版独自の変更: フィールド名、高さのみ指定
	obj.imageCaption = blurbObj:makeBannerText('tooltip')
	obj._imageAlt = blurbObj:makeBannerText('alt')
	obj._imageLink = blurbObj:makeBannerText('link')
	obj._indicatorName = cfg.padlockIndicatorNames[protectionObj.action]
		or cfg.padlockIndicatorNames.default
		or 'pp-default'
	return setmetatable(obj, Padlock)
end

function Padlock:__tostring()
	local frame = mw.getCurrentFrame()
	-- The nowiki tag helps prevent whitespace at the top of articles.
	return frame:extensionTag{name = 'nowiki'} .. frame:extensionTag{
		name = 'indicator',
		args = {name = self._indicatorName},
		content = self:renderImage()
	}
end

--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------

local p = {}

function p._exportClasses()
	-- This is used for testing purposes.
	return {
		Protection = Protection,
		Blurb = Blurb,
		BannerTemplate = BannerTemplate,
		Banner = Banner,
		Padlock = Padlock,
	}
end

function p._main(args, cfg, title)
	args = args or {}
	cfg = cfg or require(CONFIG_MODULE)

	local protectionObj = Protection.new(args, cfg, title)

	local ret = {}

	-- If a page's edit protection is equally or more restrictive than its
	-- protection from some other action, then don't bother displaying anything
	-- for the other action (except categories).
	if protectionObj.action == 'edit' or
		args.demolevel or
		not getReachableNodes(
			cfg.hierarchy,
			protectionObj.level
		)[effectiveProtectionLevel('edit', protectionObj.title)]
	then
		-- Initialise the blurb object
		local blurbObj = Blurb.new(protectionObj, args, cfg)
	
		-- Render the banner
		if protectionObj:isProtected() then
			ret[#ret + 1] = tostring(
				(yesno(args.small) and Padlock or Banner)
				.new(protectionObj, blurbObj, cfg)
			)
		end
	end

	-- Render the categories
	if yesno(args.category) ~= false then
		ret[#ret + 1] = protectionObj:makeCategoryLinks()
	end
	
	return table.concat(ret)	
end

function p.main(frame, cfg)
	cfg = cfg or require(CONFIG_MODULE)

	-- Find default args, if any.
	local parent = frame.getParent and frame:getParent()
	local defaultArgs = parent and cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')]

	-- Find user args, and use the parent frame if we are being called from a
	-- wrapper template.
	getArgs = getArgs or require('Module:Arguments').getArgs
	local userArgs = getArgs(frame, {
		parentOnly = defaultArgs,
		frameOnly = not defaultArgs
	})

	-- Build the args table. User-specified args overwrite default args.
	local args = {}
	for k, v in pairs(defaultArgs or {}) do
		args[k] = v
	end
	for k, v in pairs(userArgs) do
		args[k] = v
	end
	return p._main(args, cfg)
end

return p