Modulo:Software: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
separato p.categories() con p.wikidataCategories() e aggiunto p.wikidataCategoriesFromMainTopic() per #Categorizzare le categorie
disattivo categorie al di fuori del NS0
 
(39 versioni intermedie di 7 utenti non mostrate)
Riga 11:
 
local MAX_RECURSION = 4 -- [[Modulo:Software/man#Considerazioni implementative]]
 
local UNKNOWN_WD_LANGUAGE = "[[Categoria:Linguaggio di programmazione da Wikidata non previsto]]"
local UNKNOWN_WD_LICENSE = ""
local UNKNOWN_WD_TOOLKIT = "[[Categoria:Toolkit o framework dell'interfaccia grafica non previsto]]"
local FREE_WITHOUT_LANGUAGE = '[[Categoria:Software libero senza linguaggio]]'
 
local TEMPLATE_UNKNOWN_ARG_WARN = "&nbsp;<span style=\"font-size:75%\">(non&nbsp;in&nbsp;[[Template:Software#Linguaggi|lista]])</span>"
local TEMPLATE_UNKNOWN_ARG_CAT = "[[Categoria:Software in linguaggio non riconosciuto]]"
 
local LICENSE_CAT = "Software con licenza %s"
-- "Software con licenza GNU GPL"
 
local LICENSE_CAT_SHORTER = "Software %s"
-- "Software freeware"
 
local YEAR_CAT = 'Software del %d'
 
-------------------------------- Sgabuzzino ------------------------------------
 
--[[
-- TODO Spostare in Modulo:Wikidata
* Get the ID from a statement (claim) of type wikibase-id
function p._subclassOf(args)
*
local statements = mWikidata._getProperty({'P279', from = args.from, formatting = 'raw'}, true)
* @param table Wikibase claim
if statements then
* @return string|nil
for _, statement in ipairs(statements) do
]]
for _, entityId in ipairs(args) do
local function statementQID( claim )
if statement == entityId then
return claim.mainsnak.datavalue and claim.mainsnak.datavalue.value.id
return true
end
 
end
--[[
end
* @param string Wikidata element
* @TODO ora prende il primo, a prescindere dalla lingua (credo).
* @return string
]]
local function shortWikidataLabel(from)
local s = ''
local label = mw.wikibase.label(from)
local sitelink = mw.wikibase.sitelink(from) or label
if string.len(label) > 10 then
label = mWikidata._getProperty( { 'P1813', n = 1, from = from } ) or label
end
return "[[" .. sitelink .. "|" .. label .. "]]"
return false
end
 
 
--[[
Riga 51 ⟶ 78:
--[[
* Poi non ditemi che PHP fa schifo. asd.
* Sembra che l'operatore "#" ogni tanto non vada col Modulo:Wikidata.
* 00:28, 28 feb 2017‎ Valerio Bozzolan
* 00:28, 28 feb 2017 Valerio Bozzolan
]]
local function count(t)
Riga 59 ⟶ 87:
end
return i
end
 
local function rawProperty(property)
return mWikidata._formatStatement(property, {formatting = 'raw'})
end
 
Riga 95 ⟶ 119:
from = from and from[1]
if not from then
error("QuestQuesta non è una categoria, o è assente la proprietà Wikidata P301")
end
return rawPropertystatementQID(from)
end
 
--[[
* Formatta una categoria.
*
* @param category string Primo argomento per sprinf
* @param part string Placeholder per sprintf
* @param man boolean Mostrare solo la categoria invece che categorizzare?
* @return string
]]
local function formatCategory(category, part, man)
local colon = man and ':' or ''
return "[[" .. colon .. "Categoria:" .. string.format(category, part) .. "]]"
end
 
Riga 108 ⟶ 145:
function p.specifiesALanguage(frame)
return yesNo( p._specifiesALanguage( onlySoftwareArguments(frame) ) )
end
 
function p.specifiesAToolkit(frame)
return yesNo( mWikidata._getClaims('P277') )
end
 
Riga 120 ⟶ 161:
function p.hasAProprietaryLicense(frame)
return yesNoNil( p._hasAProprietaryLicense( fromItem(frame) ) )
end
 
function p.languageCategories( frame )
return p._languageCategories( fromItem( frame ) )
end
 
Riga 127 ⟶ 172:
]]
function p.categories(frame)
returnif p._categorize( onlySoftwareArguments(frame) ) and p.wikidataCategories(frame)then
return p.licenseCategories(frame) .. p.toolkitCategories(frame) .. p.yearsCategories(frame)
end
return nil
end
 
function p.wikidataCategoriesFromMainTopic(frame)
local s = p._wikidataCategories( fromItemMainTopic() )
return s .. string.format('[[Categoria:P301 %s Wikidata]]', s and 'letta da' or 'assente su')
end
 
Riga 135 ⟶ 188:
]]
function p.wikidataCategories(frame)
return p._wikidataCategories( fromItem(frame) ) or nil
end
 
