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

мНет описания правки
мНет описания правки
 
(не показаны 4 промежуточные версии этого же участника)
Строка 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
 
    local pattern = "[\n]%s*{{" .. modName
     if string.match("\n" .. content, pattern) then
        return "Да"
    else
         return "Нет"
         return "Нет"
     end
     end
    return "Да"
end
end


return p
return p