Modulo:Collegamenti esterni: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m aggiungo ulteriore controllo per la corretta identificazione di doppioni |
aggiungo gruppo "Gastronomia" |
||
(12 versioni intermedie di 3 utenti non mostrate) | |||
Riga 3:
]]--
require('
local getArgs = require('Modulo:Arguments').getArgs
Riga 14:
'Letteratura', 'Politica', 'Religione', 'Architettura',
'Astronomia', 'Biologia', 'Editoria', 'Geografia',
'Linguistica', 'MAB', 'Matematica', 'Software', 'Calcio', 'Sci',
'Sport', 'Videogiochi', 'Musica', 'Fumetti', 'Cinema', 'Gastronomia'
}
-- Soglie di attenzione sul numero elevato di collegamenti, per categorie di controllo
Riga 29:
local catExcessiveLoad = 'Voci con template Collegamenti esterni e molte entità Wikidata caricate'
local catDuplicates = 'Voci con template Collegamenti esterni e doppioni disattivati'
-- Avvisi per i link omessi
local tmpFound = 'Link visibile solo nell\'anteprima della pagina. È già presente il template $1'
local tmpSection = 'Questo link potrebbe essere visibile solo nell\'anteprima della pagina se in altre sezioni c\'è già uno dei seguenti template: $1'
-- Tabella dei qualificatori riconosciuti
-- Qui vanno elencati solo quelli generali, validi per tutte le dichiarazioni
Riga 42 ⟶ 45:
P577 = { par = 'data', restricted = true },
-- titolo o "indicato come" o "riferito come" o pseudonimo
P1476 = { par = 'titolo', fallback = { 'P1810', 'P1932', 'P742', 'P554' } },
-- url archiviato, solo per le proprietà di tipo URL
P1065 = { par = 'archivio' }, P2960 = { par = 'dataarch' }, P582 = { par = 'urlmorto' },
Riga 160 ⟶ 163:
-- Restituisce il parametro titolo per il modulo Citazione.
--
-- @param {number} i - il numero dell'URL a cui assegnare il titolo.
-- @return {string}
function ExtLink:_getTitolo(i)
local titolo = self.extraConf.titolo[
if self.linkConf.titolo then
titolo = self.linkConf.titolo:gsub('$1', titolo)
end
if #self.url > 1 and self.extraConf.titolodis[
return string.format('%s (%s)', titolo, self.extraConf.titolodis[
else
return titolo
Riga 188 ⟶ 192:
local ripetuto = false -- controllo se stesso titolo già usato
for j = 1, i - 1 do
if titolo == (self.extraConf.titolo[j] or self.title) then
ripetuto = true
break
Riga 205 ⟶ 209:
end
return tbl
end
-- Restituisce il parametro cid per il modulo Citazione.
--
-- @param {number} i - il numero dell'URL a cui assegnare il cid.
-- @return {string}
function ExtLink:_getCid(i)
if #self.url > 1 and self.extraConf.restrictedData then
return self.extraConf.cid[i]
else
return self.linkConf.cid
end
end
function ExtLink:_formatPreviewMsg()
local ret = ''
if self.extraConf.previewMsg then
ret = mw.html.create('abbr')
:css('color', 'red')
:css('font-weight', 'bold')
:attr('title', self.extraConf.previewMsg)
:wikitext('!')
ret = tostring(ret) .. ' '
end
return ret
end
Riga 231 ⟶ 260:
urlmorto = self.extraConf.urlmorto[idx] and 'sì' or (self.extraConf.archivio[idx] and 'no')
})
table.insert(formattedLinks, '* ' .. self:_formatPreviewMsg() .. formattedLink ..
mEditAtWikidata._showMessage({ pid = self.linkConf.pid, qid = self.from }))
end
Riga 241 ⟶ 270:
-- @return {string}
function ExtLink:getListItem()
-- restituisce il link se è già stato formattato
if self.extraConf.formattedLink then
return '* ' .. self:_formatPreviewMsg() .. self.extraConf.formattedLink
-- se invece non è specificato l'URL di formattazione presume sia una
-- proprietà di tipo URL e non di tipo "identificativo esterno"
elseif not self.linkConf.url then
return self:_formatPropertyURL()
end
Riga 252 ⟶ 284:
{
url = self.url[i],
titolo = self:_getTitolo(i),
altrilink = self:_getAltriLink(),
sito = self.linkConf.opera and '' or self.extraConf.sito,
Riga 258 ⟶ 290:
editore = self.linkConf.editore,
lingua = self.linkConf.lingua,
cid = self:_getCid(i),
autore = self.linkConf.autore or self.extraConf.autore[i],
volume = self.extraConf.volume[i],
Riga 265 ⟶ 297:
tipo = self.linkConf.tipo or self.sitodis
})
table.insert(formattedLinks, '* ' .. self:_formatPreviewMsg() .. formattedLink ..
mEditAtWikidata._showMessage({ pid = self.linkConf.pid, qid = self.from }))
end
Riga 343 ⟶ 375:
local cfg = readConfig()
local lang = mw.language.getContentLanguage()
local pageContent,
local loadedEntities = setmetatable({}, {
__newindex = function(t1, key, t2)
Riga 361 ⟶ 390:
end
for _, linkConf in ipairs(cfg[groupName]) do -- per ogni sito configurato
local claims, valido, extraConf
-- se il sito non è escluso manualmente dall'utente, avviene la lettura da Wikidata
if not (self:_Escluso(linkConf.pid, self.soloprop) or
Riga 369 ⟶ 398:
-- controlla se ci sono valori
if claims and #claims > 0 then
extraConf = { cid = {}, titolodis = { count = 0 } }
-- controlla se è un sito da escludere per soggetto non pertinente
if type(linkConf.vincolo) == 'table' then
local
for
if i % 2 ~= 0 then
local ms, k = v:match('^(%-?)(.+)$')
if
vincolo, tipo = {}, 'pos'
end
if not (tipo == 'pos' and ms == '-') then
vincolo[k] = linkConf.vincolo[i + 1]
end
end
end
for k, v in pairs(vincolo) do
valido, loadedEntities[k] = checkEntity(k, v, self.from)
if tipo == 'neg' then
valido = not valido
if not valido then break end
elseif valido then
break
end
end
else
Riga 382 ⟶ 427:
-- controlla che il link non sia generato da altri template in voce
if valido and linkConf.template then
if not pageContent then
:gsub('<!%-%-.-%-%->', '')
:gsub('<[Rr][Ee][Ff]%s.-/>', '') -- facilita la ricerca successiva
:gsub('<[Rr][Ee][Ff].->.-</[Rr][Ee][Ff]%s*>', '')
isPreview = mw.getCurrentFrame():preprocess('{{REVISIONID}}') == ''
end
for template in mw.text.gsplit(templateList, ',') do
template = template:gsub(' +', ' +')
local firstChar = template:match('^.')
firstChar = string.format('[%s%s]', firstChar:upper(), firstChar:lower())
if pageContent:match('{{%s*' .. template:gsub('^.', firstChar) .. '%s*[|}]') then
valido, duplicates = isPreview, true
if isPreview then
extraConf.previewMsg = mw.message.newRawMessage(tmpFound, template):plain()
end
break
end
end
if isPreview and not extraConf.previewMsg then
if isSection == nil then
isSection = pageContent:match('^=+[^=\n]+=+ *\n') and true or false
end
if isSection then
templateList = templateList:gsub(',', ', ')
extraConf.previewMsg = mw.message.newRawMessage(tmpSection, templateList):plain()
end
end
end
end
end
-- verifica se deve generare il link con un sottomodulo
-- che può fare a sua volta altri controlli
if valido and linkConf.sottomodulo then
local success, metamodule = pcall(require, 'Modulo:' .. linkConf.sottomodulo)
if success and type(metamodule._main) == 'function' then
extraConf.formattedLink = metamodule._main({
from = self.from,
['mostra errori'] = 'no'
})
end
if extraConf.formattedLink then
claims = {}
else
valido = false
end
end
Riga 396 ⟶ 480:
if valido then
local url = {}
-- per ogni dichiarazione
for i, claim in ipairs(claims) do
Riga 465 ⟶ 548:
catMultiSenzaQual or catLetta
self:_addCategory(linkConf.pid .. tail)
-- per verificare se un sito è ripetuto nel gruppo e necessita di disambiguazione
groupSites[groupName][extraConf.sito] = (groupSites[groupName][extraConf.sito] or 0) + 1
-- conteggio complessivo dei collegamenti
Riga 538 ⟶ 621:
local res = {}
local cfg = readConfig()
local formatString = '<tr><td>[[d:P:%s|%s (%s)]]</td><td>%s</td><td>%s</td><td>%s</td></tr>'
table.sort(orderedGroupNames)
for _, groupName in ipairs(orderedGroupNames) do
local wdLinks = {}
for _, linkConf in ipairs(cfg[groupName]) do
local label = mWikidata._getLabel({ linkConf.pid })
assert(label, string.format(
'Impossibile trovare l\'etichetta della proprietà %s del gruppo %s',
linkConf.pid, groupName))
local templates = {}
for template in string.gmatch(linkConf.template or '', '[^,]+') do
table.insert(templates, '[[t:' .. template .. '|' .. template .. ']]')
end
local wdLink = string.format(formatString,
linkConf.pid,
label,
linkConf.pid,
linkConf.url or '',
linkConf.cid or '',
table.concat(templates, ', '))
table.insert(wdLinks, wdLink)
end
local group
if frame.args[1] == 'modulo' then
group = string.format('* [[Modulo:Collegamenti esterni/%s]] (%s)',
groupName, #wdLinks)
else
local wikitable = mw.html.create('table')
local title = string.format('[[Modulo:Collegamenti esterni/%s|%s]] (%s)',
groupName, groupName, #wdLinks)
wikitable
:addClass('wikitable sortable plainlinks')
:tag('tr')
:tag('th'):wikitext('Proprietà')
:tag('th'):wikitext('Formato URL')
:tag('th'):wikitext('cid')
:tag('th'):wikitext('Template equivalenti')
:allDone()
:wikitext(table.concat(wdLinks))
group = mw.getCurrentFrame():expandTemplate{
title = 'Cassetto',
args = { titolo = title, testo = tostring(wikitable) }
}
end
table.insert(res, group)
end
Riga 562 ⟶ 673:
-- Funzione di utilità per il manuale, verifica l'assenza di proprietà duplicate.
function p.checkdup(frame)
local ids, vin, res = {}, {}, {}
local cfg = readConfig()
for _, groupName in ipairs(orderedGroupNames) do
for _, linkConf in ipairs(cfg[groupName]) do
if vin[linkConf.pid] == nil then
vin[linkConf.pid] = { pos = {}, neg = {} }
end
if vin[linkConf.pid] ~= false and linkConf.vincolo then
duplicate, vin[linkConf.pid].cur = false, {}
local tipo = 'neg'
for i, v in ipairs(linkConf.vincolo) do
if i % 2 ~= 0 then
local ms, p = v:match('^(%-?)(.+)$')
if tipo == 'neg' and ms == '' then
vin[linkConf.pid].cur, tipo = {}, 'pos'
end
if not (tipo == 'pos' and ms == '-') then
for _, q in ipairs(linkConf.vincolo[i + 1]) do
vin[linkConf.pid].cur[p .. q] = true
end
end
end
end
if tipo == 'pos' then
for k in pairs(vin[linkConf.pid].cur) do
for _, t in ipairs(vin[linkConf.pid].pos) do
if t[k] then duplicate = true break end
end
for _, t in ipairs(vin[linkConf.pid].neg) do
if not t[k] then duplicate = true break end
end
end
else
if #vin[linkConf.pid].neg == 1 then
duplicate = true
else
for _, t in ipairs(vin[linkConf.pid].pos) do
for k in pairs(t) do
if not vin[linkConf.pid].cur[k] then
duplicate = true
break
end
end
end
end
end
table.insert(vin[linkConf.pid][tipo], vin[linkConf.pid].cur)
end
if duplicate then
table.insert(res, linkConf.pid)
else
ids[linkConf.pid] = true
if not linkConf.vincolo then vin[linkConf.pid] = false end
end
end
|