الفرق بين المراجعتين ل"وحدة:Wikibase"

من موسوعة المزرعة
اذهب إلى التنقل اذهب إلى البحث
 
سطر 1: سطر 1:
 +
---------- Module:Wikibase ----------------
 
local p = {}
 
local p = {}
 +
function p.getEntityObject(id)
 +
if not mw.wikibase then return nil end
 +
entity = mw.wikibase.getEntityObject(id)
 +
return entity
 +
end
  
function p.wikidatacheck(frame)
+
-- Return the item ID of the item linked to the current page.
local pframe = frame:getParent()
+
function p.id(frame)
local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
+
if not mw.wikibase then return nil end
local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
+
entity = mw.wikibase.getEntityObject()
 +
if entity == nil then
 +
return "no entity"
 +
end
 +
return entity.id
 +
end
  
local property = config.property
+
-- Return the label of a given data item, or of connected page
local value = config.value or ""
+
-- if no argument is provided to this method.
local catbase = config.category
+
function p.label(frame)
local namespaces = config.namespaces
+
if not mw.wikibase then return nil end
local nocatsame = config.nocatsame or ""
+
if frame.args[1] == nil then
local ok = false -- one-way flag to check if we're in a good namespace
+
entity = mw.wikibase.getEntityObject()
local ns = mw.title.getCurrentTitle().namespace
+
if not entity then return nil end
for v in mw.text.gsplit( namespaces, ",", true) do
+
id = entity.id
if tonumber(v) == ns then
+
else
ok = true
+
id = mw.text.trim(frame.args[1])
end
 
 
end
 
end
if not ok then -- not in one of the approved namespaces
+
return mw.wikibase.label( id )
return ""
+
end
 +
 
 +
-- Return the description of a given data item, or of connected page
 +
-- if no argument is provided to this method.
 +
function p.description(frame)
 +
if not mw.wikibase then return nil end
 +
if frame.args[1] == nil then
 +
entity = mw.wikibase.getEntityObject()
 +
if not entity then return nil end
 +
id = entity.id
 +
else
 +
id = mw.text.trim(frame.args[1])
 
end
 
end
local entity = mw.wikibase.getEntityObject()
+
return mw.wikibase.description( id )
if not entity then -- no Wikidata item
+
end
return "[[Category:" .. catbase .. " not in Wikidata]]"
+
 
 +
-- Return the local page about a given data item, or of connected page
 +
-- if id is not specified.
 +
function p.page(frame)
 +
if not mw.wikibase then return nil end
 +
if frame.args[1] == nil then
 +
entity = mw.wikibase.getEntityObject()
 +
if not entity then return nil end
 +
id = entity.id
 +
else
 +
id = mw.text.trim(frame.args[1])
 
end
 
end
if value == "" then
+
return mw.wikibase.sitelink( id )
return nil -- Using Wikidata
+
end
end
+
 
local claims = entity.claims or {}
+
-- Return the data type of a property
local hasProp = claims[property]
+
function p.datatype(frame)
if not hasProp then -- no claim of that property
+
if not mw.wikibase then return nil end
return "[[Category:" .. catbase .. " not in Wikidata]]" -- bad. Bot needs to add the property
+
if frame.args[1] and string.find(frame.args[1], "Property:P") then
end
+
if mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P")) then
for i, v in ipairs(hasProp) do -- Now we try to iterate over all possible values?
+
return mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P") ).datatype
propValue = (v.mainsnak.datavalue or {}).value
+
end
if propValue == value then
+
elseif frame.args[1] and string.find(frame.args[1], "P") then
if nocatsame == "" then
+
if mw.wikibase.getEntityObject(frame.args[1])  then
return "[[Category:" .. catbase .. " same as Wikidata]]" -- yay!
+
return mw.wikibase.getEntityObject(frame.args[1]).datatype
else
 
return nil -- if nocatsame, the "same as" category is not added
 
end
 
 
end
 
end
 
end
 
