الفرق بين المراجعتين لصفحة: «وحدة:Uses Wikidata»

من ويكي عرب
اذهب إلى التنقل اذهب إلى البحث
ط (Changed protection settings for "Module:Uses Wikidata": High-risk template or module: 2770 transclusions (more info) ([Edit=Require extended confirmed access] (indefinite) [Move=Require extended confirmed access] (indefinite)))
ط (مراجعة واحدة)
سطر ١: سطر ١:
local p = {}
local p = {}
local wd2 = require('Module:Wikidata2').formatStatementsFromLua
local gett = require('Module:Uses_Wikidata/datatype').gettype


function p.usesProperty(frame)
function p.usesProperty(frame)
local args = frame.getParent(frame).args or nil
local parent = frame.getParent(frame)
if mw.text.trim(args[1] or '') == '' then
args = frame.args
end
local result = ''
local result = ''
local ii = 1
local ii = 1
while true do
while true do
local p_num = mw.text.trim(args[ii] or '')
local p_num = parent.args[ii] or ''
if p_num ~= '' then
if p_num ~= '' then
local label = mw.wikibase.getLabel(p_num) or "NO LABEL"
p_num = mw.text.trim( p_num )
result = result .. "<ul><li>[[File:Disc Plain blue dark.svg|middle|4px|link=]] <b><i>[[d:Property talk:" .. p_num .. "|" .. label .. " (" .. string.upper(p_num) .. ")]]</i></b> (see <span class='plainlinks'>[https://query.wikidata.org/embed.html#SELECT%20%3FWikiData_item_%20%3FWikiData_item_Label%20%3Fvalue%20%3FvalueLabel%20%3FEnglish_WikiPedia_article%20%23Show%20data%20in%20this%20order%0A%7B%0A%09%3FWikiData_item_%20wdt%3A" .. p_num .. "%20%3Fvalue%20.%20%23Collecting%20all%20items%20which%20have%20" .. p_num .. "%20data%2C%20from%20whole%20WikiData%20item%20pages%0A%09OPTIONAL%20%7B%3FEnglish_WikiPedia_article%20schema%3Aabout%20%3FWikiData_item_%3B%20schema%3AisPartOf%20%3Chttps%3A%2F%2Fen.wikipedia.org%2F%3E%20.%7D%20%23If%20collected%20item%20has%20link%20to%20English%20WikiPedia%2C%20show%20that%0A%09SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20%20%7D%20%23Show%20label%20in%20this%20language.%20%22en%22%20is%20English.%20%20%20%0A%7D%0ALIMIT%201000 uses]</span>)</li></ul>"
if mw.ustring.gsub( p_num, '%d', '' ) == 'P' then
ii = ii + 1
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
else break
end
end
ii = ii + 1
end
end
return result
return result
end
end


function p.tuProperty(frame)
Type = {
local parent = frame.getParent(frame)
["wikibase-item"]= "عنصر ويكي بيانات",
local result = ''
["wikibase-property"]= "خاصية ويكي بيانات",
["commonsMedia"]= "وسائط كومنز",
["math"]= "تعبير رياضي",
["time"]= "وقت",
["external-id"]= "معرف خارجي",
["string"]= "نص",
["globe-coordinate"]= "إحداثيات",
["quantity"]= "كمية",
["geo-shape"]= "شكل جغرافي",
["url"]= "مسار",
["monolingualtext"]= "نص بلغة وحيدة",
}
function getpropertytype(id)
local ca = ""
local mo =  gett(id)
if mo and mo ~= "" then
if Type[mo] then
ca = Type[mo]
end
else
local entity = mw.wikibase.getEntityObject(id)
if entity
and entity['datatype']
and Type[entity['datatype']]
then
ca = Type[entity['datatype']]
else ca =''
end
end
if ca and ca ~= '' then
return '<small> (' .. ca .. ')</small>'
end
return ''
end
 