--[[
function p.wikidataCategoriesFromMainTopic(frame)
* Tutte le categorie applicabili da Wikidata.
return p._wikidataCategories( fromItemMainTopic() )
*
* Per ora ci sono solo le licenze, ma qui ci devono andare anche i linguaggi.
*
* @param from string|nil Wikidata Item
* @return string
]]
function p._wikidataCategories(from)
return p._licenseCategories(from) .. p._languageCategories(from) .. p._toolkitCategories(from) .. p._yearsCategories(from)
end
 
Riga 151 ⟶ 212:
 
--[[
* Categorie legate al toolkit.
* Licenze.
*
* @return string
]]
function p.licensestoolkitCategories(frame)
return p._toolkitCategories( fromItem(frame) )
local s = ''
end
for i, l in pairs( p._licenses( fromItem(frame) ) ) do
 
local space = i == 1 and '' or '<br />'
--[[
s = s .. space .. rawProperty(l)
* Categoria legato all'anno di fondazione.
end
* @return sstring
]]
function p.yearsCategories(frame)
return p._yearsCategories( fromItem(frame), onlySoftwareArguments(frame).DataPrimaVersione )
end
 
Riga 173 ⟶ 236:
 
local args = frame and onlySoftwareArguments(frame)
local categorize = p._categorize(args)
 
local is_free = p._isFreeSoftware(args)
--[[
local tl_has = p._templateHasLanguages(args) and true or false --exclude nil
* Linguaggi dal Template:Software e da Wikidata
]]
local tl_has = p._templateHasLanguages(args) and true or false
local tl_languages = p._getTemplateLanguages(args)
local wd_languages = mWikidata._getClaims('P277')
Riga 183 ⟶ 244:
-- È il namespace principale?
local nszero = mw.title.getCurrentTitle().namespace == 0
 
-- Tutti i linguaggi sono identificati?
local allFound = true
 
-- Il template si è arricchito grazie a Wikidata?
local improved = false
 
-- Tutti i linguaggi sono identificati da Wikidata e dal template?
local tl_allFound = true
local wd_allFound = true
 
-- Il template non mostra alcun linguaggio?
local noLanguages = not tl_has and not wd_languages
 
local outputLanguages = {} -- {key = {label1, category1}, key = {label2, category2}}
local outputLanguage = function(label, category, note)
return {label = label, category = category, note = note or '' }
end
 
