Modulo:Collegamenti esterni: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
correggo cid come da discussione
aggiungo gruppo "Gastronomia"
 
(8 versioni intermedie di 2 utenti non mostrate)
Riga 3:
]]--
 
require('Modulo:No globalsstrict')
 
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 218 ⟶ 221:
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 244 ⟶ 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 254 ⟶ 270:
-- @return {string}
function ExtLink:getListItem()
-- restituisce il link se è già stato formattato
-- se è specificato l'URL di formattazione è una
if self.extraConf.formattedLink then
-- proprietà di tipo "identificativo esterno" altrimenti di tipo URL
return '* ' .. self:_formatPreviewMsg() .. self.extraConf.formattedLink
if not self.linkConf.url then
-- 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 278 ⟶ 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 356 ⟶ 375:
local cfg = readConfig()
local lang = mw.language.getContentLanguage()
local pageContent, =isPreview, mw.title.getCurrentTitle():getContent()isSection
:gsub('<!%-%-.-%-%->', '')
:gsub('<[Rr][Ee][Ff]%s.-/>', '') -- facilita la ricerca successiva
:gsub('<[Rr][Ee][Ff].->.-</[Rr][Ee][Ff]%s*>', '')
local loadedEntities = setmetatable({}, {
__newindex = function(t1, key, t2)
Riga 374 ⟶ 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 382 ⟶ 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
Riga 410 ⟶ 427:
-- controlla che il link non sia generato da altri template in voce
if valido and linkConf.template then
forlocal templatetemplateList in= mw.text.gsplit(linkConf.template, ',') do
template = mw.text.trim:gsub(template'%s*,%s*', ','):gsub(' ,+', ','):gsub('^,', +''):gsub(',$', '')
localif first_chartemplateList ~= template:match('^.') then
if not pageContent then
first_char = string.format('[%s%s]', first_char:upper(), first_char:lower())
if pageContent:match('{{%s*' = mw.title. templategetCurrentTitle():gsubgetContent('^.', first_char) .. '%s*[|}]') then
:gsub('<!%-%-.-%-%->', '')
valido, duplicates = false, true
:gsub('<[Rr][Ee][Ff]%s.-/>', '') -- facilita la ricerca successiva
break
: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 424 ⟶ 480:
if valido then
local url = {}
local extraConf = { cid = {}, titolodis = { count = 0 } }
-- per ogni dichiarazione
for i, claim in ipairs(claims) do
Riga 493 ⟶ 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 566 ⟶ 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 })
local wdLink = string.format('<tr><td>[[d:Property:%s|%s (%s)]]</td><td>%s</td><td>%s</td><td>%s</td></tr>',
assert(label, string.format(
linkConf.pid, mWikidata._getLabel({ linkConf.pid }), linkConf.pid, linkConf.url or '', linkConf.cid or '', linkConf.template and ('[[t:'..linkConf.template..'|'..linkConf.template..']]') or '')
'Impossibile trovare l\'etichetta della proprietà %s del gruppo %s',
table.insert(wdLinks, wdLink)
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 = frame.args[1] == 'modulo' and
local group
string.format('* [[Modulo:Collegamenti esterni/%s]] (%s)', groupName, #wdLinks) or
if frame.args[1] == 'modulo' then
mw.getCurrentFrame():expandTemplate {
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) }
titolo = string.format('[[Modulo:Collegamenti esterni/%s|%s]] (%s)', groupName, groupName, #wdLinks),
testo = '<table class="wikitable sortable plainlinks"><tr><th>Proprietà</th><th>Formato URL</th><th>cid</th><th>Template singolo</th></tr>' .. table.concat(wdLinks, '') .. '</table>'
}
}
end
table.insert(res, group)
end