function LabelOrDes(langcode , id , lab , args)
if lab == 'labels'
then cas = 'lab'
elseif lab == 'descriptions'
then  cas = 'des'
end
----------------------
local arg = args[id .. cas] or ''
local lan = langcode or 'ar'
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 , args , name)
local PO = ''
local Property = wd2({entityId =  id , property = prop ,formatting ='sitelink', addTrackingCat ='',noicon='t',nolink ='t', firstvalue='s'}) or ''
--if Property and Property ~='' then Property = '[[:' .. Property ...']] ({{PAGESINCAT:' .. mw.ustring.gsub(Property, 'تصنيف:' , '') .. '}} صفحة)' end
----------------------
if args[id .. 'cat'] and args[id .. 'cat'] ~= ''
then
Property = args[id .. 'cat']
end
----------------------
newtrak = args['track'] or ""
if not Property or Property == "" then
if prop == "P2875" and newtrak ~= "" then
Property = "تصنيف:صفحات تستخدم خاصية " .. id
end
end
if Property and Property ~='' then
PO = makecat(Property , name)
end
----------------------
return PO
end
 
function p._usestable(args)
aaa = {}
aa = {}
local nott = "<abbr title='قيم ليست على ويكي بيانات'>ليست.</abbr>"
local same = "<abbr title='قيم كما في ويكي بيانات'>مطابقة.</abbr>"
local def ="<abbr title='قيم مختلفة عن ويكي بيانات'>مختلفة.</abbr>"
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 = args['قالب'] or 'القالب'
local ii = 1
local ii = 1
while true do
while true do
local p_num = mw.text.trim(parent.args[ii] or '')
local p_num = args[ii] or ''
mw.log("Module:Uses Wikidata: " .. p_num)
if p_num ~= '' then
if p_num ~= '' then
local label = mw.wikibase.getLabel(p_num) or "NO LABEL"
p_num = mw.text.trim( p_num )
result = result .. "<ul><li><span style='font-size:90%;line-height:1;'>●</span>&nbsp;&nbsp;<b>[[d:Property:" .. p_num .. "|" .. label .. "]]</b> <span style='font-size:90%;'>([[d:Property talk:" .. string.upper(p_num) .. "|" .. p_num .. "]])</span></li></ul>"
if mw.ustring.gsub( p_num, '%d', '' ) == 'P' then
ii = ii + 1
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
else break
end
end
ii = ii + 1
end
if temp ~= 'القالب'
then temp = '[[قالب:' .. temp .. ']]'
end
local head_s = '{| class="wikitable sortable" style="text-align:right; width: '
local head2 = '%; font-size: 95%;"\n|+خواص [[ويكي بيانات]] المستخدمة في ' .. temp .. '\n'
local width =  args['width'] or  "75"
local head = head_s .. width .. head2
 
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('ar', p_num ,'labels' , args) or LabelOrDes('en', p_num ,'labels' , args) or "بدون تسمية"
local description = LabelOrDes( 'ar', p_num ,'descriptions' , args) or "" --"بدون وصف"
local P2875 = getprop(p_num , 'P2875' , args , '')
local P3713 = getprop(p_num , 'P3713' , args , 'ليست')
local P3734 = getprop(p_num , 'P3734' , args , 'مطابقة')
local P3709 = getprop(p_num , 'P3709' , args , 'مختلفة')
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
div1 = '<div style="height:650px; width:'..width..'%; overflow:auto; padding:3px; border:solid 1px;">\n'
down2 = mw.getCurrentFrame():preprocess('{{#تبديل:{{SUBPAGENAME}}|ملعب|doc|مختبر|نسخة|تجربة|شرح=|#default=[[تصنيف:قوالب تستخدم بيانات من ويكي بيانات]]}}' )
down = '|}' .. down2
if ii > 20 then
head = div1 .. head_s .. "100" .. head2
down = down .. "</div>"
end
final  = head  .. r .. result .. down
final1 = head  .. r1 .. result1 .. down
--######################
if FFF ~= '' then
return final
else
return final1
end
end
return result
--######################
end
end


function p.usestable(frame)
local parent = frame.getParent(frame)
return p._usestable(parent.args)
end
return p
return p

مراجعة ٠٩:٥٩، ٢٠ نوفمبر ٢٠٢١

يمكن إنشاء صفحة توثيق الوحدة في وحدة:Uses Wikidata/شرح