if wd_languages then
for i, language in pairs(wd_languages) do
local wikidataIDlanguageId = rawPropertystatementQID(language)
if languageId then
language = conf.wikidataToLanguageSlug[wikidataID]
if language then = conf.language[languageId]
outputLanguages[languageId] = outputLanguage(
if tl_languages[language] == nil then
shortWikidataLabel(languageId),
-- 'c' = 'nota linguaggio c'
tl_languages[language] =and ''p._languageCategory(language, is_free)
)
noLanguages = false
improved = true
end
else
allFound = false
end
end
Riga 213 ⟶ 277:
if tl_has then
-- Wikidata ha migliorato il template e il template aveva già altri valori
s = s .. '[[Categoria:Linguaggio di programmazioneP277 differente dasu Wikidata]]'
else
-- Wikidata ha migliorato il template che era vuoto
s = s .. '[[Categoria:LinguaggioP277 di programmazione lettoletta da Wikidata]]'
end
else
-- No, `#var` non fa quello che uno si aspetterebbe
if p._templateHasExtraInformations(args) or count(tl_languages) > count(wd_languages) then
-- Nel template c'è qualcosa in più rispetto a Wikidata
s = s .. '[[Categoria:Linguaggio di programmazioneP277 differente dasu Wikidata]]'
elseif count(wd_languages) ~= 0 then
else
-- Non ha migliorato niente perchè sono gli stessi valori
s = s .. '[[Categoria:Linguaggio di programmazioneP277 uguale asu Wikidata]]'
end
end
Riga 232 ⟶ 295:
if tl_has and nszero then
-- solo se il template specifica linguaggi ma Wikidata no
s = s .. '[[Categoria:Linguaggio di programmazioneP277 assente su Wikidata]]'
end
end
 
if noLanguages and nszerotl_languages then
for languageSlug, note in pairs(tl_languages) do
if p._isFreeSoftware(frame) then
if languageSlug == 'sconosciuto' then
s = s .. '[[Categoria:Software libero senza linguaggio]]'
outputLanguages[languageSlug] = outputLanguage(
else
"Sconosciuto",
s = s .. '[[Categoria:Software senza linguaggio]]'
TEMPLATE_UNKNOWN_ARG_CAT,
note
)
else
local languageId = conf.languageSlugToWikidata[languageSlug]
local language = conf.language[languageId]
if language then
outputLanguages[languageId] = outputLanguage(
shortWikidataLabel(languageId),
p._languageCategory(language, is_free),
note
)
else
-- Mostrala comunque, a caso, così, tanto per
outputLanguages[languageSlug] = outputLanguage(
languageSlug,
p._languageCategory(languageSlug, is_free),
note
)
tl_allFound = false
end
end
end
end
 
if not allFound and nszero then
s = s .. '[[Categoria:Linguaggio di programmazione da Wikidata non previsto]]'
end
 
local i = 0
for id, language in pairs(outputLanguages) do
local softwareLiberoSiNo = p.isFreeSoftware(args)
for language, note in pairs(tl_languages) do
local glue = i > 0 and '<br />' or ''
s = s .. glue .. frame:expandTemplate{language.label .. language.note .. (categorize and language.category or '')
title = 'Software/Linguaggio',
args = {language, args['Categorie'], softwareLiberoSiNo}
} .. note
i = i + 1
end
 
if args['LinguaggioAltri'] then
local glue = i > 0 and '<br />' or ''
s = s .. args['LinguaggioAltri']
s = s .. glue .. args['LinguaggioAltri']
end
 
if nszero then
if not tl_allFound then
s = s .. TEMPLATE_UNKNOWN_ARG_WARN .. TEMPLATE_UNKNOWN_ARG_CAT
end
if not wd_allFound then
s = s .. UNKNOWN_WD_LANGUAGE
end
if noLanguages and is_free then
s = s .. FREE_WITHOUT_LANGUAGE
end
end
 
return s
end
 
function p.manLanguages(frame)
local s = '<table class="wikitable"><tr><th>Parametro</th><th>Risultato</th><th>Categoria automatica</th></tr>'
local TD = '<td>%s</td>'
for id, language in pairs( conf.language ) do
s = s .. '<tr>'
local slugs, i = '', 0
for slug, sub_id in pairs( conf.languageSlugToWikidata ) do
if sub_id == id then
local glue = i > 0 and '<br />' or ''
slug = "<code>" .. slug .. "</code>"
slugs = slugs .. glue .. slug
i = i + 1
end
end
s = s .. string.format(TD, slugs)
s = s .. string.format(TD, shortWikidataLabel(id) )
s = s .. string.format(TD, p._languageCategory(language, nil, true, '//') )
s = s .. '</tr>'
end
return s .. '</table>'
end
 
