پرش به محتوا

پودمان:Infobox football biography: تفاوت میان نسخه‌ها

از ویکی البرز
جزبدون خلاصۀ ویرایش
جزبدون خلاصۀ ویرایش
 
(۹ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد)
خط ۳: خط ۳:


local function isSet(v)
local function isSet(v)
     if v == nil then return false end
     if v == nil or v == false then return false end
     return mw.text.trim(tostring(v)) ~= ''
     return mw.text.trim(tostring(v)) ~= ''
end
end
خط ۱۰: خط ۱۰:
     for i = 1, select('#', ...) do
     for i = 1, select('#', ...) do
         local key = select(i, ...)
         local key = select(i, ...)
         if isSet(args[key]) then
         if isSet(args[key]) then return args[key] end
            return args[key]
        end
     end
     end
     return nil
     return nil
خط ۲۰: خط ۱۸:
     if not isSet(data) then return end
     if not isSet(data) then return end
     local row = root:tag('tr')
     local row = root:tag('tr')
     row:tag('th')
     row:tag('th'):attr('scope', 'row'):addClass('infobox-label'):wikitext(label)
        :attr('scope', 'row')
     row:tag('td'):attr('colspan', '3'):addClass('infobox-data'):wikitext(data)
        :addClass('infobox-label')
        :wikitext(label)
     row:tag('td')
        :attr('colspan', '3')
        :addClass('infobox-data')
        :wikitext(data)
end
end


خط ۳۳: خط ۲۵:
     if not isSet(dataa) and not isSet(datab) and not isSet(datac) then return end
     if not isSet(dataa) and not isSet(datab) and not isSet(datac) then return end
     local row = root:tag('tr')
     local row = root:tag('tr')
     row:tag('th')
     row:tag('th'):attr('scope', 'row'):addClass('infobox-label'):wikitext(label)
        :attr('scope', 'row')
     row:tag('td'):addClass('infobox-data infobox-data-a'):wikitext(isSet(dataa) and dataa or '')
        :addClass('infobox-label')
     if isSet(datab) then row:tag('td'):addClass('infobox-data infobox-data-b'):wikitext(datab) end
        :wikitext(label)
     if isSet(datac) then row:tag('td'):addClass('infobox-data infobox-data-c'):wikitext(datac) end
 
     row:tag('td')
        :addClass('infobox-data infobox-data-a')
        :wikitext(isSet(dataa) and dataa or '')
   
     if isSet(datab) then
        row:tag('td')
            :addClass('infobox-data infobox-data-b')
            :wikitext(datab)
    end
     if isSet(datac) then
        row:tag('td')
            :addClass('infobox-data infobox-data-c')
            :wikitext(datac)
    end
end
end


function p.main(frame)
function p.main(frame)
     local args = getArgs(frame)
     local args = getArgs(frame)
     local root = mw.html.create('table')
     local root = mw.html.create('table')
         :addClass('infobox')
         :addClass('infobox')
