Jump to content
Wikipedia The Free Encyclopedia

Module:Protection banner/sandbox

From Wikipedia, the free encyclopedia
This is the module sandbox page for Module:Protection banner (diff).
See also the companion subpage for test cases (run).
Module documentation[view] [edit] [history] [purge]
Warning This Lua module is used on approximately 67,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.

This module creates protection banners and padlock icons that are placed at the top of protected pages. Most users will not need to use this module directly.

Usage

[edit ]

For adding protection templates to pages you can use the {{pp }} template, or you may find it more convenient to use one of the more specific protection templates in the table below.

Edit Move Pending changes Upload
Generic {{pp }} {{pp-move }} {{pp-pc }} {{pp-upload }}
BLP {{pp-blp }}
Blocked user's talk page {{pp-usertalk }}
Dispute {{pp-dispute }} {{pp-move-dispute }}
Extended confirmed protection {{pp-extended }}
Indefinite {{pp-semi-indef }} {{pp-move-indef }}
Main Page image {{pp-main-page }}
Office {{pp-office }}
Sockpuppetry {{pp-sock }}
Templates and images {{pp-template }} {{pp-upload }}
Vandalism {{pp-vandalism }} {{pp-move-vandalism }}
Talk page {{Permanently protected }} {{Temporarily protected }}

From wikitext

[edit ]
{{#invoke:Protection banner|main
| 1 = reason
| small = yes/no
| action = action
| date = protection date
| user = username
| section = talk page section name
| category = yes
}}

The #invoke syntax can be used for creating protection templates more specific than {{pp }}. For example, it is possible to create a protection template which always shows a padlock icon by using the code {{#invoke:Protection banner|main|small=yes}}. Pages which call this template will still be able to use other arguments, like action. However, this only works one level deep; a page calling a template which calls another template containing the above code will not automatically be able to use parameters like action.

Note: You should no longer specify the expiry, as it is automatically retrieved in all cases.

From Lua

[edit ]

First, load the module.

localmProtectionBanner=require('Module:Protection banner')

Then you can make protection banners by using the _main function.

mProtectionBanner._main(args,cfg,titleObj)

args is a table of arguments to pass to the module. For possible keys and values for this table, see the parameters section. The cfg and titleObj variables are intended only for testing; cfg specifies a customised config table to use instead of Module:Protection banner/config, and titleObj specifies a mw.title object to use instead of the current title. args, cfg and titleObj are all optional.

Parameters

[edit ]

All parameters are optional.

  • 1 – the reason that the page was protected. If set, this must be one of the values listed in the reasons table.
  • small – if set to "yes", "y", "1", or "true", a padlock icon is generated instead of a full protection banner.
  • action – the protection action. Must be one of "edit" (for normal protection), "move" (for move-protection) or "autoreview" (for pending changes). The default value is "edit".
  • date – the protection date. This must be valid input to the second parameter of the #time parser function. This argument has an effect for reasons that use the PROTECTIONDATE parameter in their configuration. As of July 2014, those were the "office" and "reset" reasons.
  • user – the username of the user to generate links for. As of July 2014, this only has an effect when the "usertalk" reason is specified.
  • section – the section name of the protected page's talk page where discussion is taking place. This works for most, but not all, values of reason.
  • category – categories are suppressed if this is set to "no", "n", "0", or "false".
  • catonly – if set to "yes", "y", "1", or "true", will only return the protection categories, and not return the banner or padlock. This has no visible output.

Reasons

[edit ]

The following table contains the available reasons, plus the actions for which they are available.

Reason Action Description
blp edit For pages protected to promote compliance with the biographies of living persons policy
dispute edit For pages protected due to editing disputes
dmca edit For pages protected by the Wikimedia Foundation due to Digital Millennium Copyright Act takedown requests
ecp edit For articles in topic areas authorized by ArbCom or meets the criteria for community use
mainpage edit For pages protected for being displayed on the Main Page
office edit For pages protected by the Wikimedia Foundation
reset edit For pages protected by the Wikimedia Foundation and "reset" to a bare-bones version
sock edit For pages protected due to sock puppetry
template edit For high-risk templates and Lua modules
usertalk edit For pages protected against disruptive edits by a particular user
vandalism edit For pages protected against vandalism
dispute move For pages protected against page moves due to disputes over the page title
vandalism move For pages protected against page-move vandalism

