67 247
contributi
Nessun oggetto della modifica |
mNessun oggetto della modifica |
||
(64 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 11: | Riga 11: | ||
end | end | ||
function p.ExtLinks(frame) | function p.ExtLinks(frame) | ||
local AllRows | local AllRows = "" | ||
local Item = mw.wikibase.getEntity() | local Item = mw.wikibase.getEntity() | ||
if not Item then | if not Item then | ||
Riga 23: | Riga 23: | ||
local LinkID | local LinkID | ||
local LinkWiki | local LinkWiki | ||
local ExternalIDList = "" | |||
if not LinkStatement['qualifiers']['P19'] then | if not LinkStatement['qualifiers']['P19'] then | ||
Riga 38: | Riga 39: | ||
end | end | ||
--[=[ | |||
if not AllRows then | if not AllRows then | ||
AllRows = "''Nessun collegamento generico [[:datatrek:Item:" .. mw.wikibase.getEntityIdForCurrentPage() .. "|trovato su DataTrek]]''" | --AllRows = "''Nessun collegamento generico [[:datatrek:Item:" .. mw.wikibase.getEntityIdForCurrentPage() .. "|trovato su DataTrek]]''" | ||
AllRows = "''Nessun collegamento generico trovato su DataTrek''" | |||
end | |||
]=] | |||
if AllRows ~= "" then | |||
AllRows = AllRows .. string.char(10) .. string.char(10) | |||
end | |||
ExternalIDList = p.ExternalID() | |||
if ExternalIDList ~= nil and ExternalIDList ~= "" then | |||
ExternalIDList = string.char(10) .. "=== Identificativi esterni ===" .. string.char(10) .. ExternalIDList | |||
end | end | ||
return AllRows .. "=== Interwiki ===" .. string.char(10) .. p.SiteLinksInterwiki() .. ExternalIDList | |||
return AllRows | |||
end | end | ||
function p.Categories(frame) | function p.Categories(frame) | ||
Riga 101: | Riga 114: | ||
local Item = mw.wikibase.getEntity() | local Item = mw.wikibase.getEntity() | ||
if not Item then | if not Item then | ||
return "''Nessun collegamento generico trovato su DataTrek''" | |||
end | end | ||
Riga 114: | Riga 127: | ||
wikidata = 'Pagina della entità su Wikidata', | wikidata = 'Pagina della entità su Wikidata', | ||
enwiki = 'Wikipedia (inglese)', | enwiki = 'Wikipedia (inglese)', | ||
itwiki = 'Wikipedia ( | itwiki = 'Wikipedia (italiano)', | ||
dewiki = 'Wikipedia (tedesco)', | |||
dema = 'Memory Alpha (tedesco)', | dema = 'Memory Alpha (tedesco)', | ||
demb = 'Memory Beta (tedesco)' | demb = 'Memory Beta (tedesco)', | ||
fanlore = 'Fanlore', | |||
trekipedia = 'Trekipedia' | |||
} | } | ||
Riga 191: | Riga 207: | ||
:wikitext(Text) | :wikitext(Text) | ||
return tostring(p) | return tostring(p) | ||
end | |||
-------------------------------------------------------------------------------- | |||
-- Set the semantic property for the linked DataTrek entity on the current page | |||
-- | |||
-- @param frame The frame of the page | |||
-------------------------------------------------------------------------------- | |||
function p.SemanticToEntity(frame) | |||
if mw.wikibase.getEntity() ~= nil then | |||
mw.smw.set("DataTrek ID = " .. mw.wikibase.getEntityIdForCurrentPage()) | |||
end | |||
end | |||
-------------------------------------------------------------------------------- | |||
-- Set the semantic property for the linked DataTrek entity on the current page | |||
-- to be used as a plain text string | |||
-- | |||
-- @param frame The frame of the page | |||
-------------------------------------------------------------------------------- | |||
function p.SemanticToItem(frame) | |||
if mw.wikibase.getEntity() ~= nil then | |||
mw.smw.set("DataTrek Item = " .. mw.wikibase.getEntityIdForCurrentPage()) | |||
end | |||
end | end | ||
function p.LabelByLang(frame) | function p.LabelByLang(frame) | ||
Riga 283: | Riga 320: | ||
return Value | return Value | ||
end | end | ||
function p.LabelOrLink(QItem, SMWProperty, AddSemantic) | |||
-------------------------------------------------------------------------------- | |||
-- Return a label ora wikilink or a link to the special Placeholder page for a | |||
-- given Property | |||
-- Return string containing label or link | |||
-- | |||
-- @param QItem The item identifier in the from 'Q0' | |||
-- @param[opt=nil] SMWProperty Name of the semantic property to add | |||
-- @param[opt=false] AddSemantic Wether to add sematinc or not | |||
-- @param[opt=""] ForcedLabel Specific label to show regardless DataTrek values | |||
-- @param[opt=false] ForceString Force to return string even in case of Page | |||
-- that should return link | |||
-- | |||
-- @treturn string String containing label or wikilink | |||
-------------------------------------------------------------------------------- | |||
function p.LabelOrLink(QItem, SMWProperty, AddSemantic, ForcedLabel, ForceString) | |||
local Label | local Label | ||
local WTLink | local WTLink | ||
Riga 292: | Riga 344: | ||
AddSemantic = false | AddSemantic = false | ||
end | end | ||
ForceString = ForceString or false | |||
local Item = mw.wikibase.getEntity(QItem) | local Item = mw.wikibase.getEntity(QItem) | ||
Riga 298: | Riga 352: | ||
end | end | ||
if not Item['claims'] or not Item['claims']['P20'] then | if ForcedLabel ~= "" and ForcedLabel ~= nil then | ||
Label = ForcedLabel | |||
elseif not Item['claims'] or not Item['claims']['P20'] then | |||
Label = Item.labels['it'].value | Label = Item.labels['it'].value | ||
else | else | ||
Riga 308: | Riga 364: | ||
end | end | ||
if not mw.wikibase.getSitelink(QItem) and string.find( | if not mw.wikibase.getSitelink(QItem) and string.find(Label, "Categoria:", 1, true) == nil then | ||
--if mw.wikibase.getSitelink(QItem) == nil or (not mw.wikibase.getSitelink(QItem)) then | --if mw.wikibase.getSitelink(QItem) == nil or (not mw.wikibase.getSitelink(QItem)) then | ||
--return Label | --return Label | ||
--https://wikitrek.org/wiki/Speciale:AboutTopic/Q64 | --https://wikitrek.org/wiki/Speciale:AboutTopic/Q64 | ||
if AddSemantic then | |||
mw.smw.set(SMWProperty .. "=" .. Label) | |||
end | |||
return "[[Special:AboutTopic/" .. QItem .. "|" .. Label .. "]]" | return "[[Special:AboutTopic/" .. QItem .. "|" .. Label .. "]]" | ||
else | else | ||
WTLink = Item.sitelinks['wikitrek'].title | if Item.sitelinks == nil then | ||
WTLink = Label | |||
else | |||
WTLink = Item.sitelinks['wikitrek'].title | |||
end | |||
if not Label then | if not Label then | ||
Label = WTLink | Label = WTLink | ||
end | end | ||
if ForceString then | |||
return WTLink | |||
end | |||
if string.find(WTLink, "Categoria:", 1, true) ~= nil then | if string.find(WTLink, "Categoria:", 1, true) ~= nil then | ||
return "[[" .. WTLink .. "]]" | return "[[" .. WTLink .. "]]" | ||
Riga 351: | Riga 419: | ||
local Table | local Table | ||
Title = Title or "Navigatore" | --Title = Title or "Navigatore" | ||
if not Item then | if not Item then | ||
Item = mw.wikibase.getEntity("Q1") | Item = mw.wikibase.getEntity("Q1") | ||
Riga 357: | Riga 425: | ||
if not Item["P7"] then | if not Item["P7"] then | ||
Previous = " | Previous = "''nessuno''" | ||
elseif Item["P7"][1].mainsnak == nil then | |||
Previous = p.LabelOrLink(Item["P7"][1].datavalue.value.id) | |||
else | else | ||
Previous = p.LabelOrLink(Item["P7"][1].datavalue.value.id) | Previous = p.LabelOrLink(Item["P7"][1].mainsnak.datavalue.value.id) | ||
end | end | ||
if not Item["P23"] then | if not Item["P23"] then | ||
Next = " | Next = "''nessuno''" | ||
elseif Item["P23"][1].mainsnak == nil then | |||
Next = p.LabelOrLink(Item["P23"][1].datavalue.value.id) | |||
else | else | ||
Next = p.LabelOrLink(Item["P23"][1].datavalue.value.id) | Next = p.LabelOrLink(Item["P23"][1].mainsnak.datavalue.value.id) | ||
end | end | ||
Table = "<div class='separatorebox'>'''" .. Title .. "'''</div>" | --Table = "<div class='separatorebox'>'''" .. Title .. "'''</div>" | ||
Table = Table .. string.char(10) .. "<table class='wikitable' style='width:100%'>" | --Table = Table .. string.char(10) .. "<table class='wikitable' style='width:100%'>" | ||
Table = Table .. string.char(10) .. "<tr><th>< Precedente</th><th>Successivo ></th></tr>" | Table = "<table class='wikitable' style='width:100%'>" | ||
if Title ~= nil then | |||
Table = Table .. string.char(10) .. "<caption>" .. Title .. "</caption>" | |||
end | |||
Table = Table .. string.char(10) .. "<tr><th id='P7' title='P7'>< Precedente</th><th id='P23' title='P23'>Successivo ></th></tr>" | |||
Table = Table .. string.char(10) .. "<tr><td style='text-align:center; width:50%;'>" .. Previous .. "</td>" | Table = Table .. string.char(10) .. "<tr><td style='text-align:center; width:50%;'>" .. Previous .. "</td>" | ||
Table = Table .. string.char(10) .. "<td style='text-align:center; width:50%;'>" .. Next .. "</td></tr>" | Table = Table .. string.char(10) .. "<td style='text-align:center; width:50%;'>" .. Next .. "</td></tr>" | ||
Riga 405: | Riga 481: | ||
if not Reference then | if not Reference then | ||
--Reference = Statement.mainsnak.datavalue.value.id | --Reference = Statement.mainsnak.datavalue.value.id | ||
AllReferences[#AllReferences + 1] = "* [[Special:AboutTopic/" .. ReferenceItem .. "]] - " .. ReferenceItem | AllReferences[#AllReferences + 1] = "* [[Special:AboutTopic/" .. ReferenceItem .. "]] - " .. ReferenceItem .. " - " .. mw.wikibase.getLabelByLang(mw.wikibase.getEntity(ReferenceItem).claims['P14'][1].mainsnak.datavalue.value.id, "it") | ||
else | else | ||
if frame.args['AddSemantic'] then | if frame.args['AddSemantic'] then | ||
Reference = "Riferimento::" .. Reference | Reference = "Riferimento::" .. Reference | ||
end | end | ||
AllReferences[#AllReferences + 1] = "* [[" .. Reference .. "]] | AllReferences[#AllReferences + 1] = "* [[" .. Reference .. "]] (" .. mw.wikibase.getLabelByLang(mw.wikibase.getEntity(ReferenceItem).claims['P14'][1].mainsnak.datavalue.value.id, "it") .. ")" | ||
end | end | ||
end | end | ||
Riga 447: | Riga 523: | ||
--local QueryResult = mw.smw.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID') | --local QueryResult = mw.smw.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID') | ||
--local queryResult = mw.smw.getQueryResult( frame.args ) | --local queryResult = mw.smw.getQueryResult( frame.args ) | ||
local QueryResult = mw.smw.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID') | local QueryResult = mw.smw.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID|?Istanza') | ||
if QueryResult == nil then | if QueryResult == nil then | ||
Riga 455: | Riga 531: | ||
if type(QueryResult) == "table" then | if type(QueryResult) == "table" then | ||
local Row = "" | local Row = "" | ||
local ImagesList = "" | |||
local ResultText = "" | |||
for k, v in pairs(QueryResult.results) do | for k, v in pairs(QueryResult.results) do | ||
if string.sub(v.fulltext, 1, 5) == "File:" then | if string.sub(v.fulltext, 1, 5) == "File:" then | ||
Row = "[[:" .. v.fulltext .. "]]" --string.sub(v.fulltext, 3) | Row = "[[:" .. v.fulltext .. "]]" --string.sub(v.fulltext, 3) | ||
ImagesList = ImagesList .. v.fulltext .. "|" .. frame:expandTemplate{ title = v.fulltext} .. string.char(10) | |||
else | else | ||
Row = "[[" .. v.fulltext .. "]]" | Row = "[[" .. v.fulltext .. "]]" | ||
end | end | ||
if v.printouts['DataTrek ID'][1] ~= nil then | if v.printouts['DataTrek ID'][1] ~= nil then | ||
Row = Row .. " - " .. v.printouts['DataTrek ID'][1] | Row = Row .. " - " .. v.printouts['DataTrek ID'][1] .. " - " .. v.printouts['Istanza'][1].fulltext | ||
end | end | ||
AllBackReferences[#AllBackReferences + 1] = "*" .. Row | AllBackReferences[#AllBackReferences + 1] = "*" .. Row | ||
end | end | ||
return table.concat(AllBackReferences, string.char(10)) | |||
ResultText = table.concat(AllBackReferences, string.char(10)) | |||
ResultText = "<div style='column-count:3;-moz-column-count:3;-webkit-column-count:3'>" .. string.char(10) .. ResultText .. string.char(10) .. "</div>" | |||
if not (ImagesList == nil or ImagesList == "") then | |||
ResultText = ResultText .. string.char(10) .. "=== Immagini collegate ===" .. string.char(10) .. frame:extensionTag( "gallery", ImagesList) | |||
end | |||
return ResultText --table.concat(AllBackReferences, string.char(10)) | |||
else | else | ||
return "''No table''" | return "''No table''" | ||
end | end | ||
return | return QueryResult | ||
end | end | ||
--- Writes a gneric UL list from property, adding SMW link if specified | --- Writes a gneric UL list from property, adding SMW link if specified |