پرش به محتوا

ماژول:ویکی دیتا مقدار

ویکی‌پدیا، آزادِ دانشنومه، جه

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

local p = {}
local getArgs = require('Module:Arguments with aliases').getArgs
local Wikidata2

local aliases = {
	only_pid = { "only_property", "only_pid" },
	use_sandbox = { "use_sandbox", "ملعب", "چنگ‌مویی" },
	barlist = { "قائمة شريطية", "نوار لیست", "قائمه شریطیه" },
	list = { "قائمة" ,"لیست", "قائمه"},
	type = { "نوع" },
	new_line = { "فاصل سطر", "خط فاصله" },
	no_wd = { "ويكي بيانات", "ویکی دیتا", "ویکی‌دیتا", "ویکی بیانات" },
	sort_before_filter = { "sort_before_filter" },

	entityId = { "صفحه", "ولگه", "آی دی", "id",  "ویکی دیتا شناسه", "ویکی‌دیتا شناسه","معرف ويكي بيانات",  "معرف ویکی بیانات",  "ویکی دیتای شناسه", "qid", "entityId" },
	is_number = { "رقم", "is_number", "شماره" },
	page = { "مقالة", "page", "مقاله" },
	noref = { "مراجع", "noref", "مراجع ويكي بيانات", "منابع", "ویکی دیتا منابع", "مراجع ویکی بیانات" },
	numberofreferences = { "numberofreferences", "عدد المراجع", "منابع شماره" },

	property = { "خاصية", "property", "pid", "خاصیه", "ویژگی", "خاصیت", "مدخل" },
	otherproperty = { "خاصية أخرى", "otherproperty", "دیگر خاصیه", "خاصیه اخری" },
	property2 = { "property2" },
	otherproperty2 = { "خاصية أخرى2", "otherproperty2", "خاصیه اخری2" },
	property3 = { "property3" },
	propertyimage = { "propertyimage" },
	property1 = { "خاصية قيمة", "property1", "خاصیه مقدار", "ویژگی مقدار", "قیمه خاصیه" },
	property1rank = { "property1rank" },
	property1after = { "property1after" },
	property1formatting = { "property1formatting" },
	property1pref = { "سابقة خاصية قيمة", "property1pref", "سابقه خاصیه قیمه", "مقدار خاصیه پیش" },
	property1suff = { "لاحقة خاصية قيمة", "property1suff", "لاحقه خاصیه قیمه", "مقدار خاصیه پئی" },
	formatcharacters = { "formatcharacters" },
	addTrackingCat = { "addTrackingCat" },
	category = { "تصنيف", "category", "رج", "تصنیف" },
	noicon = { "noicon", "رمز", "إيقونة", "آیکون" },
	nocate = { "دون تصنيف", "nocate", "بدون رج", "دون تصنیف" },
	icon2 = { "icon2" },
	urllabel = { "urllabel" },
	center = { "center" },
	image = { "صورة", "image", "عکس", "صوره", "تصویر", "پرونده" },
	size = { "حجم صورة", "size", "گتی", "عکس گتی", "اندازه تصویر", "حجم صوره", "حجم عکس" },
	separator = { "separator", "سواکر" },
	conjunction = { "conjunction", "نقطه" },
	formatting = { "formatting", "فورمت" },
	NoPropValue = { "تصنيف 3", "تصنيف3", "بديل", "بدیل" },
	limit = { "limit" },
	showlang = { "showlang" },
	langpref = { "langpref" },
	justthisqual = { "تصفية فقط", "justthisqual", "تصفیه فقط", "فیلتر فقط"},
	bothdates = { "بداية ونهاية", "bothdates", "بدایه ونهایه", "شروع و پایان" },
	withdate = { "نقطة", "withdate", "نقطه" },

	modifytime = { "modifytime" },
	modifyqualifiertime = { "modifyqualifiertime", "تنسيق تاريخ", "تاریخ فورمت", "تنسیق تاریخ" },

	enlabelcate = { "enlabelcate", "use_en_labels" },
	qual1 = { "تصفية", "فیلتر", "تصفیه" },
	qual1pref = { "سابقة تصفية", "qual1pref", "سابقه تصفیه", "فیلتر پیش" },
	qual1a = { "تصفية1", "qual1a", "تصفیه1", "فیلتر1" },
	qp1apref = { "سابقة تصفية1", "qp1apref", "qual1apref", "سابقه تصفیه1", "فیلتر پیش1" },
	qual2 = { "تصفية2", "qual2", "تصفیه2", "فیلتر2" },
	qual2pref = { "سابقة تصفية2", "qual2pref", "سابقه تصفیه2", "فیلتر پیش2" },
	qual3 = { "تصفية3", "qual3", "تصفیه3", "فیلتر3" },
	qual3pref = { "سابقة تصفية3", "qual3pref", "سابقه تصفیه3", "فیلتر پیش3" },
	qual4 = { "تصفية4", "qual4", "تصفیه4", "فیلتر4" },
	qual4pref = { "سابقة تصفية4", "qual4pref", "سابقه تصفیه4", "فیلتر پیش4" },
	qual5 = { "تصفية5", "qual5", "تصفیه5", "فیلتر5" },
	qual5pref = { "سابقة تصفية5", "qual5pref" , "سابقه تصفیه5", "فیلتر پیش5"},
	sortbytime = { "ترتیب", "ترتيب", "sortbytime" },
	option1 = { "خيار", "option1", "خیار", "گزینه", "آپشن" },
	option1value = { "قيمة خيار", "option1value", "قیمه خیار", "گزینه مقدار", "مقدار گزینه", "آپشن مقدار" },
	value_module = { "value-module" },
	value_function = { "value-function" },

	qualifierprefix = { "بادئة تصفيات", "qualifierprefix", "بادئه تصفیات", "فیلترون شروع" },
	qualifiersuffix = { "لاحقة تصفيات", "qualifiersuffix", "لاحقه تصفیات", "فیلترون پئی" },

	unitshort = { "unitshort" },
	prefervalue = { "prefervalue" },
	avoidvalue = { "avoidvalue" },
	avoidqualifier = { "تجاهل تصفية", "avoidqualifier", "فیلتر نشائن", "تجاهل تصفیه" },
	preferqualifiervalue = { "preferqualifiervalue" },
	preferqualifier = { "preferqualifier" },

	mainprefix = { "سابقه", "mainprefix", "بادئه", "پیشوند", "پیش‌ته" },
	mainsuffix = { "لاحقه", "mainsuffix", "پسوند", "پئی‌ته" },
	mainsuffixAfterIcon = { "mainsuffixAfterIcon", "لاحقه2", "پئی‌ته2", "پسوند2" },

	full_link = { "وصلة كاملة", "کامل لینک", "وصله کامله" },
	rank = { "rank" },
	firstvalue = { "firstvalue", "واحد فقط", "فقط اتا", "اتا فقط" },
	pattern = { "pattern", "نمط", "پترن", "شابلون" },

	link = { "وصلة", "لینک", "وصله" },
	linkname = { "تسمية وصلة", "لینک نوم", "تسمیه وصله" },

	illwd2y = { "illwd2y" },
	illwd2 = { "illwd2" }
}

