Butun axtardiqlarinizi tapmaq ucun buraya: DAXIL OLUN
  Mp4 Mp3 Axtar Yukle
  Video Axtar Yukle
  Shekil Axtar Yukle
  Informasiya Melumat Axtar
  Hazir Inshalar Toplusu
  AZERI CHAT + Tanishliq
  1-11 Sinif Derslikler Yukle
  Saglamliq Tibbi Melumat
  Whatsapp Plus Yukle(Yeni)

  • Ana səhifə
  • Təsadüfi
  • Yaxınlıqdakılar
  • Daxil ol
  • Nizamlamalar
İndi ianə et Əgər Vikipediya sizin üçün faydalıdırsa, bu gün ianə edin.

Modul:Wd/football

  • Modul
  • Müzakirə
< Modul:Wd

Bu modulun sənədləşdirmə səhifəsi Modul:Wd/football/doc səhifəsində yaradıla bilər

local p = {}
local wd = require "Module:Wd"
local frame = mw.getCurrentFrame()

local function getEntity()
	local id = mw.wikibase.getEntityIdForCurrentPage()
	if not id then
		return nil
	end
	return mw.wikibase.getEntity(id)
end

local function getMainId(claim)
	if not claim or not claim.mainsnak or claim.mainsnak.snaktype ~= "value" then
		return nil
	end
	local dv = claim.mainsnak.datavalue
	if not dv or not dv.value or not dv.value.id then
		return nil
	end
	return dv.value.id
end

local function getYearFromTimeValue(time)
	if not time then
		return nil
	end
	local s = time
	local posT = s:find("T", 1, true)
	if posT then
		s = s:sub(1, posT - 1)
	end
	if s:sub(1,1) == "+" or s:sub(1,1) == "-" then
		s = s:sub(2)
	end
	local y = s:sub(1,4)
	if y:match("^%-?%d%d%d%d$") then
		return y
	end
	return nil
end

local function getQualifierTimeRaw(claim, pid)
	if not claim or not claim.qualifiers or not claim.qualifiers[pid] then
		return nil
	end
	local snak = claim.qualifiers[pid][1]
	if not snak or snak.snaktype ~= "value" or not snak.datavalue or not snak.datavalue.value then
		return nil
	end
	return snak.datavalue.value.time
end

local function getQualifierQuantity(claim, pid)
	if not claim or not claim.qualifiers or not claim.qualifiers[pid] then
		return nil
	end
	local snak = claim.qualifiers[pid][1]
	if not snak or snak.snaktype ~= "value" or not snak.datavalue or not snak.datavalue.value then
		return nil
	end
	local v = snak.datavalue.value
	local amount = v.amount or v
	if type(amount) ~= "string" then
		return nil
	end
	amount = amount:gsub("^%+", "")
	return amount
end

local function getQualifierEntityId(claim, pid)
	if not claim or not claim.qualifiers or not claim.qualifiers[pid] then
		return nil
	end
	local snak = claim.qualifiers[pid][1]
	if not snak or snak.snaktype ~= "value" or not snak.datavalue or not snak.datavalue.value then
		return nil
	end
	if snak.datavalue.type ~= "wikibase-entityid" then
		return nil
	end
	local qid = snak.datavalue.value.id
	return qid
end

local function isYouthClaim(claim)
	if not claim or not claim.qualifiers or not claim.qualifiers.P2094 then
		return false
	end
	local snak = claim.qualifiers.P2094[1]
	if not snak or snak.snaktype ~= "value" or not snak.datavalue or not snak.datavalue.value or not snak.datavalue.value.id then
		return false
	end
	return snak.datavalue.value.id == "Q599867"
end

