Modulo:Criteri cancellazione immediata/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
caricamento dinamico della configurazione; entrypoint per ottenere i valori di default; altre migliorie |
usa il modulo:Enum per le enumerazioni |
||
(3 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 6:
require('strict')
-- Legge [[Modulo:Criteri cancellazione immediata/Configurazione.json]]
-- 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 23 ⟶ 24:
value = 'ns dispari'
}
})
function NamespaceType:findByValue(value)
return self:findBy('value', value)
end
-- =============================================================================
Riga 41 ⟶ 34:
-- =============================================================================
local Namespace =
DEFAULT = {
id = 'default',
Riga 52 ⟶ 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 88 ⟶ 69:
-- =============================================================================
local ListType =
DROPDOWN_LIST = {
arg = 'a discesa',
Riga 109 ⟶ 90:
})
}
})
function ListType:findByArg(arg)
return self:findBy('arg', arg)
end
function ListType:getDefault()
return self.DROPDOWN_LIST
end
-- =============================================================================
Riga 131 ⟶ 104:
-- =============================================================================
local TextType =
SYSTEM_MESSAGE = {
arg = 'messaggio di sistema',
Riga 142 ⟶ 115:
set = 'setDefinition'
}
})
function TextType:findByArg(arg)
return self:findBy('arg', arg)
end
function TextType:getDefault()
return self.SYSTEM_MESSAGE
end
-- =============================================================================
Riga 265 ⟶ 230:
for ns, props in pairs(criterion_cfg) do
ns = Namespace
if ns and type(props) == 'table' then
Riga 280 ⟶ 245:
if type(props.testi) == 'table' then
for text_type, text in pairs(props.testi) do
text_type = TextType
if text_type then
Riga 291 ⟶ 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 338 ⟶ 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 354 ⟶ 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
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
|