Modulo:DTBase: differenze tra le versioni
Da Wikitrek.
Documentation fixed |
Wikimedia Commons description added |
||
| (33 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 | ||
-- Sets semantic property | -- Sets semantic property | ||
mw.smw.set((mw.wikibase.getLabelByLang(Property, 'it') or mw.wikibase.getLabel(Property)) .. " = " .. Item.claims[Property][1].mainsnak.datavalue.value) | 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 | ||
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 | ||
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 229: | Riga 269: | ||
if mw.wikibase.getEntity() ~= nil then | if mw.wikibase.getEntity() ~= nil then | ||
mw.smw.set("DataTrek Item = " .. mw.wikibase.getEntityIdForCurrentPage()) | mw.smw.set("DataTrek Item = " .. mw.wikibase.getEntityIdForCurrentPage()) | ||
mw.smw.set("DataTrek ID = " .. mw.wikibase.getEntityIdForCurrentPage()) | |||
end | end | ||
end | end | ||
| Riga 367: | 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 | ||
--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 502: | 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.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID|?Istanza') | local QueryResult = mw.smw.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID|?Istanza') | ||
| Riga 537: | Riga 556: | ||
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 .. "]]" | --IF the back reference is a media, don't list it, but show the thumbnail only | ||
--Row = "[[:" .. v.fulltext .. "]]" | |||
ImagesList = ImagesList .. v.fulltext .. "|" .. frame:expandTemplate{ title = v.fulltext} .. string.char(10) | ImagesList = ImagesList .. v.fulltext .. "|" .. frame:expandTemplate{ title = v.fulltext} .. string.char(10) | ||
else | else | ||
Row = "[[" .. v.fulltext .. "]]" | Row = "[[" .. v.fulltext .. "]]" | ||
if v.printouts['DataTrek ID'][1] ~= nil then | |||
Row = Row .. " - " .. v.printouts['DataTrek ID'][1] | |||
if v.printouts['Istanza'][1] ~= nil then | |||
Row = Row .. " - " .. v.printouts['Istanza'][1].fulltext | |||
end | |||
end | |||
AllBackReferences[#AllBackReferences + 1] = "*" .. Row | |||
end | |||
end | end | ||