Lisää toimintoja
Ei muokkausyhteenvetoa |
Ei muokkausyhteenvetoa |
||
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 = " | categoryName = "Luokka:" .. categoryName | ||
end | end | ||
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