Jump to content

Module:Wikidata2/P54

د ويکيپېډيا، وړیا پوهنغونډ له خوا

لاسوند لپاره ددې موډيول کېدای سی په Module:Wikidata2/P54/لاسوند کي وي

local p = {}
local wl = require('Module:ص.م')
local track = require('Module:Wikidata/څار').makecategory1
local teams_id = { 
	'Q476028'
	,"Q847017" 
	}

function string.ends(String,End)
   return End=='' or string.sub(String,-string.len(End))==End
end
function format_label( label )
	lab = label
	lab = mw.ustring.gsub(lab , " فوټبال%]%]", "]]")
	lab = mw.ustring.gsub(lab , " فوټبال %[%[", "[[")
	lab = mw.ustring.gsub(lab , "%|کلب ", "|")
	lab = mw.ustring.gsub(lab , "%|غوره ", "|")
	return lab
end

local national_id = { 
		'Q23895910'
		,'Q23847779'
		,'Q6979593'
		,"Q21945604"
		,"Q23759293"
		,"Q23905105"
		,"Q3874020"
		,"Q1194951"
		, "Q6979740"
		,"Q23901137"
		,"Q23901123" -- national under-17 football team
	}
					
function template ( args )
	local rows = mw.html.create( 'tr' )
	local years = args[1] .. "–" .. args[2]
	local goals;
	if args[4] and args[4] ~=""  then
		goals = "(" .. args[4] .. ")"
	end
	rows:attr('colspan', 4)
	--head:css('background-color', '#E1E1E1')
	rows:tag('td'):tag("span"):addClass('nowrap'):wikitext(years)
	rows:tag('td'):wikitext(args[3])
	rows:tag('td'):tag("span"):addClass('nowrap'):wikitext(args[2] or "-")
	rows:tag('td'):tag("span"):addClass('nowrap'):wikitext(goals) 
	return tostring(rows)
end

function ifd ( entit )
	local s = {}
	local tt = "o"
	local fii = formatStatements( {property ='P31', entityId = entit, noref ='true' ,rank='all'
	,enbarten ='true',separator='',conjunction='',formatting ='raw'})
	local finns = false
	for k, id in pairs(teams_id) do
		if fii == id then 
			tt =  "team"
		end
	end
	if tt == "o" then
		for k, Qid in pairs(national_id) do
			if fii == Qid then 
				tt =  "national"
			end
		end
	end
	if tt == "o" then
		mw.log("* id: {{Q|" .. entit .. "}} {{P|P31}}: {{Q|" .. fii.. "}} ") 
	end
	return tt
end

function p.football( statement , options)
	if statement then
		if statement.type then
			if statement.type == 'statement' then
				--=====================================
				local value = statement.mainsnak.datavalue.value
				local entit = getEntityIdFromValue( value )
				local s = formatSnak( statement.mainsnak, options ).value
				--local s = formatEntityId( entit , options ).value
				local type_ = ifd( entit )
				if type_ and type_ ~= '' 
					then
					if s then
						local entit = getEntityIdFromValue( value )
						local flag = formatStatements( {property ='P1532', entityId = entit
							, noref ='true' ,rank='all'--,pattern =options.pattern
							,size ='20',image ='image'
							,propertyimage ='P41',enbarten ='true',separator='',conjunction=''})
						if not flag or flag == "" then
							flag = formatStatements( {property ='P17', entityId = entit
								, noref ='true' ,rank='all'--,pattern =options.pattern
								,size ='20',image ='image'
								,propertyimage ='P41',enbarten ='true',separator='',conjunction=''})
						end
						local label = formatEntityId( entit , options ).value
						label = format_label( label )
						if label and label  ~= '' then
							if flag and flag  ~= '' then
								s =  flag .. ' '.. label 
							else  
								s = label
							end
						end
						if statement.references then
							if options.reff and options.reff ~= ''  then
								reff  = formatReferences( statement, options )
								s = s..reff
							end 
						end
						if statement.qualifiers
							then
							if statement.qualifiers.P1350 or statement.qualifiers.P1351 or statement.qualifiers.P580 or statement.qualifiers.P582 then
								amatch = formatStatements({property = "P1350", enbarten = 'true'}, statement.qualifiers) or ''
								goal = formatStatements({property = "P1351", enbarten = 'true'}, statement.qualifiers) or ''
								start1 = formatStatements({property = "P580", enbarten = 'true',modifytime = 'y'}, statement.qualifiers) or ' '
								finish1 = formatStatements({property = "P582", enbarten = 'true',modifytime = 'y'}, statement.qualifiers) or ' '
								P1642 = formatStatements({property = "P1642", enbarten = 'true',modifytime = 'y'}, statement.qualifiers) or ' '
							end
						end
						--if options.football1 and options.football1 ~= '' then
						Args = {(start1 or ''),(finish1 or ''),s,(amatch or ''),(goal or ''),P1642=(P1642 or '')}
						--s = template (Args)
						s = mw.getCurrentFrame():expandTemplate{ title = "صندوق معلومات سيرة كرة قدم/سطر فريق", args =Args}
							
						--end
					end
				return {value = s , Type = type_}
				end
			end
				--=====================================
			end
		end
	end