خط ۶۶: خط ۴۲:
     root:tag('caption')
     root:tag('caption')
         :addClass('infobox-title')
         :addClass('infobox-title')
        :css('text-align', 'center')
        :css('font-weight', 'bold')
         :wikitext(title)
         :wikitext(title)


     -- تصویر
     -- تصویر
     if isSet(args.image) then
     if isSet(args.image) then
        local img = args.image
        if not img:match('^%[%[File:') and not img:match('^<') then
            img = '[[File:' .. img .. '|220px]]'
        end
         local imgCell = root:tag('tr'):tag('td')
         local imgCell = root:tag('tr'):tag('td')
             :attr('colspan', '4')
             :attr('colspan', '4')
             :addClass('infobox-image')
             :addClass('infobox-image')
             :wikitext(args.image)
            :css('text-align', 'center')
             :wikitext(img)
         if isSet(args.caption) then
         if isSet(args.caption) then
             imgCell:tag('div')
             imgCell:tag('div')
                 :addClass('infobox-caption')
                 :addClass('infobox-caption')
                :css('text-align', 'center')
                 :wikitext(args.caption)
                 :wikitext(args.caption)
         end
         end
     end
     end
    -- هدر با رنگ و وسط‌چین
    local headerCss = 'background-color: #b0c4de; text-align: center; font-weight: bold; padding: 4px;'


     -- اطلاعات شخصی
     -- اطلاعات شخصی
     if firstArg(args, 'fullname', 'full_name', 'نام کامل') or firstArg(args, 'birth_date', 'dateofbirth', 'زادروز') then
     root:tag('tr'):tag('th')
        root:tag('tr'):tag('th')
        :attr('colspan', '4')
            :attr('colspan', '4')
        :addClass('infobox-header')
            :addClass('infobox-header')
        :cssText(headerCss)
            :wikitext('اطلاعات شخصی')
        :wikitext('اطلاعات شخصی')


        addRow(root, 'نام کامل', firstArg(args, 'fullname', 'full_name', 'نام کامل'))
    addRow(root, 'نام کامل', firstArg(args, 'fullname', 'full_name', 'نام کامل'))
        addRow(root, 'زادروز', firstArg(args, 'birth_date', 'dateofbirth', 'زادروز'))
    addRow(root, 'زادروز', firstArg(args, 'birth_date', 'dateofbirth', 'زادروز'))
        addRow(root, 'زادگاه', firstArg(args, 'birth_place', 'cityofbirth', 'زادگاه'))
    addRow(root, 'زادگاه', firstArg(args, 'birth_place', 'cityofbirth', 'زادگاه'))
        addRow(root, 'تاریخ مرگ', firstArg(args, 'death_date', 'dateofdeath', 'تاریخ مرگ'))
    addRow(root, 'تاریخ مرگ', firstArg(args, 'death_date', 'dateofdeath', 'تاریخ مرگ'))
        addRow(root, 'محل مرگ', firstArg(args, 'death_place', 'محل مرگ'))
    addRow(root, 'محل مرگ', firstArg(args, 'death_place', 'محل مرگ'))
        addRow(root, 'قد', firstArg(args, 'height', 'قد'))
    addRow(root, 'قد', firstArg(args, 'height', 'قد'))
        addRow(root, 'پست', firstArg(args, 'position', 'پست'))
    addRow(root, 'پست', firstArg(args, 'position', 'پست'))
    end


     -- اطلاعات باشگاهی
     -- باشگاه کنونی
     local currentclub = firstArg(args, 'currentclub', 'باشگاه کنونی')
     local curr = firstArg(args, 'currentclub', 'باشگاه کنونی')
     if isSet(currentclub) then
     if isSet(curr) then
         root:tag('tr'):tag('th')
         root:tag('tr'):tag('th')
             :attr('colspan', '4')
             :attr('colspan', '4')
             :addClass('infobox-header')
             :addClass('infobox-header')
            :cssText(headerCss)
             :wikitext('اطلاعات باشگاهی')
             :wikitext('اطلاعات باشگاهی')
         addRow(root, 'باشگاه کنونی', currentclub)
         addRow(root, 'باشگاه کنونی', curr)
         addRow(root, 'شمارهٔ پیراهن', firstArg(args, 'clubnumber', 'شمارهٔ پیراهن'))
         addRow(root, 'شمارهٔ پیراهن', firstArg(args, 'clubnumber', 'شمارهٔ پیراهن'))
     end
     end


     -- باشگاه‌های جوانان
     -- جوانان
     local i = 1
     local i = 1
     local headerAdded = false
     local header = false
     while true do
     while i <= 7 do
         local club = args['youthclubs' .. i] or (i == 1 and args.youthclubs)
         local club = args['youthclubs' .. i] or (i == 1 and args.youthclubs)
         if not isSet(club) then break end
         if not isSet(club) then break end
         if not headerAdded then
         if not header then
             root:tag('tr'):tag('th')
             root:tag('tr'):tag('th')
                 :attr('colspan', '4')
                 :attr('colspan', '4')
                 :addClass('infobox-header')
                 :addClass('infobox-header')
                :cssText(headerCss)
                 :wikitext('باشگاه‌های جوانان')
                 :wikitext('باشگاه‌های جوانان')
             headerAdded = true
             header = true
         end
         end
         local years = args['youthyears' .. i] or (i == 1 and args.youthyears)
         addRow(root, args['youthyears' .. i] or '', club)
        addRow(root, years or '', club)
         i = i + 1
         i = i + 1
     end
     end


     -- باشگاه‌های حرفه‌ای
     -- حرفه‌ای
     i = 1
     i = 1
     headerAdded = false
     header = false
     while true do
     while i <= 10 do
         local club = args['clubs' .. i] or (i == 1 and args.clubs)
         local club = args['clubs' .. i] or (i == 1 and args.clubs)
         if not isSet(club) then break end
         if not isSet(club) then break end
         if not headerAdded then
         if not header then
             root:tag('tr'):tag('th')
             root:tag('tr'):tag('th')
                 :attr('colspan', '4')
                 :attr('colspan', '4')
                 :addClass('infobox-header')
                 :addClass('infobox-header')
                :cssText(headerCss)
                 :wikitext('باشگاه‌های حرفه‌ای')
                 :wikitext('باشگاه‌های حرفه‌ای')
             headerAdded = true
             header = true
         end
         end
        local years = args['years' .. i]
         local caps = args['caps' .. i] or args['caps(goals)' .. i]
         local caps = args['caps' .. i] or args['caps(goals)' .. i]
         local goals = args['goals' .. i]
         local goals = args['goals' .. i]
         addMultiDataRow(root, years or '', club, caps, isSet(goals) and '(' .. goals .. ')' or nil)
         addMultiDataRow(root, args['years' .. i] or '', club, caps, isSet(goals) and '('..goals..')' or nil)
         i = i + 1
         i = i + 1
     end
     end


    -- مجموع
     if isSet(args.totalcaps) or isSet(args.totalgoals) then
     if isSet(args.totalcaps) or isSet(args.totalgoals) then
         addMultiDataRow(root, 'مجموع', '', args.totalcaps, isSet(args.totalgoals) and '(' .. args.totalgoals .. ')' or nil)
         addMultiDataRow(root, 'مجموع', '', args.totalcaps, isSet(args.totalgoals) and '('..args.totalgoals..')' or nil)
     end
     end


     -- تیم ملی
     -- تیم ملی
     i = 1
     i = 1
     headerAdded = false
     header = false
     while true do
     while i <= 8 do
         local team = args['nationalteam' .. i] or (i == 1 and args.nationalteam)
         local team = args['nationalteam' .. i] or (i == 1 and args.nationalteam)
         if not isSet(team) then break end
         if not isSet(team) then break end
         if not headerAdded then
         if not header then
             root:tag('tr'):tag('th')
             root:tag('tr'):tag('th')
                 :attr('colspan', '4')
                 :attr('colspan', '4')
                 :addClass('infobox-header')
                 :addClass('infobox-header')
                :cssText(headerCss)
                 :wikitext('تیم ملی')
                 :wikitext('تیم ملی')
             headerAdded = true
             header = true
         end
         end
         local years = args['nationalyears' .. i]
         local years = args['nationalyears' .. i]
         local caps = args['nationalcaps' .. i] or args['nationalcaps(goals)' .. i]
         local caps = args['nationalcaps' .. i] or args['nationalcaps(goals)' .. i]
         local goals = args['nationalgoals' .. i]
         local goals = args['nationalgoals' .. i]
         addMultiDataRow(root, years or '', team, caps, isSet(goals) and '(' .. goals .. ')' or nil)
         addMultiDataRow(root, years or '', team, caps, isSet(goals) and '('..goals..')' or nil)
         i = i + 1
         i = i + 1
     end
     end


     -- دوران مربیگری
     -- مربیگری
     i = 1
     i = 1
     headerAdded = false
     header = false
     while true do
     while i <= 10 do
         local club = args['managerclubs' .. i]
         local club = args['managerclubs' .. i]
         if not isSet(club) then break end
         if not isSet(club) then break end
         if not headerAdded then
         if not header then
             root:tag('tr'):tag('th')
             root:tag('tr'):tag('th')
                 :attr('colspan', '4')
                 :attr('colspan', '4')
                 :addClass('infobox-header')
                 :addClass('infobox-header')
                :cssText(headerCss)
                 :wikitext('دوران مربیگری')
                 :wikitext('دوران مربیگری')
             headerAdded = true
             header = true
         end
         end
         local years = args['manageryears' .. i]
         local years = args['manageryears' .. i]
         addRow(root, years or '', club)
         addRow(root, years or '', club)
         i = i + 1
         i = i + 1
    end
    -- افتخارات
    if isSet(args.medaltemplates) then
        root:tag('tr'):tag('td')
            :attr('colspan', '4')
            :wikitext(args.medaltemplates)
     end
     end



