Modulo:Progetti interessati: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m dimensioni icone come in cronologia valutazioni
-testo alternativo dalle icone, sono soltanto decorative
 
(15 versioni intermedie di 4 utenti non mostrate)
Riga 3:
]]--
 
require('Modulo:No globalsstrict')
 
local getArgs = require('Modulo:Arguments').getArgs
 
-- Configurazione
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
-- Variabili globali
local gradeParams = { 'accuratezza', 'scrittura', 'fonti', 'immagini' }
local validGrades = { a = true, b = true, c = true, d = true, e = true }
local validImportances = { massima = true, alta = true }
 
-- =============================================================================
-------------------------------------------------------------------------------
-- Funzioni di utilità
-- =============================================================================
-------------------------------------------------------------------------------
 
-- 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)
Line 24 ⟶ 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 }
Line 30 ⟶ 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 {
Line 46 ⟶ 58:
icon = icon == '' and 'Crystal Clear app ksirtet.png' or icon
 
return string.format('[[File:%s|20px20x20px|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)$')
local param = num and ('importanza' .. num) or
(projParam == 'progetto' and 'importanza' or nil)
return args[param]
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' }
 
-- controllo importanza
for i = 2, cfg.max_progetti do
table.insert(importanceParams, 'importanza' .. i)
end
for _, param in ipairs(importanceParams) do
if args[param] and not validImportances[args[param]] then
args[param] = nil
table.insert(errcat, '[[Categoria:Pagine con template Progetti interessati con importanza invalida]]')
end
end
 
-- controllo valutazioni
Line 79 ⟶ 126:
subpage = mw.title.new('Progetto:' .. name).subpageText,
monitoraggio = titleExists(string.format('Progetto:%s/Monitoraggio voci', name)),
iconimportance = getIcongetImportance(nameparam, args),
icon = getIcon(name),
catPrefix = catPrefix[name:lower()]
})
else
table.insert(errcat, '[[Categoria:Pagine con template Progetti interessati con progetto non esistente]]')
table.insert(nonexistingProjects, name)
end
end
Line 91 ⟶ 141:
end
 