Errors

[edit ]

Below is a list of some of the common errors that this module can produce, and how to fix them.

Invalid protection date

[edit ]

Error: invalid protection date ("abc")

This error is produced if you supply a |date= parameter value that is not recognised as a valid date by the #time parser function. If in doubt, you can just use a date in the format "dd Month YYYY", e.g. "31 October 2025". To see a full range of valid inputs, see the #time documentation (only the first parameter, the format string, may be specified).

Invalid action

[edit ]

Error: invalid action ("abc")

This error is produced if you specify an invalid protection action. There are only three valid actions: edit (the default, for normal protection), move (for move-protection), and autoreview (for pending changes). This should only be possible if you are using a template that supports manually specifying the protection action, such as {{pp }}, or if you are using #invoke directly. If this is not the case, please leave a message on Module talk:Protection banner.

Reasons cannot contain the pipe character

[edit ]

Error: reasons cannot contain the pipe character ("|")

This error is produced if you specify a reason using the |1= parameter that includes a pipe character ("|"). Please check that you are not entering the {{! }} template into this parameter by mistake. The pipe character is disallowed as the module uses it internally. A list of valid reasons can be seen in the reasons section.

Other errors

[edit ]

If you see an error other than the ones above, it is likely to either be a bug in the module or mistake in the configuration. Please post a message about it at Module talk:Protection banner.

Technical details

[edit ]

This module uses configuration data from Module:Protection banner/config. Most of the module's behaviour can be configured there, making it easily portable across different wikis and different languages.

General test cases for the module can be found at Module:Protection banner/testcases, and test cases specific to enwiki's config can be found at Module:Protection banner/config/testcases.

Bug reports and feature requests should be made on the module's talk page.

