Module:ElementNTLDStats: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
--[[  
--[[
* Module:ElementNTLDStats
* Name: ElementNTLDStats
* Renders the NTLDStats element for generic TLDs (not ccTLDs), displaying a link to ntldstats.com.
* Author: Mark W. Datysgeld
* Designed for integration with the Blueprint template system.
* Description: Element module that renders NTLDStats links for generic TLDs, displaying statistics from ntldstats.com
]]
* Notes: Designed for Blueprint template system integration; excludes ccTLDs and classic TLDs from rendering; creates divider block with NTLDStats logo linking to external statistics; protected execution with error handling
]]


local p = {}
local p = {}
Line 14: Line 15:
local ErrorHandling    = require('Module:ErrorHandling')
local ErrorHandling    = require('Module:ErrorHandling')
local mw              = mw  -- MediaWiki API
local mw              = mw  -- MediaWiki API
-- Classic TLDs not integrated into NTLDStats database
local CLASSIC_TLDS = {
    com=true, net=true, org=true, info=true,
    edu=true, gov=true, mil=true, int=true,
    aero=true, asia=true, cat=true, coop=true,
    jobs=true, mobi=true, museum=true, post=true,
    tel=true, travel=true, xxx=true
}


-- Create an NTLDStats block
-- Create an NTLDStats block
Line 42: Line 52:
             end
             end


            -- Load TLD config for classic list
-- Use CLASSIC_TLDS constant defined above
            local constants = template.config.constants or {}


             -- Determine page name and TLD identifier
             -- Determine page name and TLD identifier
Line 51: Line 60:
             local ext = tldName:match("%.([^%.]+)$")
             local ext = tldName:match("%.([^%.]+)$")


            -- Skip classic TLDs
-- Skip classic TLDs
             if constants.classicTLDs and (
             if CLASSIC_TLDS[string.lower(tldName)] or (ext and CLASSIC_TLDS[string.lower(ext)]) then
              constants.classicTLDs[string.lower(tldName)] or
              (ext and constants.classicTLDs[string.lower(ext)])
            ) then
                 return ""
                 return ""
             end
             end


             -- Render divider and NTLDStats link
             -- Render divider and NTLDStats link
             local divider = TemplateHelpers.renderDividerBlock("Find out more:")
             local divider = require('Module:TemplateStructure').renderDividerBlock("Find out more:")
             local stats = string.format(
             local stats = string.format(
                 '|-\n| colspan="2" | <div class="ntldstats icannwiki-centered">[[File:NTLDStatsLogo.png|100px|alt=NTLDStats|link=https://ntldstats.com/tld/%s]]</div>',
                 '|-\n| colspan="2" | <div class="ntldstats icannwiki-centered">[[File:NTLDStatsLogo.png|100px|alt=NTLDStats|link=https://ntldstats.com/tld/%s]]</div>',