Module:Protection banner: Difference between revisions

finish converting p.getCategoryName
Enwikipedia>Mr. Stradivarius
(start converting the getCategoryName function)
Enwikipedia>Mr. Stradivarius
(finish converting p.getCategoryName)
Line 224:
local ProtectionCategory = Category:subclass('ProtectionCategory')
 
function ProtectionCategory:setName(name, configObj, protectionStatusObj, namespace)
name,
configObj,
protectionStatusObj,
namespace
)
--[[
-- Sets the protection category. If a category name is not provided, this
Line 231 ⟶ 236:
-- reason for protection, and the expiry date.
--]]
local cats = configObj:getConfigTable('categories')
-- If a name was provided, use that.
if t.valname then
Category.setName(self, name)
end
-- Get the namespace category key from the namespace number.
Line 253 ⟶ 262:
--]]
local properties = {
expiry = {order = 1, keypos = 5, val = expiryprotectionStatusObj:getExpiry()},
namespace = {order = 2, keypos = 3, val = nskey},
reason = {order = 3, keypos = 4, val = reasonprotectionStatusObj:getReason()},
level = {order = 4, keypos = 2, val = levelprotectionStatusObj:getLevel()},
action = {order = 5, keypos = 1, val = actionprotectionStatusObj:getAction()}
}
--[[
-- LoadApply the category order configuration, forif theany. reasonThe specified.configuration value
-- will be a property string, e.g. 'reason', 'namespace', etc. The property
-- The configuration is stored in the categoryOrder field of each reason
-- subtablecorresponding ofto cfg.reasons.that If the valuestring is atested table,last then(i.e. the orderit is the most
-- values specified in the table. If the value is a string, then the
-- property corresponding to that string is tested last (i.e. it is the most
-- important, because it keeps its specified value the longest) and the
-- other properties are tested in the canonical order. If theno value is ofconfiguration
-- anyvalue otheris typespecified then the canonical order is used.
--]]
local reasonTable = reason and cfg.reasons[reason]
local categoryOrder = reasonTable and reasonTable.categoryOrder
local categoryOrderType = type(categoryOrder)
local configOrder = {}
do
if categoryOrderType == 'table' then
local bannerConfig = configObj:getBannerConfig(protectionStatusObj)
local dupes = {}
local categoryOrder = reasonTable and reasonTablebannerConfig.categoryOrder
for i = 1, 5 do
local propertiesKey = categoryOrder[i]
if not propertiesKey then
local msg = 'no entry found for key '
.. i
.. ' in the cfg.reasons.'
.. reason
.. '.categoryOrder table'
error(msg)
end
local property = properties[propertiesKey]
if not property then
local msg = 'invalid value "'
.. propertiesKey
.. '" detected in the cfg.reasons.'
.. reason
.. '.categoryOrder table'
error(msg)
end
if dupes[propertiesKey] then
local msg = 'duplicate values "'
.. propertiesKey
.. '" detected in the cfg.reasons.'
.. reason
.. '.categoryOrder table'
error(msg)
else
dupes[propertiesKey] = true
end
configOrder[i] = property
end
else
for propertiesKey, t in pairs(properties) do
configOrder[t.order] = t
end
if categoryOrderType == 'string'categoryOrder then
local property = properties[categoryOrder]
if not property then
Line 321 ⟶ 294:
error(msg)
end
toTableEndtable.insert(configOrder, table.remove(configOrder, property.order))
end
end
Line 333 ⟶ 306:
-- parameter.
--]]
local activenoActive, inactive = {}, {}attemptOrder
do
for i, t in ipairs(configOrder) do
local active, inactive = {}, {}
if t.val then
for i, t in ipairs(configOrder) do
active[#active + 1] = t
if not propertyt.val then
else
inactive active[#inactiveactive + 1] = t
else
active inactive[#activeinactive + 1] = t
end
end
local noActive = #active
local attemptOrder = active
for i, t in ipairs(inactive) do
attemptOrder[#attemptOrder + 1] = t
end
end
local noActive = #active
local attemptOrder = active
for i, t in ipairs(inactive) do
attemptOrder[#attemptOrder + 1] = t
end
Line 379 ⟶ 355:
-- pos field in the property table.
--]]
local cats = configObj:getConfigTable('categories')
local cat
for i = 1, 2^noActive do
local key = {}
Line 397 ⟶ 375:
local attempt = cats[key]
if attempt then
returncat = attempt
break
end
end
if cat then
error(
Category.setName(self, cat)
'No category match found;'
else
.. ' please define the category for key "all-all-all-all-all"'
error(msg)
)
'No category match found;'
.. ' please define the category for key "all-all-all-all-all"'
)
end
end