Toggle menu
Toggle preferences menu
Toggle personal menu
Et ole kirjautunut
Your IP address will be publicly visible if you make any edits.

Ero sivun ”Moduuli:ListCategoryPages” versioiden välillä

Sarastus Wikistä
Ak: Uusi sivu: local p = {} function p.listPagesInCategory(frame) -- Name of the category to list pages from local categoryName = frame.args.category or "ExampleCategory" -- Ensure the category starts with "Category:" if not categoryName:match("^Category:") then categoryName = "Category:" .. categoryName end -- Get the category object local category = mw.title.new(categoryName) if not category or not category.exists then return "The cat...
 
Ei muokkausyhteenvetoa
 
(Yhtä välissä olevaa versiota samalta käyttäjältä ei näytetä)
Rivi 7: Rivi 7:
     -- Ensure the category starts with "Category:"
     -- Ensure the category starts with "Category:"
     if not categoryName:match("^Category:") then
     if not categoryName:match("^Category:") then
         categoryName = "Category:" .. categoryName
         categoryName = "Luokka:" .. categoryName
     end
     end


Rivi 21: Rivi 21:


     for pageTitle, _ in pairs(pages) do
     for pageTitle, _ in pairs(pages) do
         table.insert(result, pageTitle)
         -- Create a title object for the page
        local page = mw.title.new(pageTitle)
        if page then
            -- Extract the page name without the namespace
            local pageLabel = page.text
            -- Add a formatted entry with a link and label
            table.insert(result, "* [[" .. page.fullText .. "|" .. pageLabel .. "]]")
        end
     end
     end


Rivi 27: Rivi 34:
     table.sort(result)
     table.sort(result)


     -- Format the output as a bulleted list
     -- Combine the results into a single string
     local output = ""
     return table.concat(result, "\n")
    for _, title in ipairs(result) do
        output = output .. "* [[" .. title .. "]]\n"
    end
 
    return output
end
end


return p
return p

Nykyinen versio 11. joulukuuta 2024 kello 23.48

Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:ListCategoryPages/ohje

local p = {}

function p.listPagesInCategory(frame)
    -- Name of the category to list pages from
    local categoryName = frame.args.category or "ExampleCategory"
    
    -- Ensure the category starts with "Category:"
    if not categoryName:match("^Category:") then
        categoryName = "Luokka:" .. categoryName
    end

    -- Get the category object
    local category = mw.title.new(categoryName)
    if not category or not category.exists then
        return "The category does not exist."
    end

    -- Fetch all pages in the category
    local pages = category:categoryMembers()
    local result = {}

    for pageTitle, _ in pairs(pages) do
        -- Create a title object for the page
        local page = mw.title.new(pageTitle)
        if page then
            -- Extract the page name without the namespace
            local pageLabel = page.text
            -- Add a formatted entry with a link and label
            table.insert(result, "* [[" .. page.fullText .. "|" .. pageLabel .. "]]")
        end
    end

    -- Sort the result alphabetically
    table.sort(result)

    -- Combine the results into a single string
    return table.concat(result, "\n")
end

return p