Dokumentation für das Modul Quickbar Land/Test[Ansicht] [Bearbeiten] [Versionsgeschichte] [Aktualisieren]

Verwendung

Das Submodul ist eine Testversion des Moduls Quickbar Land und nicht für den Produktivbetrieb geeignet. Es dient der Weiterentwicklung des Moduls Quickbar Land, damit sich Änderungen nicht auf alle Artikel auswirken, die das Modul benutzen.

Neu- und Weiterentwicklung des Moduls für die {{Quickbar Land}}.

Testobjekte

Deutschland:

Deutschland
Lagekarte
Flagge
Kurzdaten
HauptstadtBerlin
RegierungsformRepublik,
Bundesstaat,
parlamentarische Bundesrepublik,
parlamentarische Republik
WährungEuro (EUR)
Fläche357.588 km²
Einwohnerzahl84.358.845 (2022)
AmtsspracheDeutsch
Strom/Stecker230 V, 50 Hz;
Schuko/​Eurostecker
Telefonvorwahl+49
Domain.de
ZeitzoneMEZ (UTC+1), MESZ (UTC+2)

{{#invoke:Quickbar Land/Test|qb_land
|id= Q183
|Zeitzone= MEZ (UTC+1), MESZ (UTC+2)
}}

Ägypten:

Ägypten
Lagekarte
Flagge
Kurzdaten
HauptstadtKairo
RegierungsformRepublik
Währung
Kurs (23.02.2023)[1]
ägyptisches Pfund
1 EUR = 32,479 EGP
100 EGP = 3,079 EUR
Fläche1.010.408 km²
Einwohnerzahl94.798.827 (2017)
AmtsspracheArabisch
ReligionIslam (haupts. Sunnitischer Islam) 94%, Koptische Christen und andere 6%
Strom/Stecker220 V, 50 Hz;
Eurostecker/​Schuko
Telefonvorwahl+20
Domain.eg, .مصر
ZeitzoneUTC+2, MEZ+1, MESZ+0

{{#invoke:Quickbar Land/Test|qb_land
|id= Q79
|Religion= Islam (haupts. Sunnitischer Islam) 94%, Koptische Christen und andere 6%
|Zeitzone= UTC+2, MEZ+1, MESZ+0
}}

Südafrika:

Südafrika
Lagekarte
Flagge
Kurzdaten
HauptstadtPretoria,
Bloemfontein,
Kapstadt
Regierungsformparlamentarische Republik,
repräsentative Demokratie
Währung
Kurs (08.11.2024)[2]
südafrikanischer Rand
1 EUR = 18,878 ZAR
100 ZAR = 5,297 EUR
Fläche1.221.037 km²
Einwohnerzahl62.027.503 (2022)
AmtsspracheEnglisch, Afrikaans, Süd-Ndebele, Nord-Sotho, Sesotho, Siswati, Xitsonga, Setswana, Tshivenda, IsiXhosa, isiZulu, Südafrikanische Gebärdensprache
ReligionChristen 68 % (die meisten Weißen und Farbigen), ungefähr 60 % der schwarzen Bev., 2% Muslime, 1,5% Hindus
Strom/Stecker230 V, 50 Hz;
Eurostecker/​D/​M/​IEC 60906-1
Telefonvorwahl+27
Domain.za
ZeitzoneUTC+2, MEZ+1, MESZ+0

{{#invoke:Quickbar Land/Test|qb_land
|id= Q258
|Religion= Christen 68 % (die meisten Weißen und Farbigen), ungefähr 60 % der schwarzen Bev., 2% Muslime, 1,5% Hindus
|Zeitzone= UTC+2, MEZ+1, MESZ+0
}}

Demokratische Republik Kongo:

Demokratische Republik Kongo
Lagekarte
Flagge
Kurzdaten
HauptstadtKinshasa
RegierungsformRepublik
WährungKongo-Franc (CDF)
Fläche2.344.858 km²
Einwohnerzahl86.790.567 (2019)
AmtsspracheFranzösisch
Strom/Stecker220 V, 50 Hz;
Eurostecker/​D/​E
Telefonvorwahl+243
Domain.cd
ZeitzoneMEZ

{{#invoke:Quickbar Land/Test|qb_land
|id= Q974
|Zeitzone=MEZ
}}

Thaliand: zu Testzwecken vieles manuell.

