پرش به محتوا

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

از ویکی البرز
صفحه‌ای تازه حاوی «local p = {} --================================================== -- Module:InfoboxPerson -- Part 1 -- Core utilities --================================================== local html = mw.html ---------------------------------------------------- -- NORMALIZE ---------------------------------------------------- local function normalize(value) if value == nil then return nil end value = tostring(value) value = mw.text.trim(v...» ایجاد کرد
 
جزبدون خلاصۀ ویرایش
خط ۳: خط ۳:
--==================================================
--==================================================
-- Module:InfoboxPerson
-- Module:InfoboxPerson
-- Version: Base Person Infobox
-- Part 1
-- Part 1
-- Core utilities
-- Core / Arguments / Aliases
--==================================================
--==================================================


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


value = tostring(value)
value = tostring(value)


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


if value == "" then
if value == "" then
خط ۳۵: خط ۳۸:
""
""
)
)


return value
return value
خط ۴۳: خط ۴۷:


----------------------------------------------------
----------------------------------------------------
-- ARGUMENT COLLECTION
-- COLLECT ARGUMENTS
----------------------------------------------------
----------------------------------------------------


خط ۹۲: خط ۹۶:


----------------------------------------------------
----------------------------------------------------
-- ARG ALIASES
-- ARGUMENT ALIASES
----------------------------------------------------
----------------------------------------------------


local aliases = {
local aliases = {


-- عنوان اصلی


name = {
name = {


"نام",
"نام",
"نام بازیکن",
"نام شخص",
"name",
"name"
"playername"


},
},


-- تصویر


image = {
image = {
خط ۱۱۲: خط ۱۲۰:
"تصویر",
"تصویر",
"پرونده",
"پرونده",
"image"
"image",
"photo"


},
},




خط ۱۲۵: خط ۱۳۵:
},
},


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


fullname = {
fullname = {
خط ۱۳۰: خط ۱۴۳:
"نام کامل",
"نام کامل",
"نام اصلی",
"نام اصلی",
"full_name",
"fullname",
"fullname"
"full_name"
 
},
 
 
 
birth_name = {
 
"نام تولد",
"نام زمان تولد",
"birth_name"


},
},




خط ۱۴۰: خط ۱۶۴:
"زادروز",
"زادروز",
"تاریخ تولد",
"تاریخ تولد",
"birth_date"
"birth_date",
"date_of_birth"


},
},




خط ۱۴۹: خط ۱۷۵:
"زادگاه",
"زادگاه",
"محل تولد",
"محل تولد",
"birth_place"
"birth_place",
"place_of_birth"


},
},




خط ۱۵۸: خط ۱۸۶:
"درگذشته",
"درگذشته",
"تاریخ درگذشت",
"تاریخ درگذشت",
"death_date"
"death_date",
"date_of_death"


},
},
death_place = {
"محل درگذشت",
"death_place"
},




خط ۱۷۱: خط ۲۱۰:




height = {


"قد",
citizenship = {
"height"
 
"تابعیت",
"citizenship"


},
},




weight = {


"وزن",
-- زندگی حرفه‌ای
"weight"


},
occupation = {


"پیشه",
"شغل",
"occupation"


sport = {
},


"ورزش",
"sport"


},


field = {


club = {
"زمینه فعالیت",
"حوزه فعالیت",
"رشته",
"field"


"باشگاه",
},
"club"


},




team = {
years_active = {


"تیم",
"سال‌های فعالیت",
"تیم ملی",
"دوره فعالیت",
"team"
"years_active"


},
},




coach = {


"مربی",
education = {
"سرمربی",
 
"coach"
"تحصیلات",
"education"


}
}
خط ۲۲۲: خط ۲۶۲:
}
}
--==================================================
--==================================================
-- RESOLVE ALIASES
-- RESOLVE ARGUMENTS
--==================================================
--==================================================


خط ۳۵۸: خط ۳۹۸:
:wikitext(
:wikitext(


"[[File:"  
"[[File:" ..
.. args.image
args.image ..
.. "|250px]]"
"|250px]]"


)
)
خط ۳۹۳: خط ۴۳۳:


----------------------------------------------------
----------------------------------------------------
-- ADD HEADER
-- ADD SECTION HEADER
----------------------------------------------------
----------------------------------------------------


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


local row = box:tag("tr")
local row = box:tag("tr")




خط ۴۵۳: خط ۴۹۴:
end
end
--==================================================
--==================================================
-- PERSONAL SECTION
-- PERSONAL INFORMATION SECTION
--==================================================
--==================================================


خط ۴۶۳: خط ۵۰۴:


if hasValue(args.fullname)
if hasValue(args.fullname)
or hasValue(args.birth_name)
or hasValue(args.birth_date)
or hasValue(args.birth_date)
or hasValue(args.birth_place)
or hasValue(args.birth_place)
or hasValue(args.death_date)
or hasValue(args.death_date)
or hasValue(args.death_place)
or hasValue(args.nationality)
or hasValue(args.nationality)
or hasValue(args.height)
or hasValue(args.citizenship) then
or hasValue(args.weight) then




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


خط ۵۲۲: خط ۵۷۱:
addRow(
addRow(
box,
box,
"ملیت",
"محل درگذشت",
args.nationality
args.death_place
)
)


خط ۵۲۹: خط ۵۷۸:
addRow(
addRow(
box,
box,
"قد",
"ملیت",
args.height
args.nationality
)
)


خط ۵۳۶: خط ۵۸۵:
addRow(
addRow(
box,
box,
"وزن",
"تابعیت",
args.weight
args.citizenship
)
)


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


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


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




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




if hasValue(args.sport)
if hasValue(args.occupation)
or hasValue(args.club)
or hasValue(args.field)
or hasValue(args.team)
or hasValue(args.years_active)
or hasValue(args.coach) then
or hasValue(args.education) then