The above documentation is transcluded from Module:Protection banner/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Add categories to the /doc subpage. Subpages of this module.
 -- This module implements {{pp-meta}} and its daughter templates such as
 -- {{pp-dispute}}, {{pp-vandalism}} and {{pp-sock}}.

 -- Initialise necessary modules.
 require('strict')
 localmakeFileLink=require('Module:File link')._main
 localeffectiveProtectionLevel=require('Module:Effective protection level')._main
 localeffectiveProtectionExpiry=require('Module:Effective protection expiry')._main
 localyesno=require('Module:Yesno')

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

 -- Set constants.
 localCONFIG_MODULE='Module:Protection banner/config/sandbox'-- SWITCH THIS BACK TO THE MAIN CONFIG PAGE BEFORE GOING LIVE!

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

 localfunctionmakeCategoryLink(cat,sort)
 ifcatthen
 returnstring.format(
 '[[%s:%s|%s]]',
 mw.site.namespaces[14].name,
 cat,
 sort
 )
 end
 end

 -- Validation function for the expiry and the protection date
 localfunctionvalidateDate(dateString,dateType)
 ifnotlangthen
 lang=mw.language.getContentLanguage()
 end
 localsuccess,result=pcall(lang.formatDate,lang,'U',dateString)
 ifsuccessthen
 result=tonumber(result)
 ifresultthen
 returnresult
 end
 end
 error(string.format(
 'invalid %s: %s',
 dateType,
 tostring(dateString)
 ),4)
 end

 localfunctionmakeFullUrl(page,query,display)
 returnstring.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).
 localfunctiongetReachableNodes(graph,start)
 localtoWalk,retval={[start]=true},{}
 whiletruedo
 -- Can't use pairs() since we're adding and removing things as we're iterating
 localk=next(toWalk)-- This always gets the "first" key
 ifk==nilthen
 returnretval
 end
 toWalk[k]=nil
 retval[k]=true
 for_,vinipairs(graph[k])do
 ifnotretval[v]then
 toWalk[v]=true
 end
 end
 end
 end

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

 localProtection={}
 Protection.__index=Protection

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

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

 functionProtection.new(args,cfg,title)
 localobj={}
 obj._cfg=cfg
 obj.title=titleormw.title.getCurrentTitle()

 -- Set action
 ifnotargs.actionthen
 obj.action='edit'
 elseifProtection.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.demoleveloreffectiveProtectionLevel(obj.action,obj.title)
 ifnotobj.levelor(obj.action=='move'andobj.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
 localeffectiveExpiry=effectiveProtectionExpiry(obj.action,obj.title)
 ifeffectiveExpiry=='infinity'then
 obj.expiry='indef'
 elseifeffectiveExpiry~='unknown'then
 obj.expiry=validateDate(effectiveExpiry,'expiry date')
 end

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

 -- Set protection date
 ifargs.datethen
 obj.protectionDate=validateDate(args.date,'protection date')
 end

 -- Set banner config
 do
 obj.bannerConfig={}
 localconfigTables={}
 ifcfg.banners[obj.action]then
 configTables[#configTables+1]=cfg.banners[obj.action][obj.reason]
 end
 ifcfg.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
 fori,fieldinipairs(Protection.bannerConfigFields)do
 forj,tinipairs(configTables)do
 ift[field]then
 obj.bannerConfig[field]=t[field]
 break
 end
 end
 end
 end
 returnsetmetatable(obj,Protection)
 end

 functionProtection:isUserScript()
 -- Whether the page is a user JavaScript or CSS page.
 localtitle=self.title
 returntitle.namespace==2and(
 title.contentModel=='javascript'ortitle.contentModel=='css'
 )
 end

 functionProtection:isProtected()
 returnself.level~='*'
 end

 functionProtection:shouldShowLock()
 -- Whether we should output a banner/padlock
 returnself:isProtected()andnotself:isUserScript()
 end

 -- Whether this page needs a protection category.
 Protection.shouldHaveProtectionCategory=Protection.shouldShowLock

 functionProtection:isTemporary()
 returntype(self.expiry)=='number'
 end

 functionProtection:makeProtectionCategory()
 ifnotself:shouldHaveProtectionCategory()then
 return''
 end

 localcfg=self._cfg
 localtitle=self.title

 -- Get the expiry key fragment.
 localexpiryFragment
 ifself.expiry=='indef'then
 expiryFragment=self.expiry
 elseiftype(self.expiry)=='number'then
 expiryFragment='temp'
 end

 -- Get the namespace key fragment.
 localnamespaceFragment=cfg.categoryNamespaceKeys[title.namespace]
 ifnotnamespaceFragmentandtitle.namespace%2==1then
 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.
 localorder={
 {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.reasonandcfg.reasonsWithNamespacePriority[self.reason]and2or3))

 --[[
 	-- 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.
 	--]]
 localnoActive,attemptOrder
 do
 localactive,inactive={},{}
 fori,tinipairs(order)do
 ift.valthen
 active[#active+1]=t
 else
 inactive[#inactive+1]=t
 end
 end
 noActive=#active
 attemptOrder=active
 fori,tinipairs(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.
 	--]]
 localcats=cfg.protectionCategories
 fori=1,2^noActivedo
 localkey={}
 forj,tinipairs(attemptOrder)do
 ifj>noActivethen
 key[t.keypos]='all'
 else
 localquotient=i/2^(j-1)
 quotient=math.ceil(quotient)
 ifquotient%2==1then
 key[t.keypos]=t.val
 else
 key[t.keypos]='all'
 end
 end
 end
 key=table.concat(key,'|')
 localattempt=cats[key]
 ifattemptthen
 returnmakeCategoryLink(attempt,title.text)
 end
 end
 return''
 end

 functionProtection:isIncorrect()
 localexpiry=self.expiry
 returnnotself:shouldHaveProtectionCategory()
 ortype(expiry)=='number'andexpiry<os.time()
 end

 functionProtection:isTemplateProtectedNonTemplate()
 localaction,namespace=self.action,self.title.namespace
 returnself.level=='templateeditor'
 and(
 (action~='edit'andaction~='move')
 or(namespace~=10andnamespace~=828)
 )
 end

 functionProtection:makeCategoryLinks()
 localmsg=self._cfg.msg
 localret={self:makeProtectionCategory()}
 ifself:isIncorrect()then
 ret[#ret+1]=makeCategoryLink(
 msg['tracking-category-incorrect'],
 self.title.text
 )
 end
 ifself:isTemplateProtectedNonTemplate()then
 ret[#ret+1]=makeCategoryLink(
 msg['tracking-category-template'],
 self.title.text
 )
 end
 returntable.concat(ret)
 end

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

 localBlurb={}
 Blurb.__index=Blurb

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

 functionBlurb.new(protectionObj,args,cfg)
 returnsetmetatable({
 _cfg=cfg,
 _protectionObj=protectionObj,
 _args=args
 },Blurb)
 end

 -- Private methods --

 functionBlurb:_formatDate(num)
 -- Formats a Unix timestamp into dd Month, YYYY format.
 lang=langormw.language.getContentLanguage()
 localsuccess,date=pcall(
 lang.formatDate,
 lang,
 self._cfg.msg['expiry-date-format']or'j F Y',
 '@'..tostring(num)
 )
 ifsuccessthen
 returndate
 end
 end

 functionBlurb:_getExpandedMessage(msgKey)
 returnself:_substituteParameters(self._cfg.msg[msgKey])
 end

 functionBlurb:_substituteParameters(msg)
 ifnotself._paramsthen
 localparameterFuncs={}

 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)
 localparam
 ifparameterFuncs[k]then
 param=parameterFuncs[k](self)
 end
 param=paramor''
 t[k]=param
 returnparam
 end
 })
 end

 msg=msg:gsub('${(%u+)}',self._params)
 returnmsg
 end

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

 functionBlurb:_makeEditRequestParameter()
 localmEditRequest=require('Module:Submit an edit request')
 localaction=self._protectionObj.action
 locallevel=self._protectionObj.level

 -- Get the edit request type.
 localrequestType
 ifaction=='edit'then
 iflevel=='autoconfirmed'then
 requestType='semi'
 elseiflevel=='extendedconfirmed'then
 requestType='extended'
 elseiflevel=='templateeditor'then
 requestType='template'
 end
 end
 requestType=requestTypeor'full'

 -- Get the display value.
 localdisplay=self:_getExpandedMessage('edit-request-display')

 returnmEditRequest._link{type=requestType,display=display}
 end

 functionBlurb:_makeExpiryParameter()
 localexpiry=self._protectionObj.expiry
 iftype(expiry)=='number'then
 returnself:_formatDate(expiry)
 else
 returnexpiry
 end
 end

 functionBlurb:_makeExplanationBlurbParameter()
 -- Cover special cases first.
 ifself._protectionObj.title.namespace==8then
 -- MediaWiki namespace
 returnself:_getExpandedMessage('explanation-blurb-nounprotect')
 end

 -- Get explanation blurb table keys
 localaction=self._protectionObj.action
 locallevel=self._protectionObj.level
 localtalkKey=self._protectionObj.title.isTalkPageand'talk'or'subject'

 -- Find the message in the explanation blurb table and substitute any
 -- parameters.
 localexplanations=self._cfg.explanationBlurbs
 localmsg
 ifexplanations[action][level]andexplanations[action][level][talkKey]then
 msg=explanations[action][level][talkKey]
 elseifexplanations[action][level]andexplanations[action][level].defaultthen
 msg=explanations[action][level].default
 elseifexplanations[action].defaultandexplanations[action].default[talkKey]then
 msg=explanations[action].default[talkKey]
 elseifexplanations[action].defaultandexplanations[action].default.defaultthen
 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
 returnself:_substituteParameters(msg)
 end

 functionBlurb:_makeImageLinkParameter()
 localimageLinks=self._cfg.imageLinks
 localaction=self._protectionObj.action
 locallevel=self._protectionObj.level
 localmsg
 ifimageLinks[action][level]then
 msg=imageLinks[action][level]
 elseifimageLinks[action].defaultthen
 msg=imageLinks[action].default
 else
 msg=imageLinks.edit.default
 end
 returnself:_substituteParameters(msg)
 end

 functionBlurb:_makeIntroBlurbParameter()
 ifself._protectionObj:isTemporary()then
 returnself:_getExpandedMessage('intro-blurb-expiry')
 else
 returnself:_getExpandedMessage('intro-blurb-noexpiry')
 end
 end

 functionBlurb:_makeIntroFragmentParameter()
 ifself._protectionObj:isTemporary()then
 returnself:_getExpandedMessage('intro-fragment-expiry')
 else
 returnself:_getExpandedMessage('intro-fragment-noexpiry')
 end
 end

 functionBlurb:_makePagetypeParameter()
 localpagetypes=self._cfg.pagetypes
 returnpagetypes[self._protectionObj.title.namespace]
 orpagetypes.default
 orerror('no default pagetype defined',8)
 end

 functionBlurb:_makeProtectionBlurbParameter()
 localprotectionBlurbs=self._cfg.protectionBlurbs
 localaction=self._protectionObj.action
 locallevel=self._protectionObj.level
 localmsg
 ifprotectionBlurbs[action][level]then
 msg=protectionBlurbs[action][level]
 elseifprotectionBlurbs[action].defaultthen
 msg=protectionBlurbs[action].default
 elseifprotectionBlurbs.edit.defaultthen
 msg=protectionBlurbs.edit.default
 else
 error('no protection blurb defined for protectionBlurbs.edit.default',8)
 end
 returnself:_substituteParameters(msg)
 end

 functionBlurb:_makeProtectionDateParameter()
 localprotectionDate=self._protectionObj.protectionDate
 iftype(protectionDate)=='number'then
 returnself:_formatDate(protectionDate)
 else
 returnprotectionDate
 end
 end

 functionBlurb:_makeProtectionLevelParameter()
 localprotectionLevels=self._cfg.protectionLevels
 localaction=self._protectionObj.action
 locallevel=self._protectionObj.level
 localmsg
 ifprotectionLevels[action][level]then
 msg=protectionLevels[action][level]
 elseifprotectionLevels[action].defaultthen
 msg=protectionLevels[action].default
 elseifprotectionLevels.edit.defaultthen
 msg=protectionLevels.edit.default
 else
 error('no protection level defined for protectionLevels.edit.default',8)
 end
 returnself:_substituteParameters(msg)
 end

 functionBlurb:_makeProtectionLogParameter()
 localpagename=self._protectionObj.title.prefixedText
 ifself._protectionObj.action=='autoreview'then
 -- We need the pending changes log.
 returnmakeFullUrl(
 'Special:Log',
 {type='stable',page=pagename},
 self:_getExpandedMessage('pc-log-display')
 )
 else
 -- We need the protection log.
 returnmakeFullUrl(
 'Special:Log',
 {type='protect',page=pagename},
 self:_getExpandedMessage('protection-log-display')
 )
 end
 end

 functionBlurb:_makeTalkPageParameter()
 returnstring.format(
 '[[%s:%s#%s|%s]]',
 mw.site.namespaces[self._protectionObj.title.namespace].talk.name,
 self._protectionObj.title.text,
 self._args.sectionor'top',
 self:_getExpandedMessage('talk-page-link-display')
 )
 end

 functionBlurb:_makeTooltipBlurbParameter()
 ifself._protectionObj:isTemporary()then
 returnself:_getExpandedMessage('tooltip-blurb-expiry')
 else
 returnself:_getExpandedMessage('tooltip-blurb-noexpiry')
 end
 end

 functionBlurb:_makeTooltipFragmentParameter()
 ifself._protectionObj:isTemporary()then
 returnself:_getExpandedMessage('tooltip-fragment-expiry')
 else
 returnself:_getExpandedMessage('tooltip-fragment-noexpiry')
 end
 end

 functionBlurb:_makeVandalTemplateParameter()
 returnmw.getCurrentFrame():expandTemplate{
 title="vandal-m",
 args={self._args.userorself._protectionObj.title.baseText}
 }
 end

 -- Public methods --

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

 -- Generate the text.
 localmsg=self._protectionObj.bannerConfig[key]
 iftype(msg)=='string'then
 returnself:_substituteParameters(msg)
 elseiftype(msg)=='function'then
 msg=msg(self._protectionObj,self._args)
 iftype(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
 returnself:_substituteParameters(msg)
 end
 end

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

 localBannerTemplate={}
 BannerTemplate.__index=BannerTemplate

 functionBannerTemplate.new(protectionObj,cfg)
 localobj={}
 obj._cfg=cfg

 -- Set the image filename.
 localimageFilename=protectionObj.bannerConfig.image
 ifimageFilenamethen
 obj._imageFilename=imageFilename
 else
 -- If an image filename isn't specified explicitly in the banner config,
 -- generate it from the protection status and the namespace.
 localaction=protectionObj.action
 locallevel=protectionObj.level
 localnamespace=protectionObj.title.namespace
 localreason=protectionObj.reason

 -- Deal with special cases first.
 if(
 namespace==10
 ornamespace==828
 orreasonandobj._cfg.indefImageReasons[reason]
 )
 andaction=='edit'
 andlevel=='sysop'
 andnotprotectionObj: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.
 localimages=obj._cfg.images
 ifimages[action]then
 ifimages[action][level]then
 obj._imageFilename=images[action][level]
 elseifimages[action].defaultthen
 obj._imageFilename=images[action].default
 end
 end
 end
 end
 returnsetmetatable(obj,BannerTemplate)
 end

 functionBannerTemplate:renderImage()
 localfilename=self._imageFilename
 orself._cfg.msg['image-filename-default']
 or'Transparent.gif'
 returnmakeFileLink{
 file=filename,
 size=(self.imageWidthor20)..'px',
 alt=self._imageAlt,
 link=self._imageLink,
 caption=self.imageCaption
 }
 end

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

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

 functionBanner.new(protectionObj,blurbObj,cfg)
 localobj=BannerTemplate.new(protectionObj,cfg)-- This doesn't need the blurb.
 obj.imageWidth=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.
 returnsetmetatable(obj,Banner)
 end

 functionBanner:__tostring()
 -- Renders the banner.
 makeMessageBox=makeMessageBoxorrequire('Module:Message box').main
 localreasonText=self._reasonTextorerror('no reason text set',2)
 localexplanationText=self._explanationText
 localmbargs={
 page=self._page,
 type='protection',
 image=self:renderImage(),
 text=string.format(
 "'''%s'''%s",
 reasonText,
 explanationTextand'<br />'..explanationTextor''
 )
 }
 returnmakeMessageBox('mbox',mbargs)
 end

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

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

 functionPadlock.new(protectionObj,blurbObj,cfg)
 localobj=BannerTemplate.new(protectionObj,cfg)-- This doesn't need the blurb.
 obj.imageWidth=20
 obj.imageCaption=blurbObj:makeBannerText('tooltip')
 obj._imageAlt=blurbObj:makeBannerText('alt')
 obj._imageLink=blurbObj:makeBannerText('link')
 obj._indicatorName=cfg.padlockIndicatorNames[protectionObj.action]
 orcfg.padlockIndicatorNames.default
 or'pp-default'
 returnsetmetatable(obj,Padlock)
 end

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

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

 localp={}

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

 functionp._main(args,cfg,title)
 args=argsor{}
 cfg=cfgorrequire(CONFIG_MODULE)

 localprotectionObj=Protection.new(args,cfg,title)

 localret={}

 -- 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).
 ifnotyesno(args.catonly)and(protectionObj.action=='edit'or
 args.demolevelor
 notgetReachableNodes(
 cfg.hierarchy,
 protectionObj.level
 )[effectiveProtectionLevel('edit',protectionObj.title)])
 then
 -- Initialise the blurb object
 localblurbObj=Blurb.new(protectionObj,args,cfg)

 -- Render the banner
 ifprotectionObj:shouldShowLock()then
 ret[#ret+1]=tostring(
 (yesno(args.small)andPadlockorBanner)
 .new(protectionObj,blurbObj,cfg)
 )
 end
 end

 -- Render the categories
 ifyesno(args.category)~=falsethen
 ret[#ret+1]=protectionObj:makeCategoryLinks()
 end

 -- For arbitration enforcement, flagging [[WP:PIA]] pages to enable [[Special:AbuseFilter/1339]] to flag edits to them
 ifprotectionObj.level=="extendedconfirmed"then
 ifrequire("Module:TableTools").inArray(protectionObj.title.talkPageTitle.categories,"Wikipedia pages subject to the extended confirmed restriction related to the Arab-Israeli conflict")then
 ret[#ret+1]="<p class='PIA-flag' style='display:none; visibility:hidden;' title='This page is subject to the extended confirmed restriction related to the Arab-Israeli conflict.'></p>"
 end
 end

 returntable.concat(ret)
 end

 functionp.main(frame,cfg)
 cfg=cfgorrequire(CONFIG_MODULE)

 -- Find default args, if any.
 localparent=frame.getParentandframe:getParent()
 localdefaultArgs=parentandcfg.wrappers[parent:getTitle():gsub('/sandbox$','')]

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

 -- Build the args table. User-specified args overwrite default args.
 localargs={}
 fork,vinpairs(defaultArgsor{})do
 args[k]=v
 end
 fork,vinpairs(userArgs)do
 args[k]=v
 end
 returnp._main(args,cfg)
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /