বিষয়বস্তুতে চলুন

মডিউল:Infobox: সংশোধিত সংস্করণের মধ্যে পার্থক্য

মুক্তপিডিয়া — মুক্ত জ্ঞান, সবার জন্য
মুক্তপিডিয়ার তথ্যছক মডিউল তৈরি
 
হালনাগাদ
 
১ নং লাইন: ১ নং লাইন:
local p = {}
local p = {}


local function trim( s )
local Html = mw.html
if not s then
 
return ""
--------------------------------------------------------------------
-- Utility
--------------------------------------------------------------------
 
local function trim( value )
if not value then
return nil
end
end
return mw.text.trim( tostring( s ) )
 
value = tostring( value )
value = mw.text.trim( value )
 
if value == '' then
return nil
end
 
return value
end
end


function p.render( frame )
local function exists( value )
local args = frame:getParent().args
return trim( value ) ~= nil
end
 
--------------------------------------------------------------------
-- Create Infobox
--------------------------------------------------------------------
 
local function createBox()


local html = mw.html.create( 'table' )
local root = Html.create( 'table' )
html
root
:addClass( 'infobox' )
:addClass( 'infobox' )
:css( 'width', '300px' )
:css( 'width', '22em' )
:css( 'float', 'right' )
:css( 'float', 'right' )
:css( 'clear', 'right' )
:css( 'margin', '0 0 1em 1em' )
:css( 'margin', '0 0 1em 1em' )
:css( 'border', '1px solid #a2a9b1' )
:css( 'border', '1px solid #a2a9b1' )
:css( 'background', '#f8f9fa' )
:css( 'border-collapse', 'collapse' )
:css( 'border-collapse', 'collapse' )
:css( 'background', '#fff' )
:css( 'font-size', '90%' )
:css( 'font-size', '90%' )


-- Title
return root
if trim( args["নাম"] ) ~= "" then
 
html:tag( 'tr' )
end
 
--------------------------------------------------------------------
-- Header
--------------------------------------------------------------------
 
local function addHeader( box, title )
 
title = trim( title )
 
if not title then
title = mw.title.getCurrentTitle().text
end
 
box
:tag( 'tr' )
:tag( 'th' )
:attr( 'colspan', '2' )
:addClass( 'infobox-title' )
:wikitext( title )
 
end
 
--------------------------------------------------------------------
-- Subtitle
--------------------------------------------------------------------
 
local function addSubtitle( box, subtitle )
 
if not exists( subtitle ) then
return
end
 
box
:tag( 'tr' )
:tag( 'td' )
:attr( 'colspan', '2' )
:addClass( 'infobox-subtitle' )
:wikitext( subtitle )
 
end
 
--------------------------------------------------------------------
-- Image
--------------------------------------------------------------------
 
local function addImage( box, image, caption )
 
if not exists( image ) then
return
end
 
local td =
box
:tag( 'tr' )
:tag( 'td' )
:attr( 'colspan', '2' )
:addClass( 'infobox-image' )
 
td:wikitext(
string.format(
'[[File:%s|250px|center]]',
image
)
)
 
if exists( caption ) then
 
td
:tag( 'div' )
:addClass( 'infobox-caption' )
:wikitext( caption )
 
end
 
end
 
--------------------------------------------------------------------
-- Row
--------------------------------------------------------------------
 
local function addRow( box, label, value )
 
value = trim( value )
 
if not value then
return
end
 
local tr = box:tag( 'tr' )
 
tr
:tag( 'th' )
:addClass( 'infobox-label' )
:wikitext( label )
 
tr
:tag( 'td' )
:addClass( 'infobox-data' )
:wikitext( value )
 
end
 
--------------------------------------------------------------------
-- Section
--------------------------------------------------------------------
 
local function addSection( box, title )
 
title = trim( title )
 
if not title then
return
end
 
box
:tag( 'tr' )
:tag( 'th' )
:tag( 'th' )
:attr( 'colspan', '2' )
:attr( 'colspan', '2' )
:css( 'background', '#3366cc' )
:addClass( 'infobox-section' )
:css( 'color', 'white' )
:wikitext( title )
:css( 'padding', '8px' )
 
:wikitext( args["নাম"] )
end
 
--------------------------------------------------------------------
-- Footer
--------------------------------------------------------------------
 
local function addFooter( box, footer )
 
footer = trim( footer )
 
if not footer then
return
end
end


-- Image
box
if trim( args["ছবি"] ) ~= "" then
:tag( 'tr' )
html:tag( 'tr' )
:tag( 'td' )
:tag( 'td' )
:attr( 'colspan', '2' )
:attr( 'colspan', '2' )
:css( 'text-align', 'center' )
:addClass( 'infobox-footer' )
:wikitext( string.format(
:wikitext( footer )
"[[File:%s|220px]]",
 
args["ছবি"]
end
) )
 
