The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 9: | Line 9: | ||
-- Check if the page content is available | -- Check if the page content is available | ||
if not wikitext then | if not wikitext then | ||
return "Error: Unable to fetch content for page '" .. pageTitle .. "'." | |||
end | end | ||
Line 15: | Line 15: | ||
PA = {}, | PA = {}, | ||
MD = {}, | MD = {}, | ||
Online = {} | |||
Online | |||
} | } | ||
-- Function to process each campaign row | |||
local function processRow(row) | |||
-- General pattern to capture the campaign name and locations | |||
local campaignNamePattern = "|'''%[%[(.-)%]%]'''" | |||
-- | local locationPattern = "|(.-)\n" | ||
local campaign, location = row:match(campaignNamePattern .. "%s*|%s*.-|.-|.-|.-|.-|" .. locationPattern) | |||
-- Debug output to check matches (remove this line in production) | |||
mw.log("Campaign: " .. (campaign or "nil") .. ", Location: " .. (location or "nil")) | |||
-- If the campaign name or location are not captured, return without processing | |||
if not campaign or not location then return end | |||
-- Trim whitespace from the location string | |||
location = mw.text.trim(location) | |||
-- Check and add to the relevant location | |||
if location:find("PA") then | if location:find("PA") then | ||
table.insert(campaigns.PA, | table.insert(campaigns.PA, campaign) | ||
end | |||
if location:find("MD") then | if location:find("MD") then | ||
table.insert(campaigns.MD, | table.insert(campaigns.MD, campaign) | ||
end | |||
if location:find("Online") then | if location:find("Online") then | ||
table.insert(campaigns.Online, | table.insert(campaigns.Online, campaign) | ||
end | end | ||
end | end | ||
-- Split the wikitext into rows and process each | -- Split the wikitext into rows and process each | ||
local rowPattern = "|- | local rowPattern = "|%-(.-)\n|%-" | ||
wikitext = wikitext .. '|- | wikitext = wikitext .. '|-' -- Append delimiter to capture the last row | ||
for row in wikitext:gmatch(rowPattern) do | for row in wikitext:gmatch(rowPattern) do | ||
processRow(row) | |||
end | end | ||
Line 72: | Line 59: | ||
end | end | ||
navbox = navbox .. '|}' | navbox = navbox .. '|}' | ||
return navbox | return navbox | ||
end | end | ||
return p | return p |