Modulo:Criteri cancellazione immediata/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
riscrivo |
usa il modulo:Enum per le enumerazioni |
||
(7 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 6:
require('strict')
-- oppure [[Modulo:Criteri cancellazione immediata/sandbox/Configurazione.json]]
local cfg = mw.loadJsonData(mw.getCurrentFrame():getTitle() .. '/Configurazione.json')
local Enum = require('Modulo:Enum')
-- =============================================================================
-- enum NamespaceType
-- =============================================================================
local NamespaceType =
ANY = {
value = 'any'
Riga 22 ⟶ 24:
value = 'ns dispari'
}
})
function NamespaceType:findByValue(value)
return self:findBy('value', value)
end
-- =============================================================================
Riga 40 ⟶ 34:
-- =============================================================================
local Namespace =
DEFAULT = {
id = 'default',
Riga 51 ⟶ 45:
name = 'Principale'
}
})
for _, ns in pairs(mw.site.namespaces) do
if ns.id ~= 0 then
rawset(Namespace
id = ns.id,
type = ns.id % 2 == 0 and NamespaceType.EVEN or NamespaceType.ODD,
name = ns.name
})
end
end
function Namespace:findById(id)
return self:findBy('id', tonumber(id))
end
function Namespace:findByName(name)
return self:findBy('name', name)
end
Riga 87 ⟶ 69:
-- =============================================================================
local ListType =
DROPDOWN_LIST = {
arg = 'a discesa',
Riga 108 ⟶ 90:
})
}
})
function ListType:findByArg(arg)
return self:findBy('arg', arg)
end
function ListType:getDefault()
return self.DROPDOWN_LIST
end
-- =============================================================================
Riga 126 ⟶ 104:
-- =============================================================================
local TextType =
SYSTEM_MESSAGE = {
arg = 'messaggio di sistema',
Riga 137 ⟶ 115:
set = 'setDefinition'
}
})
function TextType:findByArg(arg)
return self:findBy('arg', arg)
end
function TextType:getDefault()
return self.SYSTEM_MESSAGE
end
-- =============================================================================
Riga 163 ⟶ 137:
self.code = code
self.current_ns = Namespace.DEFAULT
self.order = { default = 0 }
self.add_link = false
self.link = { default = string.format('[[WP:IMMEDIATA|%s]]', code) }
self.system_message = { default = '' }
Riga 176 ⟶ 152:
end
function Criterion:
return self.
end
function Criterion:
return self.
end
function Criterion:getSystemMessage(
return string.format('(%s) %s',
self.system_message[self.current_ns.id] or self.system_message.default)
end
function Criterion:getDefinition(
return string.format('(%s) %s',
self.definition[self.current_ns.id] or self.definition.default)
end
function Criterion:isValid(
if self.validity[
return self.validity[
elseif self.validity[
return self.validity[
else
return self.validity.default
Riga 208 ⟶ 182:
end
function Criterion:
self.
return self
end
function Criterion:setOrder(order
self.order[
return self
end
function Criterion:
self.
return self
end
function Criterion:
self.
return self
end
function Criterion:
self.
return self
end
function Criterion:setDefinition(text)
self.definition[self.current_ns.id] = text
return self
end
function Criterion:setValid(valid)
self.validity[self.current_ns.id] = valid
return self
end
function Criterion:setValidForNsType(valid, ns_type)
self.validity[ns_type.value] = valid
return self
end
Riga 236 ⟶ 226:
-- =============================================================================
local function to_criterion(
local criterion = Criterion:new(
for ns, props in pairs(
ns = Namespace
if ns and type(props) == 'table' then
criterion:setCurrentNs(ns)
if type(props.ordine) == 'number' then
criterion:setOrder(props.ordine
end
if type(props.link) == 'string' then
criterion:setLink(props.link
end
if type(props.testi) == 'table' then
for
if text_type then
criterion[text_type.set](criterion,
end
end
Riga 263 ⟶ 255:
if ns == Namespace.DEFAULT then
if type(props['validità']) == 'table' then
for
if ns_type and type(
criterion:setValidForNsType(
end
end
end
elseif type(props['validità']) == 'boolean' then
criterion:
end
end
Riga 278 ⟶ 270:
return criterion
end
local function compare_criteria(a, b)
if a:getOrder() == b:getOrder() then
return a:getCode() < b:getCode()
else
return a:getOrder() < b:getOrder()
end
end
Riga 297:
local function get_args(frame)
local args = require('Module:Arguments').getArgs(frame, { parentOnly = true })
if args[1] and args.criterio == nil then
Riga 303:
end
args.ns = Namespace
args['tipo elenco'] = ListType
args['tipo testo'] = TextType
args.link = args.link ~= 'no' and true or false
args.ancore = (args.ancore == 'sì' or args.ancore == 'si') and true or false
Riga 318:
local p = {}
function p.get_default_value(frame)
local param = mw.text.trim(frame.args[1] or '')
if Enum[param] and Enum[param].getDefault and Enum[param]:getDefault().arg then
return string.format('"%s"', Enum[param]:getDefault().arg)
end
end
function p.list_possible_values(frame)
local param = mw.text.trim(frame.args[1] or '')
local possible_values = {}
if Enum[param] then
for _, constant in pairs(Enum[param]) do
if constant.arg then
table.insert(possible_values, string.format('"%s"', constant.arg))
end
end
end
return table.concat(possible_values, ', ')
end
function p.get_criterion(frame)
Riga 324 ⟶ 347:
local ns, criterion_code, add_link = args.ns, args.criterio, args.link
if criterion_code
local criterion = to_criterion(criterion_code, cfg[criterion_code])
criterion:setCurrentNs(ns):setAddLink(add_link)
if
return criterion[text_type.get](criterion
end
end
Riga 342 ⟶ 363:
local ns, add_anchor, add_link = args.ns, args.ancore, args.link
local suppressed_criteria = args['escludi criteri']
local list = list_type.section[ns.id]
local valid_criteria = {}
for
local criterion = to_criterion(
criterion:setCurrentNs(ns):setAddLink(add_link)
if criterion:isValid() and suppressed_criteria[criterion:getCode()] == false then
table.insert(valid_criteria, criterion)
end
end
table.sort(valid_criteria,
for _, criterion in ipairs(valid_criteria) do
list =
if add_anchor then
list =
end
list = list .. criterion[text_type.get](criterion
end
|