end
return "[[Category:" .. catbase .. " different from Wikidata]]" -- needs human review :(
 
 
end
 
end
  
 
return p
 
return p

المراجعة الحالية بتاريخ 23:35، 4 أبريل 2021

هذه الوحدة تم نسخها من المثال من صفحة توثيق الوحدة في mw:Extension:Wikibase Client/Lua. ويجب أن تبقى متسقة مع تلك الصفحة.

الاستخدام[عدل]

معرف
{{#invoke: Wikibase | id }}
تسمية
{{#invoke: Wikibase | label }}
{{#invoke: Wikibase | label | entity id (Q# or P#) }}
وصف
{{#invoke: Wikibase | description }}
{{#invoke: Wikibase | description | entity id (Q# or P#) }}
صفحة
{{#invoke: Wikibase | page }}
{{#invoke: Wikibase | page | item id (Q#) }}
نوع البيانات
{{#invoke: Wikibase | datatype | property id (P#) }}

أمثلة[عدل]

معرف[عدل]

  • {{#invoke:Wikibase | id }} ينتج ←

تسمية[عدل]

  • {{#invoke:Wikibase | label }} ينتج ←
  • {{#invoke:Wikibase | label | Q132689 }} ينتج ←
  • {{#invoke:Wikibase | label | P31 }} ينتج ←

وصف[عدل]

  • {{#invoke:Wikibase | description }} ينتج ←
  • {{#invoke:Wikibase | description | Q132689 }} ينتج ←
  • {{#invoke:Wikibase | description | P31 }} ينتج ←

صفحة[عدل]

  • {{#invoke:Wikibase | page }} ينتج ←
  • {{#invoke:Wikibase | page | Q132689 }} ينتج ←

نوع البيانات[عدل]

⧼datatypes-type-commonsMedia⧽: [[d:Property:P18|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P18)]]

  • {{#invoke:Wikibase | datatype | P18 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P18 }} ينتج ←

⧼datatypes-type-globe-coordinate⧽: [[d:Property:P625|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P625)]]

  • {{#invoke:Wikibase | datatype | P625 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P625 }} ينتج ←

⧼datatypes-type-wikibase-item⧽: [[d:Property:P6|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P6)]]

  • {{#invoke:Wikibase | datatype | P6 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P6 }} ينتج ←

⧼datatypes-type-wikibase-property⧽: [[d:Property:P1647|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P1647)]]

  • {{#invoke:Wikibase | datatype | P1647 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P1647 }} ينتج ←

⧼datatypes-type-string⧽: [[d:Property:P225|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P225)]]

  • {{#invoke:Wikibase | datatype | P225 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P225 }} ينتج ←

⧼datatypes-type-monolingualtext⧽: [[d:Property:P1448|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P1448)]]

  • {{#invoke:Wikibase | datatype | P1448 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P1448 }} ينتج ←

⧼datatypes-type-quantity⧽: [[d:Property:P1082|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P1082)]]

  • {{#invoke:Wikibase | datatype | P1082 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P1082 }} ينتج ←

⧼datatypes-type-time⧽: [[d:Property:P569|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P569)]]

  • {{#invoke:Wikibase | datatype | P569 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P569 }} ينتج ←

⧼datatypes-type-url⧽: [[d:Property:P856|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P856)]]

  • {{#invoke:Wikibase | datatype | P856 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P856 }} ينتج ←

⧼datatypes-type-math⧽: [[d:Property:P2534|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P2534)]]

  • {{#invoke:Wikibase | datatype | P2534 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P2534 }} ينتج ←

⧼datatypes-type-external-id⧽: [[d:Property:P212|

  • عنصر قائمة منقطة
  1. تحويل قالب:تسمية
Light Bulb Icon.svg
هذه تحويلة لقالب:
فضلًا اطلب حذف هذه التحويلة حذفًا سريعًا إن لم تكن ضرورية.
طالع عدد استخدامات القالب في المقالات (من هنا)

(P212)]]

  • {{#invoke:Wikibase | datatype | P212 }} ينتج ←
  • {{#invoke:Wikibase | datatype | Property:P212 }} ينتج ←

---------- Module:Wikibase ----------------
local p = {}
function p.getEntityObject(id)
	if not mw.wikibase then return nil end
	entity = mw.wikibase.getEntityObject(id)
	return entity
end

-- Return the item ID of the item linked to the current page.
function p.id(frame)
	if not mw.wikibase then return nil end
	entity = mw.wikibase.getEntityObject()
	if entity == nil then
		return "no entity"
	end
	return entity.id
end

-- Return the label of a given data item, or of connected page
-- if no argument is provided to this method.
function p.label(frame)
	if not mw.wikibase then return nil end
	if frame.args[1] == nil then
		entity =  mw.wikibase.getEntityObject()
		if not entity then return nil end
		id = entity.id
	else
		id = mw.text.trim(frame.args[1])
	end
	return mw.wikibase.label( id )
end

-- Return the description of a given data item, or of connected page
-- if no argument is provided to this method.
function p.description(frame)
	if not mw.wikibase then return nil end
	if frame.args[1] == nil then
		entity = mw.wikibase.getEntityObject()
		if not entity then return nil end
		id = entity.id
	else
		id = mw.text.trim(frame.args[1])
	end
	return mw.wikibase.description( id )
end

-- Return the local page about a given data item, or of connected page
-- if id is not specified.
function p.page(frame)
	if not mw.wikibase then return nil end
	if frame.args[1] == nil then
		entity = mw.wikibase.getEntityObject()
		if not entity then return nil end
		id = entity.id
	else
		id = mw.text.trim(frame.args[1])
	end
	return mw.wikibase.sitelink( id )
end

-- Return the data type of a property
function p.datatype(frame)
	if not mw.wikibase then return nil end
	if frame.args[1] and string.find(frame.args[1], "Property:P") then
		if mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P"))  then
			return mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P") ).datatype
		end
	elseif frame.args[1] and string.find(frame.args[1], "P") then
		if mw.wikibase.getEntityObject(frame.args[1])  then
			return mw.wikibase.getEntityObject(frame.args[1]).datatype
		end
	end
end

return p