Модуль:RandomMembers: відмінності між версіями
Admin (обговорення | внесок) (Створена сторінка: local p = {} function p.showRandomMembers(frame) local count = 4 -- Number of random members to display local category = 'Учасники_спільноти_MCC' -- The category to fetch from local members = mw.site:pagesInCategory(category, 'random', count) local output = {} for member in pairs(members) do table.insert(output, string.format('<p>%s</p>', member.fullText)) end return table.concat(output, "\n") e...) |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 4: | Рядок 4: | ||
local count = 4 -- Number of random members to display | local count = 4 -- Number of random members to display | ||
local category = 'Учасники_спільноти_MCC' -- The category to fetch from | local category = 'Учасники_спільноти_MCC' -- The category to fetch from | ||
local | local pages = mw.site.pagesInCategory(category) | ||
local output = {} | local output = {} | ||
local displayed = {} | |||
for | -- Fetching random pages | ||
table.insert(output, string.format('<p>[[%s]]</p>', | for i = 1, math.min(count, #pages) do | ||
local index = math.random(#pages) | |||
while displayed[index] do | |||
index = math.random(#pages) | |||
end | |||
displayed[index] = true | |||
local title = pages[index].title | |||
table.insert(output, string.format('<p>[[%s|%s]]</p>', title, title)) | |||
end | end | ||
Версія за 22:30, 21 квітня 2024
Документацію для цього модуля можна створити у Модуль:RandomMembers/документація
local p = {}
function p.showRandomMembers(frame)
local count = 4 -- Number of random members to display
local category = 'Учасники_спільноти_MCC' -- The category to fetch from
local pages = mw.site.pagesInCategory(category)
local output = {}
local displayed = {}
-- Fetching random pages
for i = 1, math.min(count, #pages) do
local index = math.random(#pages)
while displayed[index] do
index = math.random(#pages)
end
displayed[index] = true
local title = pages[index].title
table.insert(output, string.format('<p>[[%s|%s]]</p>', title, title))
end
return table.concat(output, "\n")
end
return p