Module:T-CountryHub: Difference between revisions

// via Wikitext Extension for VSCode
Maintenance update // via Wikitext Extension for VSCode
 
(8 intermediate revisions by the same user not shown)
Line 21: Line 21:
local CountryData  = safeRequire('Module:CountryData')
local CountryData  = safeRequire('Module:CountryData')
local TemplateHelpers = safeRequire('Module:TemplateHelpers')
local TemplateHelpers = safeRequire('Module:TemplateHelpers')
local LinkParser = safeRequire('Module:LinkParser')
local NormalizationText = safeRequire('Module:NormalizationText')
local NormalizationText = safeRequire('Module:NormalizationText')
local NormalizationDiacritic = safeRequire('Module:NormalizationDiacritic')
local NormalizationDiacritic = safeRequire('Module:NormalizationDiacritic')
Line 82: Line 83:
     return renderTable(data, columns)
     return renderTable(data, columns)
end
end
-- -- 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)
--    -- 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 browseLinkString = string.format(
--        '[{{fullurl:Special:BrowseData/%s|%s=%s}} %s →]',
--        browseType,
--        browseQueryParam,
--        encodedCountry,  -- Use the encoded country name for the URL part
--        string.format(linkTextPattern, country) -- Use the original country name for the display text
--    )
   
--    if template.current_frame and template.current_frame.preprocess then
--        local ok, result = pcall(function() return template.current_frame:preprocess(browseLinkString) end)
--        if ok then
--            return result
--        else
--            return browseLinkString -- Fallback on preprocess error
--        end
--    end
--    return browseLinkString -- Fallback if no frame or preprocess
-- end


local errorContext = ErrorHandling.createContext("T-CountryHub")
local errorContext = ErrorHandling.createContext("T-CountryHub")
Line 123: Line 100:
         organizations = true,
         organizations = true,
         people = true,
         people = true,
         laws = false,
         laws = true,
         documents = false,
         documents = false,
         geoTlds = true,
         geoTlds = true,
Line 210: Line 187:
     render = function(template, args)
     render = function(template, args)
         return '<div class="country-hub-feature-banner">' ..
         return '<div class="country-hub-feature-banner">' ..
               '<strong>Country Hubs</strong> have been enabled as a feature preview for ICANN 83, and are under <strong>HEAVY TESTING</strong>. ' ..
               '<strong>Country Hubs</strong> have been enabled as a feature preview and are still under testing.' ..
               'Help us improve them and, especially, contribute more knowledge to our database so that they can keep growing!' ..
               ' Contribute more knowledge to our database so that they can keep growing!' ..
               '</div>'
               '</div>'
     end
     end
Line 241: Line 218:
         local regionData = askCached('infoBox:region:' .. args.has_country, regionParams)
         local regionData = askCached('infoBox:region:' .. args.has_country, regionParams)
         local regionText = regionData[1] and regionData[1]['Has ICANN region'] or ''
         local regionText = regionData[1] and regionData[1]['Has ICANN region'] or ''
         regionText = NormalizationText.processWikiLink(regionText, 'strip')
         regionText = LinkParser.processWikiLink(regionText, 'strip')
          
          
         -- Check for an ISOC chapter in the country using fuzzy matching
         -- Check for an ISOC chapter in the country using fuzzy matching
Line 294: Line 271:
         if not foundMatch then
         if not foundMatch then
             ISOCText = string.format('[[Internet Society %s Chapter]]', args.has_country)
             ISOCText = string.format('[[Internet Society %s Chapter]]', args.has_country)
        end
       
        -- Check for a Youth IGF initiative in the country
        local youthParams = {
            string.format('[[Category:Youth IGF %s]]', args.has_country),
            limit = 1
        }
        local youthData = askCached('infoBox:youth:' .. args.has_country, youthParams)
        local youthText
        if youthData[1] and youthData[1]['result'] and youthData[1]['result'] ~= '' then
            youthText = youthData[1]['result']
        else
            youthText = string.format('[[Youth IGF %s]]', args.has_country)
         end
         end
          
          
Line 355: Line 319:
             :tag('th'):wikitext('ISOC chapter'):done()
             :tag('th'):wikitext('ISOC chapter'):done()
             :tag('td'):wikitext(ISOCText):done()
             :tag('td'):wikitext(ISOCText):done()
            :done()
       
        -- Youth IGF row
        infoBox:tag('tr')
            :tag('th'):wikitext('Youth IGF'):done()
            :tag('td'):wikitext(youthText):done()
             :done()
             :done()
          
          
Line 449: Line 407:
     render = function(template, args)
     render = function(template, args)
         local params = {
         local params = {
             string.format('[[Has country::%s]]', args.has_country),
             string.format('[[Has country::%s]] [[Has entity type::Norm]]', args.has_country),
            '[[Category:Laws]]',
            mainlabel = 'Law', sort = 'Has date', order = 'desc',
             limit    = 20
             limit    = 20
         }
         }
         return renderSection('laws:' .. args.has_country, params, {'Laws and Regulations'})
         local data = askCached('laws:' .. args.has_country, params)
        -- Store the raw count for masonry layout
        template._rawDataCounts = template._rawDataCounts or {}
        template._rawDataCounts.laws = #data
        -- Only render if we have data
        if #data == 0 then
            return ''
        end
        return renderTable(data, {'Laws and Regulations'})
     end,
     end,
}
}