Модуль:RandomMembers: відмінності між версіями

нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 3: Рядок 3:
function p.showRandomMembers(frame)
function p.showRandomMembers(frame)
     local category = 'Учасники_спільноти_MCC'  -- Your category
     local category = 'Учасники_спільноти_MCC'  -- Your category
     local count = 4  -- How many members to display
     local results = mw.site:getCategoryMembers({
    local pages = mw.site:getCategoryMembers(category, 'all', count)
        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
     for i, page in ipairs(pages) do
    local usedIndices = {}
         table.insert(output, string.format('<p>[[%s|%s]]</p>', page.fullText, page.fullText))
 
        if i >= count then break end
    -- 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