Thailand · Siam
[[Lagekarte|300px|class=notpageimage|Lagekarte]]
Flagge
Kurzdaten
HauptstadtKrung Thep
RegierungsformKonstitutionelle Monarchie
Währung
Kurs (08.11.2024)[3]
thailändischer Baht
1 EUR = 36,695 THB
100 THB = 2,725 EUR
Fläche513.120 km²
Einwohnerzahl66.188.503
AmtsspracheThai
ReligionBuddhismus 95 %, Islam 4 %, Christentum 0,7 %, Hinduismus 0,1%, andere 0,2%
Strom/Stecker220 V; 50 Hz;
A/C
Telefonvorwahl+66
Domain.th
ZeitzoneUTC+7 (MEZ+6, MESZ+5)

{{#invoke:Quickbar Land/Test|qb_land
|id= Q869
|Namen = Thailand '''·''' Siam
|Lage=[[File:LocationThailand.png|300px|class=notpageimage|Lagekarte]]
|Hauptstadt= [[Krung Thep]]
|Staatsform=Konstitutionelle Monarchie
|Fläche= 513.120 km²
|Bevölkerung= 66.188.503
|Amtssprache= Thai
|Religion=Buddhismus 95 %, Islam 4 %, Christentum 0,7 %, Hinduismus 0,1%, andere 0,2%
|Stromnetz= 220 V; 50 Hz
|Stecksysteme = A/C
|Zeitzone= UTC+7 (MEZ+6, MESZ+5)
}}

Kosovo:

Kosovo
Lagekarte
Flagge
Kurzdaten
HauptstadtPristina
Regierungsformparlamentarische Republik
Fläche10.909 km²
Einwohnerzahl1.586.659 (2024)
AmtsspracheAlbanisch, Serbisch
Strom/Stecker230 V, 50 Hz;
Schuko
Telefonvorwahl+383
Domain
ZeitzoneMEZ

{{#invoke:Quickbar Land/Test|qb_land
|id= Q1246
|Zeitzone=MEZ
}}


Hinweise
--[=[ Quickbar Land 2023-11-10
]=]

local yesno    = require( 'Modul:Yesno' )
local pnumber  = require( 'Module:GetNumber' )
local images   = require( 'Module:GetImage' )
local items    = require( 'Module:GetItem' )

local cfgCurrencies = mw.loadData('Modul:Währung/Länder')
local cfgCountries  = mw.loadData('Modul:CountryData/Geography')

local lang = mw.language.new( 'de' )


-- 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


-- returns the first value that is not nil
-- similar to the SQL function coalesce()
local function coalesce ( value1, value2, value3 )
   return value1 or value2 or value3
end


-- round function, which is not available in Lua
local _round = function  ( value, precision )
   local rescale = math.pow(10, precision or 0);
   return math.floor(value * rescale + 0.5) / rescale;
end


-- returns a manually created quickbar row
local function createTr ( text, label, trClass )

   -- check for valid text
   -- if there is no text, then display nothing
   if text == '' then 

      return ''

   else

      -- displaying the given info
      local tr = mw.html.create ( 'tr' )
      tr:addClass('voy-qb-item ' .. trClass )
         :tag('th')
         :addClass('voy-qb-item-key')
         :wikitext( label )
      tr:tag('td')
         :addClass( 'voy-qb-item-value1' )
         :wikitext( text )
      return tostring ( tr )
   end

end


local function checkMapObject ( id )
   local region = require ( 'Modul:Location map data ' .. id )
   if ( region ~= nil ) and ( region.data ~= nil ) then
      region.data['id'] = id
      return region
   else
      return nil
   end
end


local qbLand = {}

