وحدة:Wikidata2/otheruse

من أرابيكا، الموسوعة الحرة
اذهب إلى التنقل اذهب إلى البحث

local p = {}
local help_functions

function isvalid(x)
	if x and x ~= "" then return x end
	return nil
end

function ifd ( fii , opt )
	if isvalid(opt) then
		if opt == 'club' then
			if fii == 'Q476028' then
				return fii
			end
		elseif opt == 'team' then
			if fii == 'Q6979593' or fii == 'Q23895910'	or fii == 'Q23847779' then
				return fii
			end
		else
			return fii 
		end
	end 

end

function p.foot( claims , options)
	local formattedStatements = {}
	local statementsraw = {}
	if help_functions == nil then
		help_functions = require("Module:Wikidata2/functions2")
	end
	if isvalid(options.sortingproperty) and help_functions.sorting_methods[options.sortbynumber] then
		claims = help_functions.sortbyqualifiernumber(claims, {}, options)
	end
	if claims then
		for i, statement in pairs( claims ) do
			options.num = i
			local va = formatOneStatement( statement, nil , options )
			if va.v then
				table.insert( formattedStatements, va.v )
			end
			table.insert( statementsraw, va.raw )
		end
	end
	local tot = mw.text.listToText( formattedStatements, options.separator, options.conjunction )
	if tot == '' then tot = nil end
	if options.raw and options.raw ~= '' then
		return statementsraw
	end
	if options.numberofclaims and options.numberofclaims ~= '' then
		return #formattedStatements
	end
	return tot
end

function p.awards( datavalue, datatype, options ) -- used by template:ص.م/سطر جوائز ويكي بيانات
	if datatype == 'wikibase-item'	
		then
				local value= datavalue.value
			local image = formatStatements( {property ='P2425' , entityId = value.id
				, noref =options.noref , size ='30', image ='yes', noref='true' , firstvalue='true'})
			local image2 = formatStatements( {property ='P154' , entityId = value.id
				, noref =options.noref , size ='30', image ='yes', noref='true' , firstvalue='true'})
		local categoryid = formatStatements( {property ='P2517', entityId = value.id, noref ='true'
				, firstvalue='true',separator='',conjunction='',formatting ='raw'})
		local categoryid2 = formatStatements( {property ='P910', entityId = value.id, noref ='true'
				, firstvalue='true',separator='',conjunction='',formatting ='raw'})

		if not image or image == '' then image =image2 end
		if not categoryid or categoryid == '' then categoryid = categoryid2 end

			local category = mw.wikibase.sitelink( categoryid )
			local s = formatEntityId( value.id, options ).value
		   if s and s  ~= '' then
					if image and image ~= '' then
						s = image ..' ' .. s
					end
				if category and category  ~= '' 
					then 
							return	s.. ' [[' ..category ..']]'
				else 
					return s 
				end
		end
	else  return ''
	end
end

function p.getpropertyfromvalue( datavalue ,datatype , options)

	if datatype == 'wikibase-item'	
		then
	
					local value= datavalue.value
					local caca = formatStatements( {
						 property =options.prop2 , entityId = value.id
						, noref =options.noref , rank=options.rank	
						, size =options.size	, image =options.image
						, noref='true' , firstvalue='true'
						, propertyimage =options.prop3
						}
					)
					local asdf = formatEntityId( value.id, options ).value
			if asdf and asdf  ~= '' then
					if caca and caca  ~= '' 
						then 
								return	caca ..' '.. asdf
						else return asdf  
					end
			end

		else  return 'datatype	isn\'t wikibase-item' 
	end
end

--[[
	this is like p.formatPlaceWithQualifiers in ru:Модуль:Wikidata/Places
]]
function p.PlacesWithLocatedIn( datavalue, datatype, options )
	if datatype == 'wikibase-item'	
		then
			function P131 (id,formatting,p)
				st = formatStatements( {property =p or 'P131' , entityId = id, noref ='t', firstvalue='true',formatting=formatting})
				--if id == st then st = nil end
				return st
			end
		local value= datavalue.value
		local v = formatEntityId( value.id, options ).value
		local P1 = P131(value.id,'') 
		local P1id = P131(value.id,'raw')	
		local P2 = P131(P1id,'') 
		local P2id = P131(P1id,'raw')	
		local P3 = P131(P2id,'') 
		local P3id = P131(P2id,'raw')
		local P4 = P131(P3id,'') 
		--table.insert(tt , v)
			function dd (s1 ,s2 ,s3 )
				if s1 and s1 ~= '' then
					if s2 and s2 ~= '' 
						then 
							return	s1 .. '، '..  s2
						else 
							if s1 == s3 
								then return s1 
								else return s1 .. '، '..  s3
							end
					end
				end
			end
			if v and v	~= '' 
				then
					val = dd(v,dd(P1
									,dd(
										P2,dd(P3
												,P4
												, P131(P3id,'','P17')
											)
										, P131(P2id,'','P17')
										)
								, P131(P1id,'','P17')
								) 
							, P131(value.id,'','P17')
							) 
			end
		return val
		else
			return 'datatype  isn\'t wikibase-item' 
	end
end

return p