Modul:Faktenbox/Zeilen: Unterschied zwischen den Versionen

- smw.addAttrToList(fbdata.attr.list, "Seite", fbdata.fullpagename) verschoben nach Modul:Faktenbox/Common
(zeileGeoDaten() doppelte Koordinaten ausfiltern)
(- smw.addAttrToList(fbdata.attr.list, "Seite", fbdata.fullpagename) verschoben nach Modul:Faktenbox/Common)
 
(15 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 8: Zeile 8:
local lfd = require("Modul:LinkFormDatum")
local lfd = require("Modul:LinkFormDatum")
local wob = require("Modul:Wörterbuch")
local wob = require("Modul:Wörterbuch")
local fab_red_links = require("Modul:Faktenbox/Zeilen/RedLinks")


function p.zeileKategorieSeite_(fbdata, kindex)
function p.zeileKategorieSeite_(fbdata, kindex)
Zeile 15: Zeile 17:
-- =p.zeileKategorieSeite_({pagename="fpn",kategorie={"kat1","kat2"},kategorie_einzahl={"k1","k2"},klasse={"kla1","kla2"}}, 2)
-- =p.zeileKategorieSeite_({pagename="fpn",kategorie={"kat1","kat2"},kategorie_einzahl={"k1","k2"},klasse={"kla1","kla2"}}, 2)
local t = ""
local t = ""
local kategorie_einzahl
local kategorie = wob.mehrzahl((fbdata.kategorie or fbdata.klasse)[kindex or 1])
if fbdata.kategorie_einzahl ~= nil then
local kategorie_einzahl = (fbdata.kategorie_einzahl or fbdata.klasse)[kindex or 1]
kategorie_einzahl = fbdata.kategorie_einzahl[kindex or 1]
t = t .. "<dt>[[:Kategorie:" .. kategorie .. "|" .. kategorie_einzahl .. "]]</dt>"
else
kategorie_einzahl = fbdata.klasse[kindex or 1]
end
t = t .. "<dt>[[:Kategorie:" .. fbdata.kategorie[kindex or 1] .. "|" .. kategorie_einzahl .. "]]</dt>"
if wik.pageExists("Kategorie:" .. fbdata.pagename) then
if wik.pageExists("Kategorie:" .. fbdata.pagename) then
t = t .. "<dd>[[:Kategorie:" .. fbdata.pagename .. "|" .. fbdata.pagename .. "]]{{#set:Seite=" .. fbdata.pagename .. "}}</dd>"
t = t .. "<dd>[[:Kategorie:" .. fbdata.pagename .. "|" .. fbdata.pagename .. "]]</dd>"
else
else
t = t .. "<dd>[[Seite::" .. fbdata.pagename .. "]]</dd>"
t = t .. "<dd>'''" .. fbdata.fullpagename .. "'''</dd>"
end
end
-- mw.logObject(t, "t")
-- mw.logObject(t, "t")
Zeile 37: Zeile 35:
-- =p.zeileStrasseHnr_{strasse_hnr={strasse={{name="Erlanger Straße",hausnummer={"11", "13"}},{name="XY Straße",hausnummer={}}},anzahlGebaeude=3}}
-- =p.zeileStrasseHnr_{strasse_hnr={strasse={{name="Erlanger Straße",hausnummer={"11", "13"}},{name="XY Straße",hausnummer={}}},anzahlGebaeude=3}}
local t = ""
local t = ""
for is, sh in ipairs(fbdata.strasse_hnr.strasse) do -- Straßen/Hausnummer-Kombis durchiterieren
for is, sh in ipairs(fbdata.strasse_hnr.strasse) do -- Straßen/Hausnummer-Kombis durchiterieren
t = t .. "<dt>"
t = t .. "<dt>"
if is > 1 then
if is > 1 then
t = t .. is .. ". " -- Numerierungsanzeige "2., "3." usw.
if is == 2 and #sh.hausnummer == 0 then
t = t ..  "Ecke " -- Sonderfall Ecke
else
t = t .. is .. ". " -- Numerierungsanzeige "2., "3." usw.
end
else
else
is = "" -- keine 1, aber 2, 3, ... für weitere Verwendung
is = "" -- keine 1, aber 2, 3, ... für weitere Verwendung
end
end
t = t .. "Straße"
t = t .. "Straße"
if #sh.hausnummer > 0 then
if #sh.hausnummer > 0 then
t = t .. " / " .. "Hausnummer" -- nur wenn Hausnummern vorhanden
t = t .. " / " .. "Hausnummer" -- nur wenn Hausnummern vorhanden
if #sh.hausnummer > 1 then
if #sh.hausnummer > 1 then
t = t .. "n" -- Mehrzahl
t = t .. "n" -- Mehrzahl
end
end
end
end
t = t .. "</dt><dd>[[Straße" .. is .. "::" .. sh.name .. "]]"
t = t .. "</dt><dd>[[" .. sh.name .. "]]"
for ih, h in ipairs(sh.hausnummer) do -- Hausnummern durchiterieren
smw.addAttrToList(fbdata.attr.list, "Straße" .. is, sh.name)
for ih, h in ipairs(sh.hausnummer) do -- Hausnummern durchiterieren
local strasse_hnr_ = sh.name .. " " .. h
local strasse_hnr_ = sh.name .. " " .. h
if ih > 1 then
if ih > 1 then
t = t .. "," -- Kommas davor ab 2. Hausnummer
t = t .. "," -- Kommas davor ab 2. Hausnummer
end
end
if wik.pageExists(strasse_hnr_) then -- Link, wenn Seite vorhanden
if wik.pageExists(strasse_hnr_) then -- Link, wenn Seite vorhanden
t = t .. " [[" .. strasse_hnr_ .. "|" .. h .. "]]"
t = t .. " [[" .. strasse_hnr_ .. "|" .. h .. "]]"
else
else
t = t .. " " .. h
t = t .. " " .. h
end
end
t = t .. "{{#set:Hausnummer" .. is .. "=" .. h .. "|StraßeHnr=" .. strasse_hnr_ .. "}}"
smw.addAttrToList(fbdata.attr.list, "Hausnummer" .. is, h)
smw.addAttrToList(fbdata.attr.list, "StraßeHnr", strasse_hnr_)
end
end
t = t .. "</dd>"
t = t .. "</dd>"
end
end
t = t .. "{{#set:AnzahlGebäude=" .. fbdata.strasse_hnr.anzahlGebaeude .. "}}"
smw.addAttrToList(fbdata.attr.list, "AnzahlGebäude", fbdata.strasse_hnr.anzahlGebaeude)
-- mw.logObject(t, "t")
-- mw.logObject(t, "t")
return t
return t
Zeile 77: Zeile 81:
-- =p.zeileAktenNr_{pargs={AktenNr="D-5-63-000-1464"}}
-- =p.zeileAktenNr_{pargs={AktenNr="D-5-63-000-1464"}}
local t = ""
local t = ""
local aktennr = str.splitAndStrip(fbdata.pargs["AktenNr"] or "", ";")
local aktennr = str.splitAndStrip(fbdata.pargs["AktenNr"], ";")
if #aktennr > 0 then
if #aktennr > 0 then
t = t .. "<dt>" .. "Akten-Nr.</dt><dd>"
t = t .. "<dt>" .. "Akten-Nr.</dt><dd>"
Zeile 86: Zeile 90:
local p = smw.getPages("[[:+]][[AktenNr::" .. a .. "]]", true)
local p = smw.getPages("[[:+]][[AktenNr::" .. a .. "]]", true)
if #p > 1 then
if #p > 1 then
t = t .. "{{#queryformlink:form=Abfrage Denkmalschutz|link text=[[AktenNr::" .. a .. "]]|query string=Abfrage Denkmalschutz[AktenNr]=" .. a .. "&_run}}"
t = t .. "{{#queryformlink:form=Abfrage Denkmalschutz|link text=" .. a .. "|query string=Abfrage Denkmalschutz[AktenNr]=" .. a .. "&_run}}"
else
else
t = t .. "[[AktenNr::" .. a .. "]]"
t = t .. a
end
end
smw.addAttrToList(fbdata.attr.list, "AktenNr", a)
t = t .. " (" .. #p .. ")" -- Anzahl der Artikel mit dieser Akten-Nr. in Klammern
t = t .. " (" .. #p .. ")" -- Anzahl der Artikel mit dieser Akten-Nr. in Klammern
end
end
Zeile 141: Zeile 146:
-- =p.zeileDatum_{attr_date="Weihedatum",date="1959/11/15",attr_day="Weihetag",attr_year="Weihejahr"}
-- =p.zeileDatum_{attr_date="Weihedatum",date="1959/11/15",attr_day="Weihetag",attr_year="Weihejahr"}
local t = ""
local t = ""
local date = str.strip(args.date or "")
if args.date ~= nil then
if date ~= "" then
t = t .. "<dt>" .. (args.attr_text or args.attr_date) .. "</dt><dd>"
t = t .. "<dt>" .. (args.attr_text or args.attr_date) .. "</dt><dd>"
if com.isTrue(args.val_show_only) then
if com.isTrue(args.val_show_only) then
t = t .. lfd.linkFormDate(date)
t = t .. lfd.linkFormDate(args.date)
else
else
t = t .. lfd.linkFormDate(date, args.attr_date, args.attr_day, args.attr_year)
t = t .. lfd.linkFormDate(args.date, args.attr_date, args.attr_day, args.attr_year)
end
end
t = t .. "</dd>"
t = t .. "</dd>"
Zeile 198: Zeile 202:
if #attr_val > 0 then
if #attr_val > 0 then
-- Attribut-Text ermitteln und in Zeile übernehmen
-- Attribut-Text ermitteln und in Zeile übernehmen
local attr_text = args.attr_text or wob.attr_text(attr_name)
local attr_text = args.attr_text or wob.attrText(attr_name, args.fbdata.klasse[1])
if #attr_val > 1 then
if #attr_val > 1 then
attr_text = wob.mehrzahl(attr_text) -- Mehrzahl
attr_text = wob.mehrzahl(attr_text) -- Mehrzahl
Zeile 212: Zeile 216:
t = t .. ", " -- Listen-Kommata
t = t .. ", " -- Listen-Kommata
end
end
if mw.smw.getPropertyType(attr_name) == "_wpg" then -- Seiten-Attribute Spezialbehandlung
if not wik.pageExists("Attribut:" .. attr_name) then -- Spezialbehandlung Attribut nicht vorhanden
t = t .. p.setPageAttr(attr_name, val, args.val_show_only)
t = t .. p.setStandardAttr(args.fbdata.attr.list, attr_name, val, args.exclude_bracket_values, args.val_show_only)
else -- alle anderen Attribut-Datentypen
elseif mw.smw.getPropertyType(attr_name) == "_wpg" then -- Seiten-Attribute Spezialbehandlung
if mw.smw.getPropertyType(attr_name) == "_tel" then -- Telefonnummer Spezialbehandlung
t = t .. p.setPageAttr(args.fbdata.attr.list, attr_name, val, args.val_show_only)
val = p.getTelUri(val)
elseif mw.smw.getPropertyType(attr_name) == "_tel" then -- Telefon-Attribute Spezialbehandlung
end
t = t .. p.setTelAttr(args.fbdata.attr.list, attr_name, val, args.val_show_only)
t = t .. p.setStandardAttr(attr_name, val, args.exclude_bracket_values, args.val_show_only)
else -- Standard-Attribute
t = t .. p.setStandardAttr(args.fbdata.attr.list, attr_name, val, args.exclude_bracket_values, args.val_show_only)
end
end
end
end
Zeile 230: Zeile 235:
end
end


function p.setPageAttr(name, val, val_show_only)
function p.setPageAttr(attrlist, name, val, val_show_only)
local t = ""
local t = ""
if string.find(val, "[#=<>%[%]%|%{%}]") ~= nil then -- problematische Wikitext/HTML-Inhalte vorhanden?
if string.find(val, "[#=<>%[%]%|%{%}]") ~= nil then -- problematische Wikitext/HTML-Inhalte vorhanden?
t = t .. val -- ==> kein Link, sondern nur Attribut versteckt setzen
t = t .. val -- ==> kein Link, sondern nur Attribut versteckt setzen
if not val_show_only then
t = t .. "{{#set:" .. name .. "=" .. val .. "}}"
end
elseif wik.pageExists(val) then -- eine vorhandene Seite regulär verlinken bzw. setzen
elseif wik.pageExists(val) then -- eine vorhandene Seite regulär verlinken bzw. setzen
if val_show_only then
t = t .. "[[" .. val .. "]]"
t = t .. "[[" .. val .. "]]"
else
t = t .. "[[" .. name .. "::" .. val .. "]]"
end
else
else
val_pre_bracket, val_without_bracket, val_post_bracket = str.bracketSplitAndStrip(val) -- nach Klammern suchen und aufteilen
local val_pre_bracket, val_without_bracket, val_post_bracket = str.bracketSplitAndStrip(val) -- nach Klammern suchen und aufteilen
if not wik.pageExists(val_without_bracket) then -- Seite auch ohne Klammern nicht vorhanden?
if wik.pageExists(val_without_bracket) then -- Seite ohne Klammern vorhanden?
t = t .. val -- ==> kein Link, sondern nur Attribut versteckt setzen
if not val_show_only then
t = t .. "{{#set:" .. name .. "=" .. val .. "}}"
end
else
if val_pre_bracket ~= "" then -- Klammer-Text vor eigentlicher Seite
if val_pre_bracket ~= "" then -- Klammer-Text vor eigentlicher Seite
t = t .. val_pre_bracket .. " "
t = t .. val_pre_bracket .. " "
end
end
if val_show_only then
t = t .. "[[" .. val_without_bracket .. "]]" -- das eigentliche Attribut verlinken
t = t .. "[[" .. val_without_bracket .. "]]" -- das eigentliche Attribut verlinken
else
t = t .. "[[" .. name .. "::" .. val_without_bracket .. "]]" -- das eigentliche Attribut-Setzen
end
if val_post_bracket ~= "" then -- Klammer-Text nach eigentlicher Seite
if val_post_bracket ~= "" then -- Klammer-Text nach eigentlicher Seite
t = t .. " " .. val_post_bracket
t = t .. " " .. val_post_bracket
end
end
val = val_without_bracket
-- auch ohne Klammern existiert keine Seite => dann roten Link anzeigen?
elseif fab_red_links.red_links[name] ~= false then -- auch nil als default als roten Link
t = t .. "[[" .. val .. "]]"
else
t = t .. val
end
end
end
if not val_show_only then
smw.addAttrToList(attrlist, name, val)
end
-- mw.logObject(t, "t")
return t
end
function p.setTelAttr(attrlist, name, val, val_show_only)
local t = ""
local val_pre_bracket, tel, val_post_bracket = str.bracketSplitAndStrip(val) -- nach Klammern suchen und aufteilen
local tel = val_pre_bracket .. " " .. tel -- Klammer am Anfang wieder anfügen
tel = p.getTelUri(tel)
if string.sub(tel, 1, 1) == "+" then
t = t .. "[tel:" .. tel .. " " .. val .. "]"
else
t = t .. val
end
if not val_show_only then
smw.addAttrToList(attrlist, name, val)
end
end
-- mw.logObject(t, "t")
-- mw.logObject(t, "t")
Zeile 268: Zeile 283:
end
end


function p.setStandardAttr(name, val, exclude_bracket_values, val_show_only)
function p.setStandardAttr(attrlist, name, val, exclude_bracket_values, val_show_only)
local t = ""
local t = ""
local val_pre_bracket, val_post_bracket = "", ""
local val_pre_bracket, val_post_bracket = "", ""
Zeile 277: Zeile 292:
t = t .. val_pre_bracket .. " "
t = t .. val_pre_bracket .. " "
end
end
if com.isTrue(val_show_only) then
t = t .. val
t = t .. val
else
t = t .. "[[" .. name .. "::" .. val .. "]]"
end
if val_post_bracket ~= "" then
if val_post_bracket ~= "" then
t = t .. " " .. val_post_bracket
t = t .. " " .. val_post_bracket
end
if not val_show_only then
smw.addAttrToList(attrlist, name, val)
end
end
-- mw.logObject(t, "t")
-- mw.logObject(t, "t")
Zeile 290: Zeile 304:


function p.getTelUri(val)
function p.getTelUri(val)
local tel = str.strip(val) -- preload default
-- Alles außer Zahlen und + am Anfang ausfiltern
if mw.ustring.sub(tel, 1, 1) == "0" and -- beginnt mit 0zzz (z = Zahl)
local tel = ""
(tonumber(mw.ustring.sub(tel, 2, 2)) or 0) > 0 then
local pre_plus = false
tel = "+49 " .. mw.ustring.sub(tel, 2)
for i = 1, mw.ustring.len(val) do
elseif mw.ustring.sub(tel, 1, 3) == "+49" then -- +49 (0) ...
local char = mw.ustring.sub(val, i, i)
s, e = mw.ustring.find(tel, "%(0%)")
if (char == "+" and not pre_plus) or tonumber(char) ~= nil then -- + am Anfang erlaubt
if s ~= nil then
tel = tel .. char
tel = mw.ustring.sub(tel, 1, s - 1) .. " " .. mw.ustring.sub(tel, e + 1)
pre_plus = true
end
end
end
end
-- Alle unerlaubten Zeichen und mehrfache Leerzeichen ausfiltern
-- Sonderbehandlungen
local telUri = ""
if mw.ustring.sub(tel, 1, 2) == "00" then -- 00 ...
local previous_char = ""
tel = "+" .. mw.ustring.sub(tel, 3)
tel = tel .. " "
end
for i = 1, mw.ustring.len(tel) do
if mw.ustring.sub(tel, 1, 1) == "0" and -- beginnt mit 0zzz (z = Zahl 1-9)
local char = mw.ustring.sub(tel, i, i)
(tonumber(mw.ustring.sub(tel, 2, 2)) or 0) > 0 then -- dann wird +49 angenommen
if tonumber(char) ~= nil or
tel = "+49" .. mw.ustring.sub(tel, 2)
char == "+" or char == "-" or char == "/" or
elseif mw.ustring.sub(tel, 1, 4) == "+490" then -- +49(0) ...
(char == " " and previous_char ~= " ") then
tel = "+49" .. mw.ustring.sub(tel, 5)
telUri = telUri .. previous_char
previous_char = char
end
end
end
return telUri
return tel
end
end


return p
return p