--------------------------------------------------------------------
-- Website
--------------------------------------------------------------------
 
local function addWebsite( box, url )
 
url = trim( url )
 
if not url then
return
end
end


local fields = {
addRow(
{"জন্ম","জন্ম"},
box,
{"জন্মস্থান","জন্মস্থান"},
'ওয়েবসাইট',
{"মৃত্যু","মৃত্যু"},
string.format(
{"মৃত্যুস্থান","মৃত্যুস্থান"},
'[%s %s]',
{"জাতীয়তা","জাতীয়তা"},
url,
{"নাগরিকত্ব","নাগরিকত্ব"},
url
{"পেশা","পেশা"},
)
{"শিক্ষা","শিক্ষা"},
)
{"দাম্পত্য সঙ্গী","দাম্পত্য সঙ্গী"},
 
{"সন্তান","সন্তান"},
end
{"পুরস্কার","পুরস্কার"},
 
{"ওয়েবসাইট","ওয়েবসাইট"}
--------------------------------------------------------------------
}
-- Standard Person Fields
--------------------------------------------------------------------


for _, row in ipairs( fields ) do
local function addStandardRows( box, args )
local value = trim( args[row[1]] )


if value ~= "" then
addRow( box, 'জন্ম', args['জন্ম'] )
local tr = html:tag( 'tr' )
addRow( box, 'জন্মস্থান', args['জন্মস্থান'] )
addRow( box, 'মৃত্যু', args['মৃত্যু'] )
addRow( box, 'মৃত্যুস্থান', args['মৃত্যুস্থান'] )
addRow( box, 'জাতীয়তা', args['জাতীয়তা'] )
addRow( box, 'নাগরিকত্ব', args['নাগরিকত্ব'] )
addRow( box, 'পেশা', args['পেশা'] )
addRow( box, 'কর্মজীবন', args['কর্মজীবন'] )
addRow( box, 'শিক্ষাপ্রতিষ্ঠান', args['শিক্ষাপ্রতিষ্ঠান'] )
addRow( box, 'শিক্ষাগত যোগ্যতা', args['শিক্ষাগত_যোগ্যতা'] )
addRow( box, 'পরিচিতি', args['পরিচিতি'] )
addRow( box, 'পিতা', args['পিতা'] )
addRow( box, 'মাতা', args['মাতা'] )
addRow( box, 'দাম্পত্য সঙ্গী', args['দাম্পত্য_সঙ্গী'] )
addRow( box, 'সন্তান', args['সন্তান'] )
addRow( box, 'পুরস্কার', args['পুরস্কার'] )


tr:tag( 'th' )
addWebsite( box, args['ওয়েবসাইট'] )
:css( 'text-align', 'left' )
:css( 'padding', '5px' )
:css( 'background', '#eaecf0' )
:wikitext( row[2] )


tr:tag( 'td' )
end
:css( 'padding', '5px' )
 
:wikitext( value )
--------------------------------------------------------------------
end
-- Build infobox
--------------------------------------------------------------------
 
function p.render( args )
 
local box = createBox()
 
addHeader(
box,
args["নাম"]
)
 
addSubtitle(
box,
args["উপশিরোনাম"]
)
 
addImage(
box,
args["ছবি"],
args["ছবির_বিবরণ"]
)
 
addStandardRows(
box,
args
)
 
addFooter(
box,
args["ফুটার"] or "মুক্তপিডিয়া তথ্যছক"
)
 
return tostring( box )
 
end
 
--------------------------------------------------------------------
-- Template entry
--------------------------------------------------------------------
 
function p.main( frame )
 
local args = frame:getParent().args
 
return p.render( args )
 
end
 
--------------------------------------------------------------------
-- Direct invoke support
--------------------------------------------------------------------
 
function p.infobox( frame )
 
local args
 
if frame == mw.getCurrentFrame() then
args = frame:getParent().args
else
args = frame.args
end
end


return tostring( html )
return p.render( args )
 
end
end
--------------------------------------------------------------------
-- Export
--------------------------------------------------------------------
p._render = p.render
p._main = p.main


return p
return p

১৪:৪৮, ২২ জুলাই ২০২৬ তারিখে সম্পাদিত সর্বশেষ সংস্করণ

local p = {}

local Html = mw.html


-- Utility


local function trim( value ) if not value then return nil end

value = tostring( value ) value = mw.text.trim( value )

if value == then return nil end

return value end

