Modulo:DTBase: differenze tra le versioni

Vai alla navigazione Vai alla ricerca
Item added to References
mNessun oggetto della modifica
(Item added to References)
(44 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
--- This module represent the package containing basic functions to access data from the WikiBase instance DataTrek
-- @module p
-- @author Luca Mauri [[Utente:Lucamauri]]
-- Add other authors below
-- Keyword: wikitrek
-- Keyword: wikitrek
local p = {}
local p = {}
Riga 279: Riga 283:
return Value
return Value
end
end
function p.LabelOrLink(QItem)
function p.LabelOrLink(QItem, SMWProperty, AddSemantic)
local Label
local Label
local WTLink
local WTLink
if (not AddSemantic) and SMWProperty and (SMWProperty ~= "") then
AddSemantic = true
else
AddSemantic = false
end
local Item = mw.wikibase.getEntity(QItem)
local Item = mw.wikibase.getEntity(QItem)
if not Item then
if Item == nil then
return "''Elemento non trovato''"
return "'''Error'''"
end
end
Riga 299: Riga 309:
if not mw.wikibase.getSitelink(QItem) then
if not mw.wikibase.getSitelink(QItem) then
--if mw.wikibase.getSitelink(QItem) == nil or (not mw.wikibase.getSitelink(QItem)) then
return Label
return Label
else
else
Riga 305: Riga 316:
Label = WTLink
Label = WTLink
end
end
return "[[" .. WTLink .. "|" .. Label .. "]]"
if AddSemantic then
return "[[" .. SMWProperty .. "::" .. WTLink .. "|" .. Label .. "]]"
else
return "[[" .. WTLink .. "|" .. Label .. "]]"
end
end
end
end
end
Riga 381: Riga 396:
else
else
for _, Statement in pairs(Statements) do
for _, Statement in pairs(Statements) do
local Reference = mw.wikibase.getSitelink(Statement.mainsnak.datavalue.value.id)
local ReferenceItem = Statement.mainsnak.datavalue.value.id
local Reference = mw.wikibase.getSitelink(ReferenceItem)
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
else
if frame.args['AddSemantic'] then
Reference = "Riferimento::" .. Reference
end
AllReferences[#AllReferences + 1] = "* [[" .. Reference .. "]] - " .. ReferenceItem
end
end
if frame.args['AddSemantic'] then
end
Reference = "Riferimento::" .. Reference
return table.concat(AllReferences, string.char(10))
end
end
--- generates a list of backlink using SMW query.
--
-- @frame Info from MW session
-- @return A bullet list of backlinks
function p.ListBackReferences(frame)
-- See example here https://github.com/SemanticMediaWiki/SemanticScribunto/blob/master/docs/mw.smw.getQueryResult.md
-- See also here https://doc.semantic-mediawiki.org/md_content_extensions_SemanticScribunto_docs_mw_8smw_8getQueryResult.html
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
end
AllReferences[#AllReferences + 1] = "* [[" .. Reference .. "]]"
AllBackReferences[#AllBackReferences + 1] = "*" .. table.concat(Items, ', ')
end
end
return table.concat(AllReferences, string.char(10))
return table.concat(AllBackReferences, string.char(10))
end
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')
    if QueryResult == nil then
        return "''Nessun risultato''"
    end
    if type(QueryResult) == "table" then
        local Row = ""
        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
Row = "[[:" .. v.fulltext .. "]]" --string.sub(v.fulltext, 3)
else
Row = "[[" .. v.fulltext .. "]]"
            end
            if v.printouts['DataTrek ID'][1] ~= nil then
            Row = Row .. " - " .. v.printouts['DataTrek ID'][1]
            end
           
AllBackReferences[#AllBackReferences + 1] = "*" .. Row
        end
        return table.concat(AllBackReferences, string.char(10))
    else
    return "''No table''"
    end
    return queryResult
end
end
return p
return p

Menu di navigazione