Modulo:Protezione: differenze tra le versioni

Vai alla navigazione Vai alla ricerca
Contenuto aggiunto Contenuto cancellato
Nessun oggetto della modifica
Nessun oggetto della modifica
 
(8 versioni intermedie di 2 utenti non mostrate)
Riga 1: Riga 1:
-- scopiazzato da https://it.wikipedia.org/w/index.php?title=Modulo:Protezione&oldid=94662864
-- scopiazzato da https://it.wikipedia.org/w/index.php?title=Modulo:Protezione&oldid=130072618
--[[
--[[
* Modulo che implementa il template Blindata (ovvero Protetta).
* Modulo che implementa il template Protetta.
]]--
]]--


require('Modulo:No globals')
require('strict')


local getArgs = require('Modulo:Arguments').getArgs
local getArgs = require('Modulo:Arguments').getArgs
Riga 24: Riga 24:
local function addIcon(action, prot)
local function addIcon(action, prot)
-- l'underscore di move serve per cambiare l'ordine di visualizzazione delle icone
-- l'underscore di move serve per cambiare l'ordine di visualizzazione delle icone
if cfg.icone[action][prot] ~= nil then
local icon = string.format('<indicator name="prot%s">%s</indicator>',
local icon = string.format('<indicator name="prot%s">%s</indicator>',
action == 'move' and '_move' or action, cfg.icone[action][prot])
action == 'move' and '_move' or action, cfg.icone[action][prot])
mw.getCurrentFrame():preprocess(icon)
mw.getCurrentFrame():preprocess(icon)
end
end
end


Riga 36: Riga 38:
-- @return {string}
-- @return {string}
local function getMsg(title, action, prot)
local function getMsg(title, action, prot)
if prot ~= '?' and prot ~= nil then
local msg = cfg.messaggi[action][prot][title.namespace]
local msg = cfg.messaggi[action][prot][title.namespace]
return msg and msg:gsub('$1', string.format('[[%s|pagina di discussione]]', title.talkPageTitle.fullText)) or nil
return msg and msg:gsub('$1', string.format('[[%s|pagina di discussione]]', title.talkPageTitle.fullText)) or nil
else return nil
end
end
end


Riga 51: Riga 56:
if prot == 'autoconfirmed' then
if prot == 'autoconfirmed' then
cat = cat .. ' parzialmente'
cat = cat .. ' parzialmente'
end
if prot == 'user' then
cat = cat .. ' da modifiche anonime'
end
end
return string.format('[[Categoria:%s]]', cat)
return string.format('[[Categoria:%s]]', cat)
Riga 69: Riga 71:
elseif editProt == 'autoconfirmed' then
elseif editProt == 'autoconfirmed' then
cat = args.cat .. ' ' .. (args.generecat == 'm' and 'protetti parzialmente' or 'protette parzialmente')
cat = args.cat .. ' ' .. (args.generecat == 'm' and 'protetti parzialmente' or 'protette parzialmente')
elseif editProt == 'user' then
cat = cat .. (args.generecat == 'm' and 'protetti da modifiche anonime' or 'protette da modifiche anonime')
end
end
return cat and string.format('[[Categoria:%s]]', cat) or nil
return cat and string.format('[[Categoria:%s]]', cat) or nil
end
end
Riga 89: Riga 88:
editProt = getProtection(title, 'edit')
editProt = getProtection(title, 'edit')
moveProt = getProtection(title, 'move')
moveProt = getProtection(title, 'move')
-- moveProt=autoconfirmed è già il default in itwiki
if moveProt ~= 'sysop' then
-- moveProt=autoconfirmed è già il default
if moveProt == 'autoconfirmed' then
moveProt = nil
moveProt = nil
end
end
-- editProt=user è già il default
if editProt == 'user' then
editProt = nil
end
-- protezione per la modifica
-- protezione per la modifica
if editProt then
if editProt then
Riga 128: Riga 134:
end
end


-- Funzione per il template {{blindata}}.
-- Funzione per il template {{Protetta}}.
function p.main(frame)
function p.main(frame)
return p._main(getArgs(frame, { parentOnly = true }))
return p._main(getArgs(frame, { parentOnly = true }))

Versione attuale delle 13:37, 3 gen 2024

Codesto modulo fa funzionare il template {{Blindata}}, che mostra il livello di protezione della pagina in cui è inserito.

Ha una sottopagina di configurazione: Modulo:Protezione/Configurazione.