local function anyvalid(x)
	if x and x ~= "" then return x end
	return nil
end
local function isvalid(x)
	if x and x ~= "" and x ~= "نا" and x ~= "لا" and x ~= "نه" and x ~= "no" then return x end
	return nil
end

local function switch_qualls(property, value, props)
	--local property
	if isvalid(value) then
		return value
	end
	if property:upper():sub(1, 1) == "P" then
		property = property:sub(2)
		property = tonumber(property)
	end

	return props[property] or ""
end

local function switch_contry(property, value, props)
	if property:upper():sub(1, 1) == "P" then
		property = property:sub(2)
		property = tonumber(property)
	end

	for i, v in pairs(props) do
		if v == property then
			return value
		end
	end

	return ""
end

local function AddArgs(args)
	local contries = { 17, 1532, 27, 495 }
	local property = args.property

	if isvalid(args.type) and isvalid(args.type) == "وصله" then
		args.pattern = "autourl2"
	end
	if not isvalid(args.formatting) then
		args.formatting = switch_contry(args.property, "sitelink", { 1811, 1881 })
	end
	if not isvalid(args.property1) then
		args.property1 = switch_contry(property, "P41", contries)
	end
	if not isvalid(args.image) then
		args.image = switch_contry(property, "image", contries)
	end
	if not isvalid(args.size) then
		args.size = switch_contry(property, "20", contries)
	end
	if not isvalid(args.bothdates) then
		args.bothdates = switch_contry(property, "true", { 26, 551, 27, 69, 1376, 1532, 17, 495, 102, 1451 })
	end
	if not isvalid(args.onlyvaluewithref) then
		args.onlyvaluewithref = switch_contry(property, "t", { 172, 140, 91, 1853 })
	end

	-- value-module / value-function
	local value_module = switch_qualls(property, args.value_module, {
		[106] = "Wikidata2 sub modules/P106",
		[511] = "Wikidata2 sub modules/P106",
		[413] = "Wikidata2 sub modules/P106",
		[172] = "Wikidata2 sub modules/P172",
	})
	local value_function = switch_qualls(property, args.value_function, {
		[106] = "formatEntityWithGenderClaim",
		[511] = "formatEntityWithGenderClaim",
		[413] = "formatEntityWithGenderClaim",
		[172] = "get_P172_lab",
	})
	if isvalid(value_module) and isvalid(value_function) then
		args["value-module"] = value_module
		args["value-function"] = value_function
	end

	args.qual1 = switch_qualls(property, args.qual1, {
		[856] = "P407",   -- لغة الموقع الرسمي
		[159] = "P17",    -- بلد مقر رسمي
		[1120] = "P2868", -- خاصية دور شخص
		[1561] = "P2868", -- خاصية دور شخص
		[1132] = "P2868", -- خاصية دور شخص
	})

	-- {{#switch:{{lc:{{{خاصيه|{{{property|{{{ویژگی|}}}}}} }}}}}| p27| p1532| p17| p495=y}}
	local sw = switch_contry(property, "true", { 27, 1532, 17, 495 })

	if isvalid(args.list) or isvalid(args.withdate) or isvalid(args.bothdates) or isvalid(args.new_line)
		or isvalid(sw)
	then
		args.separator = "br"
		args.conjunction = "br"
	elseif args.separator == "empty" then
		args.separator = ""
		args.conjunction = ""
	else
		args.separator = isvalid(args.separator) or "،  و "
		args.conjunction = isvalid(args.conjunction) or "، "
	end

	if not isvalid(args.barlist) and not isvalid(args["claim-module"]) and not isvalid(args["property-module"]) then
		args.hidden = isvalid(args.hidden) or "t"
	end

	return args
end

local function parseArgs(args)
	-- dont use isvalid for it because some use as | مراجع = نا
	if anyvalid(args.noref) then
		args.noref = "t"
	end

	args.modifytime = isvalid(args.modifytime) or "dmy"
	args.modifyqualifiertime = isvalid(args.modifyqualifiertime) or "dmy"

	if not isvalid(args.property1rank) then args.property1rank = "all" end

	if not anyvalid(args.addTrackingCat) then args.addTrackingCat = "yes" end

	if not isvalid(args.illwd2) then args.illwd2 = "t" end

	if not isvalid(args.firstvalue) and isvalid(args.full_link) then
		args.firstvalue = "true"
	end

	if not isvalid(args.rank) then
		args.rank = "best"
	end

	if isvalid(args.pattern) then
		if args.pattern == "وصله" then args.pattern = "autourl2" end
	else
		if not isvalid(args.full_link) and not isvalid(args.is_number) and isvalid(args.link) then
			args.pattern = "[" .. args.link .. " " .. (args.linkname or "$1") .. "]"
		end
	end

	-- قائمة شريطية
	--[[
	if isvalid(args.barlist) then
		args.mainprefix =
			'<div style="max-height:180px; overflow: auto; padding: 2px 0 2px 5px; background-color:transparent;vertical-align:top;font-size:100%">' ..
			(args.mainprefix or "")
		args.mainsuffixAfterIcon = (args.mainsuffixAfterIcon or "") .. "</div>"
	end
	]]

	return args
end

function p.main(frame)
	local options = getArgs(frame, { aliases = aliases })

	if not isvalid(options.only_pid) and frame:getParent().args.only_pid then
		options.only_pid = frame:getParent().args.only_pid
	end

	return p.get_result(options)
end

function p.luaMain(args)
	local options = getArgs(args, { aliases = aliases })
	return p.get_result(options)
end

function p.get_result(options)
	-- لا تستخدم ويكي بيانات
	if anyvalid(options.no_wd) then
		return ""
	end

	local only_pid = options.only_pid
	if isvalid(only_pid) and only_pid:upper():sub(1, 1) == "P" and options.property ~= options.only_pid then
		return ""
	end

	-- إيجاد qid
	if not isvalid(options.entityId) then
		if isvalid(options.page) then
			options.entityId = mw.wikibase.getEntityIdForTitle(options.page)
		else
			options.entityId = mw.wikibase.getEntityIdForCurrentPage()
		end
	end

	if not isvalid(options.property) or not isvalid(options.entityId) then
		return ""
	end

	options.NosValue = options.NoPropValue
	options.showlang = "t"

	options = parseArgs(options)
	options = AddArgs(options)

	local sandbox = isvalid(options.use_sandbox) and "/چنگ‌مویی" or ""
	
	local wd2_from_lua = require('Module:Wikidata2' .. sandbox).formatStatementsFromLua
	
	local result, length = wd2_from_lua(options)
	
	if isvalid(options.returnnumberofvalues) or options.returnnumberofvalues == true then
		return result, length
	end
	return result
end

return p