Dokumentation für das Modul Quickbar Ort[Ansicht] [Bearbeiten] [Versionsgeschichte] [Aktualisieren]

Dieses Modul erzeugt eine Quickbar für Ortsartikel Es gibt nur eine Funktion, die Erzeugung einer Infobox (Quickbar) für Orte. Eine detaillierte Dokumentation findest du auf der Vorlage Quickbar Ort. 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 eingebundenen Getxxx-Module einsehen.

Submodule

Verwandte Module

Verwendung

  • Quickbar Ort – Die Vorlage dient zur Ausgabe von Kurzdaten für Städte, Großstädte oder Kleinstädte. Die Anzeige erfolgt als umflossene Box am rechten Rand, die Box ist 300px breit. Alle angezeigten Infos sind optional und zum großen Teil in der Lage, ihre Werte auch von Wikidata zu beziehen.

Benötigte weitere Module

Dieses Modul benötigt folgende weitere Module: CountryData • GetNumber • GetString • GetImage • GetP856 • GetProvince • LinkPhone • Yesno
Hinweise
--[=[ Quickbar Notruf 2023-10-04
]=]

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 province = require( 'Module:GetProvince' )

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

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 qbOrt = {}

function qbOrt.qb_ort ( 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 = ''

   -- province information are used twice
   -- variables for saving information
   local provinceName = ''
   local provinceCode = ''
   
   -- 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-ort' .. qbIso3166Class .. '">'

   -- the main image
   -- taken from Wikidata, if not provided
   display = display .. images.GetImage().getMainImageQuickbar ( qbID, coalesce ( templateArgs["bild"], '' ) )

   -- 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-item' )
   trHeader:tag('td')
      :attr('colspan', 2 )
      :addClass('voy-qb-header' )
      :wikitext(qbNamen)
   -- adding it to the quickbar
   display = display .. tostring ( trHeader )
   
   -- general information:
   -- an entry is only 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" deactivates the entry
   
   -- province
   local displayString = ''
   displayString, provinceCode = province.GetProvince().getProvinceQuickbar ( qbID, coalesce ( templateArgs["provinz"], '' ), coalesce ( templateArgs["provinzlabel"], '' ), coalesce ( templateArgs["staatok"], 'no' ) )
   display = display .. displayString
   
   -- population
   display = display .. pnumber.GetNumber().getNumbersWithDateQuickbar ( qbID, 'P1082', coalesce ( templateArgs["einwohner"], '' ) )
   
   -- altitude
   display = display .. pnumber.GetNumber().getNumbersWithUnitQuickbar ( qbID, 'P2044', nil, 0, coalesce ( templateArgs["höhe"], '' ) )

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

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

      -- trying to find it on Wikidata, if empty
      if coalesce ( templateArgs["touriinfotel"], '' ) == '' and qbID ~= '' 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
      elseif coalesce ( templateArgs["touriinfotel"], '' ) ~= '' then

         -- formatting and linking
         local cm = require( 'Module:CountryData' )
         local lp = require( 'Module:LinkPhone' )
         local lpArgs = {
            phone      = templateArgs["touriinfotel"],
            format     = true,
            isFax      = false,
            isTollfree = false
         }
         lpArgs.cc, lpArgs.size = cm.getCountryCode()
         templateArgs["touriinfotel"] = lp.linkPhoneNumbers( lpArgs )

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

   -- displaying only, if its not switched off
   if ( yesno ( coalesce ( 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 coalesce ( templateArgs["touriinfoweb"], '' ) == '' and qbID ~= '' 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
      elseif coalesce ( templateArgs["touriinfoweb"], '' ) ~= '' then

         -- 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
   
   -- adding social media
   display = display .. pstring.GetString().getSocialMediaQuickbar ( qbID )

   -- location map 
   -- the location map is always shown, but you can switch it off
   if yesno ( coalesce ( templateArgs["karte"], '' ), true ) then

      -- reading latitude and longitude from Wikidata
      local breite
      local laenge
      breite, laenge = pnumber.GetNumber().getCoordinate( qbID )

      -- got coordinates? then creating the map
      if breite ~= 0 and laenge ~= 0 then

         -- loading the configuration fopr the location maps
         local cfgLocmaps = mw.loadData('Modul:Quickbar Ort/Locmaps')

         provinceCode = string.lower ( coalesce ( provinceCode, '' ) )

         -- determining the locmap, starting with the country code
         local locmapCode = qbIso3166

         -- some countries alays use province maps (see Modul:Quickbar_Ort/Locmaps)
         if cfgLocmaps.LocMapLevel[qbIso3166] ~= nil and provinceCode ~= '' then
            locmapCode = provinceCode
         end

         -- some province maps differ from the 3166 Code
         if cfgLocmaps.LocMapNoProvince[provinceCode] ~= nil and provinceCode ~= '' then
            locmapCode = cfgLocmaps.LocMapNoProvince[provinceCode]
         end

         -- some province maps are individually wanted although normally the country map is used
         if cfgLocmaps.ForceProvinceMap[provinceCode] ~= nil and provinceCode ~= '' then
            locmapCode = cfgLocmaps.ForceProvinceMap[provinceCode]
         end

         -- is a map-code given manually in the QB? then
         if nilIf ( templateArgs["karte"], '' ) ~= nil then
            locmapCode = templateArgs["karte"]
         end

         locmapCode = string.lower ( locmapCode )

         -- creating the location map
         if locmapCode ~= '' then

            local locMap = require('Modul:Location map')
            local success, mData = pcall(checkMapObject, locmapCode)

            -- location map available?
            if success then

               -- collecting all parameters
               local locMapArgs = 
                  { args = 
                     {  map = locmapCode, 
                        lat = breite,
                        long = laenge,
                        maptype = 'quickbar',
                        label = '<b>' .. mw.text.trim(mw.ustring.gsub(destinationName, '%s%(.*%)', '' )) .. '</b>' 
                     } 
                  }

               -- creating the row and adding to the quickbar
               local trLocMap = mw.html.create ( 'tr' )
               trLocMap:addClass( 'voy-qb-locmap' )
               trLocMap:tag('td')
                  :attr('colspan', 2 )
                  :wikitext(locMap.locationMap(locMapArgs))
               display = display .. tostring ( trLocMap )

            else
               categories = categories .. '[[Kategorie:Provinz ohne Location map]]'
            end

         end -- if locmapCode ~= ''

      end -- if breite ~= 0 and laenge ~= 0

   end --  if yesno ( coalesce ( templateArgs["karte"], '' ), true )

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

   return display .. categories
   
end

return qbOrt