Modulo:Vedi anche: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiunta categoria
uniformo i template hatnote col template:Avviso permanente
 
(22 versioni intermedie di 6 utenti non mostrate)
Riga 1:
--[[
* Modulo che implementa il template {{Vedi anche}}.
]]
 
require('Modulo:No globalsstrict')
 
-- Parsifica un argomento del template (rappresenta il titolo di una pagina) e ne ritornarestituisce il wikilink.
local p = {}
--
 
-- @param {string} arg
-- Parsifica un argomento del template (rappresenta il titolo di una pagina) e ne ritorna il wikilink.
-- @return {string}
local function parseArg(arg)
local dest, count, obj, content
 
-- restituisce errore con wikilink a categorie
if arg:match('^%s*:%s*[Cc][Aa][Tt]') then
return '<span class="error">(usare il [[Template:Vedi categoria]])</span>'
end
 
-- rimuove eventuali pipe inserite tramite {{!}}
arg = arg:match('(.*-)|') or arg
-- sostituisce le HTML entity (per esempio &#39; con "'" (generato da {{PAGENAME}} quando il titolo contiene l'apostrofo)
arg = arg:gsubmw.text.decode('&#39;', "'"arg)
-- crea oggetto per il titolo
-- sostituisce # con §
argobj = mw.title.new(mw.uri.decode(arg:gsub('#', ' § PATH'))
-- sostituisce # con §, se trovato crea un piped wikilink
dest = arg
arg, count = arg:gsub('#', ' § ')
dest = count == 1 and (dest .. '|') or ''
 
-- converte la prima lettera in maiuscola o minuscola a seconda che la voce contenga il template Titolo minuscolo
return "'''[[" .. arg .. "]]'''"
content = obj and obj:getContent()
if content and content:match('{{%s*[Tt]itolo minuscolo%s*[|}]') then
arg = mw.getContentLanguage():lcfirst(arg)
else
arg = mw.getContentLanguage():ucfirst(arg)
end
 
return string.format("'''[[%s%s]]'''", dest, arg)
end
 
-- Costruisce l'HTML per contenere i wikilink alle pagine.
--
-- @param {string} wikitext
-- @return {string}
local function buildHTML(wikitext)
return mw.getCurrentFrame():extensionTag{
local tableStyle = {
['margin-bottom'] name = '.5emtemplatestyles',
args = {
border = '1px solid #CCC',
src = 'Modulo:Vedi anche/styles.css'
['text-align'] = 'left',
}
['font-size'] = '95%',
} .. mw.getCurrentFrame():expandTemplate{
background = 'transparent'
title = 'Avviso permanente',
}
args = {
local tableNode = mw.html.create('table')
immagine = 'Magnifying glass icon mgx2.svg',
tableNode
:addClass( classe = 'noprint vedi-anche'),
:wikitexttesto = string.format("''Lo stesso argomento in dettaglio: " .%s.', wikitext .. "''.")
:css(tableStyle)
}
:tag('tr')
}
:tag('td')
:css('padding', '.5em')
:wikitext('[[File:Exquisite-kfind.png|20px|class=noviewer]]')
:done()
:tag('td')
:css('width', '100%')
:wikitext("''Lo stesso argomento in dettaglio: " .. wikitext .. "''.")
:done()
 
return tostring(tableNode)
end
 
-- =============================================================================
-- entry-point per {{Vedi anche}}
-- Funzioni esportate
-- =============================================================================
 
local p = {}
 
-- entry-pointFunzione per il template {{Vedi anche}}.
function p.main(frame)
local lastArg, conjunction
local args = {}
local cat
 
for _, val in ipairs(frame:getParent().args) do
if mw.text.trim(val) ~= '' then
table.insert(args, parseArg(val))
lastArg = val
end
end
if #args > 1 and lastArg then
conjunction = mw.ustring.lower(lastArg:sub(1, 1)) == 'e' and 'ed' or 'e'
conjunction = '&#32;' .. conjunction .. '&#32;'
end
 
return buildHTML(mw.text.listToText(args, ',&#32;', '&#32;e&#32;'conjunction)) .. cat
-- se presente l'obsoleto parametro 'sezione' categorizza la voce (solo nel namespace principale)
cat = (mw.title.getCurrentTitle().namespace == 0 and frame:getParent().args.sezione) and
'[[Categoria:Vedi anche con parametro sezione]]' or ''
 
return buildHTML(mw.text.listToText(args, ',&#32;', '&#32;e&#32;')) .. cat
end