local function exists( value ) return trim( value ) ~= nil end


-- Create Infobox


local function createBox()

local root = Html.create( 'table' ) root :addClass( 'infobox' ) :css( 'width', '22em' ) :css( 'float', 'right' ) :css( 'clear', 'right' ) :css( 'margin', '0 0 1em 1em' ) :css( 'border', '1px solid #a2a9b1' ) :css( 'border-collapse', 'collapse' ) :css( 'background', '#fff' ) :css( 'font-size', '90%' )

return root

end


-- Header


local function addHeader( box, title )

title = trim( title )

if not title then title = mw.title.getCurrentTitle().text end

box :tag( 'tr' ) :tag( 'th' ) :attr( 'colspan', '2' ) :addClass( 'infobox-title' ) :wikitext( title )

end


-- Subtitle


local function addSubtitle( box, subtitle )

if not exists( subtitle ) then return end

box :tag( 'tr' ) :tag( 'td' ) :attr( 'colspan', '2' ) :addClass( 'infobox-subtitle' ) :wikitext( subtitle )

end


-- Image


local function addImage( box, image, caption )

if not exists( image ) then return end

local td = box :tag( 'tr' ) :tag( 'td' ) :attr( 'colspan', '2' ) :addClass( 'infobox-image' )

td:wikitext( string.format(

'

চিত্র:%s

',

image ) )

if exists( caption ) then

td :tag( 'div' ) :addClass( 'infobox-caption' ) :wikitext( caption )

end

end


-- Row


local function addRow( box, label, value )

value = trim( value )

if not value then return end

local tr = box:tag( 'tr' )

tr :tag( 'th' ) :addClass( 'infobox-label' ) :wikitext( label )

tr :tag( 'td' ) :addClass( 'infobox-data' ) :wikitext( value )

end


-- Section


local function addSection( box, title )

title = trim( title )

if not title then return end

box :tag( 'tr' ) :tag( 'th' ) :attr( 'colspan', '2' ) :addClass( 'infobox-section' ) :wikitext( title )

end


-- Footer


local function addFooter( box, footer )

footer = trim( footer )

if not footer then return end

box :tag( 'tr' ) :tag( 'td' ) :attr( 'colspan', '2' ) :addClass( 'infobox-footer' ) :wikitext( footer )

end


-- Website


local function addWebsite( box, url )

url = trim( url )

if not url then return end

addRow( box, 'ওয়েবসাইট', string.format( '[%s %s]', url, url ) )

end


-- Standard Person Fields


local function addStandardRows( box, args )

addRow( box, 'জন্ম', args['জন্ম'] ) addRow( box, 'জন্মস্থান', args['জন্মস্থান'] ) addRow( box, 'মৃত্যু', args['মৃত্যু'] ) addRow( box, 'মৃত্যুস্থান', args['মৃত্যুস্থান'] ) addRow( box, 'জাতীয়তা', args['জাতীয়তা'] ) addRow( box, 'নাগরিকত্ব', args['নাগরিকত্ব'] ) addRow( box, 'পেশা', args['পেশা'] ) addRow( box, 'কর্মজীবন', args['কর্মজীবন'] ) addRow( box, 'শিক্ষাপ্রতিষ্ঠান', args['শিক্ষাপ্রতিষ্ঠান'] ) addRow( box, 'শিক্ষাগত যোগ্যতা', args['শিক্ষাগত_যোগ্যতা'] ) addRow( box, 'পরিচিতি', args['পরিচিতি'] ) addRow( box, 'পিতা', args['পিতা'] ) addRow( box, 'মাতা', args['মাতা'] ) addRow( box, 'দাম্পত্য সঙ্গী', args['দাম্পত্য_সঙ্গী'] ) addRow( box, 'সন্তান', args['সন্তান'] ) addRow( box, 'পুরস্কার', args['পুরস্কার'] )

addWebsite( box, args['ওয়েবসাইট'] )

end


-- Build infobox


function p.render( args )

local box = createBox()

addHeader( box, args["নাম"] )

addSubtitle( box, args["উপশিরোনাম"] )

addImage( box, args["ছবি"], args["ছবির_বিবরণ"] )

addStandardRows( box, args )

addFooter( box, args["ফুটার"] or "মুক্তপিডিয়া তথ্যছক" )

return tostring( box )

end


-- Template entry


function p.main( frame )

local args = frame:getParent().args

return p.render( args )

end


-- Direct invoke support


function p.infobox( frame )

local args

if frame == mw.getCurrentFrame() then args = frame:getParent().args else args = frame.args end

return p.render( args )

end


-- Export


p._render = p.render p._main = p.main

return p