Modulo:Software: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
separato p.categories() con p.wikidataCategories() e aggiunto p.wikidataCategoriesFromMainTopic() per #Categorizzare le categorie |
refactoring disastroso per semplificazione Modulo:Software/Configurazione +generatore Template:Software/Linguaggio/man +categorizzazione delle categorie... per linguaggio e.g. Categoria:GNOME |
||
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 TEMPLATE_UNKNOWN_ARG_WARN = "<span style=\"font-size:75%\">(non in [[Template:Software/Linguaggio|lista]])</span>"
local TEMPLATE_UNKNOWN_ARG_CAT = "[[Categoria:Software in linguaggio non riconosciuto]]"
local LICENSE_CAT = "Software in licenza %s"
-------------------------------- Sgabuzzino ------------------------------------
Line 28 ⟶ 36:
return false
end
local function rawProperty(property)
return mWikidata._formatStatement(property, {formatting = 'raw'})
end
--[[
* @param string WIkidataItem
* @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 .. "]]"
end
--[[
Line 51 ⟶ 79:
--[[
* 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
]]
Line 59 ⟶ 88:
end
return i
end
Line 95 ⟶ 120:
from = from and from[1]
if not from then
error("
end
return rawProperty(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
--[[
* Categorie di errore nel caso non ci siano linguaggi.
*
* @param free boolean|nil È software libero?
]]
local function noLanguageWarning(free)
return free and '[[Categoria:Software libero senza linguaggio]]' or '[[Categoria:Software senza linguaggio]]'
end
Line 127 ⟶ 174:
]]
function p.categories(frame)
return p._categorize( onlySoftwareArguments(frame) ) and p.
end
function p.wikidataCategoriesFromMainTopic(frame)
return p._wikidataCategories( fromItemMainTopic() )
end
Line 136 ⟶ 187:
function p.wikidataCategories(frame)
return p._wikidataCategories( fromItem(frame) )
end
--[[
* Tutte le categorie applicabili 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.
return p._licenseCategories(
end
--[[
* Categorie legate alle licenze.
* @return string
]]
function p.
return p._licenseCategories( fromItem(frame) )
end
Line 173 ⟶ 218:
local args = frame and onlySoftwareArguments(frame)
local is_free = p._isFreeSoftware(args)
local tl_has = p._templateHasLanguages(args) and true or false --exclude nil
local tl_languages = p._getTemplateLanguages(args)
local wd_languages = mWikidata._getClaims('P277')
Line 183 ⟶ 225:
-- È il namespace principale?
local nszero = mw.title.getCurrentTitle().namespace == 0
-- 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
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
language = conf.
if language then
outputLanguages[languageId] = outputLanguage(
shortWikidataLabel(languageId),
)
noLanguages = false else
end
end
Line 219 ⟶ 267:
end
else
if p._templateHasExtraInformations(args) or count(tl_languages) > count(wd_languages) then
-- Nel template c'è qualcosa in più rispetto a Wikidata
Line 236 ⟶ 283:
end
if
for languageSlug, note in pairs(tl_languages) do
if languageSlug == 'sconosciuto' then
outputLanguages[languageSlug] = outputLanguage(
"Sconosciuto",
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
local i = 0
for id, language in pairs(outputLanguages) do
local glue = i > 0 and '<br />' or ''
s = s .. glue ..
i = i + 1
end
if args['LinguaggioAltri'] then
local glue = i > 0 and '<br />' or ''
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 then
s = s .. noLanguageWarning(is_free)
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>'
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, false, true, '//') )
s = s .. '</tr>'
end
return s .. '</table>'
end
Line 424 ⟶ 520:
function p._getTemplateLanguages(args)
local languages = {}
for i=0,3 do
local j = i == 0 and '' or i
if v then
languages[ v ] = args['NotaLinguaggio' .. end
end
Line 604 ⟶ 698:
function p._hasAProprietaryLicense(from)
return p._hasALicenseOfType(PROPRIETARY, from)
end
Line 628 ⟶ 709:
local s = ''
for i, l in pairs( p._licenses( from ) ) do
l = conf.licenseCategory[ rawProperty(l) ]
if l then
s = s ..
else
s = s .. UNKNOWN_WD_LICENSE
end
end
return s
end
--[[
* Categorie legate ai linguaggi da Wikidata.
*
* @param from string|nil
* @return string
]]
function p._languageCategories(from)
local s = ''
local languages = mWikidata._getClaims('P277', {from = from} ) -- Property:programming language
local free = p._isFreeSoftwareByWikidata(from)
local missing = false
if languages then
for _, l in pairs( languages ) do
l = conf.language[ rawProperty(l) ]
if l then
s = s .. p._languageCategory(l, free)
else
missing = true
end
end
else
s = noLanguageWarning(free)
end
if missing then
s = s .. UNKNOWN_WD_LANGUAGE
end
return s
end
--[[
* La categoria di uno specifico linguaggio di programmazione.
*
* @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.
local s
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
|