Riga 274 ⟶ 386:
]]
function p._categorize(args)
local ns = mw.title.getCurrentTitle().namespace
local v = args['Categorie']
return ns == 0 and (v == nil or mw.ustring.lower(v) ~= 'no')
if v then
return mw.ustring.lower(v) ~= 'no'
end
return true
end
 
Riga 378 ⟶ 488:
]]
function p._specifiesALanguage(args)
return p._templateHasLanguages(args) or mWikidata._getClaims_N({ 'P277' }) > 0
end
 
Riga 424 ⟶ 534:
function p._getTemplateLanguages(args)
local languages = {}
for i=0,3 do
local v = args['Linguaggio']
local j = i == 0 and '' or i
if v then
languages[local p._preferredLanguageSlug(v) ] = args['NotaLinguaggioLinguaggio'] or.. ''j]
end
for i=1,3 do
v = args['Linguaggio' .. i]
if v then
languages[v = p._preferredLanguageSlug(v)
languages[ v ] = args['NotaLinguaggio' .. ij] or ''
end
end
Riga 439 ⟶ 547:
--[[
* Questa licenza è direttamente identificabile?
*
* @TODO: Rewrite in qualche modo più umano.
*
* @param license string Wikidata item
Riga 444 ⟶ 554:
]]
function p._singleLicenseType(license)
-- Q3943414Q1156659 free softwareOSI-approved license
-- Q14624820Q5975031 non-free software copyleft license
-- Q3943414 free software license
-- Q31202214 proprietary software license
-- Q218616 proprietary software
-- Q3238057 proprietary license!
 
--[[
Riga 452 ⟶ 565:
* le prossime tre righe riassumino l'*unica* parte piacevole del Lua.
]]
return (license == 'Q3943414' or license == 'Q5975031' or license == 'Q1156659') and FREE
or (license == 'Q14624820Q31202214' or license == 'Q218616') or license == 'Q3238057') and PROPRIETARY
or UNKNOWN
end
 