function p.foot( claims , options)
   	local icon = track({property="P54", id= options.entityId or "",category= "[[وېشنيزه:مخونه چې P54ځانګړتياوې کاروي]][[وېشنيزه:په ويکيډاټا کې فوټبال لوبډلې]]"})
   	local Nationals = {}
   	local Other = {}
   	local Teams = {}
	--table.insert( Other, wl.SubTitle({'-','-' ,"b0c4de","000000",4}) )
	--table.insert( Teams, wl.SubTitle({'مسلکي فعاليت','-' ,"b0c4de","000000",4}) )
	--table.insert( Nationals , wl.SubTitle({'ملي لوبډله','-' ,"b0c4de","000000",4}) )
	--==========================================
	for i, statement in pairs( claims ) do
		options.num = i
		local stat = p.football( statement, options )
		if stat then
			local s = stat.value
			local Table;
			local Type = stat.Type
			if s == '' then s = nil end
			if s then
				if Type == 'team' 
					then --Table = Teams 
						table.insert( Teams, s )
				elseif Type == 'national' 
					then --Table = Nationals 
						table.insert( Nationals, s )
				elseif Type == 'o' 
					then --Table = Other 
						table.insert( Other, s )
				end
			
			--if s then
				--table.insert( Table, s )
				--local t = formatReferences( statement, options )
				--stat.ref = t
				--if options.justref and options.justref ~= '' 
					--then
						--table.insert( Table, t )
					--else 
						--table.insert( Table, s .. t )
				--end
			end
		end
	end
	local fs = {}
	local head = mw.html.create( 'tr' )
	head:attr('colspan', 4)
	--head:css('background-color', '#E1E1E1')
	head:tag('td'):wikitext("'''کال'''")
	head:tag('td'):wikitext("'''لوبډله'''")
	head:tag('td'):wikitext("'''سيالۍ'''")
	head:tag('td'):wikitext("'''موخه'''")
	--if #Other > 0 or #Teams > 0 or #Nationals > 0 then
		 --table.insert( fs, tostring(head) )
	--end
	local Other_tot = mw.text.listToText( Other, options.separator, options.conjunction )
	if #Other > 0 then 
		table.insert( fs, wl.SubTitle({'لوبډله ' .. icon,'-' ,"b0c4de","000000",4}) )
		table.insert( fs, tostring(head) )
		table.insert( fs, Other_tot )
	end
	
	local Teams_tot = mw.text.listToText( Teams, options.separator, options.conjunction )
	if #Teams > 0 then
		table.insert( fs, wl.SubTitle({'مسلکي فعاليت ' .. icon,'-' ,"b0c4de","000000",4}) )
		if #Other <= 0 then table.insert( fs, tostring(head) ) end
		table.insert( fs, Teams_tot )
	end
	
	local Nationals_tot = mw.text.listToText( Nationals, options.separator, options.conjunction )
	if #Nationals > 0 then
		table.insert( fs , wl.SubTitle({'ملي&nbsp;لوبډله&nbsp;'.. icon,'-' ,"b0c4de","000000",4}) )
		if (#Other <= 0) and (#Teams <= 0) then table.insert( fs, tostring(head) ) end
		table.insert( fs, Nationals_tot )
	end
	local content = mw.getCurrentFrame():expandTemplate{ title = "صندوق معلومات سيرة كرة قدم/تعديل ويكي بيانات", args ={id = options.entityId or ""} }
	local edit_at_wd = mw.html.create( 'tr' )
		:tag('td')
			:attr('scope', 'col') 
			:css('background-color', '#F9F9F9')
			:css('color', '#000000')
			:css('text-align', "left")
			:attr('colspan', 4)
			:wikitext(content)
			:done()
	if #fs > 0 then
		table.insert( fs, tostring(edit_at_wd) )
	end
	--if tot == '' then tot = nil end
	--return tot
	return table.concat(fs)
end

return p