نسخهٔ کنونی تا ‏۷ ژوئیهٔ ۲۰۲۶، ساعت ۲۰:۲۲

توضیحات این پودمان می‌تواند در پودمان:Infobox football biography/توضیحات قرار گیرد.

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

local function isSet(v)
    if v == nil or v == false then return false end
    return mw.text.trim(tostring(v)) ~= ''
end

local function firstArg(args, ...)
    for i = 1, select('#', ...) do
        local key = select(i, ...)
        if isSet(args[key]) then return args[key] end
    end
    return nil
end

local function addRow(root, label, data)
    if not isSet(data) then return end
    local row = root:tag('tr')
    row:tag('th'):attr('scope', 'row'):addClass('infobox-label'):wikitext(label)
    row:tag('td'):attr('colspan', '3'):addClass('infobox-data'):wikitext(data)
end

local function addMultiDataRow(root, label, dataa, datab, datac)
    if not isSet(dataa) and not isSet(datab) and not isSet(datac) then return end
    local row = root:tag('tr')
    row:tag('th'):attr('scope', 'row'):addClass('infobox-label'):wikitext(label)
    row:tag('td'):addClass('infobox-data infobox-data-a'):wikitext(isSet(dataa) and dataa or '')
    if isSet(datab) then row:tag('td'):addClass('infobox-data infobox-data-b'):wikitext(datab) end
    if isSet(datac) then row:tag('td'):addClass('infobox-data infobox-data-c'):wikitext(datac) end