-- scopiazzato da https://it.wikipedia.org/w/index.php?title=Modulo:Protezione&oldid=130072618
--[[
* Modulo che implementa il template Protetta.
]]--

require('strict')

local getArgs = require('Modulo:Arguments').getArgs
local cfg = mw.loadData('Modulo:Protezione/Configurazione')

-- Restituisce la protezione della pagina per l'azione richiesta o nil se non protetta.
--
-- @param {table} title
-- @param {string} action
-- @return {string}
local function getProtection(title, action)
	return title.protectionLevels[action] and title.protectionLevels[action][1]
end

-- Aggiunge l'icona per l'azione e la protezione specificate.
--
-- @param {string} action
-- @param {string} prot
local function addIcon(action, prot)
	-- l'underscore di move serve per cambiare l'ordine di visualizzazione delle icone
	if cfg.icone[action][prot] ~= nil then
		local icon = string.format('<indicator name="prot%s">%s</indicator>',
							   action == 'move' and '_move' or action, cfg.icone[action][prot])
		mw.getCurrentFrame():preprocess(icon)
	end
end

-- Restituisce il messaggio configurato per il tipo di azione e protezione sulla pagina specificata.
--
-- @param {table} title
-- @param {string} action
-- @param {string} prot
-- @return {string}
local function getMsg(title, action, prot)
	if prot ~= '?' and prot ~= nil then
		local msg = cfg.messaggi[action][prot][title.namespace]
		return msg and msg:gsub('$1', string.format('[[%s|pagina di discussione]]', title.talkPageTitle.fullText)) or nil
	else return nil
	end
end

-- Restituisce la categoria configurata per il tipo di azione e protezione sulla pagina specificata.
--
-- @param {table} title
-- @param {string} action
-- @param {string} prot
-- @return {string}
local function getCategory(title, action, prot)
	local categories = cfg.categorie[action]
	local cat = categories[title.namespace] or categories.default
	if prot == 'autoconfirmed' then
		cat = cat .. ' parzialmente'
	end
	return string.format('[[Categoria:%s]]', cat)
end

-- Restituisce la categoria arbitraria scelta dall'utente.
--
-- @param {string} editProt
-- @param {table} args
-- @return {string}
local function getUserCategory(editProt, args)
	local cat
	if editProt == 'sysop' then
		cat = args.cat .. ' ' .. (args.generecat == 'm' and 'protetti' or 'protette')
	elseif editProt == 'autoconfirmed' then
		cat = args.cat .. ' ' .. (args.generecat == 'm' and 'protetti parzialmente' or 'protette parzialmente')
	end
	return cat and string.format('[[Categoria:%s]]', cat) or nil 
end

-- =============================================================================
--                            Funzioni esportate
-- =============================================================================

local p = {}

-- Funzione per l'utilizzo da un altro modulo.
function p._main(args)
	local title, editProt, moveProt, editCat, moveCat, msg, ret

	title = mw.title.getCurrentTitle()
	editProt = getProtection(title, 'edit')
	moveProt = getProtection(title, 'move')
	
	-- moveProt=autoconfirmed è già il default 
	if moveProt == 'autoconfirmed' then
		moveProt = nil
	end
	
	-- editProt=user è già il default 
	if editProt == 'user' then
		editProt = nil
	end
	
	-- protezione per la modifica
	if editProt then
		addIcon('edit', editProt)
		msg = getMsg(title, 'edit', editProt)
		-- il parametro "cat" permette di specificare una categoria arbitraria
		if args.cat then
			editCat = getUserCategory(editProt, args)
		else
			editCat = getCategory(title, 'edit', editProt)
		end
	end

	-- protezione per lo spostamento
	if moveProt then
		addIcon('move', moveProt)
		-- la categoria per lo spostamento non è aggiunta se editProt=sysop
		if editProt ~= 'sysop' then
			moveCat = getCategory(title, 'move', moveProt)
		end
	end

	if editProt or moveProt then
		ret = (msg or '') .. (editCat or '') .. (moveCat or '')
	else
		-- la pagina non è protetta
		if title.namespace == 10 and title.isSubpage and title.subpageText:match('^[Ss]andbox$') then
			ret = '[[Categoria:Sandbox dei template]]'
		else
			ret = string.format('[[Categoria:%s]]', cfg.catSprotette)
		end
	end

	return ret
end

-- Funzione per il template {{Protetta}}.
function p.main(frame)
	return p._main(getArgs(frame, { parentOnly = true }))
end

return p