Модуль:Поиск шаблона страницы: различия между версиями

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
Строка 2: Строка 2:


function p.main(frame)
function p.main(frame)
     local args = frame.args
     local modName = frame.args[1]
    local searchText = tostring(args[1] or "")
     if not modName then
   
         return "Параметр не задан"
    searchText = searchText:match("^%s*(.-)%s*$")
    searchText = searchText:gsub("<nowiki>", ""):gsub("</nowiki>", "")
   
     if searchText == "" then
         return "Нет"
     end
     end


     local title = mw.title.getCurrentTitle()
     local title = mw.title.getCurrentTitle()
    local content = title:getContent()
     if not title then
     if not content then
         return "Не удалось получить заголовок страницы"
         return "Нет"
     end
     end


     local cleanedContent = content:gsub("{{#invoke:Поиск строк страницы|main|[^}]+}}", "")
     local content = title:getContent() or ""
     if not cleanedContent:find(searchText, 1, true) then
   
    if string.find(content, "{{#invoke:" .. modName) then
        return "Да"
     else
         return "Нет"
         return "Нет"
     end
     end
    return "Да"
end
end


return p
return p

Версия от 15:28, 6 марта 2025

Для документации этого модуля может быть создана страница Модуль:Поиск шаблона страницы/doc

local p = {}

function p.main(frame)
    local modName = frame.args[1]
    if not modName then
        return "Параметр не задан"
    end

    local title = mw.title.getCurrentTitle()
    if not title then
        return "Не удалось получить заголовок страницы"
    end

    local content = title:getContent() or ""
    
    if string.find(content, "{{#invoke:" .. modName) then
        return "Да"
    else
        return "Нет"
    end
end

return p