وحدة:Wikidata2 sub modules/P3828مثال
مثال
مثال2
local p = {}
p.typeOfKit = {
["Q170494"] = "body",
["Q223269"] = "shorts",
["Q24206679"] = "right_arm",
["Q3643394"] = "left_arm",
["Q43663"] = "socks"
}
local function get_snak_id(snak)
if
snak and snak.type and snak.type == "statement" and snak.mainsnak and snak.mainsnak.snaktype and
snak.mainsnak.snaktype == "value" and
snak.mainsnak.datavalue and
snak.mainsnak.datavalue.type and
snak.mainsnak.datavalue.type == "wikibase-entityid" and
snak.mainsnak.datavalue.value and
snak.mainsnak.datavalue.value.id
then
ID = snak.mainsnak.datavalue.value.id
return ID
end
end
local function getEntityFromId(id)
if id and id ~= "" then
-- if not(mw.wikibase.isValidEntityId(id)) or not(mw.wikibase.entityExists(id)) then
-- return false
--end
return mw.wikibase.getEntityObject(id)
else
return mw.wikibase.getEntityObject()
end
end
local function get_qualifiers_id(snak)
if
snak and snak[1] and snak[1].snaktype == "value" and snak[1].datavalue and
snak[1].datavalue.type == "wikibase-entityid" and
snak[1].datavalue.value and
snak[1].datavalue.value.id
then
return snak[1].datavalue.value.id
end
end
local function find_Kit_type(claims, id)
local kitId = ""
mw.log("Module:Wikidata2/P3828: id : " .. id)
-- Loop through each claim
for _, statement in pairs(claims) do
local statementId = get_snak_id(statement)
-- Check if the statement has qualifiers and the qualifier "P1013"
if statement.qualifiers and statement.qualifiers["P1013"] then
local id2 = get_qualifiers_id(statement.qualifiers["P1013"])
-- If the id matches the given id, set the kitId to the statementId
if id2 == id then
kitId = statementId
end
end
end
-- Return the found kitId
return kitId
end
local function getQualifierValue(qualifiers, key)
if qualifiers[key] and qualifiers[key][1] and qualifiers[key][1].snaktype == "value" then
return qualifiers[key][1].datavalue.value
end
end
local function Get_image_color(statement)
local result = { image = "", color = "" }
if statement.qualifiers then
result.image = getQualifierValue(statement.qualifiers, "P18") or ""
result.color = getQualifierValue(statement.qualifiers, "P465") or ""
end
return result
end
local function find_team_Kit(claims, id, title, options)
local kitClaims = {
body = { image = "", color = "" },
shorts = { image = "", color = "" },
right_arm = { image = "", color = "" },
left_arm = { image = "", color = "" },
socks = { image = "", color = "" }
}
local kitId = find_Kit_type(claims, id)
local entity = getEntityFromId(kitId)
if not entity or not entity.claims or not entity.claims["P527"] then
return ""
end
for _, statement in pairs(entity.claims["P527"]) do
local ssId = get_snak_id(statement)
if p.typeOfKit[ssId] then
ssId = p.typeOfKit[ssId]
end
kitClaims[ssId] = Get_image_color(statement)
end
local mainArgs = {
qid = kitId,
leftarm_color = kitClaims.left_arm.color or "",
Kit_left_arm = kitClaims.left_arm.image or "",
body_color = kitClaims.body.color or "",
Kit_body = kitClaims.body.image or "",
rightarm_color = kitClaims.right_arm.color or "",
Kit_right_arm = kitClaims.right_arm.image or "",
shorts_color = kitClaims.shorts.color or "",
Kit_shorts = kitClaims.shorts.image or "",
socks_color = kitClaims.socks.color or "",
Kit_socks = kitClaims.socks.image or "",
title = title
}
local s = mw.getCurrentFrame():expandTemplate { title = "طقم_كرة_قدم/ويكي بيانات/نواة", args =
mainArgs }
s = s .. addTrackingCategory(options)
return s
end
function p.P3828(claims, options)
options.noicon = "t"
local Main_Table = {
find_team_Kit(claims, "Q45321977", "الطقم الأساسي", options),
find_team_Kit(claims, "Q45321990", "الطقم الاحتياطي", options),
find_team_Kit(claims, "Q45322173", "الطقم الثالث", options)
}
return mw.text.listToText(Main_Table, "", "")
end
return p
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia