Module:Uses Wikidata

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

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

local p = {}
local wd2 = require('Module:Wikidata2').formatStatementsFromLua

function p.usesProperty(frame)
	local parent = frame.getParent(frame)
	local result = ''
	local ii = 1
	while true do
		local p_num = parent.args[ii] or ''
		if p_num ~= '' then
			p_num = mw.text.trim( p_num )
			if mw.ustring.gsub( p_num, '%d', '' ) == 'P' then
				local label = mw.wikibase.label(p_num) or "بغير وصف"
			result = result .. "<li><b><i>[[d:Property:" .. p_num .. "|" .. label .. " <small>(" .. string.upper(p_num) .. ")</small>]]</i></b> (وګورئ [[d:Special:WhatLinksHere/Property:" .. p_num .. "|کارونه]])</li>"
			end

		else break
		end
		ii = ii + 1
	end
	return result
end

Type = {
		["wikibase-item"]= "ویکی بیس آيټم",
		["wikibase-property"]= "خاصیت ویکی بیس",
		["commonsMedia"]= "کومنز ميډيا",
		["math"]= "ریاضی",
		["time"]= "وقت",
		["external-id"]= "بهرنې آئی ډی",
		["string"]= "نص",
		["globe-coordinate"]= "متناسقات",
		["quantity"]= "مقدار",
		["geo-shape"]= "شکل جغرافیه",
		["url"]= "یو آر ایل",
		["monolingualtext"]= "نص بلغة وحيدة",
		}
function getpropertytype(id) 
	local entity = mw.wikibase.getEntityObject(id)
		if entity
		and entity['datatype']
		and Type[entity['datatype']]
		then
			ca = Type[entity['datatype']]
			else ca =''
		end
	if ca and ca ~= '' then
	return '<small> (' .. ca ..	 ')</small>'
	end
return ''
end

function LabelOrDes(langcode , id , lab , parent) 
	if lab == 'labels'
		then cas = 'lab'
	elseif lab == 'descriptions'
		then  cas = 'des'
	end
	----------------------
	local arg = parent.args[id .. cas] or ''
	local lan = langcode or 'ps'
	local entity = mw.wikibase.getEntityObject(id)
	----------------------
	if arg and arg ~= '' 
	then 
		return arg
	else
		if entity
		and entity[''..lab ..'']
		and entity[''..lab ..''][''..lan..'']
		and entity[''..lab ..''][''..lan..''].value 
		then
			local lang = entity[''..lab ..''][''..lan..'']
				if lang['language'] == lan 
				then
					return entity[''..lab ..''][''..lan..''].value
				else
					return nil
				end
		end
	end
end

function makecat(P, name)
	PO = ''
	----------------------
	if P and P ~='' then
		local cat = mw.ustring.gsub(P, 'وېشنيزه:' , '')
		local catname = mw.ustring.gsub(cat, 'مخونه استعمال خاصیت' , 'مخونه استعمال')
		if name and name ~= '' then	 catname = name end
		PO = "[[:" .. P .. "|" .. catname .. "]] (<abbr title='عدد استعمالات'>په</abbr> " .. mw.site.stats.pagesInCategory(cat, 'all') .. " مخ)"		
	end
	----------------------
	return PO
end

function getprop(id , prop , parent , name)
	local PO = ''
	local Property = wd2({entityId =  id , property = prop ,formatting ='sitelink', addTrackingCat ='',noicon='t',nolink ='t', enbarten='s'}) or ''
	--if Property and Property ~='' then Property = '[[:' .. Property ...']] ({{PAGESINCAT:' .. mw.ustring.gsub(Property, 'وېشنيزه:' , '') ..	 '}} مخ)' end
	----------------------
	if parent.args[id .. 'cat'] and parent.args[id .. 'cat'] ~= '' 
	then 
		Property = parent.args[id .. 'cat'] 
	end
	----------------------
	if Property and Property ~='' then
		PO = makecat(Property , name)
	end
	----------------------
	return PO
end

