پرش به محتوا

پودمان:InfoboxPerson: تفاوت میان نسخه‌ها

از ویکی البرز
جزبدون خلاصۀ ویرایش
جزبدون خلاصۀ ویرایش
خط ۳: خط ۳:
--==================================================
--==================================================
-- Module:InfoboxPerson
-- Module:InfoboxPerson
-- Version: Base Person Infobox
-- Core Person Infobox
-- Part 1
-- Core / Arguments / Aliases
--==================================================
--==================================================


خط ۲۰: خط ۱۸:
return nil
return nil
end
end


value = tostring(value)
value = tostring(value)
خط ۳۲: خط ۲۹:




-- حذف نیم‌فاصله و کاراکترهای نامرئی
value = mw.ustring.gsub(
value = mw.ustring.gsub(
value,
value,
خط ۴۷: خط ۴۳:


----------------------------------------------------
----------------------------------------------------
-- COLLECT ARGUMENTS
-- GET ARGUMENTS
----------------------------------------------------
----------------------------------------------------


local function collectArgs(frame)
local function getArgs(frame)


local args = {}
local args = {}
خط ۶۲: خط ۵۸:




for key, value in pairs(tbl) do
for k,v in pairs(tbl) do


local k = normalize(key)
local key = normalize(k)
local v = normalize(value)
local value = normalize(v)




if k and v then
if key and value then
args[k] = v
args[key] = value
end
end


خط ۹۶: خط ۹۲:


----------------------------------------------------
----------------------------------------------------
-- ARGUMENT ALIASES
-- ALIASES
----------------------------------------------------
----------------------------------------------------


local aliases = {
local aliases = {
-- عنوان اصلی


name = {
name = {
"نام",
"نام",
"نام شخص",
"name"
"name"
},
},


-- تصویر


image = {
image = {
"تصویر",
"تصویر",
"پرونده",
"پرونده",
"image",
"image"
"photo"
 
},
},




caption = {
caption = {
"توضیح تصویر",
"توضیح تصویر",
"زیرنویس",
"caption"
"caption"
},
},


-- اطلاعات هویتی


fullname = {
fullname = {
"نام کامل",
"نام کامل",
"نام اصلی",
"fullname"
"fullname",
"full_name"
 
},
},
birth_name = {
"نام تولد",
"نام زمان تولد",
"birth_name"
},




birth_date = {
birth_date = {
"زادروز",
"زادروز",
"تاریخ تولد",
"تاریخ تولد",
"birth_date",
"birth_date"
"date_of_birth"
 
},
},




birth_place = {
birth_place = {
"زادگاه",
"زادگاه",
"محل تولد",
"محل تولد",
"birth_place",
"birth_place"
"place_of_birth"
 
},
},




death_date = {
death_date = {
"درگذشته",
"درگذشته",
"تاریخ درگذشت",
"تاریخ درگذشت",
"death_date",
"death_date"
"date_of_death"
 
},
},
death_place = {
"محل درگذشت",
"death_place"
},




nationality = {
nationality = {
"ملیت",
"ملیت",
"nationality"
"nationality"
},
citizenship = {
"تابعیت",
"citizenship"
},
},


-- زندگی حرفه‌ای


occupation = {
occupation = {
"پیشه",
"پیشه",
"شغل",
"شغل",
"occupation"
"occupation"
},
},




field = {
field = {
"زمینه فعالیت",
"زمینه فعالیت",
"حوزه فعالیت",
"حوزه فعالیت",
"رشته",
"field"
"field"
},
years_active = {
"سال‌های فعالیت",
"دوره فعالیت",
"years_active"
},
},




education = {
education = {
"تحصیلات",
"تحصیلات",
"education"
"education"
}
}


}
}
--==================================================
--==================================================
-- RESOLVE ARGUMENTS
-- 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
-- CHECK VALUE
----------------------------------------------------
----------------------------------------------------


خط ۳۳۲: خط ۲۵۱:
----------------------------------------------------
----------------------------------------------------


local function addTitle(box, args)
local function addTitle(box,args)




خط ۳۴۶: خط ۲۶۵:




local row = box:tag("tr")
box:tag("tr")
 
 
row
: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)




خط ۳۸۳: خط ۲۹۹:




local row = box:tag("tr")
box:tag("tr")
 
 
 
row
: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]]"
)
)




خط ۴۱۰: خط ۳۱۹:




local caption = box:tag("tr")
box:tag("tr")
 
 
caption
: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 SECTION HEADER
-- ADD HEADER
----------------------------------------------------
----------------------------------------------------


local function addHeader(box, text)
local function addHeader(box,text)
 
 
local row = box:tag("tr")




row
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)




خط ۴۷۴: خط ۳۷۷:




local row = box:tag("tr")
box:tag("tr")
 
 
 
row
:tag("th")
:tag("th")
:wikitext(label)
:wikitext(label)




 
box:tag("tr")
row
:tag("td")
:tag("td")
:wikitext(value)
:wikitext(value)
خط ۴۹۴: خط ۳۹۲:
end
end
--==================================================
--==================================================
-- PERSONAL INFORMATION SECTION
-- PERSONAL SECTION
--==================================================
--==================================================


local function addPersonal(box, args)
local function addPersonal(box,args)
 
 
local hasData = false
 
 
if hasValue(args.fullname)
or hasValue(args.birth_name)
or hasValue(args.birth_date)
or hasValue(args.birth_place)
or hasValue(args.death_date)
or hasValue(args.death_place)
or hasValue(args.nationality)
or hasValue(args.citizenship) then


 
local hasData =
hasData = true
hasValue(args.fullname)
 
or hasValue(args.birth_date)
end
or hasValue(args.birth_place)
or hasValue(args.death_date)
or hasValue(args.nationality)




خط ۵۳۸: خط ۴۲۵:
"نام کامل",
"نام کامل",
args.fullname
args.fullname
)
addRow(
box,
"نام تولد",
args.birth_name
)
)


خط ۵۶۶: خط ۴۴۶:
"درگذشته",
"درگذشته",
args.death_date
args.death_date
)
addRow(
box,
"محل درگذشت",
args.death_place
)
)


خط ۵۸۰: خط ۴۵۳:
"ملیت",
"ملیت",
args.nationality
args.nationality
)
addRow(
box,
"تابعیت",
args.citizenship
)
)


خط ۵۹۴: خط ۴۶۰:




--==================================================
----------------------------------------------------
-- CAREER INFORMATION SECTION
-- CAREER SECTION
--==================================================
----------------------------------------------------


local function addCareer(box, args)
local function addCareer(box,args)




local hasData = false
local hasData =
 
hasValue(args.occupation)
 
or hasValue(args.field)
if hasValue(args.occupation)
or hasValue(args.education)
or hasValue(args.field)
or hasValue(args.years_active)
or hasValue(args.education) then
 
 
hasData = true
 
end




خط ۶۴۷: خط ۵۰۵:
addRow(
addRow(
box,
box,
"سال‌های فعالیت",
"تحصیلات",
args.years_active
args.education
)
)




addRow(
end
box,
 
"تحصیلات",
 
args.education
 
----------------------------------------------------
-- 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 rawArgs = collectArgs(frame)
local args = resolveArgs(
 
getArgs(frame)
 
)
 
local args = resolveArgs(rawArgs)





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

توضیحات این پودمان می‌تواند در پودمان: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