Модуль:Сущность/data: различия между версиями

Нет описания правки
Отмена версии 315901, сделанной Pok (обсуждение)
Метка: отмена
 
(не показаны 3 промежуточные версии этого же участника)
Строка 239: Строка 239:


     return table.concat(out, "\n")
     return table.concat(out, "\n")
end
local function normalizeFilterKey(s)
    s = trim(s or "")
    s = s:gsub("%s*_%s*", "_")
    return s
end
end


Строка 245: Строка 251:
         return false
         return false
     end
     end
    callKey = normalizeFilterKey(callKey)
    compositeKey = normalizeFilterKey(compositeKey)
     return list[callKey] or list[compositeKey] or false
     return list[callKey] or list[compositeKey] or false
end
end
Строка 512: Строка 520:
     if not str or str == "" then return res end
     if not str or str == "" then return res end
     for item in string.gmatch(str, "[^,]+") do
     for item in string.gmatch(str, "[^,]+") do
         local s = trim(item)
         local s = normalizeFilterKey(item)
         if s ~= "" then
         if s ~= "" then
             local a, b = s:match("^([^_]+)_(.+)$")
             local a, b = s:match("^([^_]+)_(.+)$")
Строка 697: Строка 705:
end
end


local function has_matching_keys(parsed, filter)
local function extract_whitelist_search_strings(keyFilter)
     if not filter or not filter.hasWhitelist then
     if not keyFilter or not keyFilter.hasWhitelist then
         return true
         return nil
    end
 
    local strings = {}
    for sw, keys in pairs(keyFilter.whitelist) do
        if type(keys) == "table" then
            for key in pairs(keys) do
                strings[#strings + 1] = key
            end
        end
     end
     end


     if type(parsed) ~= "table" then
     if #strings == 0 then
         return false
         return nil
     end
     end


     for _, sw in ipairs(switchModeOrder) do
     return strings
        local mode = switchModeRegistry[sw] or {}
end
        local keys
        if type(mode.get_keys) == "function" then
            keys = mode.get_keys(parsed)
        else
            keys = parsed[sw] or {}
        end


        if type(keys) == "table" then
local function content_matches_whitelist(content, searchStrings)
            for _, key in ipairs(keys) do
    if not searchStrings then
                if should_include_key(filter, sw, key) then
        return true
                    return true
    end
                end
    if not content then
            end
         return false
         end
     end
     end


     if type(parsed.cardTag) == "string" and parsed.cardTag ~= "" then
     for _, s in ipairs(searchStrings) do
         if should_include_key(filter, "card", "cardTag") then
         if string.find(content, s, 1, true) then
             return true
             return true
         end
         end
Строка 756: Строка 766:
     local protoHasWhitelist = next(protoWhitelistSet) ~= nil
     local protoHasWhitelist = next(protoWhitelistSet) ~= nil
     local anyEntityWhitelist = compHasWhitelist or protoHasWhitelist
     local anyEntityWhitelist = compHasWhitelist or protoHasWhitelist
    local whitelistSearchStrings = extract_whitelist_search_strings(keyFilter)


     local function processEntity(kind, name, isStore)
     local function processEntity(kind, name, isStore)
Строка 769: Строка 781:
                 onMissing(kind, name, isStore, tplPath)
                 onMissing(kind, name, isStore, tplPath)
             end
             end
            return
        end
        if not content_matches_whitelist(content, whitelistSearchStrings) then
             return
             return
         end
         end
Строка 777: Строка 793:
         end
         end


        local needsExtra = has_matching_keys(parsed, keyFilter)
         local extra = ""
         local extra = ""
         if needsExtra and dp then
         local paramNames = get_template_params(tplPath, content)
            local paramNames = get_template_params(tplPath, content)
        if dp then
             local dataPage = tplPath .. ".json"
             local dataPage = tplPath .. ".json"
             extra = get_selective_extra(id, dataPage, paramNames)
             extra = get_selective_extra(id, dataPage, paramNames)