-- messaggio d'errore con progetti non esistenti
return args, projects, errcat
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 = {
Line 108 ⟶ 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
Line 119 ⟶ 185:
end
 
-- =============================================================================
-------------------------------------------------------------------------------
-- Funzioni base del Monitoraggio
-- =============================================================================
-------------------------------------------------------------------------------
 
-- 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
Line 161 ⟶ 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 = {}
Line 204 ⟶ 284:
table.insert(ret, '[[' .. cat .. ']]')
end
end
if project.importance and project.catPrefix then
cat = string.format('Categoria:%s - importanza %s', project.catPrefix, project.importance)
table.insert(ret, '[[' .. cat .. ']]')
end
end
 
-- per la "Situazione monitoraggio per mese" di [[Progetto:Qualità/Monitoraggio voci/Tabella]]
if args.datalivello then
if args.data then
cat = string.format('Categoria:Voci monitorate - %s', args.data)
if titleExists(cat) then
table.insert(ret, '[[' .. cat .. ']]')
else
table.insert(ret, '[[Categoria:Errori di compilazione del template Progetti interessati]]')
end
else
table.insert(ret, '[[Categoria:ErroriVoci dimonitorate compilazione- delnon template Progetti interessatidatate]]')
end
elseif (args.data or args.utente) and not args.note then
else
table.insert(ret, '[[Categoria:VociPagine monitoratecon -template nonProgetti datateinteressati con utente o data e senza monitoraggio]]')
end
 
Line 222 ⟶ 310:
end
 
-- =============================================================================
------------------------------------------------------------------------------
-- classe Classe ProjectsTable
-- =============================================================================
-------------------------------------------------------------------------------
 
-- 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 = {}
Line 235 ⟶ 330:
end
 
-- Restituisce la tabella HTML con una riga di introduzione e una per la sottotabella progetti.
--
-- @return {string}
function ProjectsTable:getHTML()
local tableStyle = {
Line 242 ⟶ 340:
['background-color'] = cfg.bgcolor,
}
local text = (#self.projects > 1 and cfg.progetti.text2 or cfg.progetti.text) ..
(hasMonitoraggio(self.projects) and
(#self.projects > 1 and cfg.progetti.text4 or cfg.progetti.text3) or '')
local tableNode = mw.html.create('table'):css(tableStyle)
tableNode
Line 256 ⟶ 352:
:wikitext(mw.getCurrentFrame():preprocess(text))
:done()
tableNode
:tag('tr')
:tag('td')
:attr('colspan', '2')
:node(self:getNodeProjects_getNodeProjects())
: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.
function ProjectsTable:getNodeProjects()
--
-- @return {table}
function ProjectsTable:_getNodeProjects()
local tableStyle = {
width = '100%',
Line 288 ⟶ 397:
:done()
:tag('td')
:addClass('plainlinks')
:wikitext('<div class="plainlinks" style="padding-left: 5px">' .. self:getWlinkProject(project) .. '</div>')
:css('padding-left', '5px')
:wikitext(self:_getWlinkProject(project))
:done()
:tag('td')
:css('width', '11em')
:wikitext((project.importance and project.catPrefix) and
string.format('[[:Categoria:%s - importanza %s|importanza %s]]',
project.catPrefix, project.importance, project.importance) or '')
:done()
end
Line 295 ⟶ 412:
end
 
-- Restituisce il link al progetto, al bar di progetto e all'eventuale monitoraggio delle voci.
function ProjectsTable:getWlinkProject(project)
--
-- @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]]'
local fmtIcon2 = '[[File:VisualEditor - Icon - Search-big.svg|20x20px|monitoraggio delle voci|link=Progetto:%s/Monitoraggio voci]]'
 
table.insert(links, string.format(fmtIcon, project.name))
Line 305 ⟶ 426:
if project.monitoraggio then
table.insert(links, string.format(fmtIcon2, project.name))
table.insert(links, string.format('[[Progetto:%s/Monitoraggio voci|monitoraggio delle voci]]', project.name))
end
 
Line 311 ⟶ 432:
end
 
-- =============================================================================
-------------------------------------------------------------------------------
-- classe PreMonitoraggioTableClasse MonitoraggioTable
-- =============================================================================
-------------------------------------------------------------------------------
 
-- La classe ProjectsTable rappresenta la seconda delle due tabelle HTML
local PreMonitoraggioTable = {}
-- prodotte dal modulo, quella per visualizzare la valutazione del monitoraggio.
 
function PreMonitoraggioTable:new()
local self = {}
setmetatable(self, { __index = PreMonitoraggioTable })
return self
end
 
function PreMonitoraggioTable:getHTML()
local tableStyle = {
margin = '5px 10% 0 10%',
width = '80%',
border = '1px solid #a7d7f9',
['background-color'] = cfg.bgcolor,
}
local tableNode = mw.html.create('table'):css(tableStyle)
tableNode
:tag('tr')
:tag('td')
:css('width', '52px')
:css('text-align', 'center')
:wikitext(cfg.monitoraggio.icon)
:done()
:tag('td')
:wikitext(cfg.monitoraggio.text)
:done()
 
return tostring(tableNode)
end
 
-------------------------------------------------------------------------------
-- classe MonitoraggioTable
-------------------------------------------------------------------------------
 
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 = {}
Line 359 ⟶ 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 = {
margin = '05px 10% 5px 10%',
width = '80%',
border = '1px solid #a7d7f9',
['background-color'] = cfg.bgcolor,
['border-top'] = '0',
}
local tableNode = mw.html.create('table')
Line 372 ⟶ 471:
:css(tableStyle)
 
-- livello
tableNode
:node(self:getNodeLivello_getNodeLivello())
-- valutazioni
tableNode
Line 385 ⟶ 484:
:css('width', '100%')
:css('border-collapse', 'collapse')
:node(self:getNodeGrade_getNodeGrade('accuratezza'))
:node(self:getNodeGrade_getNodeGrade('scrittura'))
:node(self:getNodeGrade_getNodeGrade('fonti'))
:node(self:getNodeGrade_getNodeGrade('immagini'))
-- note
if self.args.note then
Line 399 ⟶ 498:
self.args.note:match('^[#*]') and '\n' or '',
self.args.note))
end
-- data
if self.args.data then
local data = self:_getTextData()
tableNode
:tag('tr')
:tag('td')
:css('text-align', 'right')
:css('font-size', '80%')
:css('line-height', '1')
:attr('colspan', '3')
:wikitext(string.format('Monitoraggio effettuato %s%s',
data:match('^[ao]') and 'nell\'' or 'nel ', data))
end
 
Line 404 ⟶ 516:
end
 
-- Restituisce la prima riga della tabella HTML, contenente il risultato del monitoraggio
function MonitoraggioTable:getNodeLivello()
-- oppure l'indicazione che il monitoraggio non è ancora stato effettuato.
local url = mw.title.getCurrentTitle():fullUrl( { action = 'edit' } )
--
-- @return {table}
function MonitoraggioTable:_getNodeLivello()
local text, icon
if self.livello then
if self.livello:sub(1, 1) == '0' then
icon, text = cfg.monitoraggio.icon_pc, cfg.monitoraggio.text_pc
else
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:_getWlinkLivello(), self:_getTextData())
end
else
icon, text = cfg.monitoraggio.icon_nc, cfg.monitoraggio.text_nc
end
return mw.html.create('tr')
:tag('td')
:css('background-colorwidth', 'none52px')
:css('widthtext-align', '90pxcenter')
:wikitext(icon)
:node(self:getWlinkLivello())
:done()
:tag('td')
:wikitext(mw.getCurrentFrame():preprocess(text))
:wikitext(self.livello and cfg.livello[self.livello].msg .. ' ' .. self:getTextData() or
'<div class="plainlinks">La voce non è stata ancora valutata, [' .. url .. ' fallo ora]!</div>')
:done()
:tag('td')
:css('width', '80px')
:wikitext('')
:done()
end
 
