Modul:Quickbar Notruf/Test

Aus Wikivoyage
Dokumentation für das Modul Quickbar Notruf/Test[Ansicht] [Bearbeiten] [Versionsgeschichte] [Aktualisieren]

Testobjekte

Notrufnummern Deutschland

Notrufnummern
Notrufnummer(n)Euronotruf 112,
110 (Polizei)


Notrufnummern Demokratische Republik Kongo

Notrufnummern
Notrufnummer(n)113 (Feuerwehr),
114 (Polizei),
118 (Polizei)

Hinweise
--[=[ Quickbar Notruf 2023-02-12
]=]

local items    = require( 'Module:GetItem' )


-- returns nil, if both values are equal, otherwise the value
-- similar to the SQL function nullif()
local function nilIf ( value, equalValue )

   if ( value == nil ) then
      return nil
   elseif ( tostring ( value ) == tostring ( equalValue ) ) then
      return nil
   else
      return value
   end

end


local qbNotruf = {}

function qbNotruf.qb_notruf ( frame )
  
   -- copying and lowering the given parameters
   local templateArgs = {}
   for key,value in pairs ( frame.args ) do
      templateArgs[string.lower(key)] = value
   end
   for key,value in pairs ( frame:getParent().args ) do
      templateArgs[string.lower(key)] = value
   end

   -- variables for the whole quickbar content and the categories
   local display = ''
   local categories = ''
   
   -- contains some site.infos
   -- needed as fallback for the  parameter "Namen" and the location map
   local page = {}
   page = mw.title.getCurrentTitle()   

   -- getting or determining (if needed) the wikidata-ID
   if templateArgs.id == '' then templateArgs.id = nil end
   local qbID = nilIf ( nilIf ( templateArgs.id, 'self' ), '' ) or mw.wikibase.getEntityIdForCurrentPage() or ''

   -- determining the country 
   -- (not urgently needed, but if someone wants to develop country- specific quickbars)
   -- getting from Wikidata, if not provided
   -- if you want to save processing time, you should provide it
   -- e.g. in country specific infobox tables
   local qbIso3166 = templateArgs["iso-3166"] or ''
   local qbIso3166Class = '' 
   if qbIso3166 == '' then
      if qbID ~= '' then
         local wdCountry = mw.wikibase.getBestStatements( qbID, 'P17' )
         local wdIso3166 = {}
         if #wdCountry > 0 then
            -- there where empty values
            if wdCountry[1].mainsnak.datavalue ~= nil then
               wdIso3166 = mw.wikibase.getBestStatements( wdCountry[1].mainsnak.datavalue.value["id"], 'P297' )
               if #wdIso3166 > 0 then
                  qbIso3166 = string.lower(wdIso3166[1].mainsnak.datavalue.value)
                  qbIso3166Class =  ' voy-qb-' .. qbIso3166
               else
                  qbIso3166Class = ''
               end
            else 
               qbIso3166Class = ''
            end
         end
      end
   else
      qbIso3166Class = ' voy-qb-' .. qbIso3166
   end


   -- starting the quickbar table
   display = display .. '<div class="voy-qb-rightdiv"><table cellspacing="0" class="voy-qb voy-qb-emergency-calls' .. qbIso3166Class .. '">'
   
   -- creating the row with the heading
   local trHeader = mw.html.create ( 'tr' )
   trHeader:addClass( 'voy-qb-header' )
   trHeader:tag('td')
      :attr('colspan', 2 )
      :wikitext('Notrufnummern')

   -- adding it to the quickbar
   display = display .. tostring ( trHeader )


   -- official language
   display = display .. mw.ustring.gsub ( items.GetItem().getItemsQuickbar ( qbID, 'P2852' ), 'Notruf ', '' )

   -- finishing the HTML table
   display = display .. '</table></div>'

   return display .. categories
   
end

return qbNotruf