|
|
| (21 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) |
| Zeile 4: |
Zeile 4: |
| local str = require("Modul:String") | | local str = require("Modul:String") |
| local wik = require("Modul:Wiki") | | local wik = require("Modul:Wiki") |
| local que = require("Modul:Queries") | | local smw = require("Modul:SMW") |
| local lfd = require("Modul:LinkFormDatum")
| |
|
| |
|
| local fab_zeilen = require("Modul:Faktenbox/Zeilen") | | local fab_zeilen = require("Modul:Faktenbox/Zeilen") |
| local fab_common = require("Modul:Faktenbox/Common") | | local fab_common = require("Modul:Faktenbox/Common") |
|
| |
| local sort_iteration_limit_countdown
| |
|
| |
|
| function p.universalDatenTab_(fbdata) | | function p.universalDatenTab_(fbdata) |
| Zeile 25: |
Zeile 22: |
|
| |
|
| -- Zusammenbau | | -- Zusammenbau |
| t = t .. "<dl class = 'dataTable'>"
| |
| for a, _ in pairs(fbdata.pargs) do | | for a, _ in pairs(fbdata.pargs) do |
| if not com.isTrue(no_show_attr[a]) then | | if not com.isTrue(no_show_attr[a]) then |
| Zeile 31: |
Zeile 27: |
| end | | end |
| end | | end |
| t = t .. "</dl>" | | if t ~= "" then |
| t = t .. fab_zeilen.zeileSemantikBrowsenAbfrage_(fbdata)
| | t = p.table_header_footer_(t) |
| | t = t .. fab_zeilen.zeileSemantikBrowsenAbfrage_(fbdata) |
| | end |
|
| |
|
| -- Tab draus machen | | -- Tab draus machen |
| Zeile 40: |
Zeile 38: |
| end | | end |
|
| |
|
| function p.bildTab_(fbdata, seite) | | function p.bildTab_(fbdata) |
| -- mw.log("bildTab_(fbdata, " .. (seite or "nil") .. ")") | | -- mw.log("bildTab_(fbdata)") |
| -- mw.logObject(fbdata.pargs) | | -- mw.logObject(fbdata.pargs, "fbdata.pargs") |
| -- Konsolenzeile zum Debuggen: | | -- Konsolenzeile zum Debuggen: |
| -- =p.bildTab_{pargs={Bild="Erloeserkirche.jpg"}} | | -- =p.bildTab_{pargs={Bild="Erloeserkirche.jpg"}} |
| local t = "" | | local t = "" |
| local beschreibung = que.getValues("Datei:" .. (fbdata.pargs["Bild"] or ""), "Beschreibung") | | local bild = fbdata.pargs["Bild"] |
| local beschreibung = beschreibung[1] or ""
| | if bild ~= nil then |
| if (fbdata.pargs["Bild"] or "") ~= "" and wik.pageExists("Bild:" .. fbdata.pargs["Bild"]) then | | local bildlink = "" |
| t = t .. '{| class = "factbox_imagetable" border = "0" cellpadding = "0" cellspacing = "0" width = "100%"\n' | | if fbdata.bildlink ~= nil then |
| t = t .. '|-\n' | | bildlink = "|link=" .. fbdata.bildlink |
| t = t .. '|[[Bild::Datei:' .. fbdata.pargs["Bild"] .. '|768px|link=' .. (seite or '') .. ']]\n'
| |
| if beschreibung ~= "" then
| |
| t = t .. '|-\n' | |
| t = t .. '|' .. beschreibung .. '\n'
| |
| end | | end |
| t = t .. '|}' | | if wik.pageExists("Datei:" .. bild) then |
| end
| | local beschreibung = smw.getValues("Datei:" .. bild, "Beschreibung") |
| -- Tab draus machen
| | t = t .. "{| class = \"factbox_imagetable\" border = \"0\" cellpadding = \"0\" cellspacing = \"0\" width = \"100%\"\n" |
| t = p.tab_(t, "Bild")
| | t = t .. "|-\n" |
| -- mw.log("t = " .. t)
| | t = t .. "|[[Datei:" .. bild .. "|768px" .. bildlink .. "]]\n" |
| return t
| | if beschreibung[1] ~= nil then |
| end
| | t = t .. "|-\n" |
| | | t = t .. "|" .. beschreibung[1] .. "\n" |
| function p.kartenTab_(fbdata)
| |
| -- mw.log("kartenTab_(fbdata)")
| |
| -- mw.logObject(fbdata)
| |
| -- Konsolenzeile zum Debuggen:
| |
| -- fab=require("Modul:Faktenbox/Work"); fab_common = require("Modul:Faktenbox/Common"); fbdata=fab_common.fbdata_{pargs={["location"]="Erlanger Straße 11, Fürth, Bayern, Deutschland",Debug="ja"}}; print(p.kartenTab_(fbdata))
| |
| -- fab=require("Modul:Faktenbox/Work"); fab_common = require("Modul:Faktenbox/Common"); fbdata=fab_common.fbdata_{pargs={["Gebäude"]="Erlanger Straße 11;Erlanger Straße 12",Debug="ja"}}; print(p.kartenTab_(fbdata))
| |
| t = ""
| |
| if string.find(fbdata.pagename, ";") ~= nil then
| |
| t = "Semikolon im Artikel-/Seitennamen für korrekte Kartendarstellung nicht erlaubt!"
| |
| else
| |
| local args = {
| |
| lat = fbdata.pargs["lat"] or "", location = fbdata.pargs["location"] or "", | |
| lon = fbdata.pargs["lon"] or "", locationlist = fbdata.pargs["locationlist"] or "", | |
| geojson = fbdata.pargs["geojson"] or "", zoom = fbdata.pargs["zoom"] or "18", -- 18 ist default-zoom
| |
| Debug = fbdata.pargs["Debug"] or "",
| |
| width = "", height = "", -- passt sich beides automatisch an die Box an
| |
| box = "nein", form = "ja" -- keine eigene Box; Seite hat Formular
| |
| }
| |
| -- Wenn kein geojson-Formular-Wert vorgegeben, prüfen,
| |
| -- ob sich hinter der Artikelseite eine gleichnamige GeoJson-Karte versteckt oder
| |
| -- über Formular-Wert GeoJsonKarte eine Karte aktiviert ist
| |
| if args.geojson == "" then
| |
| if wik.pageExists("GeoJson:" .. fbdata.pagename) or com.isTrue(fbdata.pargs["GeoJsonKarte"]) then
| |
| args.geojson = fbdata.pagename
| |
| end | | end |
| | t = t .. "|}" |
| end | | end |
| -- Verwende Geolokation des Gebäudes, sofern vorhanden und wenn keine location oder locationlist übergeben | | smw.addAttrToList(fbdata.attr.list, "Bild", "Datei:" .. bild) |
| if args.location == "" and args.locationlist == "" then
| |
| local gebaeude = str.splitAndStrip(fbdata.pargs["Gebäude"] or "", ";")
| |
| if #gebaeude > 0 then -- Gebäude angegeben?
| |
| args.locationlist = ""
| |
| local first = true
| |
| for _, g in ipairs(gebaeude) do -- alle Gebäude durchiterieren
| |
| local seite = que.getValues(g, "Seite", true)
| |
| if seite[1] ~= fbdata.pagename then -- Weiterleitung auf sich selbst rausfiltern
| |
| local geolokation = que.getValues(g, "Geolokation", true)
| |
| for _, l in ipairs(geolokation) do -- alle Geolokationen eines Gebäudes durchiterieren
| |
| if first then
| |
| first = false
| |
| else
| |
| args.locationlist = args.locationlist .. ";"
| |
| end
| |
| args.locationlist = args.locationlist .. l
| |
| end
| |
| end
| |
| end
| |
| end
| |
| end
| |
| -- Karte-Vorlage einbinden
| |
| -- mw.logObject(args)
| |
| if (args.lat ~= "" and args.lon ~= "") or args.location ~= "" or args.locationlist ~= "" or args.geojson ~= "" then
| |
| t = fbdata.frame:expandTemplate{title = "Karte", args = args}
| |
| end
| |
| end | | end |
| -- Tab draus machen | | -- Tab draus machen |
| t = p.tab_(t, "Karte") | | t = p.tab_(t, "Bild") |
| -- mw.log("t = " .. t) | | -- mw.logObject(t, "t") |
| return t | | return t |
| end | | end |
| Zeile 171: |
Zeile 116: |
| -- Tab draus machen | | -- Tab draus machen |
| t = p.tab_(t, "Benennungen") | | t = p.tab_(t, "Benennungen") |
| -- mw.log("t = " .. t)
| |
| return t
| |
| end
| |
|
| |
| function p.adressenTab_(fbdata)
| |
| -- mw.log("adressenTab_()")
| |
| -- mw.logObject(fbdata)
| |
| -- Konsolenzeile zum Debuggen:
| |
| -- =p.adressenTab_({fullpagename="Jakob Bock"})
| |
| -- =p.adressenTab_({fullpagename="Ludwig Erhard"})
| |
| -- =p.adressenTab_({fullpagename="Druck & Kopie Hartmann KG"})
| |
| -- =p.adressenTab_({fullpagename="Rathaus"})
| |
| -- =p.adressenTab_({fullpagename="E-Tankstelle Hochstraße"})
| |
| -- =p.adressenTab_({fullpagename="TestPerson2"})
| |
| local t = ""
| |
|
| |
| -- Attribute-Liste
| |
| local attr = {
| |
| ["Adressart"] = { querypostfix = "", default = ""},
| |
| ["Straße"] = { querypostfix = "#-", default = ""},
| |
| ["Hausnummer"] = { querypostfix = "", default = 0},
| |
| ["StraßeHnr"] = { querypostfix = "#-", default = ""},
| |
| ["VonObjekt"] = { querypostfix = "#-", default = ""},
| |
| ["AdresseVon"] = { querypostfix = "", default = ""},
| |
| ["AdresseBis"] = { querypostfix = "", default = ""}}
| |
|
| |
| -- DB-Abfrage
| |
| local query = "[[-Has subobject::".. fbdata.fullpagename .. "]][[SubObjektTyp::Adresse]]|?#-|limit=100"
| |
| for i, a in pairs(attr) do
| |
| query = query .. "|?" .. i .. a.querypostfix
| |
| end
| |
| local addresses = mw.smw.ask(query)
| |
|
| |
| if addresses ~= nil then
| |
|
| |
| -- defaults fehlender Attribute und Sortier-Index setzen
| |
| for i, _ in pairs(addresses) do
| |
| for j, a in pairs(attr) do
| |
| addresses[i][j] = addresses[i][j] or a.default
| |
| end
| |
| addresses[i].von_sort_index = smwDate2SortIndex(addresses[i]["AdresseVon"])
| |
| addresses[i].bis_sort_index = smwDate2SortIndex(addresses[i]["AdresseBis"])
| |
| end
| |
|
| |
| -- Tabelle sortieren
| |
| sort_iteration_limit_countdown = 1000
| |
| table.sort(addresses, vonBisSortCompare)
| |
|
| |
| -- Liste erstellen
| |
| t = t .. "<nowiki></nowiki>\n" -- nötig, warum auch immer, damit erster Listeeintrag richtig gerendert wird
| |
| for _, e in ipairs(addresses) do
| |
| t = t .. "* '''" -- Zeilenanfang Liste
| |
| -- Straße/Hausnummer ausgeben
| |
| if wik.pageExists(e["StraßeHnr"]) then -- Link zu Einzel-Gebäude-Seite
| |
| t = t .. "[[" .. e["StraßeHnr"] .. "]]"
| |
| elseif wik.pageExists(e["VonObjekt"]) then -- alternativ Link zu Gebäude-Komplex-Seite
| |
| t = t .. "[[" .. e["VonObjekt"] .. "|" .. e["StraßeHnr"] .. "]]"
| |
| elseif wik.pageExists(e["Straße"]) then -- alternativ Link zu Straße-Seite
| |
| t = t .. "[[" .. e["Straße"] .. "]] " .. tostring(e["Hausnummer"])
| |
| else
| |
| t = t .. "" .. e["StraßeHnr"] .. "" -- alternativ nur fetter Text
| |
| end
| |
| t = t .. "'''"
| |
|
| |
| -- Zusatzinfos in Klammern anfügen
| |
| local bracket = {}
| |
| if e["Adressart"] ~= "" then
| |
| table.insert(bracket, e["Adressart"])
| |
| end
| |
| if e["AdresseVon"] ~= "" then
| |
| table.insert(bracket, "von " .. lfd.formatDate(e["AdresseVon"]))
| |
| end
| |
| if e["AdresseBis"] ~= "" then
| |
| table.insert(bracket, "bis " .. lfd.formatDate(e["AdresseBis"]))
| |
| end
| |
| if #bracket > 0 then
| |
| t = t .. " (" .. table.concat(bracket, " ") ..")"
| |
| end
| |
| t = t .. "\n"
| |
| end
| |
| end
| |
|
| |
| -- Tab draus machen
| |
| t = p.tab_(t, "Adressen")
| |
| -- mw.log("t = " .. t) | | -- mw.log("t = " .. t) |
| return t | | return t |
| Zeile 260: |
Zeile 121: |
|
| |
|
| function p.tab_(t, name) | | function p.tab_(t, name) |
| -- mw.log("tab(t)")
| |
| -- mw.logObject(t)
| |
| t = str.strip(t) | | t = str.strip(t) |
| if t ~= "" then | | if t ~= "" then |
| t = "<tab name = ".. name .. ">" .. t .. "</tab>" | | t = "<tab name = ".. name .. ">" .. t .. "</tab>" |
| end | | end |
| -- mw.log("t = " .. t)
| |
| return t | | return t |
| end | | end |
|
| |
|
| function smwDate2SortIndex(date) | | function p.table_header_footer_(t) |
| -- mw.log("smwDate2SortIndex(" .. date .. ")")
| | t = str.strip(t) |
| -- Konsolenzeile zum Debuggen:
| | if t ~= "" then |
| -- =p.smwDate2SortIndex("2000")
| | t = "<dl class = \"dataTable\">" .. t .. "</dl>" |
| -- =p.smwDate2SortIndex("Februar 2000")
| |
| -- =p.smwDate2SortIndex("3. Februar 2000")
| |
| local sort_index = "" | |
| local date=str.split2(date, " ")
| |
| | |
| if #date == 1 then -- nur Jahr | |
| sort_index = tostring(date[1]) ..
| |
| "0101" -- 1. Januar
| |
| elseif #date == 2 then -- nur Monat + Jahr
| |
| sort_index = tostring(date[2]) .. | |
| string.format("%02d", com.getMonthnr(date[1])) ..
| |
| "01" -- 1. Tag
| |
| elseif #date == 3 then -- komplettes Datum
| |
| sort_index = tostring(date[3]) ..
| |
| string.format("%02d",com.getMonthnr(date[2])) ..
| |
| string.format("%02d", tonumber(string.match(date[1], "%d*")))
| |
| end | | end |
| sort_index = tonumber(sort_index) or 0
| | return t |
| -- mw.log("sort_index = " .. tostring(sort_index))
| |
| return sort_index | |
| end | | end |
|
| |
|
| function vonBisSortCompare(k1, k2) | | function p.factbox_header_footer_(t) |
| -- mw.log("vonBisSortCompare(k1, k2)")
| | t = str.strip(t) |
| -- mw.logObject(k1)
| | if t ~= "" then |
| -- mw.logObject(k2)
| | t = "<div class = \"factbox\"><tabs>" .. t .. "</tabs></div>" |
| local swap = false
| |
| if sort_iteration_limit_countdown > 0 then | |
| if k2.von_sort_index ~= 0 then
| |
| if k1.bis_sort_index ~= 0 then
| |
| swap = ( k1.bis_sort_index > k2.von_sort_index )
| |
| elseif k1.von_sort_index ~= 0 then
| |
| swap = ( k1.von_sort_index > k2.von_sort_index )
| |
| else
| |
| swap = true
| |
| end
| |
| elseif k2.bis_sort_index ~= 0 then
| |
| if k1.bis_sort_index ~= 0 then
| |
| swap = ( k1.bis_sort_index > k2.bis_sort_index )
| |
| elseif k1.von_sort_index ~= 0 then
| |
| swap = ( k1.von_sort_index > k2.bis_sort_index )
| |
| else
| |
| swap = true
| |
| end
| |
| end
| |
| sort_iteration_limit_countdown = sort_iteration_limit_countdown - 1
| |
| end | | end |
| -- mw.log("swap = " .. tostring(swap))
| | return t |
| return not swap | |
| end | | end |
|
| |
|
| return p | | return p |