Modulo:DTBase: differenze tra le versioni

Da Wikitrek.
mNessun oggetto della modifica
Wikimedia Commons description added
 
(50 versioni intermedie di uno stesso utente non sono mostrate)
Riga 50: Riga 50:
end
end
ExternalIDList = p.ExternalID()
ExternalIDList = p.ExternalID(frame)
if ExternalIDList ~= nil and ExternalIDList ~= "" then
if ExternalIDList ~= nil and ExternalIDList ~= "" then
Riga 132: Riga 132:
demb = 'Memory Beta (tedesco)',
demb = 'Memory Beta (tedesco)',
fanlore = 'Fanlore',
fanlore = 'Fanlore',
trekipedia = 'Trekipedia'
trekipedia = 'Trekipedia',
commonswiki = 'Wikimedia Commons'
}
}
Riga 156: Riga 157:
return table.concat(AllLinks, string.char(10))
return table.concat(AllLinks, string.char(10))
end
end
function p.ExternalID()
function p.ExternalID(frame)
local AllExtID = {}
local AllExtID = {}
local AllSources
local SourcesP = {}
local Item = mw.wikibase.getEntity()
local Item = mw.wikibase.getEntity()
local AllP
local AllP
local finalList = ""
if not Item then
if not Item then
Item = mw.wikibase.getEntity('Q1')
Item = mw.wikibase.getEntity('Q1')
Riga 165: Riga 169:
AllP = mw.wikibase.orderProperties(Item:getProperties())
AllP = mw.wikibase.orderProperties(Item:getProperties())
SourcesP = {P200 = true}
for _, Property in pairs(AllP) do
for _, Property in pairs(AllP) do
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
-- Sets semantic property
mw.smw.set((mw.wikibase.getLabelByLang(Property, 'it') or mw.wikibase.getLabel(Property)) .. " = " .. Item.claims[Property][1].mainsnak.datavalue.value)
if (SourcesP[Property]) then
--ID is for external source
if AllSources == nil then
AllSources = {}
end
table.insert(AllSources, "* " .. frame:expandTemplate{title = 'CitazioneIEEE', args = {'Contributori Memory Alpha', Item.sitelinks['itma'].title, 'Memory Alpha', Item.claims[Property][1].qualifiers['P201'][1].datavalue.value.time, p.ExtIDLink(Property, Item.claims[Property][1].mainsnak.datavalue.value)}})
else
--ID is normal external link
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))
end
end
end
end
end
return table.concat(AllExtID, string.char(10))
if AllExtID ~= nil and AllExtID ~= "" then
finalList = table.concat(AllExtID, string.char(10))
end
if AllSources ~= nil and AllSources ~= "" then
finalList = finalList .. string.char(10) .. "== Fonti Esterne (" .. frame:expandTemplate{title = 'Beta'} .. ") ==" .. string.char(10) .. table.concat(AllSources, string.char(10))
end
mw.smw.set("finalList = " .. finalList)
return finalList
end
end
--------------------------------------------------------------------------------
-- Return a URL for the external IDentifier
--
-- @param Property The P beign processed
-- @param The ID value itself
--
-- @return string String containing escaped URL
--------------------------------------------------------------------------------
function p.ExtIDLink(Property, Value)
function p.ExtIDLink(Property, Value)
local ExtIDP = 'P5'
local ExtIDP = 'P5'
local URL
local URL
local FullLink
URL = mw.wikibase.getEntity(Property).claims[ExtIDP][1].mainsnak.datavalue.value
URL = mw.wikibase.getEntity(Property).claims[ExtIDP][1].mainsnak.datavalue.value
return string.gsub(URL, '$1', Value)
if string.find(Value, "[%%%+%-%*%?]") ~= nil and string.find(Value, " ") ~= nil then
FullLink = string.gsub(URL, '$1', mw.uri.encode(Value, "QUERY"):gsub("%%", "%%%%"))
else
FullLink = string.gsub(URL, '$1', Value)
end
return FullLink
end
end
function p.LinkToEntity(frame, AddSemantic)
function p.LinkToEntity(frame, AddSemantic)
Riga 207: Riga 249:
       :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())
