Modulo:Interprojeto
--[[categoria:Modełi - Wikidata]]
-- Modulo per implementare le funzionalità di template:Interprojeto
require('strict')
local p = {} -- per l'esportazione delle funzioni del modulo
local cfg = {}
local root = mw.html.create('') -- radice del markup html
local debug = {} -- per debug
local categories = {} -- categorie di errore da aggiungere
local errors_msg = {} -- messaggi di errore da aggiungere
-- per non usare numeri "magici" nel codice
local category_namespace_number = 14
-- ============================================================================================================
-- Ritorna la stringa se è definita e diversa da stringa vuota, altrimenti nil
-- ============================================================================================================
local function is_defined(s)
if s and s ~= '' then
return s
else
return nil
end
end
-- ============================================================================================================
-- Aggiunge uno spazio alla stringa se non termina per "'" (apostrofo)
-- ============================================================================================================
local function add_space(s)
if not is_defined(s) then
return ''
elseif mw.ustring.sub(s, -1) == "'" then
return s
else
return s .. ' '
end
end
-- ============================================================================================================
-- Aggiunge la categoria "category" alla lista di categorie da aggiungere alla voce
-- ============================================================================================================
local function add_category(category)
if category then
categories[category] = true
end
end
-- ============================================================================================================
-- Aggiunge il messaggio di errore "error_msg" alla lista di messaggi di errore da visualizzare.
-- Se viene precisata una categoria di errore la aggiunge alle categorie in cui inserire la voce,
-- altrimenti inserisce la categoria di errore standard
-- ============================================================================================================
local function add_error(error_msg, category)
if error_msg then
errors_msg[#errors_msg+1] = error_msg
if category then
add_category(category)
else
add_category('Erore de conpi')
end
end
end
-- ============================================================================================================
-- Ritorna un collegamento di default dato il nome di un projeto, nil in caso di errori
-- ============================================================================================================
local function get_default_collegamento(key_projeto, fullpagename)
if cfg.parameters[key_projeto] then
if cfg.parameters[key_projeto]['collegamento_non_esistente'] then
add_error(cfg.parameters[key_projeto]['collegamento_non_esistente'])
return nil
elseif cfg.parameters[key_projeto].collegamento_default_minuscolo then
return mw.ustring.gsub(fullpagename, '^%u', string.lower)
else
return fullpagename
end
else
return nil
end
end
-- ============================================================================================================
-- Ordina una tabella in funzione della chiave "ordene" degli elementi della tabella
-- ============================================================================================================
local function sort_by_ordene(t1, t2)
if t1.ordene < t2.ordene or t1.ordene == t2.ordene and t1.lengua < t2.lengua then
return true
end
end
-- ============================================================================================================
-- Classe per gestire la raccolta di informazioni da Wikidata
-- ============================================================================================================
local Wikidata_entity = {}
function Wikidata_entity:new(ignore_wikidata)
-- Carica i dati da Wikidata se esistono
local self = {}
if not ignore_wikidata then
self.entity = mw.wikibase.getEntityObject()
end
setmetatable(self, { __index = Wikidata_entity,
__tostring = function(t) return self:__tostring() end })
self.collegamenti = {}
self.badge = {}
self.from_property_category = {}
self.article_link = {}
self.lengua = {}
if self.entity then
self.targheta = self.entity:getLabel('vec')
-- Imposta il corsivo se la pagina su Wikidata ha la proprietà P31 ("Istance of", [[wikidata:Property:P31]])
-- con valore corrispondente a un'opera, come definito in cfg.check_opera
self.corsivo = self:hasPropertyValue('P31', cfg.check_opera)
-- Considera disambigua se la pagina su Wikidata ha la proprietà P31 ("Istance of", [[wikidata:Property:P31]])
-- con valore 4167410 ("Wikimedia disambiguation page", [[wikidata:Q4167410]])
self.disambigua = self:hasPropertyValue('P31', '4167410')
-- Controlla se la voce è relativa a una categoria
self.is_category = self:hasPropertyValue('P31', '4167836')
self:loadCollegamenti()
end
return self
end
function Wikidata_entity:getClaim(property_id)
if self.entity.claims and
self.entity.claims[property_id] and
self.entity.claims[property_id][1].mainsnak.datavalue.type == 'string' then
return self.entity.claims[property_id][1].mainsnak.datavalue.value
else
return nil
end
end
function Wikidata_entity:getInterwiki(project, property_language)
local interwiki = { project }
if property_language and self.entity.claims and self.entity.claims[property_language] then
project = project:sub(3)
for _, claim in ipairs(self.entity.claims[property_language]) do
if claim.mainsnak.datavalue.type == 'wikibase-entityid' then
local entityId = 'Q' .. claim.mainsnak.datavalue.value['numeric-id']
if entityId ~= 'Q652' then
local claims = mw.wikibase.getBestStatements(entityId, 'P424')
local language_code = claims[1] and claims[1].mainsnak.datavalue.value
if language_code then
if project == 'wikisource' and language_code == 'grc' then
language_code = 'el'
end
table.insert(interwiki, language_code .. project)
self.lengua[language_code .. project] = language_code
end
end
end
end
end
return interwiki
end
-- ============================================================================================================
-- Carica collegamenti e badge da Wikidata controllando i progetti elencati in cfg.automatic_link
-- ============================================================================================================
function Wikidata_entity:loadCollegamenti()
for key_projeto, projeto in pairs(cfg.automatic_link) do
-- Carica i collegamenti di un projeto solo se non disambigua o tipo di projeto abilitato in disambigua
if not self.disambigua or cfg.parameters[key_projeto].abilita_in_disambigua then
for i, interwiki in ipairs(self:getInterwiki(projeto.interwiki, projeto.property_language)) do
local sitelink = self.entity:getSitelink(interwiki)
-- Dà sempre precedenza al sitelink se è una categoria
if sitelink and mw.ustring.find(sitelink, '^Category:') then
-- 'false' disabilita la consultazione della proprietà
self.from_property_category[key_projeto] = false
end
local claim
if projeto.property_category and self.from_property_category[key_projeto] ~= false then
claim = self:getClaim(projeto.property_category)
if claim then
self.collegamenti[key_projeto] = 'Category:' .. claim
self.from_property_category[key_projeto] = true
end
end
if sitelink then
if self.from_property_category[key_projeto] then
self.article_link[key_projeto] = sitelink
elseif i > 1 then
local lengua = self.lengua[interwiki]
key_projeto = string.format('%s_%s', key_projeto, lengua)
self.lengua[key_projeto] = lengua
self.collegamenti[key_projeto] = string.format('%s:%s', lengua, sitelink)
else
self.collegamenti[key_projeto] = sitelink
end
if i == 1 and self.entity.sitelinks[interwiki].badges then
local badge_class = {}
local badge_title = {}
for _, badge_quality in ipairs(self.entity.sitelinks[interwiki].badges) do
if cfg.badges[badge_quality] then
badge_class[#badge_class+1] = cfg.badges[badge_quality].class
badge_title[#badge_title+1] = cfg.badges[badge_quality].title
end
end
self.badge[key_projeto] = {}
self.badge[key_projeto].class = table.concat(badge_class, ' ' )
self.badge[key_projeto].title = table.concat(badge_title, ', ' )
end
elseif not self.is_category and projeto.property_gallery and not self.from_property_category[key_projeto] then
claim = self:getClaim(projeto.property_gallery)
self.collegamenti[key_projeto] = claim
end
end
end
end
end
-- ============================================================================================================
-- Verifica se una determinata proprietà ha uno dei valori specificati nella lista "values".
-- Riadattata da "hasPropertyValue" su [[wikiquote:vec:Modulo:Interprojeto]] a sua volta
-- riadattata da "instanceof(arg)" su [[wikisource:vec:Modulo:Autore]]
-- ============================================================================================================
function Wikidata_entity:hasPropertyValue(propertyId, values)
if self.entity.claims and self.entity.claims[propertyId] then
for _, claim in ipairs(self.entity.claims[propertyId]) do
if claim.mainsnak.datavalue.value then
local datavalue = claim.mainsnak.datavalue
if datavalue.type == 'wikibase-entityid' and
datavalue.value['entity-type'] == 'item' and
(type(values) == 'table' and values[tostring(datavalue.value['numeric-id'])]) or
values == tostring(datavalue.value['numeric-id']) then
return true
end
end
end
end
return false
end
-- ============================================================================================================
-- Fine definizione della classe Wikidata_entity
-- ============================================================================================================
-- ============================================================================================================
-- Classe per gestire i collegamenti interprojeto
-- ============================================================================================================
local Collegamento = {}
function Collegamento:new(key_projeto, args, entity, default)
-- Crea un collegamento a un projeto, riceve il nome del projeto, gli argomenti da usare per determinare
-- i valori dei vari parametri del collegamento. Si appoggia alla tabella esterna cfg.parameters per i
-- valori di default del projeto e alla tabella globale default per i valori di default generali
local self = {}
setmetatable(self, { __index = Collegamento,
__tostring = function(t) return self:__tostring() end })
local default_projeto = cfg.parameters[key_projeto:match('^[^_]+')]
if default_projeto == nil then
-- projeto non riconosciuto
return nil
end
self.collegamento = args[key_projeto]
if not is_defined(self.collegamento) then
-- Collegamento non definito correttamente
return nil
else
self.default_projeto = default_projeto
self.ordene = default_projeto.ordene
self.badge_leftbar = {}
self.badge_leftbar.class = (entity.badge[key_projeto] and entity.badge[key_projeto].class) or ''
self.badge_leftbar.title = (entity.badge[key_projeto] and entity.badge[key_projeto].title) or ''
self.targheta = is_defined(args[key_projeto .. '_targheta']) or (default_projeto.targheta_lower and default.targheta_lower) or default.targheta
-- elabora l'ojeto per i testi completi su wikisource quando il collegamento è ricavato da wikidata e il parametro testo_prepoxision è compilato
local alias_s_ojeto = key_projeto == 's' and args.testo_prepoxision and not args.orig_s and not args.s_prepoxision and cfg.parameters['testo'].ojeto
self.ojeto = args[key_projeto .. '_ojeto'] or alias_s_ojeto or default.ojeto or default_projeto.ojeto
if default.frase_unificata or default_projeto.prepoxision then
-- consulta il parametro testo_prepoxision se il collegamento a wikisource non è manuale
local alias_s_prepoxision = key_projeto == 's' and not args.orig_s and args.testo_prepoxision
self.prepoxision = args[key_projeto .. '_prepoxision'] or alias_s_prepoxision or default.prepoxision or default_projeto.prepoxision
else
self.prepoxision = ''
end
if default.frase_unificata then
self.testo_prima = ''
self.testo_dopo = ''
else
self.testo_prima = default_projeto.testo_prima
self.testo_dopo = default_projeto.testo_dopo
end
if key_projeto == 'notizia' and is_defined(args.data) then
self.testo_dopo = ' <small>' .. args.data .. '</small>'
end
local lengua = key_projeto == 's_el' and 'lengua greca' or
entity.lengua[key_projeto] and require('Modulo:Łénguaji').get_voce(entity.lengua[key_projeto]) or
args[key_projeto .. '_lengua'] and 'lengua ' .. args[key_projeto .. '_lengua']
if default_projeto.lengua and lengua then
self.lengua = ' in ' .. lengua
else
self.lengua = ''
end
return self
end
end
function Collegamento:Link()
local default_projeto = self.default_projeto
if default_projeto.link == 'Link' then
return self:Link_text()
elseif default_projeto.link == 'LinkWithLanguage' then
return self:Link_language()
elseif default_projeto.link == 'LinkRicette' then
return self:Link_ricette()
elseif default_projeto.link == 'LinkIncubator' then
return self:Link_incubator()
end
add_error('Eror interior mòduło Interprojeto')
return ''
end
function Collegamento:Link_lb()
local default_projeto = self.default_projeto
if default_projeto.link == 'Link' then
return self:Link_text_lb()
elseif default_projeto.link == 'LinkWithLanguage' then
return self:Link_language_lb()
elseif default_projeto.link == 'LinkRicette' then
return self:Link_text_lb()
elseif default_projeto.link == 'LinkIncubator' then
return self:Link_incubator_lb()
end
add_error('Eror interior mòduło Interprojeto')
return ''
end
function Collegamento:Link_text()
local default_projeto = self.default_projeto
return "* [[File:", default_projeto.icona, "|link=", default_projeto.prefix, "|", default_projeto.grandesa_icona, "|Cołaborea a ",
default_projeto.nome_projeto, "]] [[", default_projeto.prefix, "|", default_projeto.nome_projeto, "]] el detien ",
self.ojeto, self.lengua, " ", add_space(self.prepoxision), self.testo_prima, "'''[[", default_projeto.prefix,
self.collegamento, "|", self.targheta, "]]'''", self.testo_dopo
end
function Collegamento:Link_text_lb()
local default_projeto = self.default_projeto
return "[[", default_projeto.prefix, self.collegamento, "|", default_projeto.nome_leftbar or default_projeto.nome_projeto, "]]"
end
function Collegamento:Link_ricette()
local default_projeto = self.default_projeto
return "* [[File:", default_projeto.icona, "|link=", default_projeto.prefix, "|", default_projeto.grandesa_icona,
"|Cołaborea a ", default_projeto.nome_projeto, "]] Il ''[[b:Libro di cucina|Libro di cucina]]'' di [[b:|Wikibooks]] el detien '''[[",
default_projeto.prefix, self.collegamento, "|ricette]]''' relative a questo argomento"
end
function Collegamento:Link_language()
local default_projeto = self.default_projeto
local main_page_link = tostring(mw.uri.fullUrl(default_projeto.prefix, {uselang='en'}))
return "* [[File:", default_projeto.icona, "|link=", main_page_link, "|", default_projeto.grandesa_icona, "|Cołaborea a ",
default_projeto.nome_projeto, "]] <span class=\"plainlinks\">[", main_page_link, " ", default_projeto.nome_projeto,
"]</span> el detien ", self.ojeto, " ", add_space(self.prepoxision), self.testo_prima,
"'''<span class=\"plainlinks\">[", tostring(mw.uri.fullUrl(default_projeto.prefix .. self.collegamento, {uselang='vec'})),
" ", self.targheta, "]</span>'''", self.testo_dopo
end
function Collegamento:Link_language_lb()
local default_projeto = self.default_projeto
return "<span class=\"plainlinks\" title=\"", default_projeto.prefix , self.collegamento, "\">[",
tostring(mw.uri.fullUrl(default_projeto.prefix .. self.collegamento, {uselang='vec'})), " ",
default_projeto.nome_leftbar or default_projeto.nome_projeto, "]</span>"
end
function Collegamento:Link_incubator()
local default_projeto = self.default_projeto
local ojeto = self.ojeto
if not cfg.prefix_incubator[ojeto] then
ojeto = default_projeto.ojeto
end
local collegamento = tostring(mw.uri.fullUrl(table.concat({'incubator:', cfg.prefix_incubator[ojeto],
'/', self.collegamento}), {uselang='vec'}))
local main_page_incubator = tostring(mw.uri.fullUrl('incubator:Incubator:Main Page/vec', {uselang='vec'}))
local main_page_projeto = ''
if ojeto == 'wikipedia' then
main_page_projeto = '[[Wikipedia]]'
else
main_page_projeto = table.concat({'[[', ojeto, ':vec:|', ojeto:gsub('^%l', string.upper), ']]'})
end
return "* [[File:", default_projeto.icona, "|link=", main_page_incubator, "|", default_projeto.grandesa_icona,
"|Collabora a Incubator]] <span class=\"plainlinks\">[", main_page_incubator, " Incubator]</span> el detien un tèst",
main_page_projeto, self.lengua, " ", add_space(self.prepoxision), "'''<span class=\"plainlinks\">[", collegamento, " ", self.targheta, "]</span>'''"
end
function Collegamento:Link_incubator_lb()
local default_projeto = cfg.parameters[self.key_projeto]
local ojeto = self.ojeto
if not cfg.prefix_incubator[ojeto] then
ojeto = default_projeto.ojeto
end
local collegamento = tostring(mw.uri.fullUrl(table.concat({'incubator:', cfg.prefix_incubator[ojeto],
'/', self.collegamento}), {uselang='en'}))
return mw.message.newRawMessage("<span class=\"plainlinks\" title=\"$1\">[$2 Incubator]</span>", {self.targheta, collegamento}):plain()
end
-- ============================================================================================================
-- Fine definizione della classe Collegamento
-- ============================================================================================================
-- ============================================================================================================
-- Scandisce la tabella progetti e produce il codice html per l'elenco dei collegamenti nella barra di sinistra
-- Imposta il tag div id="interProject" (vedi [[MediaWiki:InterProject.js]] incluso da [[Mediawiki:Common.js]])
-- ============================================================================================================
local function RenderLeftBar(progetti)
local leftbar = mw.html.create('ul'):attr('title', 'Collegamenti verso gli altri progetti Wikimedia')
for _, projeto in ipairs(progetti) do
leftbar:newline()
leftbar:wikitext('<li class=\"', projeto.badge_leftbar.class, '\" title=\"', projeto.badge_leftbar.title, '\">')
leftbar:wikitext(projeto:Link_lb())
if projeto.default_projeto.nome_leftbar then
leftbar:wikitext('<br />(', projeto.default_projeto.nome_projeto, ')')
end
leftbar:wikitext('</li>')
end
root:tag('div')
-- :attr('id', 'interProject')
:addClass('toccolours')
:cssText('display: none; clear: both; margin-top: 2em')
:tag('p')
-- :attr('id', 'sisterProjects')
:cssText('background-color: #efefef; font-weight: bold; margin: 0')
:tag('span')
:wikitext('Altri progetti')
:done()
:done()
:node(leftbar)
end
-- ============================================================================================================
-- Scandisce la tabella progetti e produce il codice html per l'elenco puntato dei collegamenti interprojeto
-- ============================================================================================================
local function RenderLinksInText(progetti)
for _, projeto in ipairs(progetti) do
root:newline()
root:wikitext(projeto:Link())
end
end
-- ============================================================================================================
-- Confronta i collegamenti manuali con quelli automatici e genera le categorie di classificazione nei casi di:
-- - Presenza di link manuale e assenza di link su wikidata
-- - Differenza tra link manuale e link su wikidata
-- - Differenza tra link manuale a categoria e e categoria su wikidata
-- - Presenza di link manuale a categoria e a catagoria su wikidata
-- ============================================================================================================
local function check_with_wikidata(key_projeto, entity, collegamento)
if collegamento == nil then return end -- se non c'è un collegamento manuale ritorna immediatamente
local entity_collegamento = entity.collegamenti[key_projeto]
-- si assicura che il collegamento manuale inizi con la 'C' maiuscola se è una categoria
local collegamento_normalizzato = mw.ustring.gsub(collegamento, '^category:', 'Category:')
local collegamento_is_category = mw.ustring.find(collegamento_normalizzato, '^Category:')
-- Check se il collegamento manuale è una categoria, se il tipo di projeto prevede una proprietà a parte
-- per le categorie e se la sua consultazione non è stata disabilitata
if collegamento_is_category and cfg.automatic_link[key_projeto].property_category and entity.from_property_category[key_projeto] ~= false then
-- se esiste un collegamento su wikidata dalla proprietà per la categoria la confronta con quello manuale
if entity.from_property_category[key_projeto] then
if entity_collegamento ~= collegamento_normalizzato then
add_category(cfg.automatic_link[key_projeto].category_wikidata_category_diff)
end
-- se non esiste un collegamento manuale su wikidata lo marca come assente
else
add_category(cfg.automatic_link[key_projeto].category_wikidata_category_missing)
end
else
local article_link
-- recupera il collegamento automatico alla voce (può essere in entity.article_link[key_projeto] o
-- in entity.collegamento[key_projeto] a seconda del sitelink e della proprietà per le categorie)
if entity.from_property_category[key_projeto] then
article_link = entity.article_link[key_projeto]
else
article_link = entity_collegamento
end
-- Se ha recuperato un valore per article_link lo confronta con quello normalizzato
-- altrimenti aggiunge il tracking di collegamento mancante in wikidata
if article_link then
if article_link ~= collegamento_normalizzato then
add_category(cfg.automatic_link[key_projeto].category_wikidata_diff)
end
else
add_category(cfg.automatic_link[key_projeto].category_wikidata_missing)
end
end
end
-- ============================================================================================================
-- Funzione principale richiamata dal template Interprojeto
-- ============================================================================================================
function p.interprojeto(frame)
-- se chiamata da una sandbox carica la configurazione della sandbox
if nil ~= string.find (frame:getTitle(), 'sandbox', 1, true) then
cfg = mw.loadData('Module:Interprojeto/Configurasion/sandbox')
else
cfg = mw.loadData('Module:Interprojeto/Configurasion')
end
local origArgs
-- ========================================================================================================
-- Se chiamata mediante #invoke, usa gli argomenti passati al template invocante.
-- Altrimenti a scopo di test assume che gli argomenti siano passati direttamente
-- ========================================================================================================
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame
end
-- Tabella con i parametri di default valorizzati
local default = {}
-- ========================================================================================================
-- Carica il nome della pagina corrente
-- ========================================================================================================
local current_page = mw.title.getCurrentTitle()
local current_namespace = current_page.namespace
local current_pagename = current_page.text
-- Per i namespace usa il nome canonico (inglese) per non avere differenze tra progetti:
-- esempio: Utente/User, Categoria/Category, ma anche Wikiquote/Wikipedia (Project), ecc.
if current_namespace ~= 0 then
default.current_fullpagename = mw.site.namespaces[current_namespace].canonicalName .. ':' .. current_pagename
else
default.current_fullpagename = current_pagename
end
-- ========================================================================================================
-- Carica i dati da Wikidata nell'ojeto "entity"
-- ========================================================================================================
local ignore_wikidata = false
local nowikidata = origArgs.nowikidata and origArgs.nowikidata:lower()
if nowikidata == 's' or nowikidata == 'sì' or nowikidata == 'si' then
ignore_wikidata = true
end
local entity = Wikidata_entity:new(ignore_wikidata)
-- ========================================================================================================
-- Calcola l'targheta di default per i collegamenti, in ordene di priorità:
-- 1) Se è definita l'targheta in lengua italiana su Wikidata usa questa (eliminando un eventuale
-- "Categoria:" di fronte alla voce)
-- 2) Altrimenti usa il nome della pagina corrente, eliminando un'eventuale disambigua in coda alla voce,
-- e definisce targheta_lower come il nome della voce con iniziale minuscola.
-- Se la voce è segnalata come opera su Wikidata allora l'targheta è in corsivo (senza iniziale minuscola)
-- ========================================================================================================
if is_defined(origArgs.targheta) then
default.targheta = origArgs.targheta
else
if entity.targheta then
-- Elimina un eventuale "Categoria:" in fronte del nome
default.targheta = mw.ustring.gsub(entity.targheta, '^Categoria:', '')
else
-- Elimina un'eventuale disambigua dal nome
default.targheta = mw.ustring.gsub(current_pagename, ' %(.*%)$', '')
if current_namespace == 0 then
default.targheta_lower = mw.ustring.gsub(default.targheta, '^%u', string.lower)
end
end
if entity.corsivo then
default.targheta = '<span style=\"font-style:italic;\">' .. default.targheta .. '</span>'
default.targheta_lower = default.targheta
end
end
-- ========================================================================================================
-- Calcola prepoxision e ojeto di default, modificandoli se il namespace quello delle categorie
-- ========================================================================================================
if current_namespace ~= category_namespace_number then
default.prepoxision = origArgs.prepoxision
default.ojeto = origArgs.ojeto
else
default.prepoxision = origArgs.prepoxision or "so l'argomento"
default.ojeto = origArgs.ojeto or "una categoria"
default.frase_unificata = true
end
-- ========================================================================================================
-- Copia i parametri in una nuova tabella, creando coppie projeto/collegamento per i parametri posizionali
-- e controllando per parametri duplicati e nomi di projeto non conosciuti
-- ========================================================================================================
local newArgs = {}
local nolink = false
newArgs.orig_s = origArgs.s
for key, value in pairs(origArgs) do
if tonumber(key) then
local key_projeto = mw.text.trim(value)
if cfg.parameters[key_projeto] then
if origArgs[key_projeto] then
add_error('Ligamento a \"' .. value .. '\" scrivesto sia cofà paràmatro poxisionałe sia cofà nomenałe')
else
if key_projeto == 's' then newArgs.orig_s = key_projeto end
newArgs[key_projeto] = get_default_collegamento(key_projeto, default.current_fullpagename)
end
else
if key == 1 and key_projeto == 'nolink' then
nolink = true
end
end
else
newArgs[key] = value
end
end
-- ========================================================================================================
-- Controlla i collegamenti inseriti manualmente integrandoli eventualmente con quelli presenti in Wikidata.
-- Salta questo passo se c'è un collegamento a "notizia" dato che in questo caso deve essere unico e quindi
-- non deve aggiungere i collegamenti da Wikidata. Inoltre, in caso di "disambigua", salta i progetti non
-- abilitati in disambigua che in ogni caso non devono essere aggiunti
-- ========================================================================================================
if not newArgs.notizia then
-- ====================================================================================================
-- Controlla il collegamento compilato manualmente e quello caricato da Wikidata
-- ====================================================================================================
for key_projeto, collegamento in pairs(newArgs) do
if cfg.parameters[key_projeto] and cfg.automatic_link[key_projeto] and entity.entity then
if not entity.disambigua or cfg.parameters[key_projeto].abilita_in_disambigua then
check_with_wikidata(key_projeto, entity, collegamento)
end
end
end
-- ====================================================================================================
-- Aggiunge il collegamento da Wikidata se non è presente quello compilato manualmente o se rinvia a
-- un projeto in lengua non italiana che non è registrato nella configurazione e non va sovrascritto
-- ====================================================================================================
for key_projeto, collegamento in pairs(entity.collegamenti) do
if not cfg.automatic_link[key_projeto] or not (newArgs[key_projeto] or newArgs[cfg.automatic_link[key_projeto].alias]) then
newArgs[key_projeto] = collegamento
-- Segnala che il collegamento è stato aggiunto da Wikidata
add_category(cfg.automatic_link[key_projeto:match('^[^_]+')].category_wikidata)
end
end
end
-- ========================================================================================================
-- Sulla base della lista di argomenti ripulita costruisce la lista dei collegamenti da inserire
-- ========================================================================================================
local progetti = {}
local collegamento_found = false
for key_projeto, collegamento in pairs(newArgs) do
if cfg.parameters[key_projeto] or entity.collegamenti[key_projeto] then
-- Salta i collegamenti a Wikidata per le voci nel namespace principale eccetto che per la Pagina principale
if key_projeto ~= 'wikidata' or current_namespace ~= 0 or current_pagename == 'Pagina principale' then
local projeto = Collegamento:new(key_projeto, newArgs, entity, default)
if projeto then
collegamento_found = true
-- Se è disambigua registra solo i valori per i progetti abilitati in disambigua
if not entity.disambigua or cfg.parameters[key_projeto] and cfg.parameters[key_projeto].abilita_in_disambigua then
progetti[#progetti+1] = projeto
end
end
end
end
end
table.sort(progetti, sort_by_ordene)
-- ========================================================================================================
-- Genera il codice html
-- ========================================================================================================
if entity.disambigua and #progetti == 0 and collegamento_found then
add_error('Ligaminti no vixuałixàbiłi parché ła voxe so Wikidata ła xe na dexanbìgua',
'Eror de conpiłasion del modeło Interprojeto - Ligaminti in dexanbìgua')
elseif #progetti == 0 then
--add_error('Template interprojeto vuoto e senza dati da recuperare da Wikidata', 'Errri di conpiłamento del modeło Interprojeto - Modeło vodo')
add_error('', 'Voxe co modeło interprojeto vodo')
else
local nobarra = origArgs.nobarra and origArgs.nobarra:lower()
if nobarra ~= 's' and nobarra ~= 'sì' and nobarra ~= 'si' then
RenderLeftBar(progetti)
end
if not nolink then
RenderLinksInText(progetti)
end
end
-- =================================================================================================================================
-- Nei namespace ammessi inserisce le categorie di segnalazione di errori/avvisi
-- =================================================================================================================================
if cfg.whitelist_category[current_namespace] then
for category, _ in pairs(categories) do
root:wikitext('[[Categoria:' .. category .. ']]')
end
end
-- =================================================================================================================================
-- Aggiunge i messaggi di errore
-- =================================================================================================================================
if #errors_msg > 0 then
if #progetti > 0 then
root:wikitext('\n')
end
root:wikitext('<strong class=\"error\">' .. table.concat(errors_msg, '; ') .. '</strong>')
end
return tostring(root)
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve









