Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Indian Assembly Tracker

From Wikipedia, the free encyclopedia
-- Module:Indian_Assembly_Tracker
local p = {}

function p.renderRow(frame)
    local qid = frame.args[1] or frame:getParent().args[1]        -- Constituency QID (e.g., Q7127885)
    local party_code = frame.args[2] or frame:getParent().args[2] -- Party Code (e.g., TVK)
    local seat_no = frame.args[3] or frame:getParent().args[3] or "" -- Optional Seat Number

    -- 1. Fetch constituency name from Wikidata
    local seat_name = mw.wikibase.getLabel(qid) or "Unknown"
    local seat_link = "[[" .. seat_name .. " Assembly constituency|" .. seat_name .. "]]"

    -- 2. Fetch MLA name from Wikidata (Property P1313 - incumbent)
    local mla_display = "Vacant"
    local entity = mw.wikibase.getEntity(qid)
    if entity then
        local claims = entity:getBestStatements('P1313')
        if claims and #claims > 0 and claims[1].mainsnak.datavalue then
            local mla_qid = claims[1].mainsnak.datavalue.value.id
            local mla_name = mw.wikibase.getLabel(mla_qid)
            if mla_name then
                mla_display = "[[" .. mla_name .. "]]"
            end
        end
    end

    -- 3. Fetch Party & Alliance information from your Data Module
    local party_data = mw.loadData('Module:Indian_Political_Party_Alliances/data')
    local party_name = party_code
    local party_color = "#FFFFFF"
    local state_alliance = "Independent"
    local national_alliance = "Non-Aligned"

    if party_data[party_code] then
        party_name = party_data[party_code].name
        party_color = party_data[party_code].color or "#FFFFFF"
        state_alliance = party_data[party_code].state_alliance or "Independent"
        national_alliance = party_data[party_code].national_alliance or "Non-Aligned"
    end

    -- 4. Construct the MediaWiki table row syntax
    local row = "|-\n"
    if seat_no ~= "" then
        row = row .. "| " .. seat_no .. "\n"
    end
    row = row .. "| " .. seat_link .. "\n"
    row = row .. "| " .. mla_display .. "\n"
    row = row .. "| style=\"background-color:" .. party_color .. "; color:black; font-weight:bold;\" | [[" .. party_name .. "|" .. party_code .. "]]\n"
    row = row .. "| " .. state_alliance .. "\n"
    row = row .. "| " .. national_alliance .. "\n"

    return row
end

return p