Module:T-Campaign: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 183: Line 183:
         end
         end
          
          
         -- Step 1: Get the raw title value
         -- WORKAROUND for Scribunto bug: Launder the string and replace directly.
 
        -- 1. Get the raw title value
         local rawTitle = args._campaign_data.defaults.title or "Campaign"
         local rawTitle = args._campaign_data.defaults.title or "Campaign"
       
 
         -- Step 2: Launder the string to work around suspected Scribunto bug
         -- 2. Launder the string to create a clean copy
         local function launderString(inputStr)
         local function launderString(inputStr)
             if type(inputStr) ~= 'string' then return tostring(inputStr) end
             if type(inputStr) ~= 'string' then return tostring(inputStr) end
Line 195: Line 197:
             return newStr
             return newStr
         end
         end
         local cleanTitle = launderString(rawTitle)
         local cleanTitle = launderString(rawTitle)
       
        ErrorHandling.addStatus(context, 'campaignBanner', 'Laundered String', 'Original Type: ' .. type(rawTitle) .. ', Cleaned Value: "' .. cleanTitle .. '"')


         -- If it's a table, we need to serialize it to see what's inside.
         -- 3. Directly replace the placeholder in the banner content string
         if type(rawTitle) == 'table' then
         bannerContent = bannerContent:gsub("%$CAMPAIGN_NAME%$", cleanTitle)
            -- This is a simple serializer for demonstration.
            local serialized = "{"
            for k, v in pairs(rawTitle) do
                serialized = serialized .. ' [' .. tostring(k) .. '] = "' .. tostring(v) .. '",'
            end
            if serialized:sub(-1) == ',' then
                serialized = serialized:sub(1, -2)
            end
            serialized = serialized .. " }"
            ErrorHandling.addStatus(context, 'campaignBanner', 'Raw title is a table', 'Serialized content: ' .. serialized)
           
            -- Attempt to extract a string value. Let's assume the first value is what we want.
            if rawTitle[1] then
                cleanTitle = launderString(tostring(rawTitle[1]))
                ErrorHandling.addStatus(context, 'campaignBanner', 'Extracted value from table', 'Using value at index 1: "' .. cleanTitle .. '"')
            else
                -- Fallback if we can't find a value at index 1
                cleanTitle = launderString(tostring(rawTitle))
            end
        end


         -- Step 3: Use the processed title for the placeholder
         -- 4. Pass the processed content to the WikitextProcessor for link handling only
        local placeholderValues = {
         bannerContent = WikitextProcessor.processWikiLinksToHTML(bannerContent, context)
            CAMPAIGN_NAME = cleanTitle
        }
       
        ErrorHandling.addStatus(context, 'campaignBanner', 'Final placeholder value set', 'CAMPAIGN_NAME = "' .. cleanTitle .. '"')
       
         bannerContent = WikitextProcessor.processContentForFrontend(bannerContent, placeholderValues, context)
          
          
         local noticeData = {
         local noticeData = {