local p = {}
local wd2 = require('Module:Wikidata2').formatStatementsFromLua
local gett = require('Module:Uses_Wikidata/datatype').gettype

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 ca = ""
	local mo =  gett(id)
	if mo and mo ~= "" then
		if Type[mo] then
			ca = Type[mo]
		end
	else
		local entity = mw.wikibase.getEntityObject(id)
		if entity
		and entity['datatype']
		and Type[entity['datatype']]
		then
			ca = Type[entity['datatype']]
			else ca =''
		end
	end
	if ca and ca ~= '' then
		return '<small> (' .. ca ..	 ')</small>'
	end
return ''
end

function LabelOrDes(langcode , id , lab , args) 
	if lab == 'labels'
		then cas = 'lab'
	elseif lab == 'descriptions'
		then  cas = 'des'
	end
	----------------------
	local arg = args[id .. cas] or ''
	local lan = langcode or 'ar'
	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 , args , name)
	local PO = ''
	local Property = wd2({entityId =  id , property = prop ,formatting ='sitelink', addTrackingCat ='',noicon='t',nolink ='t', firstvalue='s'}) or ''
	--if Property and Property ~='' then Property = '[[:' .. Property ...']] ({{PAGESINCAT:' .. mw.ustring.gsub(Property, 'تصنيف:' , '') ..	 '}} صفحة)' end
	----------------------
	if args[id .. 'cat'] and args[id .. 'cat'] ~= '' 
	then 
		Property = args[id .. 'cat'] 
	end
	----------------------
	newtrak = args['track'] or ""
	if not Property or Property == "" then 
		if prop == "P2875" and newtrak ~= "" then
			Property = "تصنيف:صفحات تستخدم خاصية " .. id
		end
	end
	if Property and Property ~='' then
		PO = makecat(Property , name)
	end
	----------------------
	return PO
end

function p._usestable(args)
	aaa = {}
	aa = {}
	local nott = "<abbr title='قيم ليست على ويكي بيانات'>ليست.</abbr>"
	local same = "<abbr title='قيم كما في ويكي بيانات'>مطابقة.</abbr>"
	local def ="<abbr title='قيم مختلفة عن ويكي بيانات'>مختلفة.</abbr>"
	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	= args['قالب'] or 'القالب'
	local ii = 1
	while true do
		local p_num = args[ii] or ''
		mw.log("Module:Uses Wikidata: " .. 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_s = '{| class="wikitable sortable" style="text-align:right; width: '
	local head2 = '%; font-size: 95%;"\n|+خواص [[ويكي بيانات]] المستخدمة في ' .. temp .. '\n'
	local width =  args['width'] or  "75"
	local head = head_s .. width .. head2

	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('ar', p_num ,'labels' , args) or LabelOrDes('en', p_num ,'labels' , args) or "بدون تسمية"
			local description = LabelOrDes( 'ar', p_num ,'descriptions'	 , args) or "" --"بدون وصف"
			local P2875 = getprop(p_num , 'P2875' , args , '')
			local P3713 = getprop(p_num , 'P3713' , args , 'ليست')
			local P3734 = getprop(p_num , 'P3734' , args , 'مطابقة')
			local P3709 = getprop(p_num , 'P3709' , args , 'مختلفة')
			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
	div1 = '<div style="height:650px; width:'..width..'%; overflow:auto; padding:3px; border:solid 1px;">\n'
	down2 = mw.getCurrentFrame():preprocess('{{#تبديل:{{SUBPAGENAME}}|ملعب|doc|مختبر|نسخة|تجربة|شرح=|#default=[[تصنيف:قوالب تستخدم بيانات من ويكي بيانات]]}}' )
	down = '|}' .. down2
	if ii > 20 then 
		head = div1 .. head_s .. "100" .. head2
		down = down .. "</div>"
	end
	
	final  = head  .. r .. result .. down
	final1 = head  .. r1 .. result1 .. down
	--######################
	if FFF ~= '' then 
		return final
	else
		return final1
	end
	--######################
end

function p.usestable(frame)
	local parent = frame.getParent(frame)
	return p._usestable(parent.args)
end
return p