Модуль:Песочница/Pok: различия между версиями

мНет описания правки
Полностью удалено содержимое страницы
Метка: очистка
 
(не показано 28 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}


function p.occurrences(frame)
  local args = frame.args
  local pageArg = args.page or args[1]
  local title
  if pageArg and pageArg ~= "" then
    title = mw.title.new(pageArg)
  else
    title = mw.title.getCurrentTitle()
  end
  if not title then
    return 'Страница не найдена'
  end
  local content = title:getContent() or ''
  local word = args.word or args.w or ''
  if word == '' then return 'Укажите word=...' end
  local lc = mw.ustring.lower(content)
  local target = mw.ustring.lower(word)
  local esc = mw.ustring.gsub(target, "([^%w])", "%%%1")
  local pattern = '%f[%w]' .. esc .. '%f[%W]'
  local count = 0
  for _ in mw.ustring.gmatch(lc, pattern) do
    count = count + 1
  end
  return tostring(count)
end
return p