Modul:Quickbar Region

Aus Wikivoyage
Dokumentation für das Modul Quickbar Region[Ansicht] [Bearbeiten] [Versionsgeschichte] [Aktualisieren]

Dieses Modul erzeugt eine Quickbar, die für Regionenarikel (allgemeine Regionen, Provinzen, Bundesstaaten) aber auch Nationalparks usw. verwendet werden kann. Es gibt nur eine Funktion, die Erzeugung einer Infobox (Quickbar) für Regionen. Eine detaillierte Dokumentation findest du auf der Vorlage Quickbar Region. Daher sind die Parameter hier nicht noch mal aufgelistet.

Das Modul erzeugt indirekt auch eine Reihe von Wartungskategorien durch die verwendeten Wikidata-Module. Diese kannst du auf den Modulseiten der Getxxx-Module einsehen.

Verwandte Module

Verwendung in Vorlagen

Benötigte weitere Module

Dieses Modul benötigt folgende weitere Module: GetNumber • GetString • GetImage • GetItem • GetP856 • GetProvince • Yesno
Hinweise
--[=[ Quickbar Notruf 2024-03-27
]=]

local yesno    = require( 'Modul:Yesno' )
local pnumber  = require( 'Module:GetNumber' )
local pstring  = require( 'Module:GetString' )
local p856     = require( 'Module:GetP856' )
local images   = require( 'Module:GetImage' )
local items    = require( 'Module:GetItem' )
local province = require( 'Module:GetProvince' )

-- default values
local defaultValues = {
   -- flag + coat of arms
   hoheitszeichen    = 'FC'
}

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

local qbRegion = {}

