Modulo:Progetti interessati: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m +categoria di servizio |
-testo alternativo dalle icone, sono soltanto decorative |
||
(6 versioni intermedie di 4 utenti non mostrate) | |||
Riga 3:
]]--
require('
local getArgs = require('Modulo:Arguments').getArgs
local cfg = mw.loadData('Modulo:Progetti interessati/Configurazione')
local catPrefix = mw.loadData('Modulo:Progetti interessati/Categorie')
-- Nomi e valori consentiti dei parametri di monitoraggio/importanza richiesti da più funzioni
local gradeParams = { 'accuratezza', 'scrittura', 'fonti', 'immagini' }
local validGrades = { a = true, b = true, c = true, d = true, e = true }
local validImportances = { massima = true, alta = true }
-- =============================================================================
--
-- =============================================================================
-- Wrapper di mw.title.exists, verifica sia che name sia valido, sia che esista.
--
-- @param {string} name
-- @return {boolean}
local function titleExists(name)
local title = mw.title.new(name)
Riga 26:
end
-- Restituisce il valore della valutazione ("a", "b", "c" o "d") più bassa inserita
-- nei quattro parametri "accuratezza", "scrittura", "fonti" e "immagini".
--
-- @param {table} args
-- @return {string}
local function lowestGrade(args)
local t = { args.accuratezza, args.scrittura, args.fonti, args.immagini }
Riga 32 ⟶ 37:
end
-- Restituisce l'icona da visualizzare per il progetto specificato,
-- utilizzando il template Icona argomento e verificando se è un sottoprogetto.
--
-- @param {string} name
-- @return {string}
local function getIcon(name)
local icon = mw.getCurrentFrame():expandTemplate {
Riga 48 ⟶ 58:
icon = icon == '' and 'Crystal Clear app ksirtet.png' or icon
return string.format('[[File:%s|20x20px|alt= ]]', icon)
end
-- Restituisce il valore del parametro importanzaN relativo al progettoN specificato,
-- o nil se non usato dall'utente.
--
-- @param {string} projParam
-- @param {table} args
-- @return {string}
local function getImportance(projParam, args)
local num = mw.ustring.match(projParam, '^progetto(%d)$')
Riga 58 ⟶ 74:
end
-- Controlla gli argomenti importanzaN e quelli per la valutazione del monitoraggio.
-- Per ogni parametro progettoN specificato crea una table con i dati del progetto.
--
-- @param {table} args
-- @return {table} gli argomenti passati alla funzione
-- @return {table} una sequence di table che descrivono i singoli progetti
-- @return {table} eventuali categorie di errore
-- @return {string} un eventuale messaggio di errore per i progetti non esistenti
local function parseArgs(args)
local errcat = {}
local projects = {}
local nonexistingProjects = {}
local errmsg
local importanceParams = { 'importanza' }
local projectParams = { 'progetto' }
Riga 106 ⟶ 132:
else
table.insert(errcat, '[[Categoria:Pagine con template Progetti interessati con progetto non esistente]]')
table.insert(nonexistingProjects, name)
end
end
Riga 114 ⟶ 141:
end
-- messaggio d'errore con progetti non esistenti
if #nonexistingProjects > 0 then
local descr = #nonexistingProjects > 1 and 'non esistono i progetti' or 'non esiste il progetto'
errmsg = string.format('<span class="error" style="margin:5px 10%%">Errore: %s %s</span>',
descr, mw.text.listToText(nonexistingProjects))
end
return args, projects, errcat, errmsg
end
-- Formatta i valori assegnati ai parametri "accuratezza", "scrittura", "fonti" e "immagini".
--
-- @param {string} value
-- @return {table}
local function getLabelGrade(value)
local codeStyle = {
Riga 131 ⟶ 169:
end
-- Restituisce true se almeno un progetto tra quelli specificati
-- ha attivato il monitoraggio.
--
-- @param {table} projects
-- @return {boolean}
local function hasMonitoraggio(projects)
local ret = false
Riga 142 ⟶ 185:
end
-- =============================================================================
-- Funzioni base
-- =============================================================================
-- Restituisce il risultato del monitoraggio in base alle valutazioni inserite
-- nei quattro parametri "accuratezza", "scrittura", "fonti" e "immagini".
-- Il valore restituito, dal basso verso l'alto, può essere:
-- "0.2", "0.3", "0.4", "0.5", "IMMAGINI", "F", "W", "BOZZA", "1", "2", "3", "4".
--
-- @param {table} args
-- @return {string}
local function getLivello(args)
local ret
Riga 184 ⟶ 234:
end
-- Restituisce le categorie di servizio in base al livello del monitoraggio ottenuto,
-- agli eventuali parametri "importanza" e alla presenza di errori utente di compilazione.
--
-- @param {string} livello
-- @param {table} args
-- @param {table} projects
-- @return {table}
local function getCategories(livello, args, projects)
local ret = {}
Riga 253 ⟶ 310:
end
-- =============================================================================
--
-- =============================================================================
-- La classe ProjectsTable rappresenta la prima delle due tabelle HTML
-- prodotte dal modulo, quella per elencare i wikiprogetti.
local ProjectsTable = {}
-- Costruttore della classe ProjectsTable.
--
-- @param {table} projects
-- @return {table} un nuovo oggetto ProjectsTable
function ProjectsTable:new(projects)
local self = {}
Riga 266 ⟶ 330:
end
-- Restituisce la tabella HTML con una riga di introduzione e una per la sottotabella progetti.
--
-- @return {string}
function ProjectsTable:getHTML()
local tableStyle = {
Riga 285 ⟶ 352:
:wikitext(mw.getCurrentFrame():preprocess(text))
:done()
tableNode
:tag('tr')
:tag('td')
:attr('colspan', '2')
:node(self:
:done()
if titleExists(mw.getCurrentFrame():preprocess('WP:Bibliografia/{{SUBJECTPAGENAME}}')) then
tableNode
:tag('tr')
:tag('td')
:css('text-align', 'center')
:attr('colspan', '2') :wikitext(mw.getCurrentFrame():preprocess('[[WP:Bibliografia/{{SUBJECTPAGENAME}}|Bibliografia utilizzabile]]'))
:done()
end
return tostring(tableNode)
end
-- Restituisce la sottotabella HTML con un progetto per riga.
--
-- @return {table}
function ProjectsTable:_getNodeProjects()
local tableStyle = {
width = '100%',
Riga 319 ⟶ 399:
:addClass('plainlinks')
:css('padding-left', '5px')
:wikitext(self:
:done()
:tag('td')
Riga 332 ⟶ 412:
end
-- Restituisce il link al progetto, al bar di progetto e all'eventuale monitoraggio delle voci.
--
-- @param {table} project
-- @return {string}
function ProjectsTable:_getWlinkProject(project)
local links = {}
local fmtIcon = '[[File:Rpb dialog icon.svg|23x15px|bar di progetto|link=Discussioni progetto:%s]]'
Riga 348 ⟶ 432:
end
-- =============================================================================
--
-- =============================================================================
-- La classe ProjectsTable rappresenta la seconda delle due tabelle HTML
-- prodotte dal modulo, quella per visualizzare la valutazione del monitoraggio.
local MonitoraggioTable = {}
-- Costruttore della classe MonitoraggioTable.
--
-- @param {string} livello
-- @param {table} args
-- @return {table} un nuovo oggetto MonitoraggioTable
function MonitoraggioTable:new(livello, args)
local self = {}
Riga 362 ⟶ 454:
end
-- Restituisce la tabella HTML con una riga di introduzione e una per la sottotabella
-- collassabile per "accuratezza", "scrittura", "fonti" e "immagini".
-- Termina con due righe opzionali in base alla presenza delle note e della data.
--
-- @return {string}
function MonitoraggioTable:getHTML()
local tableStyle = {
Riga 374 ⟶ 471:
:css(tableStyle)
-- livello
tableNode
:node(self:
-- valutazioni
tableNode
Riga 387 ⟶ 484:
:css('width', '100%')
:css('border-collapse', 'collapse')
:node(self:
:node(self:
:node(self:
:node(self:
-- note
if self.args.note then
Riga 404 ⟶ 501:
-- data
if self.args.data then
local data = self:
tableNode
:tag('tr')
Riga 419 ⟶ 516:
end
-- Restituisce la prima riga della tabella HTML, contenente il risultato del monitoraggio
-- oppure l'indicazione che il monitoraggio non è ancora stato effettuato.
--
-- @return {table}
function MonitoraggioTable:_getNodeLivello()
local text, icon
if self.livello then
Riga 427 ⟶ 528:
icon, text = cfg.monitoraggio.icon, cfg.monitoraggio.text
text = string.format('%s<br />Ha ottenuto una valutazione di livello %s <small>(%s)</small>.',
text, self:
end
else
Riga 443 ⟶ 544:
end
-- Restituisce il wikilink del risultato del monitoraggio, formattato opportunamente.
--
-- @return {string}
function MonitoraggioTable:_getWlinkLivello()
local codeStyle = {
['font-weight'] = 'bold',
Riga 460 ⟶ 564:
end
-- Restituisce la data del monitoraggio se esiste la relativa categoria
-- di monitoraggio per mese oppure un messaggio di errore.
--
-- @return {string}
function MonitoraggioTable:_getTextData()
local ret
if self.args.data then
Riga 471 ⟶ 579:
end
-- Restituisce la riga della tabella HTML per ciascuna delle quattro valutazioni di
-- "accuratezza", "scrittura", "fonti" e "immagini", formattata opportunamente.
--
-- @param {string} param
-- @return {table}
function MonitoraggioTable:_getNodeGrade(param)
return mw.html.create('tr')
:css('background-color', 'white')
Riga 485 ⟶ 598:
end
-- =============================================================================
-- Funzioni
-- =============================================================================
local p = {}
--
function p._livello(args)
return getLivello(parseArgs(args))
end
--
function p.livello(frame)
return p._livello(getArgs(frame))
end
--
function p.categorie(frame)
local args, projects = parseArgs(getArgs(frame))
local livello = getLivello(args)
local categories = getCategories(livello, args, projects)
return args.debug and ( table.concat(categories, '<br />'):gsub('%[%[', '[[:') ) .. '<br />' or
Riga 510 ⟶ 623:
end
--
-- per retrocompatibilità con template che lo usavano.
function p.classe(frame)
local value = frame:getParent().args[1]
Riga 517 ⟶ 630:
end
--
function p.main(frame)
local args, projects, errcat, errmsg = parseArgs(getArgs(frame, { parentOnly = true }))
if hasMonitoraggio(projects) then
local livello = getLivello(args)
local categories = mw.title.getCurrentTitle().namespace == 1 and
(table.concat(getCategories(livello, args, projects)) .. table.concat(errcat)) or ''
return (errmsg or '') ..
ProjectsTable:new(projects):getHTML() .. MonitoraggioTable:new(livello, args):getHTML() ..
categories
else
return (errmsg or '') ..
ProjectsTable:new(projects):getHTML() .. table.concat(errcat)
end
|