end

function p.main(frame)
    local args = getArgs(frame)
    local root = mw.html.create('table')
        :addClass('infobox')
        :addClass(args.child == 'yes' and 'infobox-subbox' or nil)
        :cssText(args.bodystyle or 'width: 22em; line-height: 1.2em;')

    -- عنوان
    local title = firstArg(args, 'name', 'playername') or mw.title.getCurrentTitle().text
    root:tag('caption')
        :addClass('infobox-title')
        :css('text-align', 'center')
        :css('font-weight', 'bold')
        :wikitext(title)

    -- تصویر
    if isSet(args.image) then
        local img = args.image
        if not img:match('^%[%[File:') and not img:match('^<') then
            img = '[[File:' .. img .. '|220px]]'
        end
        local imgCell = root:tag('tr'):tag('td')
            :attr('colspan', '4')
            :addClass('infobox-image')
            :css('text-align', 'center')
            :wikitext(img)
        if isSet(args.caption) then
            imgCell:tag('div')
                :addClass('infobox-caption')
                :css('text-align', 'center')
                :wikitext(args.caption)
        end
    end

    -- هدر با رنگ و وسط‌چین
    local headerCss = 'background-color: #b0c4de; text-align: center; font-weight: bold; padding: 4px;'

    -- اطلاعات شخصی
    root:tag('tr'):tag('th')
        :attr('colspan', '4')
        :addClass('infobox-header')
        :cssText(headerCss)
        :wikitext('اطلاعات شخصی')

    addRow(root, 'نام کامل', firstArg(args, 'fullname', 'full_name', 'نام کامل'))
    addRow(root, 'زادروز', firstArg(args, 'birth_date', 'dateofbirth', 'زادروز'))
    addRow(root, 'زادگاه', firstArg(args, 'birth_place', 'cityofbirth', 'زادگاه'))
    addRow(root, 'تاریخ مرگ', firstArg(args, 'death_date', 'dateofdeath', 'تاریخ مرگ'))
    addRow(root, 'محل مرگ', firstArg(args, 'death_place', 'محل مرگ'))
    addRow(root, 'قد', firstArg(args, 'height', 'قد'))
    addRow(root, 'پست', firstArg(args, 'position', 'پست'))

    -- باشگاه کنونی
    local curr = firstArg(args, 'currentclub', 'باشگاه کنونی')
    if isSet(curr) then
        root:tag('tr'):tag('th')
            :attr('colspan', '4')
            :addClass('infobox-header')
            :cssText(headerCss)
            :wikitext('اطلاعات باشگاهی')
        addRow(root, 'باشگاه کنونی', curr)
        addRow(root, 'شمارهٔ پیراهن', firstArg(args, 'clubnumber', 'شمارهٔ پیراهن'))
    end

    -- جوانان
    local i = 1
    local header = false
    while i <= 7 do
        local club = args['youthclubs' .. i] or (i == 1 and args.youthclubs)
        if not isSet(club) then break end
        if not header then
            root:tag('tr'):tag('th')
                :attr('colspan', '4')
                :addClass('infobox-header')
                :cssText(headerCss)
                :wikitext('باشگاه‌های جوانان')
            header = true
        end
        addRow(root, args['youthyears' .. i] or '', club)
        i = i + 1
    end

    -- حرفه‌ای
    i = 1
    header = false
    while i <= 10 do
        local club = args['clubs' .. i] or (i == 1 and args.clubs)
        if not isSet(club) then break end
        if not header then
            root:tag('tr'):tag('th')
                :attr('colspan', '4')
                :addClass('infobox-header')
                :cssText(headerCss)
                :wikitext('باشگاه‌های حرفه‌ای')
            header = true
        end
        local caps = args['caps' .. i] or args['caps(goals)' .. i]
        local goals = args['goals' .. i]
        addMultiDataRow(root, args['years' .. i] or '', club, caps, isSet(goals) and '('..goals..')' or nil)
        i = i + 1
    end

    if isSet(args.totalcaps) or isSet(args.totalgoals) then
        addMultiDataRow(root, 'مجموع', '', args.totalcaps, isSet(args.totalgoals) and '('..args.totalgoals..')' or nil)
    end

    -- تیم ملی
    i = 1
    header = false
    while i <= 8 do
        local team = args['nationalteam' .. i] or (i == 1 and args.nationalteam)
        if not isSet(team) then break end
        if not header then
            root:tag('tr'):tag('th')
                :attr('colspan', '4')
                :addClass('infobox-header')
                :cssText(headerCss)
                :wikitext('تیم ملی')
            header = true
        end
        local years = args['nationalyears' .. i]
        local caps = args['nationalcaps' .. i] or args['nationalcaps(goals)' .. i]
        local goals = args['nationalgoals' .. i]
        addMultiDataRow(root, years or '', team, caps, isSet(goals) and '('..goals..')' or nil)
        i = i + 1
    end

    -- مربیگری
    i = 1
    header = false
    while i <= 10 do
        local club = args['managerclubs' .. i]
        if not isSet(club) then break end
        if not header then
            root:tag('tr'):tag('th')
                :attr('colspan', '4')
                :addClass('infobox-header')
                :cssText(headerCss)
                :wikitext('دوران مربیگری')
            header = true
        end
        local years = args['manageryears' .. i]
        addRow(root, years or '', club)
        i = i + 1
    end

    -- پانویس
    local footer = {}
    if isSet(args.pcupdate) then
        table.insert(footer, "* آمار باشگاهی به‌روزرسانی شده در تاریخ " .. args.pcupdate)
    end
    if isSet(args.ntupdate) then
        table.insert(footer, "‡ آمار ملی به‌روزرسانی شده در تاریخ " .. args.ntupdate)
    end
    if #footer > 0 then
        root:tag('tr'):tag('td')
            :attr('colspan', '4')
            :addClass('infobox-below')
            :css('font-size', '82%')
            :wikitext(table.concat(footer, '<br>'))
    end

    return tostring(root)
end

return p