انتقل إلى المحتوى

مودول:WikiContestTracker

من ويكيپيديا

يمكن إنشاء صفحة توثيق الوحدة في مودول:WikiContestTracker/شرح

-- Module:WikiContestTracker
local p = {}

local function getProgressBarColor(percent)
    if percent <= 0 then return 'E82F37'
    elseif percent <= 10 then return 'F05F2A'
    elseif percent <= 20 then return 'F3901B'
    elseif percent <= 30 then return 'F8C10E'
    elseif percent <= 40 then return 'FDF100'
    elseif percent <= 50 then return 'D7E40E'
    elseif percent <= 60 then return 'ADDA1F'
    elseif percent <= 70 then return '7FCC28'
    elseif percent <= 80 then return '56C137'
    elseif percent <= 90 then return '2EB445'
    else return '07AA59'
    end
end

function p.main(frame)
    local output = {}
    local args = frame.args
    
    -- Table Header
    table.insert(output, '{| class="wikitable sortable" style="width: 90%; margin:auto; font-size:95%; text-align:center;"\n')
    table.insert(output, '! style="width:10px;" |م\n')
    table.insert(output, '! | المقالة\n')
    table.insert(output, '! | المصدر\n')
    table.insert(output, '! style="width:150px;" | حجم المقالة الفايت\n')
    table.insert(output, '! style="width:150px;" | حجم المقالة\n')
    table.insert(output, '! style="width:125px;" | شكون خداها...\n')
    table.insert(output, '! style="width:155px;" | نسبة التقدم\n')
    table.insert(output, '! style="width:25px;" | الحالة\n')
    
    -- Process each row
    local i = 1
    while args['م_' .. i] do
        local article = args['المقالة_' .. i] or ''
        
        if article ~= '' then
            local originalSize = tonumber(args['الحجم الأصلي_' .. i]) or 0
            local targetSize = tonumber(args['الحجم المستهدف_' .. i])
            local sizeRequirement = 4000  -- CHANGED FROM 5000 TO 4000
            
            -- Allow custom size requirement per article if provided
            local customRequirement = tonumber(args['شرط الحجم_' .. i])
            if customRequirement then
                sizeRequirement = customRequirement
            end

            if not targetSize then
                targetSize = originalSize + sizeRequirement
            end

            local currentSize = tonumber(mw.getCurrentFrame():preprocess('{{PAGESIZE:' .. article .. '|R}}')) or 0
            local percent = (targetSize > 0) and (currentSize / targetSize) * 100 or 0

            table.insert(output, '|-\n')
            table.insert(output, '| ' .. (args['م_' .. i] or '') .. '\n')
            table.insert(output, '| [[' .. article .. ']]\n')
            table.insert(output, '| ' .. (args['المصدر_' .. i] or '') .. '\n')
            table.insert(output, '| ' .. originalSize .. '\n')
            table.insert(output, '| ' .. targetSize .. " / '''" .. currentSize .. "''' بايت" .. '\n')
            
            -- START MODIFICATION: Format username with user and talk page links
            local username = args['لخدايمي_' .. i] or ''
            local userCellContent = ''
            if username ~= '' then
                userCellContent = '[[user:' .. username .. '|' .. username .. ']] ([[user talk:' .. username .. '|مداكرة]])'
            end
            table.insert(output, '| ' .. userCellContent .. '\n')
            -- END MODIFICATION
            
            local barWidth = math.min(100, percent)
            local barColor = getProgressBarColor(percent)
            local progressBarHtml = string.format(
                '<div>%0.1f%%</div>' ..
                '<div style="border:1px solid #AAA; background-color:#F0F0F0; height:10px; width:150px;">' ..
                '<div style="width:%f%%; height:100%%; background-color:#%s;"></div></div>',
                percent, barWidth, barColor
            )
            table.insert(output, '| ' .. progressBarHtml .. '\n')

            local statusIcon
            if currentSize == 0 then
                statusIcon = '[[ملف:No Cross.svg|20px|وصلة=|لم تُنشأ بعد!]]'
            elseif currentSize >= targetSize then
                statusIcon = '[[ملف:Green Checkmark Circle.svg|20px|وصلة=|جاهزة!]]'
            else
                statusIcon = '[[ملف:Writing Circle Yellow.svg|20px|وصلة=|تحت التطوير!]]'
            end
            table.insert(output, '| ' .. mw.getCurrentFrame():preprocess(statusIcon) .. '\n')
        end
        
        i = i + 1
    end

    table.insert(output, '|}')
    return table.concat(output)
end

return p