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

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
 
(не показано 6 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}
local p = {}


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*$")
 
     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

Текущая версия от 04:13, 15 апреля 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 ""

    local pattern = "[\n]%s*{{" .. modName
    if string.match("\n" .. content, pattern) then
        return "Да"
    else
        return "Нет"
    end
end

return p