خط ۵۷۷: خط ۶۲۶:
addHeader(
addHeader(
box,
box,
"اطلاعات ورزشی"
"زندگی و فعالیت"
)
)


خط ۵۸۴: خط ۶۳۳:
addRow(
addRow(
box,
box,
"ورزش",
"پیشه",
args.sport
args.occupation
)
)


خط ۵۹۱: خط ۶۴۰:
addRow(
addRow(
box,
box,
"باشگاه",
"زمینه فعالیت",
args.club
args.field
)
)


خط ۵۹۸: خط ۶۴۷:
addRow(
addRow(
box,
box,
"تیم",
"سال‌های فعالیت",
args.team
args.years_active
)
)


خط ۶۰۵: خط ۶۵۴:
addRow(
addRow(
box,
box,
"مربی",
"تحصیلات",
args.coach
args.education
)
)


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




addSport(
addCareer(
box,
box,
args
args
خط ۶۷۵: خط ۷۲۴:


return render(args)
return render(args)


end
end

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

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

local p = {}

--==================================================
-- Module:InfoboxPerson
-- Version: Base Person Infobox
-- Part 1
-- Core / Arguments / Aliases
--==================================================

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



----------------------------------------------------
-- COLLECT ARGUMENTS
----------------------------------------------------

local function collectArgs(frame)

	local args = {}


	local function read(tbl)

		if not tbl then
			return
		end


		for key, value in pairs(tbl) do

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


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

		end

	end



	local parent = frame:getParent()


	if parent then
		read(parent.args)
	end


	read(frame.args)


	return args

end



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

local aliases = {


	-- عنوان اصلی

	name = {

		"نام",
		"نام شخص",
		"name"

	},



	-- تصویر

	image = {

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

	},



	caption = {

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

	},



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

	fullname = {

		"نام کامل",
		"نام اصلی",
		"fullname",
		"full_name"

	},



	birth_name = {

		"نام تولد",
		"نام زمان تولد",
		"birth_name"

	},



	birth_date = {

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

	},



	birth_place = {

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

	},



	death_date = {

		"درگذشته",
		"تاریخ درگذشت",
		"death_date",
		"date_of_death"

	},



	death_place = {

		"محل درگذشت",
		"death_place"

	},



	nationality = {

		"ملیت",
		"nationality"

	},



	citizenship = {

		"تابعیت",
		"citizenship"

	},



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

	occupation = {

		"پیشه",
		"شغل",
		"occupation"

	},



	field = {

		"زمینه فعالیت",
		"حوزه فعالیت",
		"رشته",
		"field"

	},



	years_active = {

		"سال‌های فعالیت",
		"دوره فعالیت",
		"years_active"

	},



	education = {

		"تحصیلات",
		"education"

	}

}
--==================================================
-- RESOLVE ARGUMENTS
--==================================================

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


	return result

end



----------------------------------------------------
-- VALUE CHECK
----------------------------------------------------

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



	local row = box:tag("tr")


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



	local row = box:tag("tr")



	row
		:tag("td")
		:attr("colspan", "2")
		:css({

			["text-align"] = "center",
			padding = "5px"

		})
		:wikitext(

			"[[File:" ..
			args.image ..
			"|250px]]"

		)




	if hasValue(args.caption) then


		local caption = box:tag("tr")


		caption
			:tag("td")
			:attr("colspan", "2")
			:css({

				["text-align"] = "center",
				["font-size"] = "90%"

			})
			:wikitext(args.caption)


	end


end



----------------------------------------------------
-- ADD SECTION HEADER
----------------------------------------------------

local function addHeader(box, text)


	local row = box:tag("tr")


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



	local row = box:tag("tr")



	row
		:tag("th")
		:wikitext(label)



	row
		:tag("td")
		:wikitext(value)



	return true

end
--==================================================
-- PERSONAL INFORMATION SECTION
--==================================================

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


		hasData = true

	end



	if not hasData then

		return

	end



	addHeader(
		box,
		"اطلاعات شخصی"
	)



	addRow(
		box,
		"نام کامل",
		args.fullname
	)


	addRow(
		box,
		"نام تولد",
		args.birth_name
	)


	addRow(
		box,
		"زاده",
		args.birth_date
	)


	addRow(
		box,
		"زادگاه",
		args.birth_place
	)


	addRow(
		box,
		"درگذشته",
		args.death_date
	)


	addRow(
		box,
		"محل درگذشت",
		args.death_place
	)


	addRow(
		box,
		"ملیت",
		args.nationality
	)


	addRow(
		box,
		"تابعیت",
		args.citizenship
	)


end



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

local function addCareer(box, args)


	local hasData = false


	if hasValue(args.occupation)
	or hasValue(args.field)
	or hasValue(args.years_active)
	or hasValue(args.education) then


		hasData = true

	end



	if not hasData then

		return

	end



	addHeader(
		box,
		"زندگی و فعالیت"
	)



	addRow(
		box,
		"پیشه",
		args.occupation
	)


	addRow(
		box,
		"زمینه فعالیت",
		args.field
	)


	addRow(
		box,
		"سال‌های فعالیت",
		args.years_active
	)


	addRow(
		box,
		"تحصیلات",
		args.education
	)


end



--==================================================
-- RENDER
--==================================================

local function render(args)


	local box = createBox()



	addTitle(
		box,
		args
	)



	addImage(
		box,
		args
	)



	addPersonal(
		box,
		args
	)



	addCareer(
		box,
		args
	)



	return tostring(box)

end



--==================================================
-- ENTRY POINT
--==================================================

function p.main(frame)


	local rawArgs = collectArgs(frame)



	local args = resolveArgs(rawArgs)



	return render(args)

end



return p