User:Herzi Pinki/Sandbox/Module:Any Austrian ID

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

--

--[[
  Lua module for handling multiple existing IDs as used in 
   * Template:Denkmalgeschütztes Objekt Österreich
   * Template:Tiroler Kunstkataster
   * Template:Naturdenkmal Österreich
   etc.

  AllIDs():
  Interface:
  * takes a single WD-Item (Q id),
  * reads all relevant and configured IDs (with multiple values)
  * creates the templates for the various existing IDs
  * errors: if WD-Item does not exist
  
  There is no need of localization here, as this is done in the templates called

  Referenzen:
  - https://de.wikipedia.org/w/index.php?title=Vorlage:Denkmalliste_%C3%96sterreich_Tabellenzeile&oldid=167492395
  - https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual
  - https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
]]

local WLink = require('Module:WLink').WLink()
local AdressenSort = require('Module:AdressenSort')
local FormatDate = require('Modul:Vorlage:FormatDate')

--[[
    set of
    <WD property id> = {-- <WD property name> for readability
                        template = "<name of template to generate>",
                        params   = array of param descriptions { name, type } for template
                                   with type = "id" | "iso"
                       },
]]

local config = {
    P2951 = {-- Objekt-ID der Datenbank österreichischer Kulturdenkmale
             template = "Denkmalgeschütztes Objekt Österreich",
             params   = [{"1", "id"}]
            },
    P4219 = {-- Inventarnummer des Tiroler Kunstkatasters
             template = "Tiroler Kunstkataster",
             params   = [{"1", "id"}]
            },
    P42190 = {-- Inventarnummer des Tiroler Kunstkatasters (TODO)
             template = "Naturdenkmal Österreich",
             params   : [{"1", "id"},
                         {"2", "iso"}
                        ]
            },
]

local function _withoutEmptyFields(t)
  local new = {}
  for k, v in pairs(t) do
    if #v > 0 then
      new[k] = v
    end
  end
  return new
end

local function _argumentOrWikidata(args, argsKey, wikidataProperty)
  if argKey and args[argKey] then
    return args[argKey]
  elseif not args['WD-Item'] then
    return nil
  end
  local statement = mw.wikibase.getBestStatements(args['WD-Item'], wikidataProperty)
  return (statement[1] and statement[1].mainsnak.datavalue.value) or nil
end

--
    td:wikitext(mw.getCurrentFrame():expandTemplate({title = 'Bilderwunsch/encode', args = {
      Ort = args.Artikel or mw.title.getCurrentTitle().text,
      Name = args.Name or '',
      KoordLat = args['Breitengrad'] or '',
      KoordLon = args['Längengrad'] or ''
    }}))
--
p = {}

p.AllIDs= function(frame)
  local args = frame.args
  if not args or not args.WD-Item then
    args = mw.getCurrentFrame():getParent().args
  end
  args = _withoutEmptyFields(args)
  --
  local tr = mw.html.create('tr')
  if args.ObjektID then
    tr:attr('id', 'objektid-' .. args.ObjektID)
    tr:addClass('vcard')
  end
  if args.Datenfehler then
    tr:addClass('BDAerror')
  end

  return tostring(tr)
end

return p

--