67 179
contributi
(Set CollectionTable if nil) |
mNessun oggetto della modifica |
||
(32 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 7: | Riga 7: | ||
--local OperatorTree = require('Modulo:DTFunzioniComuni').OperatorTree | --local OperatorTree = require('Modulo:DTFunzioniComuni').OperatorTree | ||
local PropertiesOnTree = require('Modulo:DTFunzioniComuni').PropertiesOnTree | local PropertiesOnTree = require('Modulo:DTFunzioniComuni').PropertiesOnTree | ||
local ShipNameCore = require('Modulo:FunzioniGeneriche').ShipNameCore | |||
local p = {} | local p = {} | ||
function p.QFromP(Property) | function p.QFromP(Property) | ||
Riga 86: | Riga 87: | ||
local Item = mw.wikibase.getEntity() | local Item = mw.wikibase.getEntity() | ||
local ItemQ = mw.wikibase.getEntityIdForCurrentPage() | local ItemQ = mw.wikibase.getEntityIdForCurrentPage() | ||
local InstanceQ | |||
local IsEpisode = false | local IsEpisode = false | ||
local OperatorName = "" | local OperatorName = "" | ||
Riga 91: | Riga 93: | ||
local AstroD = nil | local AstroD = nil | ||
local ListProp = {} | local ListProp = {} | ||
local PageName | |||
if not Item then | if not Item then | ||
Riga 104: | Riga 107: | ||
end | end | ||
ExcludeP = {P3 = true, P7 = true, P8 = true, P11 = true, P21 = IsEpisode, P23 = true, P26 = true, P37 = true, P46 = true, P58 = true, P68 = true, P52 = true, P79 = true, P90 = true} | ExcludeP = {P3 = true, P7 = true, P8 = true, P11 = true, P21 = IsEpisode, P23 = true, P26 = true, P37 = true, P46 = true, P58 = true, P68 = true, P52 = true, P61 = true, P79 = true, P90 = true, P104 = true, P162 = true} | ||
AllP = mw.wikibase.orderProperties(Item:getProperties()) | AllP = mw.wikibase.orderProperties(Item:getProperties()) | ||
Riga 127: | Riga 130: | ||
mw.smw.set(ITLabel .. "=" .. ITValue) | mw.smw.set(ITLabel .. "=" .. ITValue) | ||
end | end | ||
PageName = ITValue | |||
if (mw.wikibase.getLabelByLang(ItemQ, 'it')) ~= PageTitle.text then | if (mw.wikibase.getLabelByLang(ItemQ, 'it')) ~= PageTitle.text then | ||
AllRows[#AllRows + 1] = {ITLabel .. ":", {ITValue}} | AllRows[#AllRows + 1] = {ITLabel .. ":", {ITValue}} | ||
Riga 145: | Riga 149: | ||
table.insert(ListProp, Property) | table.insert(ListProp, Property) | ||
if (not ExcludeP[Property]) and Item.claims[Property][1].mainsnak.datatype ~= 'external-id' then | if (not ExcludeP[Property]) and Item.claims[Property][1].mainsnak.datatype ~= 'external-id' then | ||
-- START specific property | |||
if Property == "P46" then | if Property == "P46" then | ||
-- Collection | -- Collection | ||
Riga 168: | Riga 173: | ||
POnTree = {{"P40", 3, false}, {"P41", 3, false}, {"P88", 3, false}} | POnTree = {{"P40", 3, false}, {"P41", 3, false}, {"P88", 3, false}} | ||
for _, Prop in pairs(POnTree) do | for _, Prop in pairs(POnTree) do | ||
local PropValue = table.concat(PropertiesOnTree(Prop[1], Prop[2], Prop[3], true)) | --local PropValue = table.concat(PropertiesOnTree(Prop[1], Prop[2], Prop[3], true)) | ||
local PropValue = PropertiesOnTree(Prop[1], Prop[2], Prop[3], true) | |||
if (PropValue ~= nil) and (PropValue ~= "") then | if (PropValue ~= nil) and (PropValue ~= "") then | ||
local PropName = mw.wikibase.getLabelByLang(Prop[1], 'it') or mw.wikibase.getLabel(Prop[1]) | local PropName = mw.wikibase.getLabelByLang(Prop[1], 'it') or mw.wikibase.getLabel(Prop[1]) | ||
Riga 185: | Riga 191: | ||
end | end | ||
end | end | ||
end | |||
InstanceQ = Item.claims[Property][1].mainsnak.datavalue.value.id | |||
if InstanceQ == "Q876" or InstanceQ == "Q78" then | |||
--Spaceship or starship | |||
mw.smw.set("Nome=" .. ShipNameCore(PageName)) | |||
end | end | ||
Riga 195: | Riga 208: | ||
end]==] | end]==] | ||
--mw.smw.set("OperatorName2=" .. OperatorName) | --mw.smw.set("OperatorName2=" .. OperatorName) | ||
-- END specific property | |||
else | else | ||
-- Unspecified Property | -- START Unspecified Property | ||
local Header = {Property, (mw.wikibase.getLabelByLang(Property, 'it') or mw.wikibase.getLabel(Property))} -- .. ":"} -- or {Property, mw.wikibase.getLabel(Property) .. ":"} --'-' .. Property .. ":"} | local Header = {Property, (mw.wikibase.getLabelByLang(Property, 'it') or mw.wikibase.getLabel(Property))} -- .. ":"} -- or {Property, mw.wikibase.getLabel(Property) .. ":"} --'-' .. Property .. ":"} | ||
local Values = Item['claims'][Property] | local Values = Item['claims'][Property] | ||
local AccValues = {} | local AccValues = {} | ||
local Year = "" | |||
--mw.smw.set("OperatorName3=" .. OperatorName) | --mw.smw.set("OperatorName3=" .. OperatorName) | ||
for _, SnakValue in | for _, SnakValue in ipairs(Values) do | ||
local Value = SnakValue.mainsnak.datavalue['value'] | local Value = SnakValue.mainsnak.datavalue['value'] | ||
--mw.smw.set("OperatorName4=" .. OperatorName) | --mw.smw.set("OperatorName4=" .. OperatorName) | ||
if (type(Value) == "table") then | if (type(Value) == "table") then | ||
if Property == "P72" then --CASE Assigments | -- DataValue is an array | ||
if Property == "P72" then | |||
--CASE Assigments | |||
local Assignment = "" | local Assignment = "" | ||
local AssLabel = "" | |||
if SnakValue.qualifiers ~= nil then | if SnakValue.qualifiers ~= nil then | ||
-- Timeline year | -- Timeline year | ||
if SnakValue.qualifiers['P73'] ~= nil then | if SnakValue.qualifiers['P73'] ~= nil then | ||
Year = LabelOrLink(SnakValue.qualifiers['P73'][1].datavalue.value['id']) | |||
Assignment = Year .. " " | |||
end | end | ||
Riga 217: | Riga 236: | ||
Assignment = Assignment .. SnakValue.qualifiers['P15'][1].datavalue.value .. " " | Assignment = Assignment .. SnakValue.qualifiers['P15'][1].datavalue.value .. " " | ||
end | end | ||
end | |||
-- If Wikitrek label (P20) is present, force it | |||
if SnakValue.qualifiers ~= nil and SnakValue.qualifiers['P20'] ~= nil then | |||
AssLabel = SnakValue.qualifiers['P20'][1].datavalue.value | |||
end | end | ||
if AddSemantic then | if AddSemantic then | ||
Assignment = Assignment .. LabelOrLink(Value['id'], "Assegnazione", true) | Assignment = Assignment .. LabelOrLink(Value['id'], "Assegnazione", true, AssLabel) | ||
else | else | ||
Assignment = Assignment .. LabelOrLink(Value['id'] | Assignment = Assignment .. LabelOrLink(Value['id'], "", false, AssLabel) | ||
end | end | ||
if SnakValue.qualifiers ~= nil then | if SnakValue.qualifiers ~= nil then | ||
-- Suffix | |||
if SnakValue.qualifiers['P19'] ~= nil then | |||
Assignment = Assignment .. " " .. SnakValue.qualifiers['P19'][1].datavalue.value --.. " " | |||
end | |||
-- Rank | -- Rank | ||
if SnakValue.qualifiers['P76'] then | if SnakValue.qualifiers['P76'] then | ||
Riga 242: | Riga 265: | ||
end | end | ||
--AccValues[#AccValues + 1] = LabelOrLink(SnakValue.qualifiers['P73'][1].datavalue.value['id']) .. " " .. LabelOrLink(Value['id']) .. ", " .. LabelOrLink(SnakValue.qualifiers['P76'][1].datavalue.value['id']) .. ", " .. LabelOrLink(SnakValue.qualifiers['P77'][1].datavalue.value['id']) | --AccValues[#AccValues + 1] = LabelOrLink(SnakValue.qualifiers['P73'][1].datavalue.value['id']) .. " " .. LabelOrLink(Value['id']) .. ", " .. LabelOrLink(SnakValue.qualifiers['P76'][1].datavalue.value['id']) .. ", " .. LabelOrLink(SnakValue.qualifiers['P77'][1].datavalue.value['id']) | ||
AccValues[#AccValues + 1] = Assignment | --AccValues[#AccValues + 1] = Assignment | ||
table.insert(AccValues, Assignment) | |||
table.sort(AccValues) | |||
elseif Value['entity-type'] == 'item' then | elseif Value['entity-type'] == 'item' then | ||
--mw.smw.set("OperatorName5=" .. OperatorName) | --mw.smw.set("OperatorName5=" .. OperatorName) | ||
Riga 274: | Riga 299: | ||
if SnakValue.qualifiers and SnakValue.qualifiers['P19'] then | if SnakValue.qualifiers and SnakValue.qualifiers['P19'] then | ||
GenericItem = GenericItem .. " " .. SnakValue.qualifiers['P19'][1].datavalue.value | GenericItem = GenericItem .. " " .. SnakValue.qualifiers['P19'][1].datavalue.value | ||
end | |||
if SnakValue.qualifiers and SnakValue.qualifiers['P73'] ~= nil and Year == "" then | |||
GenericItem = GenericItem .. " (" .. LabelOrLink(SnakValue.qualifiers['P73'][1].datavalue.value['id']) .. ")" | |||
end | end | ||
Riga 302: | Riga 331: | ||
YearLink = LabelOrLink(SnakValue.qualifiers['P74'][1].datavalue.value['id'], nil, nil, PrintDate) | YearLink = LabelOrLink(SnakValue.qualifiers['P74'][1].datavalue.value['id'], nil, nil, PrintDate) | ||
end | end | ||
QualiString = " " .. "(" .. p.ProcessQualifiers(SnakValue) .. ")" | QualiString = " " .. p.ProcessQualifiers(SnakValue) --"(" .. p.ProcessQualifiers(SnakValue) .. ")" | ||
end | end | ||
Riga 348: | Riga 377: | ||
AccValues[#AccValues + 1] = 'Unspecified TABLE' | AccValues[#AccValues + 1] = 'Unspecified TABLE' | ||
end | end | ||
elseif SnakValue.mainsnak.datatype == 'url' then | |||
--URL, URI or URN | |||
local URLString | |||
URLString = SnakValue.mainsnak.datavalue.value | |||
if SnakValue.qualifiers['P20'][1].datavalue.value ~= nil then | |||
--Label is present | |||
URLString = "[" .. URLString .. " " .. mw.text.nowiki(SnakValue.qualifiers['P20'][1].datavalue.value) .. "]" | |||
end | |||
table.insert(AccValues, URLString) | |||
else | else | ||
-- String items | -- String items | ||
Riga 357: | Riga 395: | ||
end | end | ||
AllRows[#AllRows + 1] = {Header, AccValues} | AllRows[#AllRows + 1] = {Header, AccValues} | ||
-- END Unspecified Property | |||
end | end | ||
end | end | ||
Riga 449: | Riga 488: | ||
function p.DescrWithTemplate(frame) | function p.DescrWithTemplate(frame) | ||
local RawDescription = mw.wikibase.getDescription() | local RawDescription = mw.wikibase.getDescription() | ||
local Pattern = "{{. | local Pattern = "{{.-}}" | ||
--[==[ | --[==[ | ||
Riga 480: | Riga 519: | ||
for _, Qualifier in pairs(SnakValue.qualifiers) do | for _, Qualifier in pairs(SnakValue.qualifiers) do | ||
if Qualifier[1].property == "P4" then | if Qualifier[1].property == "P4" then | ||
--Broadcaster | --Broadcaster | ||
QualiValue[#QualiValue + 1] = Qualifier[1].datavalue.value | --QualiValue[#QualiValue + 1] = Qualifier[1].datavalue.value | ||
table.insert(QualiValue, Qualifier[1].datavalue.value) | |||
elseif Qualifier[1].property == "P19" then --SnakValue.qualifiers['P19'] ~= nil then | |||
-- Suffix | |||
table.insert(QualiValue, Qualifier[1].datavalue.value) | |||
end | end | ||
end | end | ||
Riga 525: | Riga 567: | ||
ImageString = "[[File:Menu.png|left|middle|30px|HyperTrek logo]]" | ImageString = "[[File:Menu.png|left|middle|30px|HyperTrek logo]]" | ||
DataString = "Informazioni originali lette dal database di <h2 class='hiddenheaderbold'>HyperTrek</h2> datato " .. frame:expandTemplate{title = 'TimeL', args = {Tipo='ITMedia', Istante=HTNodes.mainsnak.datavalue.value.time}} .. " con i seguenti dettagli: " | DataString = "Informazioni originali lette dal database di <h2 class='hiddenheaderbold'>HyperTrek</h2> datato " .. frame:expandTemplate{title = 'TimeL', args = {Tipo='ITMedia', Istante=HTNodes.mainsnak.datavalue.value.time}} .. " con i seguenti dettagli: " | ||
if AddSemantic then | |||
mw.smw.set(mw.wikibase.getLabelByLang('P79', 'it') .. "=" .. Item.claims['P79'][1].mainsnak.datavalue.value.time) | |||
end | |||
for _, Qualifier in pairs(HTNodes.qualifiers) do | for _, Qualifier in pairs(HTNodes.qualifiers) do | ||
Riga 539: | Riga 585: | ||
mw.smw.set(QualiName .. "=" .. QualiValue) | mw.smw.set(QualiName .. "=" .. QualiValue) | ||
end | end | ||
-- | |||
if QualiProp == "P86" then | |||
--Sezione ID, add link to page | |||
QualiValue = frame:expandTemplate{title = 'HTSezioneID', args = {QualiValue}} | |||
end | |||
QualiString = QualiString .. "<li " .. "title='" .. QualiProp .. "'>'''" .. string.gsub(QualiName, "HyperTrek", "HT") .. "''': " .. QualiValue .. "</li>" | QualiString = QualiString .. "<li " .. "title='" .. QualiProp .. "'>'''" .. string.gsub(QualiName, "HyperTrek", "HT") .. "''': " .. QualiValue .. "</li>" | ||
end | end |