66 403
contributi
Nessun oggetto della modifica |
(New labels for Interwiki) |
||
(48 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 46: | Riga 46: | ||
end | end | ||
function p.Categories(frame) | function p.Categories(frame) | ||
local Opening = '[[ | local Opening = '[[Category:' | ||
local CategoryP = 'P30' | local CategoryP = 'P30' | ||
local AbbrP = 'P24' | local AbbrP = 'P24' | ||
Riga 116: | Riga 116: | ||
itwiki = 'Wikipedia (inglese)', | itwiki = 'Wikipedia (inglese)', | ||
dema = 'Memory Alpha (tedesco)', | dema = 'Memory Alpha (tedesco)', | ||
demb = 'Memory Beta (tedesco)' | demb = 'Memory Beta (tedesco)', | ||
fanlore = 'Fanlore', | |||
trekipedia = 'Trekipedia' | |||
} | } | ||
Riga 287: | Riga 289: | ||
local WTLink | local WTLink | ||
if | if AddSemantic and SMWProperty and (SMWProperty ~= "") then | ||
AddSemantic = true | AddSemantic = true | ||
else | else | ||
Riga 308: | Riga 310: | ||
end | end | ||
if not mw.wikibase.getSitelink(QItem) 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 | --return Label | ||
--https://wikitrek.org/wiki/Speciale:AboutTopic/Q64 | |||
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 AddSemantic then | if string.find(WTLink, "Categoria:", 1, true) ~= nil then | ||
return "[[" .. WTLink .. "]]" | |||
elseif AddSemantic then | |||
return "[[" .. SMWProperty .. "::" .. WTLink .. "|" .. Label .. "]]" | return "[[" .. SMWProperty .. "::" .. WTLink .. "|" .. Label .. "]]" | ||
else | else | ||
Riga 352: | Riga 363: | ||
if not Item["P7"] then | if not Item["P7"] then | ||
Previous = " | Previous = "''nessuno''" | ||
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''" | ||
else | else | ||
Next = p.LabelOrLink(Item["P23"][1].datavalue.value.id) | Next = p.LabelOrLink(Item["P23"][1].mainsnak.datavalue.value.id) | ||
end | end | ||
Riga 396: | Riga 407: | ||
else | else | ||
for _, Statement in pairs(Statements) do | for _, Statement in pairs(Statements) do | ||
local | 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/" .. | AllReferences[#AllReferences + 1] = "* [[Special:AboutTopic/" .. ReferenceItem .. "]] - " .. ReferenceItem | ||
else | else | ||
if frame.args['AddSemantic'] then | if frame.args['AddSemantic'] then | ||
Reference = "Riferimento::" .. Reference | |||
end | |||
AllReferences[#AllReferences + 1] = "* [[" .. Reference .. "]] - " .. ReferenceItem | |||
end | end | ||
end | end | ||
Riga 415: | Riga 427: | ||
-- @return A bullet list of backlinks | -- @return A bullet list of backlinks | ||
function p.ListBackReferences(frame) | 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 AllBackReferences = {} | ||
--[=[ | --[=[ | ||
Riga 439: | Riga 453: | ||
--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 | local QueryResult = mw.smw.getQueryResult('[[Riferimento::' .. mw.title.getCurrentTitle().text .. ']]|?DataTrek ID') | ||
if | if QueryResult == nil then | ||
return " | return "''Nessun risultato''" | ||
end | end | ||
if type( | if type(QueryResult) == "table" then | ||
local | local Row = "" | ||
for k,v in pairs( | for k, v in pairs(QueryResult.results) do | ||
if v.fulltext and v.fullurl then | --[=[if v.fulltext and v.fullurl then | ||
myResult = myResult .. k .. " | " .. v.fulltext .. " " .. v.fullurl .. " | " .. "<br/>" | myResult = myResult .. k .. " | " .. v.fulltext .. " " .. v.fullurl .. " | " .. "<br/>" | ||
else | else | ||
myResult = myResult .. k .. " | no page title for result set available (you probably specified ''mainlabel=-')" | 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 | end | ||
AllBackReferences[#AllBackReferences + 1] = "*" .. Row | |||
end | end | ||
return table.concat(AllBackReferences, string.char(10)) | |||
else | |||
return "''No table''" | |||
end | end | ||
return queryResult | return queryResult | ||
end | |||
--- Writes a gneric UL list from property, adding SMW link if specified | |||
-- | |||
-- @param PName Info from MW session | |||
-- @param SMWPrefix | |||
-- @return A bullet list of backlinks | |||
function p.PropertyList(frame) | |||
--{{#invoke:DTBase|PropertyList|P59|Scritto da}} | |||
local AllReferences = {} | |||
local Item = mw.wikibase.getEntityIdForCurrentPage() | |||
if not Item then | |||
Item = 'Q1' | |||
end | |||
local Statements = mw.wikibase.getAllStatements(Item, frame.args["Property"]) | |||
if not Statements then | |||
return "Nessun riferimento trovato" | |||
elseif table.getn(Statements) == 1 then | |||
return p.LabelOrLink(Statements[1].mainsnak.datavalue.value.id, frame.args["SMWPrefix"], true) | |||
else | |||
for _, Statement in pairs(Statements) do | |||
--local ReferenceItem = Statement.mainsnak.datavalue.value.id | |||
AllReferences[#AllReferences + 1] = "<li>" .. p.LabelOrLink(Statement.mainsnak.datavalue.value.id, frame.args["SMWPrefix"], true) .. "</li>" | |||
end | |||
return "<ul>" .. table.concat(AllReferences, string.char(10)) .. "</ul>" | |||
end | |||
end | end | ||
return p | return p |