Modulo:Criteri cancellazione immediata/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
aggiungo entrypoint per ottenere l'elenco dei list types e text types |
usa il modulo:Enum per le enumerazioni |
||
(5 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 256 ⟶ 230:
for ns, props in pairs(criterion_cfg) do
ns = Namespace
if ns and type(props) == 'table' then
Riga 271 ⟶ 245:
if type(props.testi) == 'table' then
for text_type, text in pairs(props.testi) do
text_type = TextType
if text_type then
Riga 282 ⟶ 256:
if type(props['validità']) == 'table' then
for ns_type, valid in pairs(props['validità']) do
ns_type = NamespaceType
if ns_type and type(valid) == 'boolean' then
Riga 323 ⟶ 297:
local function get_args(frame)
local args = require('Module:Arguments').getArgs(frame, { parentOnly = true })
if args[1] and args.criterio == nil then
Riga 329 ⟶ 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 345 ⟶ 319:
local p = {}
function p.
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.
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(
end
Riga 370 ⟶ 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)
return criterion[text_type.get](criterion)
end
end
end
Riga 404 ⟶ 379:
for _, criterion in ipairs(valid_criteria) do
list =
if add_anchor then
list =
end
|