local function isSubclassOf(target, classId, depth)
	if classId == target then
		return true
	end
	if depth <= 0 then
		return false
	end
	local ent = mw.wikibase.getEntity(classId)
	if not ent or not ent.claims or not ent.claims.P279 then
		return false
	end
	for _, stmt in ipairs(ent.claims.P279) do
		if stmt.mainsnak and stmt.mainsnak.snaktype == "value" and stmt.mainsnak.datavalue and stmt.mainsnak.datavalue.value and stmt.mainsnak.datavalue.value.id then
			local pid = stmt.mainsnak.datavalue.value.id
			if pid == target or isSubclassOf(target, pid, depth - 1) then
				return true
			end
		end
	end
	return false
end

local function isInstanceOf(target, entityId, depth)
	local ent = mw.wikibase.getEntity(entityId)
	if not ent or not ent.claims or not ent.claims.P31 then
		return false
	end
	for _, stmt in ipairs(ent.claims.P31) do
		if stmt.mainsnak and stmt.mainsnak.snaktype == "value" and stmt.mainsnak.datavalue and stmt.mainsnak.datavalue.value and stmt.mainsnak.datavalue.value.id then
			local cid = stmt.mainsnak.datavalue.value.id
			if cid == target then
				return true
			end
			if depth > 0 and isSubclassOf(target, cid, depth - 1) then
				return true
			end
		end
	end
	return false
end

local function getTeamClaims(teamtype)
	local entity = getEntity()
	if not entity or not entity.claims or not entity.claims.P54 then
		return nil
	end
	local out = {}
	for _, claim in ipairs(entity.claims.P54) do
		if claim.rank ~= "deprecated" then
			local v = getMainId(claim)
			if v and isInstanceOf(teamtype, v, 3) then
				table.insert(out, claim)
			end
		end
	end
	if #out == 0 then
		return nil
	end
	table.sort(out, function(a, b)
		local eaSnak = a.qualifiers and a.qualifiers.P582 and a.qualifiers.P582[1] or nil
		local ebSnak = b.qualifiers and b.qualifiers.P582 and b.qualifiers.P582[1] or nil

		local ea = eaSnak and eaSnak.snaktype == "value" and eaSnak.datavalue and eaSnak.datavalue.value and eaSnak.datavalue.value.time or nil
		local eb = ebSnak and ebSnak.snaktype == "value" and ebSnak.datavalue and ebSnak.datavalue.value and ebSnak.datavalue.value.time or nil

		local hasEndA = ea ~= nil
		local hasEndB = eb ~= nil

		if hasEndA ~= hasEndB then
			return hasEndA and not hasEndB
		end

		if hasEndA and hasEndB and ea ~= eb then
			return ea < eb
		end

		local ta = getQualifierTimeRaw(a, "P580") or ""
		local tb = getQualifierTimeRaw(b, "P580") or ""
		return ta < tb
	end)
	return out
end

local function getYouthClaims()
	local entity = getEntity()
	if not entity or not entity.claims or not entity.claims.P54 then
		return nil
	end
	local out = {}
	for _, claim in ipairs(entity.claims.P54) do
		if claim.rank ~= "deprecated" and isYouthClaim(claim) then
			table.insert(out, claim)
		end
	end
	if #out == 0 then
		return nil
	end
	table.sort(out, function(a, b)
		local eaSnak = a.qualifiers and a.qualifiers.P582 and a.qualifiers.P582[1] or nil
		local ebSnak = b.qualifiers and b.qualifiers.P582 and b.qualifiers.P582[1] or nil

		local ea = eaSnak and eaSnak.snaktype == "value" and eaSnak.datavalue and eaSnak.datavalue.value and eaSnak.datavalue.value.time or nil
		local eb = ebSnak and ebSnak.snaktype == "value" and ebSnak.datavalue and ebSnak.datavalue.value and ebSnak.datavalue.value.time or nil

		local hasEndA = ea ~= nil
		local hasEndB = eb ~= nil

		if hasEndA ~= hasEndB then
			return hasEndA and not hasEndB
		end

		if hasEndA and hasEndB and ea ~= eb then
			return ea < eb
		end

		local ta = getQualifierTimeRaw(a, "P580") or ""
		local tb = getQualifierTimeRaw(b, "P580") or ""
		return ta < tb
	end)
	return out
