Module:T-CountryHub: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 69: Line 69:
end
end


-- generateProcessedBrowseLink: Constructs and preprocesses a MediaWiki link for browsing data, with {{fullurl:...}} correctly expanded by MediaWiki before the link is rendered.
-- -- generateProcessedBrowseLink: Constructs and preprocesses a MediaWiki link for browsing data, with {{fullurl:...}} correctly expanded by MediaWiki before the link is rendered.
local function generateProcessedBrowseLink(template, browseType, browseQueryParam, linkTextPattern, country)
-- local function generateProcessedBrowseLink(template, browseType, browseQueryParam, linkTextPattern, country)
     -- Explicitly URL-encode the country name for use in the URL query parameter
--     -- Explicitly URL-encode the country name for use in the URL query parameter
     local encodedCountry = mw.uri.encode(country, 'QUERY') -- 'QUERY' mode is for query string values
--     local encodedCountry = mw.uri.encode(country, 'QUERY') -- 'QUERY' mode is for query string values


     local browseLinkString = string.format(
--     local browseLinkString = string.format(
         '[{{fullurl:Special:BrowseData/%s|%s=%s}} %s →]',
--         '[{{fullurl:Special:BrowseData/%s|%s=%s}} %s →]',
         browseType,
--         browseType,
         browseQueryParam,  
--         browseQueryParam,  
         encodedCountry,  -- Use the encoded country name for the URL part
--         encodedCountry,  -- Use the encoded country name for the URL part
         string.format(linkTextPattern, country) -- Use the original country name for the display text
--         string.format(linkTextPattern, country) -- Use the original country name for the display text
     )
--     )
      
      
     if template.current_frame and template.current_frame.preprocess then
--     if template.current_frame and template.current_frame.preprocess then
         local ok, result = pcall(function() return template.current_frame:preprocess(browseLinkString) end)
--         local ok, result = pcall(function() return template.current_frame:preprocess(browseLinkString) end)
         if ok then
--         if ok then
             return result
--             return result
         else
--         else
             return browseLinkString -- Fallback on preprocess error
--             return browseLinkString -- Fallback on preprocess error
         end
--         end
     end
--     end
     return browseLinkString -- Fallback if no frame or preprocess
--     return browseLinkString -- Fallback if no frame or preprocess
end
-- end


local errorContext = ErrorHandling.createContext("T-CountryHub")
local errorContext = ErrorHandling.createContext("T-CountryHub")