function qbRegion.qb_region ( 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
   -- will be filled with content later and only, if needed
   local page = {}

   -- getting or determining (if needed) the wikidata-ID
   if templateArgs.id == '' then templateArgs.id = nil end
   local qbID = templateArgs.id 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
                  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-region' .. qbIso3166Class .. '">'

   -- Adding the emblems, if wanted
   if templateArgs["hoheitszeichen"] ~= nil then

      local qbEmblems = ''

      if templateArgs["hoheitszeichen"] ~= '' then
         qbEmblems = templateArgs["hoheitszeichen"]
      else
         qbEmblems = defaultValues["hoheitszeichen"]
      end

      if yesno ( templateArgs["hoheitszeichen"], true ) then
         display = display .. images.GetImage().getEmblemsQuickbar ( qbID, qbEmblems )
      end

   end

   -- the main image
   -- adding a picture, if wanted instead of the emblems, even both (emblems and image) are possible
   -- taken from Wikidata, if not provided
   if templateArgs["bild"] ~= nil then

      local qbImage = ''

      if templateArgs["bild"] ~= '' then
         qbImage = templateArgs["bild"]
      end

      if yesno ( templateArgs["bild"], true ) then
         display = display .. images.GetImage().getMainImageQuickbar ( qbID, qbImage )
      end

   end

   -- 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
        -- getting the siteinfo
        -- no test necessary, its the first use here
      page = mw.title.getCurrentTitle()   
      qbNamen = page.text
   end
   
   -- creating the row with the heading
   local trHeader = mw.html.create ( 'tr' )
   trHeader:addClass( 'voy-qb-item' )
   trHeader:tag('td')
      :attr('colspan', 2 )
      :addClass('voy-qb-header' )
      :wikitext(qbNamen)
   -- adding it to the quickbar
   display = display .. tostring ( trHeader )

   -- province
   -- hardly used (only in a few district articles in South Africa) 
   -- will be reprogrammed later for the Quickbar for cities
   
   -- general information:
   -- an entry is onl added when the parameter is used
   -- if the parameter is empty, the information is fetched from Wikidata
   -- if the parameter is not empty, the local information is used, but mostly compared Wikidata, and maintenance categories are used
   -- the parameter with the value "no" deactvates the entry
   
   -- capital
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P36', coalesce ( templateArgs["hauptstadt"], '') )
   
   -- province (hardly used, just in one district regions)
   if templateArgs["provinz"] ~= nil then

      local qbProvince = ''

      if templateArgs["provinz"] ~= '' then
         qbProvince = templateArgs["provinz"]
      end

      if yesno ( templateArgs["provinz"], true ) then
         display = display .. province.GetProvince().getProvinceQuickbar ( qbID, qbProvince )
      end

   end
   
   -- population
   display = display .. pnumber.GetNumber().getNumbersWithDateQuickbar ( qbID, 'P1082', coalesce ( templateArgs["einwohner"], '' ) )
   
   -- area
   display = display .. pnumber.GetNumber().getNumbersWithUnitQuickbar ( qbID, 'P2046', nil, 0, coalesce ( templateArgs["fläche"], '' ) )
   
   -- postal code
   display = display .. pstring.GetString().getStringsQuickbar ( qbID, 'P281', nil, coalesce ( templateArgs["postleitzahl"], '' ) )

   -- area calling code
   display = display .. pstring.GetString().getStringsQuickbar ( qbID, 'P473', nil, coalesce ( templateArgs["vorwahl"], '' ) )

   -- timezone
   -- after asking in the lounge its not taken from Wikidata because its
   --   - not often necessary
   --   - sometimes ver specific
   --   - UTC is not useful to everyone
   if templateArgs["zeitzone"] ~= nil then
      if ( templateArgs["zeitzone"] ~= '' and yesno ( templateArgs["zeitzone"], true ) ) then
         local trTimeZone = mw.html.create ( 'tr' )
         trTimeZone:addClass('voy-qb-item voy-qb-timezone' )
            :tag('th')
            :addClass('voy-qb-item-key')
            :wikitext('[[Zeitzonen|Zeitzone]]')
         trTimeZone:tag('td')
            :addClass( 'voy-qb-item-value1' )
            :wikitext( templateArgs["zeitzone"] )
         display = display .. tostring ( trTimeZone )
      end
   end
   
   -- website
   display = display .. p856.GetP856().getUrlAsLinkWithHostQuickbar ( qbID, coalesce ( templateArgs["webseite"], '' ) )

   -- tourist info 
   -- it has two parameters: phone number and webseite
   -- they can used both or single
   
   -- Wikidata-ID of the tourist info
   local wdTouristInfo = {}   
   local touristInfoID = ''

   -- tourist info: phone number
   -- it contains the wiki markup of the whole row
   local touristInfoPhone = ''
   local touristInfoWeb = ''

   -- table row for the entries
   local trTouristInfo = ''

   if templateArgs["touriinfotel"] ~= nil then

      -- displaying only, if its not switched off
      if ( yesno ( templateArgs["touriinfotel"], true ) ) then

         -- trying to find it on Wikidata, if empty
         if templateArgs["touriinfotel"] == '' then

            wdTouristInfo = mw.wikibase.getBestStatements( qbID, 'P2872' )
            if #wdTouristInfo > 0 then
               touristInfoID = wdTouristInfo[1].mainsnak.datavalue.value["id"]
            end

            -- Found it on Wikidata? > showing the phone number
            if touristInfoID ~= '' then
               touristInfoPhone = pstring.GetString().getStringsQuickbar ( touristInfoID, 'P1329', nil, nil, 'Tourist-Info' )
            end

         -- if provided locally then just showing it
         else

            -- displaying the given info
            trTouristInfo = mw.html.create ( 'tr' )
            trTouristInfo:addClass('voy-qb-item voy-qb-tourist-info' )
               :tag('th')
               :addClass('voy-qb-item-key')
               :wikitext('Tourist-Info')
            trTouristInfo:tag('td')
               :addClass( 'voy-qb-item-value1' )
               :wikitext( templateArgs["touriinfotel"] )
            touristInfoPhone = tostring ( trTouristInfo )

         end

         -- showing the entry
         display = display .. touristInfoPhone

      end

   end

   -- tourist info: website
   if templateArgs["touriinfoweb"] ~= nil then

      -- displaying only, if its not switched off
      if ( yesno ( templateArgs["touriinfoweb"], true ) ) then

         -- if there is a row for the phone number, then no label in the second row
         local trLabel
         if touristInfoPhone == '' then
            trLabel = 'Tourist-Info'
         else
            trLabel = ''
         end

         -- trying to find it on Wikidata, if empty
         if templateArgs["touriinfoweb"] == '' then 

            -- is the WikidataID known already (from above)?
            if touristInfoID == '' then
               wdTouristInfo = mw.wikibase.getBestStatements( qbID, 'P2872' )
               if #wdTouristInfo > 0 then
                  touristInfoID = wdTouristInfo[1].mainsnak.datavalue.value["id"]
               end
            end

            -- Found it on Wikidata? > showing the phone number
            if touristInfoID ~= '' then
               touristInfoWeb = p856.GetP856().getUrlAsLinkWithHostQuickbar ( touristInfoID, nil, trLabel )
            end

         -- if provided just showing it
         else

            -- displaying the given info
            trTouristInfo = mw.html.create ( 'tr' )
            trTouristInfo:addClass('voy-qb-item voy-qb-tourist-information' )
               :tag('th')
               :addClass('voy-qb-item-key')
               :wikitext(trLabel)
            trTouristInfo:tag('td')
               :addClass( 'voy-qb-item-value1' )
               :wikitext( templateArgs["touriinfoweb"] )
            touristInfoWeb = tostring ( trTouristInfo )

         end

         -- showing the entry
         display = display .. touristInfoWeb

      end

   end

   -- position map
   local qbPositionMap = coalesce ( templateArgs["lagekarte"], '' )
   local qbPositionMapWidth = coalesce ( templateArgs["breitelagekarte"], '' )
   local qbImageMap = coalesce ( templateArgs["imagemap"], '' )

   if yesno ( qbPositionMap, true ) then
      if yesno ( qbImageMap, true ) then
         display = display .. images.GetImage().getPositionMapQuickbar ( qbID, nil, qbPositionMapWidth, qbPositionMap, qbImageMap, frame )
      else
         display = display .. images.GetImage().getPositionMapQuickbar ( qbID, nil, qbPositionMapWidth, qbPositionMap )
      end
   end

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

   return display .. categories
   
end

return qbRegion