end

local function getCoachClaims()
	local entity = getEntity()
	if not entity or not entity.claims or not entity.claims.P6087 then
		return nil
	end
	local out = {}
	for _, claim in ipairs(entity.claims.P6087) do
		if claim.rank ~= "deprecated" then
			table.insert(out, claim)
		end
	end
	if #out == 0 then
		return nil
	end
	table.sort(out, function(a, b)
		local eaSnak = a.qualifiers and a.qualifiers.P582 and a.qualifiers.P582[1] or nil
		local ebSnak = b.qualifiers and b.qualifiers.P582 and b.qualifiers.P582[1] or nil

		local ea = eaSnak and eaSnak.snaktype == "value" and eaSnak.datavalue and eaSnak.datavalue.value and eaSnak.datavalue.value.time or nil
		local eb = ebSnak and ebSnak.snaktype == "value" and ebSnak.datavalue and ebSnak.datavalue.value and ebSnak.datavalue.value.time or nil

		local hasEndA = ea ~= nil
		local hasEndB = eb ~= nil

		if hasEndA ~= hasEndB then
			return hasEndA and not hasEndB
		end

		if hasEndA and hasEndB and ea ~= eb then
			return ea < eb
		end

		local ta = getQualifierTimeRaw(a, "P580") or ""
		local tb = getQualifierTimeRaw(b, "P580") or ""
		return ta < tb
	end)
	return out
end

local function normalizeDateForFlag(time)
	if not time then
		return nil
	end
	local s = time
	local posT = s:find("T", 1, true)
	if posT then
		s = s:sub(1, posT - 1)
	end
	if s:sub(1,1) == "+" or s:sub(1,1) == "-" then
		s = s:sub(2)
	end
	return s
end

local function cleanLabel(id)
	local label = wd._label{ [wd.args.eid] = id }
	if not label or label == "" then
		return nil
	end

	local patterns = {
		["%s*PFK$"] = "",               -- PFK
		["%s*FK$"] = "",                -- FK
		["%s*Sports Club$"] = "",
		["%s*[Mm]illi futbol komandası$"] = "", -- MFK
		["%s*[Mm]illi komandası$"] = "",        -- MK
		["%s*[Mm]illi futbol komandası %((%d+)%s*yaşlılar%)"] = "U-%1",
		["%s*[Ww]omen's national football team$"] = "",
		["%s*[Mm]en's national football team$"] = "",
		["%s*[Nn]ational youth football team$"] = "",
		["[Nn]ational under%-(%d%d?) [Aa]ssociation [Ff]ootball [Tt]eam"] = "U-%1",
		["[Nn]ational under%-(%d%d?) [Ff]ootball [Tt]eam"] = "U-%1",
		["[Nn]ational under%-(%d%d?) [Tt]eam"] = "U-%1",
		["%s*$"] = ""
	}

	for pattern, repl in pairs(patterns) do
		label = mw.ustring.gsub(label, pattern, repl)
	end

	label = mw.text.trim(label)
	return label
end

local function formatTeamName(teamid)
	local label = cleanLabel(teamid)
	if not label then
		return ""
	end
	local title = mw.wikibase.getSitelink(teamid)
	if title then
		if label ~= "" and label ~= title then
			return "[[" .. title .. "|" .. label .. "]]"
		else
			return "[[" .. title .. "]]"
		end
	end
	return label
end

local function isLiving()
	local id = mw.wikibase.getEntityIdForCurrentPage()
	if not id then
		return false
	end
	local ent = mw.wikibase.getEntity(id)
	if not ent or not ent.claims or not ent.claims.P570 then
		return true
	end
	return false
end

