Jump to content

Module:ThinkerRelations2

From No Subject

Documentation for this module may be created at Module:ThinkerRelations2/doc

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
    local args = getArgs(frame)
    local root = mw.html.create('div')

    local has_relations = false
    for k, _ in pairs(args) do
        if k:match('^relation_%d+_target$') then
            has_relations = true
            break
        end
    end

    if not has_relations then
        return ''
    end

    root:tag('div')
        :addClass('thinker-section-header')
        :wikitext('Critical Network')

    for i = 1, 50 do
        local target = args['relation_' .. i .. '_target']
        local content = args['relation_' .. i .. '_content']
        local rel_type = args['relation_' .. i .. '_type'] or 'Relation'

        if target then
            local clean_target = target:gsub('%[%[', ''):gsub('%]%]', '')
            local block = root:tag('div'):addClass('relation-block')

            local header = block:tag('div'):addClass('relation-header')
            header:wikitext('To [[' .. clean_target .. ']]')

            local tag = header:tag('span')
                :addClass('relation-type-tag')
                :wikitext(rel_type)

            local type_lower = rel_type:lower()
            if type_lower:find('critique') then
                block:css('border-left-color', '#e74c3c')
            elseif type_lower:find('influenc') then
                block:css('border-left-color', '#2ecc71')
            elseif type_lower:find('clinic') then
                block:css('border-left-color', '#3498db')
            end

            if content then
                block:tag('div')
                    :addClass('relation-content')
                    :wikitext(content)
            end

            -- Semantic MediaWiki hook (optional future use)
            -- mw.smw.subobject({
            --     ['Has relation to'] = clean_target,
            --     ['Has relation type'] = rel_type,
            --     ['Has description'] = content
            -- })
        end
    end

    return tostring(root)
end

return p