Módulo:Testes/EPorto (WMB)
A documentação para este módulo pode ser criada na página Módulo:Testes/EPorto (WMB)/doc
local p = {}
local function getPageContent(frame)
local url = mw.title.new("Utilizador:EPorto (WMB)/Testes");--mw.title.getCurrentTitle();
local content = url:getContent();
return content
end
local function getSections(content)
local titles = {}
for line in content:gmatch("[^\r\n]+") do
local title = line:match("^%s*==(.-)==%s*$")
if title then
table.insert(titles, title)
end
end
return titles
end
local function extractContentOfSections(content)
local _, startIndex = mw.ustring.find(content,"==(.-)==")
if startIndex then
return content:sub(startIndex)
else
return content
end
end
local function getSectionContent(content, section)
local cleanContent = extractContentOfSections(content)
local inSection = false
local sectionContent = ""
count = 0
linesused = ""
for line in cleanContent:gmatch("[^\r\n]+") do
local sectionTitle = line:match("^%s*==%s*(.-)%s*==%s*$")
if section == "all" then
if sectionTitle then
if not inSection then
inSection = true
end
end
if inSection and not sectionTitle then
sectionContent = sectionContent .. line .. "\n"
count = count + select(2, string.gsub(line, "Utilizador:EPorto %(WMB%)/Testes/Programa de educação", ""))
linesused = linesused .. line .. '\n'
end
elseif sectionTitle and sectionTitle == section then
inSection = true
elseif inSection then
if not sectionTitle then
sectionContent = sectionContent .. line .. "\n"
count = count + select(2, string.gsub(line, "Utilizador:EPorto %(WMB%)/Testes/Programa de educação", ""))
end
end
end
return sectionContent, count
end
function p.count_institutions(frame)
local content = getPageContent(frame)
local section = frame.args["section"] or "all"
local titles = getSections(content)
local subcontent, count = getSectionContent(content, section)
return count
end
return p