function qbLand.qb_land ( 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 ''

   -- getting object name
   -- uses WD sitelink and the page name as fallback
   local destinationName
   if qbID ~= '' then 
      destinationName = coalesce ( mw.wikibase.getSitelink( qbID, 'dewikivoyage' ), page.text, 'Ort')
   else
      destinationName = coalesce ( page.text, 'Ort')
   end

   -- 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
                  if wdIso3166[1].mainsnak.snaktype == 'value' then
                     qbIso3166 = string.lower(wdIso3166[1].mainsnak.datavalue.value)
                     qbIso3166Class =  ' voy-qb-' .. qbIso3166
                  else
                  	 qbIso3166Class = ''
                  end
               else
                  qbIso3166Class = ''
               end
            else 
               qbIso3166Class = ''
            end
         end
      end
   else
      qbIso3166Class = ' voy-qb-' .. qbIso3166
   end

   -- DEBUG: showing the parameters
   -- it was just for development
   -- display = display .. '<br />Parameter:<br />' ..  mw.dumpObject(templateArgs)

   -- starting the quickbar table
   display = display .. '<table cellspacing="0" class="voy-qb voy-qb-right voy-qb-country' .. qbIso3166Class .. '">'

   -- heading
   -- is mandatory, even if you do not provide it, its shown (with the sitename)
   -- initialising with given heading
   local qbNamen = coalesce ( templateArgs["namen"], '' )
   
   -- if no heading is provided, get the sitename
   if qbNamen == '' then
      qbNamen = destinationName
   end
   
   -- creating the row with the heading
   local trHeader = mw.html.create ( 'tr' )
   trHeader:addClass( 'voy-qb-header' )
   trHeader:tag('td')
      :attr('colspan', 2 )
      :wikitext(qbNamen)

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

   -- the position map
   -- taken from Wikidata, if not provided
   display = display .. images.GetImage().getPositionMapQuickbar ( qbID, nil, nil, coalesce ( templateArgs["lage"], '' ) )
   
   -- creating the row with the flag heading
   trHeader = mw.html.create ( 'tr' )
   trHeader:addClass( 'voy-qb-header voy-qb-header-flag' )
   trHeader:tag('td')
      :attr('colspan', 2 )
      :wikitext('Flagge')

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

   -- flag
   -- always taken from Wikidata
   display = display .. images.GetImage().getEmblemsQuickbar ( qbID, 'F' )
   
   -- creating the row with the info heading
   trHeader = mw.html.create ( 'tr' )
   trHeader:addClass( 'voy-qb-header voy-qb-header-info' )
   trHeader:tag('td')
      :attr('colspan', 2 )
      :wikitext('Kurzdaten')

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

   -- capital
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P36', coalesce ( templateArgs["hauptstadt"], '') )

   -- basic form of government
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P122', coalesce ( templateArgs["staatsform"], '') )

   -- currency
   if cfgCurrencies[qbID] ~= nil then

      -- getting exchange rate
      local exchangeRate = 0
      local exchangeDate = ''
      local exchangeSource = ''
      local exchangeTable = {}

      -- trying Commons: Data:ECB euro foreign exchange reference rates.tab
      exchangeTable = mw.ext.data.get( 'ECB euro foreign exchange reference rates.tab' )

      for i, entry in pairs ( exchangeTable.data ) do
         if entry[1] == cfgCurrencies[qbID][4] then
            exchangeRate = _round ( tonumber ( entry[2] ), 3 )
            exchangeDate = entry[3]
            exchangeSource = exchangeTable.sources
            break
         end
      end

      -- trying Commons: Data:Xe.com exchange rates.tab
      if exchangeRate == 0 then

         exchangeTable = mw.ext.data.get( 'Xe.com exchange rates.tab' )

         for i, entry in pairs ( exchangeTable.data ) do
            if entry[1] == cfgCurrencies[qbID][4] then
               exchangeRate = _round ( tonumber ( entry[3] ), 3 )
               exchangeDate = entry[6]
               exchangeSource = exchangeTable.sources
               break
            end
         end

      end

      if exchangeRate > 0 and cfgCurrencies[qbID][4] ~= 'EUR' then

         -- formatting exchange rate
         local exchangeRateText = '<br />'

         -- first row (EUR > local)
         exchangeRateText = exchangeRateText .. '1&#x202F;EUR&#x202F;=&#x202F;' .. lang:formatNum ( exchangeRate ) ..  '&#x202F;' .. cfgCurrencies[qbID][4]

         -- second row (local > EUR)
         exchangeRateText = exchangeRateText .. '<br />'

         if exchangeRate > 10000 then
            exchangeRateText = exchangeRateText .. '100.000&#x202F;' .. cfgCurrencies[qbID][4] .. '&#x202F;=&#x202F;' .. lang:formatNum ( _round ( 100000 / exchangeRate, 3 ) ) ..  '&#x202F;EUR'
         elseif exchangeRate > 1000 then
            exchangeRateText = exchangeRateText .. '10.000&#x202F;' .. cfgCurrencies[qbID][4] .. '&#x202F;=&#x202F;' .. lang:formatNum ( _round ( 10000 / exchangeRate, 3 ) ) ..  '&#x202F;EUR'
         elseif exchangeRate > 100 then
            exchangeRateText = exchangeRateText .. '1.000&#x202F;' .. cfgCurrencies[qbID][4] .. '&#x202F;=&#x202F;' .. lang:formatNum ( _round ( 1000 / exchangeRate, 3 ) ) ..  '&#x202F;EUR'
         elseif exchangeRate > 10 then
            exchangeRateText = exchangeRateText .. '100&#x202F;' .. cfgCurrencies[qbID][4] .. '&#x202F;=&#x202F;' .. lang:formatNum ( _round ( 100 / exchangeRate, 3 ) ) ..  '&#x202F;EUR'
         elseif exchangeRate > 1 then
            exchangeRateText = exchangeRateText .. '10&#x202F;' .. cfgCurrencies[qbID][4] .. '&#x202F;=&#x202F;' .. lang:formatNum ( _round ( 10 / exchangeRate, 3 ) ) ..  '&#x202F;EUR'
         else
            exchangeRateText = exchangeRateText .. '1&#x202F;' .. cfgCurrencies[qbID][4] .. '&#x202F;=&#x202F;' .. lang:formatNum ( _round ( 1 / exchangeRate, 3 ) ) ..  '&#x202F;EUR'
         end

         -- adding the ref-Tag
         exchangeSource = frame:extensionTag{ name = 'ref', content = '[' .. exchangeSource .. ']' }

         display = display .. createTr ( cfgCurrencies[qbID][3] .. exchangeRateText, 'Währung<br />Kurs&#x202F;<span class="voy-small">(' .. lang:formatDate ( 'd.m.Y', exchangeDate ) .. ')' .. exchangeSource .. '</span>', 'voy-commons-content voy-qb-item-currency' )

      else

         display = display .. createTr ( cfgCurrencies[qbID][3] .. ' (' .. cfgCurrencies[qbID][4] .. ')', 'Währung', 'voy-qb-item-currency' )

      end
   end

   -- area
   display = display .. pnumber.GetNumber().getNumbersWithUnitQuickbar ( qbID, 'P2046', nil, 0, coalesce ( templateArgs["fläche"], '' ) )

   -- population
   display = display .. pnumber.GetNumber().getNumbersWithDateQuickbar ( qbID, 'P1082', coalesce ( templateArgs["bevölkerung"], '' ) )

   -- official language
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P37', coalesce ( templateArgs["amtssprache"], ''), nil, ', ' )

   -- religion (no wikidata)
   if coalesce ( templateArgs["religion"], '' ) ~= '' then
      display = display .. createTr ( templateArgs["religion"], 'Religion', 'voy-qb-item-religion' )
   end

   -- electricity
   -- getting the Voltage
   local voltage = coalesce ( nilIf ( templateArgs["stromnetz"], '' ), pnumber.GetNumber().getNumbersWithUnit( qbID, 'P2884' ) , '' )

   -- getting the plugs
   -- when fetching the items as "label only", no categories are provided, they are saved in the second result
   -- "label only" has zo beused, because the result is used in a link and the categories destroy the link 
   -- normally getItems delivers complete links (if available) with the maintenance categories
   local plugs, plugsaCat = coalesce ( nilIf ( templateArgs["stecksysteme"], '' ), mw.ustring.gsub ( items.GetItem().getItems( qbID, 'P2853', nil, 'label', '/&#8203;' ), 'Stecker%-Typ ', '' ), '' )

   if voltage ~= '' or plugs ~= '' then

      local electricity = voltage
      local electricityLabel = ''
      if plugs ~= '' then
         if voltage ~= '' then
            electricity = electricity .. ';<br />[[Stromsysteme#Steckertypen|' .. plugs .. ']]'
            electricityLabel = '[[Stromsysteme|Strom/Stecker]]'
            categories = categories .. coalesce ( plugsaCat, '' )
         else
            electricity = '[[Stromsysteme#Steckertypen|' .. plugs .. ']]'
            electricityLabel = '[[Stromsysteme|Stecker]]'
         end
      else
         electricityLabel = '[[Stromsysteme|Stromnetz]]'
      end
      display = display .. createTr ( electricity, electricityLabel, 'voy-qb-item-electricity' )
   end

   -- calling code
   if cfgCountries.countries[qbID] ~= nil then
         display = display .. createTr ( cfgCountries.countries[qbID].cc, 'Telefonvorwahl', 'voy-qb-item-calling-code' )
   end
   
   if cfgCountries.adminEntities[qbID] ~= nil then
         display = display .. createTr ( cfgCountries.adminEntities[qbID].cc, 'Telefonvorwahl', 'voy-qb-item-calling-code' )
   end

   -- top level domain
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P78', nil, nil, ', ' )

   -- timezone (no wikidata, for several reasons discussed in community)
   if coalesce ( templateArgs["zeitzone"], '' ) ~= '' then
      display = display .. createTr ( templateArgs["zeitzone"], 'Zeitzone', 'voy-qb-item-time-zone' )
   end

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

   return display .. categories
   
end

return qbLand