Riga 571 ⟶ 684:
--[[
* Ha un certo tipo di licenza?
*
* Per motivi di performance dal 29 luglio 2017 si cerca solo fino alla prima licenza identificabile.
*
* @param type FREE|PROPRIETARY|UNKNOWN
Riga 578 ⟶ 693:
function p._hasALicenseOfType(type, from)
for _, l in pairs( p._licenses(from) ) do
l = rawPropertystatementQID(l)
if p._licenseType(l) == type then
local retrievedType = p._licenseType(l)
return true
if type ~= UNKNOWN then
return type == retrievedType
end
end
end
Riga 587 ⟶ 705:
 
--[[
* La voce haè almeno unasotto licenza di software libero in Wikidata?
*
* @param from string|nil Wikidata item
Riga 597 ⟶ 715:
 
--[[
* La voce haè almeno unasotto licenza di software proprietario in Wikidata?
*
* @param from string|nil Wikidata item
Riga 605 ⟶ 723:
return p._hasALicenseOfType(PROPRIETARY, from)
end
 
 
--[[
* TutteCategorie lelegate categoriealle applicabililicenze da Wikidata.
*
* Per ora ci sono solo le licenze, ma qui ci devono andare anche i linguaggi.
*
* @param from string|nil Wikidata Item
* @return string
]]
function p._wikidataCategories_licenseCategories(from)
local s = ''
return p._licenseCategories(from)
for i, l in pairs( p._licenses( from ) ) do
local id = statementQID( l ) -- can be nil but don't care
local name = conf.licenseCategory[ id ]
if name then
local cat = conf.licenseCategoryShorter[id] and LICENSE_CAT_SHORTER or LICENSE_CAT
s = s .. formatCategory(cat, name)
else
s = s .. UNKNOWN_WD_LICENSE
end
end
return s
end
 
--[[
* Categorie legate alleai licenzelinguaggi da Wikidata.
*
* @param from string|nil Wikidata Item
* @return string
]]
function p._licenseCategories_languageCategories(from)
local s = ''
local languages = mWikidata._getClaims('P277', {from = from} ) -- Property:programming language
for i, l in pairs( p._licenses( from ) ) do
local free = p._isFreeSoftwareByWikidata(from)
l = rawProperty(l)
local missing = false
l = conf.licenseCategory[l]
if llanguages then
for _, l in pairs( languages ) do
s = s .. string.format("[[Categoria:Software in licenza %s]]", l)
l = conf.language[ statementQID(l) ]
if l then
s = s .. p._languageCategory(l, free)
else
missing = true
end
end
elseif free then
s = FREE_WITHOUT_LANGUAGE
end
if missing then
s = s .. UNKNOWN_WD_LANGUAGE
end
return s
end
 
 
 
--------------------------- Non usate. Perchè? Boh. ----------------------------
 
--[[
* Categorie legate ai toolkit o framework dell'interfaccia grafica da Wikidata.
* Albero inverso di Modulo:Software/Configurazione
*
* @param from string|nil E.g.Wikidata 'cpp'Item
* @return string|nil E.g. 'Q2407'
]]
function p._toolkitCategories(from)
local _languageSlugToWikidata = {}
local s = ''
function p._languageSlugToWikidata(slug)
local toolkits = mWikidata._getClaims('P1414', {from = from} ) -- Property:GUI toolkit or framework
if next(_languageSlugToWikidata) == nil then
local free = p._isFreeSoftwareByWikidata(from)
for q,l in pairs(conf.wikidataToLanguageSlug) do
local missing = false
_languageSlugToWikidata[l] = q
if toolkits then
for _, t in pairs( toolkits ) do
t = conf.language[ statementQID( t ) ] -- the ID can be nil but don't care
if t then
s = s .. p._languageCategory(t, free)
else
missing = true
end
end
end
if missing then
return _languageSlugToWikidata[ p._preferredLanguageSlug(slug) ]
s = s .. UNKNOWN_WD_TOOLKIT
end
return s
end
 
--[[
* La categoria di uno specifico linguaggio di programmazione.
* Usata solo per debug.
* In realtà questa categorizzazione è analoga anche per i toolkit.
*
* @param language table
* @param free boolean|nil È software libero?
* @param man boolean|nil È a fini di documentazione?
* @param deefault string|nil Valore di default nel caso mancasse
* @see Modulo:Software/Configurazione
* @return string
]]
function p.languageSlugToWikidata_languageCategory(framelang, free, man, default)
local s
return p._languageSlugToWikidata( getArgs(frame)[1] )
if lang.cat then
s = free and lang.free and "Software libero in %s" --free = true
or free == false and lang.nonfree and "Software proprietario in %s" --free = false
or "Software in %s" --free = nil
s = formatCategory(s, lang.cat, man)
end
return s or default or ''
end
 
--[[
* Categoria legata alla data di fondazione.
* @todo Capire quale deve prevalere fra data di pubblicazione e data di creazione
* @param from string|nil Wikidata Item
* @param value string|nil Local value
* @return string
]]
function p._yearsCategories(from, value)
local mCategoryByYear = require('Modulo:Categoria per anno')._main
local creation = mCategoryByYear( { YEAR_CAT, from = from, value = value, raw = true } )
if '' == creation then
return mCategoryByYear( { YEAR_CAT, from = from, value = value, prop = 'P577', checkCat = 'Data di pubblicazione', checkGenre = 'fs' } )
end
return mCategoryByYear( { YEAR_CAT, from = from, value = value } )
end