মডিউল:Infobox: সংশোধিত সংস্করণের মধ্যে পার্থক্য
Md Abu Sayeed (আলোচনা | অবদান) মুক্তপিডিয়ার তথ্যছক মডিউল তৈরি |
Md Abu Sayeed (আলোচনা | অবদান) হালনাগাদ |
||
| ১ নং লাইন: | ১ নং লাইন: | ||
local p = {} | local p = {} | ||
local function trim( | local Html = mw.html | ||
if not | |||
return | -------------------------------------------------------------------- | ||
-- Utility | |||
-------------------------------------------------------------------- | |||
local function trim( value ) | |||
if not value then | |||
return nil | |||
end | end | ||
value = tostring( value ) | |||
value = mw.text.trim( value ) | |||
if value == '' then | |||
return nil | |||
end | |||
return value | |||
end | end | ||
function | local function exists( value ) | ||
local | return trim( value ) ~= nil | ||
end | |||
-------------------------------------------------------------------- | |||
-- Create Infobox | |||
-------------------------------------------------------------------- | |||
local function createBox() | |||
local | local root = Html.create( 'table' ) | ||
root | |||
:addClass( 'infobox' ) | :addClass( 'infobox' ) | ||
:css( 'width', ' | :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( 'border-collapse', 'collapse' ) | :css( 'border-collapse', 'collapse' ) | ||
:css( 'background', '#fff' ) | |||
:css( 'font-size', '90%' ) | :css( 'font-size', '90%' ) | ||
-- | return root | ||
if | |||
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' ) | ||
: | :addClass( 'infobox-section' ) | ||
: | :wikitext( title ) | ||
end | |||
-------------------------------------------------------------------- | |||
-- Footer | |||
-------------------------------------------------------------------- | |||
local function addFooter( box, footer ) | |||
footer = trim( footer ) | |||
if not footer then | |||
return | |||
end | end | ||
box | |||
:tag( 'tr' ) | |||
:tag( 'td' ) | :tag( 'td' ) | ||
:attr( 'colspan', '2' ) | :attr( 'colspan', '2' ) | ||
: | :addClass( 'infobox-footer' ) | ||
:wikitext( | :wikitext( footer ) | ||
end | |||
-------------------------------------------------------------------- | |||
-- Website | |||
-------------------------------------------------------------------- | |||
local function addWebsite( box, url ) | |||
url = trim( url ) | |||
if not url then | |||
return | |||
end | 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 | end | ||
return | 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(
'
',
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