Module:ProjectCounts: Difference between revisions

Al Piskun (talk | contribs)
No edit summary
Al Piskun (talk | contribs)
No edit summary
 
Line 1: Line 1:
-- Module:ProjectCounts
-- Module:ProjectCounts
-- Counts BOINC project table rows and related figures for the wiki.
--
-- {{#invoke:ProjectCounts|count|Section name|page=Page title}}
--    Data rows in the wikitable(s) of one section.
-- {{#invoke:ProjectCounts|total|Section A|Section B|...|page=Page title}}
--    Sum of data rows across several sections of one page.
-- {{#invoke:ProjectCounts|documented|Local BOINC project wiki pages|page=Main Page}}
--    Distinct existing mainspace articles linked in a section.
-- {{#invoke:ProjectCounts|recordings|Screensaver Gallery|page=BOINC project screensavers}}
--    Unique YouTube recordings linked in a section.
local p = {}
local p = {}


Line 42: Line 52:
end
end


-- {{#invoke:ProjectCounts|count|Section name|page=Page title}}
function p.count(frame)
function p.count(frame)
return countSection(frame.args.page or 'BOINC projects', frame.args[1] or '')
return countSection(frame.args.page or 'BOINC projects', frame.args[1] or '')
end
end


-- {{#invoke:ProjectCounts|total|Section A|Section B|...|page=Page title}}
function p.total(frame)
function p.total(frame)
local page = frame.args.page or 'BOINC projects'
local page = frame.args.page or 'BOINC projects'
Line 60: Line 68:
end
end


-- {{#invoke:ProjectCounts|documented|Local BOINC project wiki pages|page=Main Page}}
-- Counts distinct mainspace article links in a section, skipping redlinks.
function p.documented(frame)
function p.documented(frame)
local page = frame.args.page or 'Main Page'
local page = frame.args.page or 'Main Page'
Line 80: Line 86:
end
end
end
end
return n
end
function p.recordings(frame)
local content = getContent(frame.args.page or 'BOINC project screensavers')
if not content then return 0 end
local body = getSection(content, mw.text.trim(frame.args[1] or 'Screensaver Gallery'))
if not body then return 0 end
local seen, n = {}, 0
local function mark(id)
if id and id ~= '' and not seen[id] then
seen[id] = true
n = n + 1
end
end
for id in body:gmatch('youtube%.com/watch%?v=([%w_-]+)') do mark(id) end
for id in body:gmatch('youtu%.be/([%w_-]+)') do mark(id) end
for id in body:gmatch('img%.youtube%.com/vi/([%w_-]+)') do mark(id) end
return n
return n
end
end


return p
return p