Модуль:RandomMembers: відмінності між версіями
| Admin (обговорення | внесок) Немає опису редагування | Admin (обговорення | внесок)  Немає опису редагування | ||
| Рядок 3: | Рядок 3: | ||
| function p.showRandomMembers(frame) | function p.showRandomMembers(frame) | ||
|      local category = 'Учасники_спільноти_MCC'  -- Your category |      local category = 'Учасники_спільноти_MCC'  -- Your category | ||
|      local  |      local results = mw.site:getCategoryMembers({ | ||
|         title = category, | |||
|         namespace = 0,      -- Assuming members are in the main namespace | |||
|         limit = 500         -- Adjust limit based on expected category size | |||
|     }) | |||
|      local output = {} |      local output = {} | ||
|      local count = 0 | |||
|     local usedIndices = {} | |||
|          table.insert(output, string.format('<p> | |||
|     -- Random selection logic | |||
|      while count < 4 and count < #results do | |||
|         local index = math.random(#results) | |||
|          if not usedIndices[index] then | |||
|             usedIndices[index] = true | |||
|             local member = results[index] | |||
|             table.insert(output, string.format('<p><a href="/wiki/%s">%s</a></p>', mw.uri.encode(member.title, 'WIKI'), member.title)) | |||
|             count = count + 1 | |||
|         end | |||
|      end |      end | ||
Версія за 22:32, 21 квітня 2024
Документацію для цього модуля можна створити у Модуль:RandomMembers/документація
local p = {}
function p.showRandomMembers(frame)
    local category = 'Учасники_спільноти_MCC'  -- Your category
    local results = mw.site:getCategoryMembers({
        title = category,
        namespace = 0,      -- Assuming members are in the main namespace
        limit = 500         -- Adjust limit based on expected category size
    })
    local output = {}
    local count = 0
    local usedIndices = {}
    -- Random selection logic
    while count < 4 and count < #results do
        local index = math.random(#results)
        if not usedIndices[index] then
            usedIndices[index] = true
            local member = results[index]
            table.insert(output, string.format('<p><a href="/wiki/%s">%s</a></p>', mw.uri.encode(member.title, 'WIKI'), member.title))
            count = count + 1
        end
    end
    return table.concat(output, "\n")
end
return p