local function getPeriod(claim, living)
	if not claim or not claim.qualifiers then
		return ""
	end
	local qs = claim.qualifiers
	local s = qs.P580 and qs.P580[1] or nil
	local e = qs.P582 and qs.P582[1] or nil
	local ys, ye
	if s and s.snaktype == "value" and s.datavalue and s.datavalue.value then
		ys = getYearFromTimeValue(s.datavalue.value.time)
	end
	if e and e.snaktype == "value" and e.datavalue and e.datavalue.value then
		ye = getYearFromTimeValue(e.datavalue.value.time)
	end
	if ys and ye then
		if ys == ye then
			return ys
		end
		return ys .. "–" .. ye
	elseif ys then
		if living then
			return ys .. "–h.h."
		else
			return ys .. "–"
		end
	elseif ye then
		return "–" .. ye
	else
		return ""
	end
end

function p._teams(teamtype)
	local claims = getTeamClaims(teamtype)
	if not claims then
		return nil
	end
	local living = isLiving()
	local args = {}
	local idx = 1

	for _, j in ipairs(claims) do
		if not isYouthClaim(j) then
			local teamid = getMainId(j)
			local period = getPeriod(j, living)
			local matches = getQualifierQuantity(j, "P1350")
			local goals = getQualifierQuantity(j, "P1351")
			local conditionId = getQualifierEntityId(j, "P1642")
			local isLoan = (conditionId == "Q2914547")
			local teamname = formatTeamName(teamid)
	
			local formattedteam = teamname
			if isLoan then
				formattedteam = frame:expandTemplate{ title = "icarə"} .. " " .. formattedteam
			end
	
			local stats = matches
			if stats and goals then
				goals = mw.text.trim(goals)
				stats = stats .. " (" .. goals .. ")"
			end
	
			args[idx] = period or ""
			args[idx + 1] = formattedteam or ""
			args[idx + 2] = stats or ""
			idx = idx + 3
		end
	end

	return frame:expandTemplate{ title = "futbol karyerası", args = args }
end

local function buildManagement()
	local claims = getCoachClaims()
	if not claims then
		return nil
	end
	local living = isLiving()
	local args = {}
	local idx = 1

	for _, j in ipairs(claims) do
		local teamid = getMainId(j)
		local period = getPeriod(j, living)
		local teamname = formatTeamName(teamid)

		args[idx] = period or ""
		args[idx + 1] = teamname or ""
		args[idx + 2] = ""
		idx = idx + 3
	end

	return frame:expandTemplate{ title = "futbol karyerası", args = args }
end

local function buildYouth()
	local claims = getYouthClaims()
	if not claims then
		return nil
	end
	local living = isLiving()
	local args = {}
	local idx = 1

	for _, j in ipairs(claims) do
		local teamid = getMainId(j)
		local period = getPeriod(j, living)
		local matches = getQualifierQuantity(j, "P1350")
		local goals = getQualifierQuantity(j, "P1351")
		local conditionId = getQualifierEntityId(j, "P1642")
		local isLoan = (conditionId == "Q2914547")
		local teamname = formatTeamName(teamid)

		local formattedteam = teamname
		if isLoan then
			formattedteam = frame:expandTemplate{ title = "icarə"} .. " " .. formattedteam
		end

		local stats = matches
		if stats and goals then
			goals = mw.text.trim(goals)
			stats = stats .. " (" .. goals .. ")"
		end

		args[idx] = period or ""
		args[idx + 1] = formattedteam or ""
		args[idx + 2] = stats or ""
		idx = idx + 3
	end

	return frame:expandTemplate{ title = "futbol karyerası", args = args }
end

function p.clubs(frame)
	return p._teams("Q847017")
end

function p.national(frame)
	return p._teams("Q6979593")
end

function p.youth(frame)
	return buildYouth()
end

function p.management(frame)
	return buildManagement()
end

return p
Mənbə — "https://az.wikipedia.org/w/index.php?title=Modul:Wd/football&oldid=8367901"
Informasiya Melumat Axtar