Modulo:Interprogetto/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m +table
genera un collegamento per ogni wikisource nella lingua originale di scrittura
Riga 83:
-- ============================================================================================================
local function sort_by_ordine(t1, t2)
if t1.ordine < t2.ordine or t1.ordine == t2.ordine and t1.lingua < t2.lingua then
return true
end
Riga 137:
end
 
function Wikidata_entity:getLanguagegetInterwiki(project, property_language)
local interwiki = { project }
if self.entity.claims and
if self.entity.claims and self.entity.claims[property_language] andthen
for i, claim in ipairs(self.entity.claims[property_language][1]) do
if claim.mainsnak.datavalue.type == 'wikibase-entityid' then
local entityId = 'Q' .. self.entity.claims[property_language][1]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
return { codice = table.insert(interwiki, language_code, nome.. = require('Modulo:Linguaggiwikisource').get_voce(language_code) }
self.lingua[language_code .. 'wikisource'] = language_code
end
end
end
end
end
return nilinterwiki
end
 
Riga 159 ⟶ 165:
-- Carica i collegamenti di un progetto solo se non disambigua o tipo di progetto abilitato in disambigua
if not self.disambigua or cfg.parameters[key_progetto].abilita_in_disambigua then
localfor i, interwiki =in ipairs(self:getInterwiki(progetto.interwiki, progetto.property_language)) do
local sitelink = self.entity:getSitelink(interwiki)
if progetto.property_language then
-- Dà sempre precedenza al sitelink se è una categoria
self.lingua[key_progetto] = self:getLanguage(progetto.property_language)
if sitelink and mw.ustring.find(sitelink, '^Category:') then
interwiki = mw.message.newRawMessage(interwiki, { self.lingua[key_progetto].codice }):plain()
-- 'false' disabilita la consultazione della proprietà
end
self.from_property_category[key_progetto] = false
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_progetto] = false
end
local claim
if progetto.property_category and self.from_property_category[key_progetto] ~= false then
claim = self:getClaim(progetto.property_category)
if claim then
self.collegamenti[key_progetto] = 'Category:' .. claim
self.from_property_category[key_progetto] = true
end
end local claim
if progetto.property_category and self.from_property_category[key_progetto] ~= false then
if sitelink then
claim = self:getClaim(progetto.property_category)
if self.from_property_category[key_progetto] then
local if claim then
self.article_link[key_progetto] = sitelink
elseif self.linguacollegamenti[key_progetto] then= 'Category:' .. claim
self.collegamentifrom_property_category[key_progetto] = string.format('%s:%s', self.lingua[key_progetto].codice, sitelink)true
else end
self.collegamenti[key_progetto] = sitelink
end
if self.entity.sitelinks[interwiki].badgessitelink then
if self.from_property_category[key_progetto] = truethen
local badge_class = {}
self.article_link[key_progetto] = sitelink
local badge_title = {}
forelseif _, badge_quality in ipairs(self.entity.sitelinkslingua[interwiki].badges) dothen
iflocal cfglingua = self.badgeslingua[badge_qualityinterwiki] then
key_progetto = string.format('%s_%s', key_progetto, lingua)
badge_class[#badge_class+1] = cfg.badges[badge_quality].class
self.lingua[key_progetto] = self:getLanguage(progetto.property_language)lingua
badge_title[#badge_title+1] = cfg.badges[badge_quality].title
self.collegamenti[key_progetto] = string.format('%s:%s', lingua, sitelink)
else
self.collegamenti[key_progetto] = 'Category:' .. claimsitelink
end
if self.entity.sitelinks[interwiki].badges and not self.lingua[interwiki] 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
if self.from_property_categorybadge[key_progetto] then= {}
self.badge[key_progetto].class = table.concat(badge_class, ' ' )
self.badge[key_progetto].title = table.concat(badge_title, ', ' )
end
elseif not self.badgeis_category and progetto.property_gallery and not self.from_property_category[key_progetto] = {}then
claim = self:getClaim(progetto.property_gallery)
self.badge[key_progetto].class = table.concat(badge_class, ' ' )
self.badgecollegamenti[key_progetto].title = table.concat(badge_title, ', ' )claim
end
elseif not self.is_category and progetto.property_gallery and not self.from_property_category[key_progetto] then
claim = self:getClaim(progetto.property_gallery)
self.collegamenti[key_progetto] = claim
end
end
Riga 252 ⟶ 258:
setmetatable(self, { __index = Collegamento,
__tostring = function(t) return self:__tostring() end })
local default_progetto = cfg.parameters[key_progetto:match('^[^_]+')]
if default_progetto == nil then
-- Progetto non riconosciuto
Riga 262 ⟶ 268:
return nil
else
self.key_progetto = key_progetto:match('^[^_]+')
self.ordine = default_progetto.ordine
self.badge_leftbar = {}
Riga 288 ⟶ 294:
self.testo_dopo = ' <small>' .. args.data .. '</small>'
end
local lingua = entity.lingua[key_progetto] and require('Modulo:Linguaggi').get_voce(entity.lingua[key_progetto].nome) or
args[key_progetto .. '_lingua'] and 'lingua ' .. args[key_progetto .. '_lingua']
if default_progetto.lingua and lingua then
Riga 607 ⟶ 613:
-- ====================================================================================================
for key_progetto, collegamento in pairs(entity.collegamenti) do
if not newArgs[key_progetto] and not (cfg.automatic_link[key_progetto] and cfg.automatic_link[key_progetto].alias and newArgs[cfg.automatic_link[key_progetto].alias]) then
newArgs[key_progetto] = collegamento
-- Segnala che il collegamento è stato aggiunto da Wikidata
add_category(cfg.automatic_link[key_progetto:match('^[^_]+')].category_wikidata)
end
end
Riga 620 ⟶ 626:
local collegamento_found = false
for key_progetto, collegamento in pairs(newArgs) do
if cfg.parameters[key_progetto:match('^[^_]+')] then
-- Salta i collegamenti a Wikidata per le voci nel namespace principale eccetto che per la Pagina principale
if key_progetto ~= 'wikidata' or current_namespace ~= 0 or current_pagename == 'Pagina principale' then
Riga 631 ⟶ 637:
if progetto then
progetti[#progetti+1] = progetto
add_category(cfg.parameters[key_progetto].categoria)
end
end