function p.usestable(frame)
	aaa = {}
	aa = {}
	local nott = "<abbr title='قيم ليست على ويكي بيانات'>ليست.</abbr>"
	local same = "<abbr title='قيم كما في ويكي بيانات'>مطابقة.</abbr>"
	local def ="<abbr title='قيم مختلفة عن ويكي بيانات'>مختلفة.</abbr>"
	local parent = frame.getParent(frame)
	local r = '! data-sort-type="number" style="width: 20%;"| الخاصية'
	r =	 r .. '!! style="width: 45%; " | وصفها'
	r =	 r .. '!! style="width: 30%; " | تصنيف تتبع الاستخدام' 
	local r1 = r .. '\n|-\n'
	r =	 r .. '!! style="width: 30%; " | ' .. nott
	r =	 r .. '!! style="width: 30%; " | ' .. same
	r =	 r .. '!! style="width: 30%; " | ' .. def
	r =	 r .. '\n|-\n'
	local temp	= parent.args['کينډۍ'] or 'کينډۍ'
	local ii = 1
	while true do
		local p_num = parent.args[ii] or ''
		mw.log(p_num)
		if p_num ~= '' then
			p_num = mw.text.trim( p_num )
			if mw.ustring.gsub( p_num, '%d', '' ) == 'P' then
				table.insert(aa, p_num)
			--else
				
				--if mw.ustring.gsub( p_num, 'کينډۍ=', '' ) ~= p_num then
					--temp = mw.ustring.gsub( p_num, 'کينډۍ=', '' )
				--end
			end
		else break
		end	
		ii = ii + 1
	end
	if temp ~= 'القالب' 
		then temp = '[[کينډۍ:' .. temp .. ']]' 
	end
	local head = '{| class="wikitable sortable" style="text-align:right; width: 80%; font-size: 95%;"\n|+'
	local head = head .. 'خواص [[ويکيډاټا]] استعمال په ' .. temp .. '\n'

	local result = ''
	local result1 = ''
	local FFF = ''
	--table.sort(aa, function(a, b) return a < b end)
	table.sort(aa)
	for k, p_num in pairs(aa) do
			local rr = " (انظر [[d:Special:WhatLinksHere/Property:" .. p_num .. "|الاستخدام]])"
			local label = LabelOrDes('ps', p_num ,'labels' , parent) or LabelOrDes('en', p_num ,'labels' , parent) or "د تسميي بغير"
			local description = LabelOrDes( 'ps', p_num ,'descriptions'	 , parent) or "" --"د څرګندولو پرته"
			local P2875 = getprop(p_num , 'P2875' , parent , '')
			local P3713 = getprop(p_num , 'P3713' , parent , 'ليست')
			local P3734 = getprop(p_num , 'P3734' , parent , 'مطابقة')
			local P3709 = getprop(p_num , 'P3709' , parent , 'مختلفة')
			if P3713 ~='' or P3734 ~='' or P3709 ~='' then
				FFF = 'sa'
			end
			--local pro = '<span style="font-family: monospace, monospace;">' .. string.upper(p_num) .. '</span>'
			--local span= ' data-sort-value="' .. mw.ustring.gsub(p_num, 'P' , '').. '"| ' .. pro .. ''
			--local name  = "|" .. span	 .. "|| <b>[[d:Property:" .. p_num .. "|" .. label .. "]]</b> || "
			local propertytype = getpropertytype(p_num)
			local pro = ' (' .. string.upper(p_num) .. ')'
			local span= '| data-sort-value="' .. mw.ustring.gsub(p_num, 'P' , '').. '"| '
			--local name  = span  .. " <small>[[d:Property:" .. p_num .. "|" .. label .. pro .. "]]</small>" .. propertytype.. " ||"
			local name	= span	.. " <b>[[d:Property:" .. p_num .. "|" .. label .. pro .. "]]</b>" .. propertytype.. " ||"
			result = result .. name .. description
			result1 = result1 .. name .. description  .. "|| " .. P2875 ..	"\n|-\n"
			result = result	 .. "|| " .. P2875
			result = result	 .. "|| " .. P3713
			result = result	 .. "|| " .. P3734
			result = result	 .. "|| " .. P3709
			result = result ..	"\n|-\n"
	end
	final  = head  .. r .. result .. '|}[[وېشنيزه:کينډۍ چي د ويکيډاټا معلومات کاروي]]'
	final1 = head  .. r1 .. result1 .. '|}[[وېشنيزه:کينډۍ چي د ويکيډاټا معلومات کاروي]]'
	--######################
	if FFF ~= '' then 
		return final
	else
		return final1
	end
	--######################
end

return p