Modul:SMW: Unterschied zwischen den Versionen

uniFilter() optimiert
(uniFilter() com.isEmpty(suchtext))
Markierung: Zurückgesetzt
(uniFilter() optimiert)
 
(9 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 70: Zeile 70:
-- mw.log("uniFilter(" .. suchtext .. ")")
-- mw.log("uniFilter(" .. suchtext .. ")")
local filter = ""
local filter = ""
suchtext = str.strip(tostring(suchtext or ""))
if not com.isEmpty(suchtext) and type(suchtext) ~= "table" then
if com.isEmpty(suchtext) then
suchtext = tostring(suchtext) -- Suchtext bereinigen
filter = "+"
suchtext = string.gsub(suchtext, "%[", "") -- Link-Klammern rauslöschen
else
suchtext = string.gsub(suchtext, "%[", "")
suchtext = string.gsub(suchtext, "%]", "")
suchtext = string.gsub(suchtext, "%]", "")
filter = filter .. suchtext -- exakte Suche (immer)
suchtext = string.gsub(suchtext, "|", " ")
filter = filter .. "||~*" .. suchtext .. "*" -- Wildcard-Suche des ganzen Suchtextes (immer)
suchtext = str.strip(suchtext)
semikolonVorhanden = (string.find(suchtext, ";") ~= nil)
if suchtext == "*" or suchtext == "" then -- Filter irgendein Wert
    if semikolonVorhanden then
filter = "+"
suchtextSplit = str.split2(suchtext, ";") -- Einzelwort-Suche
else
if #suchtextSplit > 1 then
filter = uniFilterAddGrossKlein(suchtext) -- Suchtext in Gänze
for _, ft in ipairs(suchtextSplit) do
local suchtext = str.splitAndStrip(suchtext, ";") -- Suchbegriffsliste hinzufügen
ft = str.strip(ft)
if #suchtext > 1 then
if ft ~= "" then
for _, st in ipairs(suchtext) do
filter = filter .. "||~*" .. ft .. "*" .. "||" .. ft
filter = filter .. "||" .. uniFilterAddGrossKlein(st)
end
end
end
end
end
    end
end
end
end
-- mw.log(filter)
-- mw.log(filter)
Zeile 95: Zeile 92:
end
end


function p.dateLastDayCompleter(date)
function uniFilterAddGrossKlein(suchtext)
local last_date
local filter = ""
if #date == 4 then -- nur "Jahr" vorhanden
suchtext = -- zuerst klein geschrieben
last_date = date .. "/12/31"
string.lower(string.sub(suchtext, 1, 1)) .. string.sub(suchtext, 2)
elseif #date ~= 10 then -- "Monat Jahr" vorhanden
filter = filter ..
local days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
"~*" .. suchtext .. "*" .. "||" .. suchtext
local month = string.sub(date, 1, string.find(date, " ") - 1)
local suchtext_gross = -- dann groß geschrieben
month = com.getMonthnr(month)
string.upper(string.sub(suchtext, 1, 1)) .. string.sub(suchtext, 2)
local year = string.sub(date, string.find(date, " ") + 1)
if suchtext_gross ~= suchtext then
last_date = year .. "/" .. month .. "/"
filter = filter ..
if month == 2 and year % 4 == 0 then -- Sonderfall Feb. Schaltjahr
"||~*" .. suchtext_gross .. "*" .. "||" .. suchtext_gross
last_date = last_date .. "29"
end
return filter
end
 
function p.subobjectIdCleaner(id)
local id_clean = ""
for i = 1, mw.ustring.len(id) do
local char = mw.ustring.sub(id, i, i)
if char == "." then
id_clean = id_clean .. "_"
else
else
last_date = last_date .. days[month]
id_clean = id_clean .. char
end
end
return id_clean
end
 
function p.addAttrToList(attrlist, attr, val)
-- Kommandozeile zum Debuggen:
-- attrlist={["t"]={"1","2"}}; p.addAttrToList(attrlist, "t", {"3", "4"}); mw.logObject(attrlist)
if val ~= nil then
if type(val) ~= "table" then
val = {val}
end
if attrlist[attr] == nil then
attrlist[attr] = val
else
for _, v in ipairs(val) do
table.insert(attrlist[attr], v)
end
end
end
else
last_date = date
end
end
return last_date
end
end


return p
return p