Module:Τέταρτηθέση
Τεκμηρίωση module[δημιουργία]
Μπορείτε να συμβάλλετε στη δημιουργία σελίδας τεκμηρίωσης για αυτό το Scribunto module. Οι συντάκτες μπορούν να πειραματίζονται στο πρόχειρο (δημιουργία | αντίγραφο) και στις δοκιμαστικές σελίδες (δημιουργία) του module. Παρακαλούμε να προσθέτετε τις κατηγορίες στην υποσελίδα τεκμηρίωσης. Υποσελίδες αυτού του module. |
local p = {}
function p.main(frame)
local entity = mw.wikibase.getEntity()
if not entity or not entity.claims or not entity.claims.P1923 then
mw.log("no claims")
return
end
-- select P1923 with P1352
local data = {}
for i, v in ipairs(entity.claims.P1923) do
if (v.type == "statement") and (v.rank ~= "deprecated") and v.qualifiers and v.qualifiers.P1352 -- not deprecated statement with qualifier P1352
and v.mainsnak.snaktype == "value"
then
-- select MIN(P1352) although there is mostly one
local rank
for _, e in ipairs(v.qualifiers.P1352) do
if e.snaktype == "value" then
local value = tonumber(e.datavalue.value.amount)
if value then
if not rank then
rank = value
elseif value < rank then
rank = value
end
end
end
end
if rank then
local id = v.mainsnak.datavalue.value.id
table.insert(data, { id, rank })
end
end
end
if #data == 0 then
mw.log("there is no data with rank")
return
end
local function makeResult(id)
local sitelink = mw.wikibase.sitelink(id)
local label = mw.wikibase.label(id)
if sitelink and label and (sitelink ~= label) then
return "[["..sitelink.."|"..label.."]]"
elseif sitelink then
return "[["..sitelink.."]]"
elseif label then
return "[["..label.."]]"
else
return id
end
end
local result = {}
local rank = 4
-- select data with fourth rank
for _, v in ipairs(data) do
if v[2] == rank then
table.insert(result, makeResult(v[1]))
end
end
mw.log(table.concat(result, ", "))
return table.concat(result, ", ")
end
return p