Anonimo

Modulo:DTBase: differenze tra le versioni

Da Wikitrek.
m
Semantic values for external IDs
(Error in case of no linked entity)
m (Semantic values for external IDs)
(21 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''"
AllRows = "''Nessun collegamento generico trovato su DataTrek''"
end
end
]=]
--return AllRows .. string.char(10) .. string.char(10) .. "=== Interwiki ===" .. string.char(10) .. "* " .. frame:expandTemplate{title = 'InterlinkMA', args = {Nome=Item:getSitelink("enma")}} .. string.char(10) .. p.SiteLinksInterwiki()
 
return AllRows .. string.char(10) .. string.char(10) .. "=== Interwiki ===" .. string.char(10) .. p.SiteLinksInterwiki() .. string.char(10) .. "=== Identificativi esterni ===" .. string.char(10) .. p.ExternalID()
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
return AllRows .. "=== Interwiki ===" .. string.char(10) .. p.SiteLinksInterwiki() .. ExternalIDList
end
end
function p.Categories(frame)
function p.Categories(frame)
Riga 102: Riga 114:
local Item = mw.wikibase.getEntity()
local Item = mw.wikibase.getEntity()
if not Item then
if not Item then
Item = mw.wikibase.getEntity('Q1')
return "''Nessun collegamento generico trovato su DataTrek''"
end
end
Riga 116: Riga 128:
enwiki = 'Wikipedia (inglese)',
enwiki = 'Wikipedia (inglese)',
itwiki = 'Wikipedia (italiano)',
itwiki = 'Wikipedia (italiano)',
dewiki = 'Wikipedia (tedesco)',
dema = 'Memory Alpha (tedesco)',
dema = 'Memory Alpha (tedesco)',
demb = 'Memory Beta (tedesco)',
demb = 'Memory Beta (tedesco)',
Riga 155: Riga 168:
if Item.claims[Property][1].mainsnak.datatype == 'external-id' then
if Item.claims[Property][1].mainsnak.datatype == 'external-id' then
AllExtID[#AllExtID + 1] = "* ["  .. p.ExtIDLink(Property, Item.claims[Property][1].mainsnak.datavalue.value) .. " ''" .. Item.claims[Property][1].mainsnak.datavalue.value .. "''], " .. (mw.wikibase.getLabelByLang(Property, 'it') or mw.wikibase.getLabel(Property)) -- [[:" .. SiteLink['site'] .. ":" .. SiteLink['title'] .. "|''" .. SiteLink['title'] .. "'']], " .. TitleLabel
AllExtID[#AllExtID + 1] = "* ["  .. p.ExtIDLink(Property, Item.claims[Property][1].mainsnak.datavalue.value) .. " ''" .. Item.claims[Property][1].mainsnak.datavalue.value .. "''], " .. (mw.wikibase.getLabelByLang(Property, 'it') or mw.wikibase.getLabel(Property)) -- [[:" .. SiteLink['site'] .. ":" .. SiteLink['title'] .. "|''" .. SiteLink['title'] .. "'']], " .. TitleLabel
-- Sets semantic property
mw.smw.set((mw.wikibase.getLabelByLang(Property, 'it') or mw.wikibase.getLabel(Property)) .. " = " .. Item.claims[Property][1].mainsnak.datavalue.value)
end
end
end
end
Riga 194: Riga 209:
       :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 286: Riga 322:
return Value
return Value
end
end
function p.LabelOrLink(QItem, SMWProperty, AddSemantic, ForcedLabel)
 
--------------------------------------------------------------------------------
-- 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 295: Riga 346:
AddSemantic = false
AddSemantic = false
end
end
ForceString = ForceString or false
local Item = mw.wikibase.getEntity(QItem)
local Item = mw.wikibase.getEntity(QItem)
Riga 331: Riga 384:
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 475: Riga 533:
     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  v.fulltext and v.fullurl then
                myResult = myResult .. k .. " | " .. v.fulltext .. " " .. v.fullurl .. " | " .. "<br/>"
            else
                myResult = myResult .. k .. " | no page title for result set available (you probably specified ''mainlabel=-')"
            end]=]
             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 .. "]]"
Riga 492: Riga 548:
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 queryResult
     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