mw.smw.set("DataTrek ID = " .. mw.wikibase.getEntityIdForCurrentPage())
end
end
end
function p.LabelByLang(frame)
function p.LabelByLang(frame)
Riga 299: Riga 363:
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 308: Riga 387:
AddSemantic = false
AddSemantic = false
end
end
ForceString = ForceString or false
local Item = mw.wikibase.getEntity(QItem)
local Item = mw.wikibase.getEntity(QItem)
Riga 327: Riga 408:
if not mw.wikibase.getSitelink(QItem) and string.find(Label, "Categoria:", 1, true) == nil then
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
--return Label
--https://wikitrek.org/wiki/Speciale:AboutTopic/Q64
--https://wikitrek.org/wiki/Speciale:AboutTopic/Q64
if AddSemantic then
if AddSemantic then
mw.smw.set(SMWProperty .. "=" .. Label)
mw.smw.set(SMWProperty .. "=" .. Label)
end
end
return "[[Special:AboutTopic/" .. QItem .. "|" .. Label .. "]]"
if ForceString then
return Label
else
return "[[Special:AboutTopic/" .. QItem .. "|" .. Label .. "]]"
end
else
else
if Item.sitelinks == nil then
if Item.sitelinks == nil then
Riga 344: Riga 426:
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 356: Riga 443:
-- using the LDoc format
-- using the LDoc format
-- @param Item Father of Previous and Next
-- @param Item Father of Previous and Next
-- @param[opt="Navigatore"]
-- @param[opt="Navigatore"] Title
-- @return Table
-- @return Table
function p.MakeNavTable(Item, Title)
function p.MakeNavTable(Item, Title)
Riga 451: Riga 538:
--- generates a list of backlink using SMW query.
--- generates a list of backlink using SMW query.
--  
--  
-- @frame Info from MW session
-- @param frame Info from MW session
-- @return A bullet list of backlinks
-- @return A bullet list of backlinks
function p.ListBackReferences(frame)
function p.ListBackReferences(frame)
Riga 457: Riga 544:
-- See also here https://doc.semantic-mediawiki.org/md_content_extensions_SemanticScribunto_docs_mw_8smw_8getQueryResult.html
-- See also here https://doc.semantic-mediawiki.org/md_content_extensions_SemanticScribunto_docs_mw_8smw_8getQueryResult.html
local AllBackReferences = {}
local AllBackReferences = {}
--[=[
local QueryResult = mw.smw.ask('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID|format=broadtable')
if not QueryResult then
return "''Nessun risultato''"
else
for _, Row in pairs(QueryResult) do
local Items = {}
for _, Field in pairs(Row) do
if string.sub(Field, 1, 7) == "[[File:" then
Items[#Items + 1] = "[[:" .. string.sub(Field, 3)
else
Items[#Items + 1] = Field
end
end
AllBackReferences[#AllBackReferences + 1] = "*" .. table.concat(Items, ', ')
end
return table.concat(AllBackReferences, string.char(10))
end
]=]
--local QueryResult = mw.smw.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID')
--local queryResult = mw.smw.getQueryResult( frame.args )
local QueryResult = mw.smw.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID|?Istanza')
local QueryResult = mw.smw.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID|?Istanza')
Riga 491: Riga 555:
         local ResultText = ""
         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)
--IF the back reference is a media, don't list it, but show the thumbnail only
ImagesList = ImagesList .. v.fulltext .. "|thumb|right|" .. frame:expandTemplate{ title = v.fulltext} .. string.char(10)
--Row = "[[:" .. v.fulltext .. "]]"
ImagesList = ImagesList .. v.fulltext .. "|" .. frame:expandTemplate{ title = v.fulltext} .. string.char(10)
else
else
Row = "[[" .. v.fulltext .. "]]"
Row = "[[" .. v.fulltext .. "]]"
            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
if v.printouts['Istanza'][1] ~= nil then
            end
Row = Row .. " - " .. v.printouts['Istanza'][1].fulltext
           
end
AllBackReferences[#AllBackReferences + 1] = "*" .. Row
end
AllBackReferences[#AllBackReferences + 1] = "*" .. Row
end
        end
       
        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
         end
        ResultText = table.concat(AllBackReferences, string.char(10))
        return ResultText --table.concat(AllBackReferences, string.char(10))
        if ImagesList ~= nil and 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''"