-- Restituisce il wikilink del risultato del monitoraggio, formattato opportunamente.
function MonitoraggioTable:getWlinkLivello()
--
-- @return {string}
function MonitoraggioTable:_getWlinkLivello()
local codeStyle = {
['font-weight'] = 'bold',
['font-size'] = '125%',
['padding-left'] = '.4em',
['padding-right'] = '.4em',
border = '1px solid lightsteelblue',
background = (self.livello and cfg.livello[self.livello].color) and cfg.livello[self.livello].color or 'white',
color = 'blue'
}
local text = string.format('[[:Categoria:Voci monitorate - %s|%s]]',
cfg.livello[self.livello].cat, cfg.livello[self.livello].label)
local codeNode = mw.html.create('code')
codeNode:css(codeStyle)
local text
if self.livello and cfg.livello[self.livello].label then
text = string.format('[[:Categoria:Voci monitorate - %s|%s]]',
cfg.livello[self.livello].cat, cfg.livello[self.livello].label)
elseif not self.livello then
text = '[[:Categoria:Voci monitorate - non compilate|NC]]'
end
if text then
codeNode:css(codeStyle)
else
text = '[[File:Symbol stub class.svg|25px|center]]'
end
codeNode:wikitext(text)
return tostring(codeNode)
 
return codeNode
end
 
-- Restituisce la data del monitoraggio se esiste la relativa categoria
function MonitoraggioTable:getTextData()
-- di monitoraggio per mese oppure un messaggio di errore.
--
-- @return {string}
function MonitoraggioTable:_getTextData()
local ret
if self.args.data then
local cat = string.format('Categoria:Voci monitorate - %s', self.args.data)
if titleExists(cat) then
ret = string.format('<small>(%s)</small>', self.args.data)
end
end
return ret or "(<span style=\"color:red;\"><small>'''''mese e anno'''''</small></span>)"
end
 
-- Restituisce la riga della tabella HTML per ciascuna delle quattro valutazioni di
function MonitoraggioTable:getNodeGrade(param)
-- "accuratezza", "scrittura", "fonti" e "immagini", formattata opportunamente.
return mw.html.create('tr')
--
-- @param {string} param
-- @return {table}
function MonitoraggioTable:_getNodeGrade(param)
return mw.html.create('tr')
:css('background-color', 'white')
:css('border', 'thin solid #D8D8D8')
Line 475 ⟶ 598:
end
 
-- =============================================================================
-------------------------------------------------------------------------------
-- Funzioni APIesportate
-- =============================================================================
-------------------------------------------------------------------------------
 
local p = {}
 
-- PerFunzione per l'utilizzo da un altro modulo.
function p._livello(args)
return getLivello(parseArgs(args))
end
 
-- Entry-pointFunzione per {{#invoke:Progetti interessati|livello}}.
function p.livello(frame)
return p._livello(getArgs(frame))
end
 
-- Entry-pointFunzione per {{#invoke:Progetti interessati|categorie}}.
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
Line 500 ⟶ 623:
end
 
-- Entry-pointFunzione per il sottotemplate {{Progetti interessati/classe}}
-- per retrocompatibilità con template che lo usavano.
function p.classe(frame)
local value = frame:getParent().args[1]
Line 507 ⟶ 630:
end
 
-- Entry-pointFunzione per il template {{Progetti interessati}}.
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() ..
PreMonitoraggioTable:new():getHTML() ..
MonitoraggioTable:new(livello, args):getHTML() ..
categories
else
return (errmsg or '') ..
ProjectsTable:new(projects):getHTML() ..
table.concat(errcat)
end