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

мНет описания правки
мНет описания правки
 
(не показано 7 промежуточных версий этого же участника)
Строка 2: Строка 2:


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


     local pattern = "([^%wА-Яа-яёЁ])" .. searchText .. "([^%wА-Яа-яёЁ])"
     local pattern = "[\n]%s*{{" .. modName
   
     if string.match("\n" .. content, pattern) then
     if not cleanedContent:match(pattern) then
        return "Да"
    else
         return "Нет"
         return "Нет"
     end
     end
    return "Да"
end
end


return p
return p