کاربر ناشناس
پودمان:Protection banner: تفاوت میان نسخهها
جز
1 revision imported
جز (۱ نسخه واردشده) |
جز (1 revision imported) |
||
خط ۱: | خط ۱: | ||
-- This module implements {{pp-meta}} and its daughter templates such as | -- This module implements {{pp-meta}} and its daughter templates such as | ||
-- {{pp-dispute}}, {{pp-vandalism}} and {{pp-sock}}. | -- {{pp-dispute}}, {{pp-vandalism}} and {{pp-sock}}. | ||
-- Initialise necessary modules. | -- Initialise necessary modules. | ||
require('Module:No globals') | require('Module:No globals') | ||
local makeFileLink = require('Module:File link')._main | local makeFileLink = require('Module:File link')._main | ||
local effectiveProtectionLevel = require('Module:Effective protection level')._main | local effectiveProtectionLevel = require('Module:Effective protection level')._main | ||
خط ۲۰: | خط ۱۸: | ||
-- Helper functions | -- Helper functions | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local function makeCategoryLink(cat, sort) | local function makeCategoryLink(cat, sort) | ||
خط ۵۹: | خط ۳۳: | ||
local function validateDate(dateString, dateType) | local function validateDate(dateString, dateType) | ||
if not lang then | if not lang then | ||
lang = mw.language.getContentLanguage() | |||
end | end | ||
local success, result = pcall(lang.formatDate, lang, 'U | local success, result = pcall(lang.formatDate, lang, 'U', dateString) | ||
if success then | if success then | ||
result = tonumber(result) | result = tonumber(result) | ||
خط ۷۰: | خط ۴۳: | ||
end | end | ||
error(string.format( | error(string.format( | ||
'%s | 'invalid %s: %s', | ||
dateType, | dateType, | ||
tostring(dateString) | tostring(dateString) | ||
خط ۱۴۰: | خط ۱۱۳: | ||
else | else | ||
error(string.format( | error(string.format( | ||
' | 'invalid action: %s', | ||
tostring(args.action) | tostring(args.action) | ||
), 3) | ), 3) | ||
خط ۱۵۸: | خط ۱۳۱: | ||
obj.expiry = 'indef' | obj.expiry = 'indef' | ||
elseif effectiveExpiry ~= 'unknown' then | elseif effectiveExpiry ~= 'unknown' then | ||
obj.expiry = validateDate(effectiveExpiry, ' | obj.expiry = validateDate(effectiveExpiry, 'expiry date') | ||
end | end | ||
خط ۱۶۵: | خط ۱۳۸: | ||
obj.reason = mw.ustring.lower(args[1]) | obj.reason = mw.ustring.lower(args[1]) | ||
if obj.reason:find('|') then | if obj.reason:find('|') then | ||
error(' | error('reasons cannot contain the pipe character ("|")', 3) | ||
end | end | ||
end | end | ||
خط ۱۷۱: | خط ۱۴۴: | ||
-- Set protection date | -- Set protection date | ||
if args.date then | if args.date then | ||
obj.protectionDate = validateDate(args.date, ' | obj.protectionDate = validateDate(args.date, 'protection date') | ||
end | end | ||
خط ۳۹۴: | خط ۳۶۷: | ||
function Blurb:_formatDate(num) | function Blurb:_formatDate(num) | ||
-- Formats a Unix timestamp into dd Month, YYYY format. | -- Formats a Unix timestamp into dd Month, YYYY format. | ||
lang = lang or mw.language.getContentLanguage() | |||
lang = lang or mw. | |||
local success, date = pcall( | local success, date = pcall( | ||
lang.formatDate, | lang.formatDate, | ||
lang, | lang, | ||
self._cfg.msg['expiry-date-format'] or ' | self._cfg.msg['expiry-date-format'] or 'j F Y', | ||
'@' .. | '@' .. tostring(num) | ||
) | ) | ||
if success then | if success then | ||
خط ۴۵۶: | خط ۴۲۸: | ||
-- We need the move log link. | -- We need the move log link. | ||
return makeFullUrl( | return makeFullUrl( | ||
' | 'Special:Log', | ||
{type = 'move', page = pagename}, | {type = 'move', page = pagename}, | ||
self:_getExpandedMessage('current-version-move-display') | self:_getExpandedMessage('current-version-move-display') | ||
خط ۵۲۹: | خط ۵۰۱: | ||
else | else | ||
error(string.format( | error(string.format( | ||
' | 'could not find explanation blurb for action "%s", level "%s" and talk key "%s"', | ||
action, | action, | ||
level, | level, | ||
خط ۵۵۵: | خط ۵۲۷: | ||
function Blurb:_makeIntroBlurbParameter() | function Blurb:_makeIntroBlurbParameter() | ||
if self._protectionObj:isTemporary() then | if self._protectionObj:isTemporary() then | ||
return | return self:_getExpandedMessage('intro-blurb-expiry') | ||
else | else | ||
return self:_getExpandedMessage('intro-blurb-noexpiry') | return self:_getExpandedMessage('intro-blurb-noexpiry') | ||
خط ۵۶۳: | خط ۵۳۵: | ||
function Blurb:_makeIntroFragmentParameter() | function Blurb:_makeIntroFragmentParameter() | ||
if self._protectionObj:isTemporary() then | if self._protectionObj:isTemporary() then | ||
return | return self:_getExpandedMessage('intro-fragment-expiry') | ||
else | else | ||
return self:_getExpandedMessage('intro-fragment-noexpiry') | return self:_getExpandedMessage('intro-fragment-noexpiry') | ||
خط ۵۷۳: | خط ۵۴۵: | ||
return pagetypes[self._protectionObj.title.namespace] | return pagetypes[self._protectionObj.title.namespace] | ||
or pagetypes.default | or pagetypes.default | ||
or error(' | or error('no default pagetype defined', 8) | ||
end | end | ||
خط ۵۸۸: | خط ۵۶۰: | ||
msg = protectionBlurbs.edit.default | msg = protectionBlurbs.edit.default | ||
else | else | ||
error(' | error('no protection blurb defined for protectionBlurbs.edit.default', 8) | ||
end | end | ||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
خط ۶۱۴: | خط ۵۸۶: | ||
msg = protectionLevels.edit.default | msg = protectionLevels.edit.default | ||
else | else | ||
error(' | error('no protection level defined for protectionLevels.edit.default', 8) | ||
end | end | ||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
خط ۶۲۴: | خط ۵۹۶: | ||
-- We need the pending changes log. | -- We need the pending changes log. | ||
return makeFullUrl( | return makeFullUrl( | ||
' | 'Special:Log', | ||
{type = 'stable', page = pagename}, | {type = 'stable', page = pagename}, | ||
self:_getExpandedMessage('pc-log-display') | self:_getExpandedMessage('pc-log-display') | ||
خط ۶۳۱: | خط ۶۰۳: | ||
-- We need the protection log. | -- We need the protection log. | ||
return makeFullUrl( | return makeFullUrl( | ||
' | 'Special:Log', | ||
{type = 'protect', page = pagename}, | {type = 'protect', page = pagename}, | ||
self:_getExpandedMessage('protection-log-display') | self:_getExpandedMessage('protection-log-display') | ||
خط ۶۵۰: | خط ۶۲۲: | ||
function Blurb:_makeTooltipBlurbParameter() | function Blurb:_makeTooltipBlurbParameter() | ||
if self._protectionObj:isTemporary() then | if self._protectionObj:isTemporary() then | ||
return | return self:_getExpandedMessage('tooltip-blurb-expiry') | ||
else | else | ||
return self:_getExpandedMessage('tooltip-blurb-noexpiry') | return self:_getExpandedMessage('tooltip-blurb-noexpiry') | ||
خط ۶۵۸: | خط ۶۳۰: | ||
function Blurb:_makeTooltipFragmentParameter() | function Blurb:_makeTooltipFragmentParameter() | ||
if self._protectionObj:isTemporary() then | if self._protectionObj:isTemporary() then | ||
return | return self:_getExpandedMessage('tooltip-fragment-expiry') | ||
else | else | ||
return self:_getExpandedMessage('tooltip-fragment-noexpiry') | return self:_getExpandedMessage('tooltip-fragment-noexpiry') | ||
خط ۶۷۶: | خط ۶۴۸: | ||
if not key or not Blurb.bannerTextFields[key] then | if not key or not Blurb.bannerTextFields[key] then | ||
error(string.format( | error(string.format( | ||
' | '"%s" is not a valid banner config field', | ||
tostring(key) | tostring(key) | ||
), 2) | ), 2) | ||
خط ۶۸۹: | خط ۶۶۱: | ||
if type(msg) ~= 'string' then | if type(msg) ~= 'string' then | ||
error(string.format( | error(string.format( | ||
' | 'bad output from banner config function with key "%s"' | ||
.. ' ( | .. ' (expected string, got %s)', | ||
tostring(key), | tostring(key), | ||
type(msg) | type(msg) | ||
خط ۷۸۳: | خط ۷۵۵: | ||
-- Renders the banner. | -- Renders the banner. | ||
makeMessageBox = makeMessageBox or require('Module:Message box').main | makeMessageBox = makeMessageBox or require('Module:Message box').main | ||
local reasonText = self._reasonText or error(' | local reasonText = self._reasonText or error('no reason text set', 2) | ||
local explanationText = self._explanationText | local explanationText = self._explanationText | ||
local mbargs = { | local mbargs = { | ||
خط ۸۸۷: | خط ۸۵۹: | ||
-- Find default args, if any. | -- Find default args, if any. | ||
local parent = frame.getParent and frame:getParent() | local parent = frame.getParent and frame:getParent() | ||
local defaultArgs = parent and cfg.wrappers[ | 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 | -- Find user args, and use the parent frame if we are being called from a |