پودمان:InfoboxPerson: تفاوت میان نسخهها
ظاهر
جزبدون خلاصۀ ویرایش |
جزبدون خلاصۀ ویرایش |
||
| خط ۳: | خط ۳: | ||
--================================================== | --================================================== | ||
-- Module:InfoboxPerson | -- Module:InfoboxPerson | ||
-- | -- Core Person Infobox | ||
--================================================== | --================================================== | ||
| خط ۲۰: | خط ۱۸: | ||
return nil | return nil | ||
end | end | ||
value = tostring(value) | value = tostring(value) | ||
| خط ۳۲: | خط ۲۹: | ||
value = mw.ustring.gsub( | value = mw.ustring.gsub( | ||
value, | value, | ||
| خط ۴۷: | خط ۴۳: | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
-- | -- GET ARGUMENTS | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
local function | local function getArgs(frame) | ||
local args = {} | local args = {} | ||
| خط ۶۲: | خط ۵۸: | ||
for | for k,v in pairs(tbl) do | ||
local | local key = normalize(k) | ||
local | local value = normalize(v) | ||
if | if key and value then | ||
args[ | args[key] = value | ||
end | end | ||
| خط ۹۶: | خط ۹۲: | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
-- | -- ALIASES | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
local aliases = { | local aliases = { | ||
name = { | name = { | ||
"نام", | "نام", | ||
"name" | "name" | ||
}, | }, | ||
image = { | image = { | ||
"تصویر", | "تصویر", | ||
"پرونده", | "پرونده", | ||
"image" | "image" | ||
}, | }, | ||
caption = { | caption = { | ||
"توضیح تصویر", | "توضیح تصویر", | ||
"caption" | "caption" | ||
}, | }, | ||
fullname = { | fullname = { | ||
"نام کامل", | "نام کامل", | ||
"fullname" | |||
"fullname" | |||
}, | }, | ||
birth_date = { | birth_date = { | ||
"زادروز", | "زادروز", | ||
"تاریخ تولد", | "تاریخ تولد", | ||
"birth_date" | "birth_date" | ||
}, | }, | ||
birth_place = { | birth_place = { | ||
"زادگاه", | "زادگاه", | ||
"محل تولد", | "محل تولد", | ||
"birth_place" | "birth_place" | ||
}, | }, | ||
death_date = { | death_date = { | ||
"درگذشته", | "درگذشته", | ||
"تاریخ درگذشت", | "تاریخ درگذشت", | ||
"death_date" | "death_date" | ||
}, | }, | ||
nationality = { | nationality = { | ||
"ملیت", | "ملیت", | ||
"nationality" | "nationality" | ||
}, | }, | ||
occupation = { | occupation = { | ||
"پیشه", | "پیشه", | ||
"شغل", | "شغل", | ||
"occupation" | "occupation" | ||
}, | }, | ||
field = { | field = { | ||
"زمینه فعالیت", | "زمینه فعالیت", | ||
"حوزه فعالیت", | "حوزه فعالیت", | ||
"field" | "field" | ||
}, | }, | ||
education = { | education = { | ||
"تحصیلات", | "تحصیلات", | ||
"education" | "education" | ||
} | } | ||
} | } | ||
--================================================== | --================================================== | ||
-- RESOLVE | -- RESOLVE ALIASES | ||
--================================================== | --================================================== | ||
| خط ۲۷۱: | خط ۱۷۹: | ||
for key, list in pairs(aliases) do | for key, list in pairs(aliases) do | ||
for i = 1, #list do | for i = 1, #list do | ||
| خط ۲۸۵: | خط ۱۹۲: | ||
end | end | ||
end | |||
end | |||
-- نگهداری پارامترهای تخصصی | |||
-- برای ماژولهای فرزند | |||
for key, value in pairs(args) do | |||
if not result[key] then | |||
result[key] = value | |||
end | end | ||
| خط ۲۹۷: | خط ۲۱۶: | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
-- VALUE | -- CHECK VALUE | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
| خط ۳۳۲: | خط ۲۵۱: | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
local function addTitle(box, args) | local function addTitle(box,args) | ||
| خط ۳۴۶: | خط ۲۶۵: | ||
box:tag("tr") | |||
:tag("th") | :tag("th") | ||
:attr("colspan", "2") | :attr("colspan","2") | ||
:css({ | :css({ | ||
["background-color"] = "#2C5F9E", | ["background-color"]="#2C5F9E", | ||
color = "#FFFFFF", | color="#FFFFFF", | ||
["text-align"] = "center", | ["text-align"]="center", | ||
["font-size"] = "120%", | ["font-size"]="120%", | ||
padding = "8px" | padding="8px" | ||
}) | }) | ||
| خط ۳۷۲: | خط ۲۸۸: | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
local function addImage(box, args) | local function addImage(box,args) | ||
| خط ۳۸۳: | خط ۲۹۹: | ||
box:tag("tr") | |||
:tag("td") | :tag("td") | ||
:attr("colspan", "2") | :attr("colspan","2") | ||
:css({ | :css({ | ||
["text-align"] = "center", | ["text-align"]="center", | ||
padding = "5px" | padding="5px" | ||
}) | }) | ||
:wikitext( | :wikitext( | ||
"[[File:" .. | "[[File:" .. | ||
args.image .. | args.image .. | ||
"|250px]]" | "|250px]]" | ||
) | ) | ||
| خط ۴۱۰: | خط ۳۱۹: | ||
box:tag("tr") | |||
:tag("td") | :tag("td") | ||
:attr("colspan", "2") | :attr("colspan","2") | ||
:css({ | :css({ | ||
["text-align"] = "center", | ["text-align"]="center", | ||
["font-size"] = "90%" | ["font-size"]="90%" | ||
}) | }) | ||
| خط ۴۳۳: | خط ۳۳۹: | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
-- ADD | -- ADD HEADER | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
local function addHeader(box, text | local function addHeader(box,text) | ||
box:tag("tr") | |||
:tag("th") | :tag("th") | ||
:attr("colspan", "2") | :attr("colspan","2") | ||
:css({ | :css({ | ||
["background-color"] = "#2C5F9E", | ["background-color"]="#2C5F9E", | ||
color = "#FFFFFF", | color="#FFFFFF", | ||
["text-align"] = "center" | ["text-align"]="center" | ||
}) | }) | ||
| خط ۴۶۳: | خط ۳۶۶: | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
local function addRow(box, label, value) | local function addRow(box,label,value) | ||
| خط ۴۷۴: | خط ۳۷۷: | ||
box:tag("tr") | |||
:tag("th") | :tag("th") | ||
:wikitext(label) | :wikitext(label) | ||
box:tag("tr") | |||
:tag("td") | :tag("td") | ||
:wikitext(value) | :wikitext(value) | ||
| خط ۴۹۴: | خط ۳۹۲: | ||
end | end | ||
--================================================== | --================================================== | ||
-- PERSONAL | -- PERSONAL SECTION | ||
--================================================== | --================================================== | ||
local function addPersonal(box, args) | local function addPersonal(box,args) | ||
local hasData = | |||
hasValue(args.fullname) | |||
or hasValue(args.birth_date) | |||
or hasValue(args.birth_place) | |||
or hasValue(args.death_date) | |||
or hasValue(args.nationality) | |||
| خط ۵۳۸: | خط ۴۲۵: | ||
"نام کامل", | "نام کامل", | ||
args.fullname | args.fullname | ||
) | ) | ||
| خط ۵۶۶: | خط ۴۴۶: | ||
"درگذشته", | "درگذشته", | ||
args.death_date | args.death_date | ||
) | ) | ||
| خط ۵۸۰: | خط ۴۵۳: | ||
"ملیت", | "ملیت", | ||
args.nationality | args.nationality | ||
) | ) | ||
| خط ۵۹۴: | خط ۴۶۰: | ||
-- | ---------------------------------------------------- | ||
-- CAREER | -- CAREER SECTION | ||
-- | ---------------------------------------------------- | ||
local function addCareer(box, args) | local function addCareer(box,args) | ||
local hasData = | local hasData = | ||
hasValue(args.occupation) | |||
or hasValue(args.field) | |||
or hasValue(args.education) | |||
| خط ۶۴۷: | خط ۵۰۵: | ||
addRow( | addRow( | ||
box, | box, | ||
" | "تحصیلات", | ||
args. | args.education | ||
) | ) | ||
end | |||
---------------------------------------------------- | |||
-- LOAD EXTENSION MODULES | |||
---------------------------------------------------- | |||
local function loadSection(moduleName, box, args) | |||
local ok, module = pcall( | |||
require, | |||
moduleName | |||
) | ) | ||
if ok and module and module.render then | |||
module.render( | |||
box, | |||
args | |||
) | |||
end | |||
| خط ۶۶۳: | خط ۵۴۲: | ||
-- | ---------------------------------------------------- | ||
-- RENDER | -- RENDER | ||
-- | ---------------------------------------------------- | ||
local function render(args) | local function render(args) | ||
| خط ۶۹۶: | خط ۵۷۵: | ||
addCareer( | addCareer( | ||
box, | |||
args | |||
) | |||
-------------------------------------------------- | |||
-- تخصصها | |||
-------------------------------------------------- | |||
loadSection( | |||
"Module:InfoboxPerson/Sport", | |||
box, | |||
args | |||
) | |||
loadSection( | |||
"Module:InfoboxPerson/Artist", | |||
box, | |||
args | |||
) | |||
loadSection( | |||
"Module:InfoboxPerson/Scientist", | |||
box, | box, | ||
args | args | ||
| خط ۷۰۸: | خط ۶۱۶: | ||
-- | ---------------------------------------------------- | ||
-- ENTRY POINT | -- ENTRY POINT | ||
-- | ---------------------------------------------------- | ||
function p.main(frame) | function p.main(frame) | ||
local | local args = resolveArgs( | ||
getArgs(frame) | |||
) | |||
نسخهٔ ۱۲ ژوئیهٔ ۲۰۲۶، ساعت ۲۱:۱۱
توضیحات این پودمان میتواند در پودمان:InfoboxPerson/توضیحات قرار گیرد.
local p = {}
--==================================================
-- Module:InfoboxPerson
-- Core Person Infobox
--==================================================
local html = mw.html
----------------------------------------------------
-- NORMALIZE
----------------------------------------------------
local function normalize(value)
if value == nil then
return nil
end
value = tostring(value)
value = mw.text.trim(value)
if value == "" then
return nil
end
value = mw.ustring.gsub(
value,
"[\u200C\u200D\uFEFF]",
""
)
return value
end
----------------------------------------------------
-- GET ARGUMENTS
----------------------------------------------------
local function getArgs(frame)
local args = {}
local function read(tbl)
if not tbl then
return
end
for k,v in pairs(tbl) do
local key = normalize(k)
local value = normalize(v)
if key and value then
args[key] = value
end
end
end
local parent = frame:getParent()
if parent then
read(parent.args)
end
read(frame.args)
return args
end
----------------------------------------------------
-- ALIASES
----------------------------------------------------
local aliases = {
name = {
"نام",
"name"
},
image = {
"تصویر",
"پرونده",
"image"
},
caption = {
"توضیح تصویر",
"caption"
},
fullname = {
"نام کامل",
"fullname"
},
birth_date = {
"زادروز",
"تاریخ تولد",
"birth_date"
},
birth_place = {
"زادگاه",
"محل تولد",
"birth_place"
},
death_date = {
"درگذشته",
"تاریخ درگذشت",
"death_date"
},
nationality = {
"ملیت",
"nationality"
},
occupation = {
"پیشه",
"شغل",
"occupation"
},
field = {
"زمینه فعالیت",
"حوزه فعالیت",
"field"
},
education = {
"تحصیلات",
"education"
}
}
--==================================================
-- RESOLVE ALIASES
--==================================================
local function resolveArgs(args)
local result = {}
for key, list in pairs(aliases) do
for i = 1, #list do
local value = args[list[i]]
if value then
result[key] = value
break
end
end
end
-- نگهداری پارامترهای تخصصی
-- برای ماژولهای فرزند
for key, value in pairs(args) do
if not result[key] then
result[key] = value
end
end
return result
end
----------------------------------------------------
-- CHECK VALUE
----------------------------------------------------
local function hasValue(value)
return normalize(value) ~= nil
end
----------------------------------------------------
-- CREATE INFOBOX
----------------------------------------------------
local function createBox()
local box = html.create("table")
box
:addClass("infobox")
:addClass("person-infobox")
return box
end
----------------------------------------------------
-- ADD TITLE
----------------------------------------------------
local function addTitle(box,args)
local title = args.name
if not title then
title = mw.title.getCurrentTitle().text
end
box:tag("tr")
:tag("th")
:attr("colspan","2")
:css({
["background-color"]="#2C5F9E",
color="#FFFFFF",
["text-align"]="center",
["font-size"]="120%",
padding="8px"
})
:wikitext(title)
end
----------------------------------------------------
-- ADD IMAGE
----------------------------------------------------
local function addImage(box,args)
if not hasValue(args.image) then
return
end
box:tag("tr")
:tag("td")
:attr("colspan","2")
:css({
["text-align"]="center",
padding="5px"
})
:wikitext(
"[[File:" ..
args.image ..
"|250px]]"
)
if hasValue(args.caption) then
box:tag("tr")
:tag("td")
:attr("colspan","2")
:css({
["text-align"]="center",
["font-size"]="90%"
})
:wikitext(args.caption)
end
end
----------------------------------------------------
-- ADD HEADER
----------------------------------------------------
local function addHeader(box,text)
box:tag("tr")
:tag("th")
:attr("colspan","2")
:css({
["background-color"]="#2C5F9E",
color="#FFFFFF",
["text-align"]="center"
})
:wikitext(text)
end
----------------------------------------------------
-- ADD ROW
----------------------------------------------------
local function addRow(box,label,value)
if not hasValue(value) then
return false
end
box:tag("tr")
:tag("th")
:wikitext(label)
box:tag("tr")
:tag("td")
:wikitext(value)
return true
end
--==================================================
-- PERSONAL SECTION
--==================================================
local function addPersonal(box,args)
local hasData =
hasValue(args.fullname)
or hasValue(args.birth_date)
or hasValue(args.birth_place)
or hasValue(args.death_date)
or hasValue(args.nationality)
if not hasData then
return
end
addHeader(
box,
"اطلاعات شخصی"
)
addRow(
box,
"نام کامل",
args.fullname
)
addRow(
box,
"زاده",
args.birth_date
)
addRow(
box,
"زادگاه",
args.birth_place
)
addRow(
box,
"درگذشته",
args.death_date
)
addRow(
box,
"ملیت",
args.nationality
)
end
----------------------------------------------------
-- CAREER SECTION
----------------------------------------------------
local function addCareer(box,args)
local hasData =
hasValue(args.occupation)
or hasValue(args.field)
or hasValue(args.education)
if not hasData then
return
end
addHeader(
box,
"زندگی و فعالیت"
)
addRow(
box,
"پیشه",
args.occupation
)
addRow(
box,
"زمینه فعالیت",
args.field
)
addRow(
box,
"تحصیلات",
args.education
)
end
----------------------------------------------------
-- LOAD EXTENSION MODULES
----------------------------------------------------
local function loadSection(moduleName, box, args)
local ok, module = pcall(
require,
moduleName
)
if ok and module and module.render then
module.render(
box,
args
)
end
end
----------------------------------------------------
-- RENDER
----------------------------------------------------
local function render(args)
local box = createBox()
addTitle(
box,
args
)
addImage(
box,
args
)
addPersonal(
box,
args
)
addCareer(
box,
args
)
--------------------------------------------------
-- تخصصها
--------------------------------------------------
loadSection(
"Module:InfoboxPerson/Sport",
box,
args
)
loadSection(
"Module:InfoboxPerson/Artist",
box,
args
)
loadSection(
"Module:InfoboxPerson/Scientist",
box,
args
)
return tostring(box)
end
----------------------------------------------------
-- ENTRY POINT
----------------------------------------------------
function p.main(frame)
local args = resolveArgs(
getArgs(frame)
)
return render(args)
end
return p