پرش به محتوا

پودمان:Wikidata for infobox

از ویکی‌پدیا، دانشنامهٔ آزاد
توضیحات پودمان[ایجاد] [پاکسازی]
--
-- Wikidata used to get data for infoboxes which are separated by occupation.
--
-- Author: Alireza (User:علیرضا)
-- Distributed under the terms of the CC-BY-SA 4.0
--

local infobox = require("Module:Infobox").infobox
local getArgs = require("Module:Arguments").getArgs
local entity = mw.wikibase.getEntityObject()
local p = {}

local function getInfoboxDataByOccupation()  
  if not entity then
    error("entity is a nil value")
  end

  local occupation = p.getPropertyValue("P106")

  if occupation == mw.wikibase.label("Q82955") then
    return require("Module:Wikidata for infobox/occupations/politician")
  else
    error("There is no infobox data for this occupation.")
  end
end

function p.getLabel(frame)
  local args = getArgs(frame, {parentOnly = true})
  args[1] = args[1] and string.upper(args[1]) or nil

  if not args[1] then
    error("No item given.")
  end

  return mw.wikibase.label(args[1])
end

function p.getPropertyValue(property)
  property = property and string.upper(property) or nil

  if not property then
    error("No property given.")
  end

  return entity:formatPropertyValues(property).value
end

function p.makeInfobox()
  local methods = require("Module:Wikidata for infobox/occupations")

  return infobox( methods:makeCompatible( getInfoboxDataByOccupation() ) )
end

return p