For faster navigation, this Iframe is preloading the Wikiwand page for وحدة:صندوق مستخدم.

وحدة:صندوق مستخدم

-- This module implements ((صندوق مستخدم)).

local categoryHandler = require('Module:Category handler').main

local p = {}

--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------

local function checkNum(val, default)
	-- Checks whether a value is a number greater than or equal to zero. If so,
	-- returns it as a number. If not, returns a default value.
	val = tonumber(val)
	if val and val >= 0 then
		return val
	else
		return default
	end
end

local function addSuffix(num, suffix)
	-- Turns a number into a string and adds a suffix.
	if num then
		return tostring(num) .. suffix
	else
		return nil
	end
end

local function checkNumAndAddSuffix(num, default, suffix)
	-- Checks a value with checkNum and adds a suffix.
	num = checkNum(num, default)
	return addSuffix(num, suffix)
end

local function makeCat(cat, sort)
	-- Makes a category link.
	if sort then
		return mw.ustring.format('[[تصنيف:%s|%s]]', cat, sort)
	else
		return mw.ustring.format('[[تصنيف:%s]]', cat)
	end
end

--------------------------------------------------------------------------------
-- Argument processing
--------------------------------------------------------------------------------

local function makeInvokeFunc(funcName)
	return function (frame)
		local origArgs = require('Module:Arguments').getArgs(frame)
		local args = {}
		for k, v in pairs(origArgs) do
			args[k] = v
		end
		return p.main(funcName, args)
	end
end

p.userbox = makeInvokeFunc('_userbox')
p['userbox-2'] = makeInvokeFunc('_userbox-2')
p['userbox-r'] = makeInvokeFunc('_userbox-r')

--------------------------------------------------------------------------------
-- Main functions
--------------------------------------------------------------------------------

function p.main(funcName, args)
	local userboxData = p[funcName](args)
	local userbox = p.render(userboxData)
	local cats = p.categories(args)
	return userbox .. (cats or '')
end

function p._userbox(args)
	-- Does argument processing for ((userbox)).
	local data = {}

	-- Get div tag values.
	data.float = args.float or 'left'
	local borderWidthNum = checkNum(args['border-width'] or args['border-s'] or args['سمك الحدود'], 1) -- Used to calculate width.
	data.borderWidth = addSuffix(borderWidthNum, 'px')
	data.borderColor = args['border-color'] or args['لون الحدود'] or args['border-c'] or args[1] or args['id-c'] or '#999'
	data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag.
	data.bodyClass = args.bodyclass

	-- Get table tag values.
	data.backgroundColor = args['info-background'] or args[2] or args['info-c'] or args['لون خلفية النص'] or '#eee'

	-- Get info values.
	data.info = args.info or args[4] or args['info'] or args['النص'] or "<code>(({النص))}</code>"
	data.infoTextAlign = args['info-a'] or args['info-a'] or args['موضع النص'] or 'right'
	data.infoFontSize = checkNumAndAddSuffix(args['info-size'] or args['info-s'] or args['حجم خط النص'], 10, 'pt')
	data.infoHeight = checkNumAndAddSuffix(args['logo-height'] or args['id-h'] or args['ارتفاع الصورة'], 45, 'px')
	data.infoPadding = args['info-padding'] or args['info-p'] or args['حشوة النص'] or '0 4px 0 4px'
	data.infoLineHeight = args['info-line-height'] or args['المسافة بين الأسطر'] or args['المسافة بين أسطر النص'] or args['info-lh'] or '1.25em'
	data.infoColor = args['info-color'] or args['info-fc'] or args['لون النص'] or 'black'
	data.infoOtherParams = args['info-other-param'] or args['info-op'] or args['إعدادات أخرى للنص']
	data.infoClass = args['info-class'] or args['فئة النص']

	-- Get id values.
	local id = args.logo or args['الصورة'] or args[3] or args.id
	data.id = id
	data.showId = id and true or false
	data.idWidth = checkNumAndAddSuffix(args['logo-width'] or args['id-w'] or args['عرض الصورة'], 45, 'px')
	data.idHeight = checkNumAndAddSuffix(args['logo-height'] or args['id-h'] or args['ارتفاع الصورة'], 45, 'px')
	data.idBackgroundColor = args['logo-background'] or args[1] or args['id-c'] or args['لون خلفية الصورة'] or '#ddd'
	data.idTextAlign = args['id-a'] or args['موضع الصورة'] or 'center'
	data.idFontSize = checkNum(args['logo-size'] or args[5] or args['id-s'] or args['حجم خط الصورة'], 14)
	data.idColor = args['logo-color'] or args['id-fc'] or args['id-fc'] or args['لون الصورة'] or data.infoColor
	data.idPadding = args['logo-padding'] or args['id-p'] or args['حشوة الصورة'] or '0 1px 0 0'
	data.idLineHeight = args['logo-line-height'] or args['id-lh'] or args['المسافة بين أسطر الصورة'] or '1.25em'
	data.idOtherParams = args['logo-other-param'] or args['id-op'] or args['إعدادات أخرى للصورة']
	data.idClass = args['id-class'] or args['فئة الصورة']

	return data
end

p['_userbox-2'] = function (args)
	-- Does argument processing for ((userbox-2)).
	local data = {}

	-- Get div tag values.
	data.float = args.float or 'left'
	local borderWidthNum = checkNum(args['border-s'] or args[9] or args['سمك الحدود'], 1) -- Used to calculate width.
	data.borderWidth = addSuffix(borderWidthNum, 'px')
	data.borderColor = args['border-c'] or args[6] or args['لون الحدود'] or args['id1-c'] or args[1] or '#999999'
	data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag.
	data.bodyClass = args.bodyclass or args['فئة الصندوق']

	-- Get table tag values.
	data.backgroundColor = args['info-c'] or args[2] or args['لون خلفية النص'] or '#eeeeee'

	-- Get info values.
	data.info = args.info or args[4] or args['info'] or args['النص'] or "<code>(({النص))}</code>"
	data.infoTextAlign = args['info-a'] or args['موضع النص'] or 'right'
	data.infoFontSize = checkNumAndAddSuffix(args['info-s'] or args['حجم خط النص'], 10, 'pt')
	data.infoColor = args['info-fc'] or args[8] or args['لون النص'] or 'black'
	data.infoPadding = args['info-p'] or args['حشوة النص'] or '0 4px 0 4px'
	data.infoLineHeight = args['info-lh'] or args['المسافة بين أسطر النص'] or args['المسافة بين الأسطر'] or '1.25em'
	data.infoOtherParams = args['info-op'] or args['إعدادات أخرى للنص']

	-- Get id values.
	data.showId = true
	data.id = args.logo or args[3] or args['الصورة'] or args['الصورة 1'] or args.id1 or 'id1'
	data.idWidth = checkNumAndAddSuffix(args['id1-w'] or args['عرض الصورة 1'] or args['عرض الصورة'], 45, 'px')
	data.idHeight = checkNumAndAddSuffix(args['id-h'] or args['ارتفاع الصورة'] or args['ارتفاع الصورة 1'], 45, 'px')
	data.idBackgroundColor = args['id1-c'] or args[1] or args['لون خلفية الصورة'] or args['لون خلفية الصورة 1'] or '#dddddd'
	data.idTextAlign = 'center'
	data.idFontSize = checkNum(args['id1-s'] or args['حجم خط الصورة'] or args['حجم خط الصورة 1'], 14)
	data.idLineHeight = args['id1-lh'] or args['المسافة بين أسطر الصورة'] or args['المسافة بين أسطر الصورة 1'] or '1.25em'
	data.idColor = args['id1-fc'] or args['لون الصورة'] or args['لون الصورة 1'] or data.infoColor
	data.idPadding = args['id1-p'] or args['حشوة الصورة 1'] or args['حشوة الصورة'] or '0 1px 0 0'
	data.idOtherParams = args['id1-op'] or args['إعدادات أخرى للصورة'] or args['إعدادات أخرى للصورة 1']

	-- Get id2 values.
	data.showId2 = true
	data.id2 = args.logo or args[5] or args['الصورة 2'] or args.id2 or 'id2'
	data.id2Width = checkNumAndAddSuffix(args['id2-w'] or args['عرض الصورة 2'], 45, 'px')
	data.id2Height = data.idHeight or args['ارتفاع الصورة 2']
	data.id2BackgroundColor = args['id2-c'] or args[7] or args[1] or args['لون خلفية الصورة 2'] or '#dddddd'
	data.id2TextAlign = 'center'
	data.id2FontSize = checkNum(args['id2-s'] or args['حجم خط الصورة 2'], 14)
	data.id2LineHeight = args['id2-lh'] or args['المسافة بين أسطر الصورة 2'] or '1.25em'
	data.id2Color = args['id2-fc'] or args['لون الصورة 2'] or data.infoColor
	data.id2Padding = args['id2-p'] or args['حشوة الصورة 2'] or '0 0 0 1px'
	data.id2OtherParams = args['id2-op'] or args['إعدادات أخرى للصورة 2']

	return data
end

p['_userbox-r'] = function (args)
	-- Does argument processing for ((userbox-r)).
	local data = {}

	-- Get div tag values.
	data.float = args.float or 'left'
	local borderWidthNum = checkNum(args['border-width'] or args['border-s'] or args['سمك الحدود'], 1) -- Used to calculate width.
	data.borderWidth = addSuffix(borderWidthNum, 'px')
	data.borderColor = args['border-color'] or args['لون الحدود'] or args['border-c'] or args[1] or args['id-c'] or '#999'
	data.width = addSuffix(240 - 2 * borderWidthNum, 'px') -- Also used in the table tag.
	data.bodyClass = args.bodyclass or args['فئة الصندوق']
	
	-- Get table tag values.
	data.backgroundColor = args['info-background'] or args[2] or args['لون خلفية النص'] or args['info-c'] or '#eee'

	-- Get id values.
	data.showId = false -- We only show id2 in userbox-r.

	-- Get info values.
	data.info = args.info or args[4] or args['info'] or args['النص'] or "<code>(({النص))}</code>"
	data.infoTextAlign = args['info-align'] or args['info-a'] or args['موضع النص'] or 'right'
	data.infoFontSize = checkNumAndAddSuffix(args['info-size'] or args['info-s'] or args['حجم خط النص'], 10, 'pt')
	data.infoPadding = args['info-padding'] or args['info-p'] or args['حشوة النص'] or '0 4px 0 4px'
	data.infoLineHeight = args['info-line-height'] or args['info-lh'] or args['المسافة بين أسطر النص'] or '1.25em'
	data.infoColor = args['info-color'] or args['لون النص'] or args['info-fc'] or 'black'
	data.infoOtherParams = args['info-other-param'] or args['info-op'] or args['إعدادات أخرى للنص']
	
	-- Get id2 values.
	data.showId2 = true
	data.id2 = args.logo or args['الصورة'] or args['صورة'] or args[3] or args.id or 'id'
	data.id2Width = checkNumAndAddSuffix(args['logo-width'] or args['عرض الصورة'] or args['id-w'], 45, 'px')
	data.id2Height = checkNumAndAddSuffix(args['logo-height'] or args['ارتفاع الصورة'] or args['id-h'], 45, 'px')
	data.id2BackgroundColor = args['logo-background'] or args['لون خلفية الصورة'] or args[1] or args['id-c'] or '#ddd'
	data.id2TextAlign = args['id-a'] or args['موضع الصورة'] or 'center'
	data.id2FontSize = checkNum(args['logo-size'] or args['حجم خط الصورة'] or args[5] or args['id-s'], 14)
	data.id2Color = args['logo-color'] or args['id-fc'] or args['لون الصورة'] or data.infoColor
	data.id2Padding = args['logo-padding'] or args['حشوة الصورة'] or args['id-p'] or '0 0 0 1px'
	data.id2LineHeight = args['logo-line-height'] or args['المسافة بين أسطر الصورة'] or args['id-lh'] or '1.25em'
	data.id2OtherParams = args['logo-other-param'] or args['id-op'] or args['إعدادات أخرى للصورة']

	return data
end

function p.render(data)
	-- Renders the userbox html using the content of the data table. 
	-- Render the div tag html.
	local root = mw.html.create('div')
	root
		:css('float', data.float)
		:css('border', (data.borderWidth or '') .. ' solid ' .. (data.borderColor or ''))
		:css('margin', '1px')
		:css('width', data.width)
		:addClass('wikipediauserbox')
		:addClass(data.bodyClass)

	-- Render the table tag html.
	local tableroot = root:tag('table')
	tableroot
		:attr('role', 'presentation')
		:css('border-collapse', 'collapse')
		:css('width', data.width)
		:css('margin-bottom', '0')
		:css('margin-top', '0')
		:css('background', data.backgroundColor)
	
	-- Render the id html.
	local tablerow = tableroot:tag('tr')
	if data.showId then
		tablerow:tag('td')
			:css('border', '0')
			:css('width', data.idWidth)
			:css('height', data.idHeight)
			:css('background', data.idBackgroundColor)
			:css('text-align', data.idTextAlign)
			:css('font-size', data.idFontSize .. 'pt')
			:css('font-weight', 'bold')
			:css('color', data.idColor)
			:css('padding', data.idPadding)
			:css('line-height', data.idLineHeight)
			:css('vertical-align', 'middle')
			:cssText(data.idOtherParams)
			:addClass(data.idClass)
			:wikitext(data.id)
	end

	-- Render the info html.
	tablerow:tag('td')
		:css('border', '0')
		:css('text-align', data.infoTextAlign)
		:css('font-size', data.infoFontSize)
		:css('padding', data.infoPadding)
		:css('height', data.infoHeight)
		:css('line-height', data.infoLineHeight)
		:css('color', data.infoColor)
		:css('vertical-align', 'middle')
		:cssText(data.infoOtherParams)
		:addClass(data.infoClass)
		:wikitext(data.info)
	
	-- Render the second id html.
	if data.showId2 then
		tablerow:tag('td')
			:css('border', '0')
			:css('width', data.id2Width)
			:css('height', data.id2Height)
			:css('background', data.id2BackgroundColor)
			:css('text-align', data.id2TextAlign)
			:css('font-size', data.id2FontSize .. 'pt')
			:css('font-weight', 'bold')
			:css('color', data.id2Color)
			:css('padding', data.id2Padding)
			:css('line-height', data.id2LineHeight)
			:css('vertical-align', 'middle')
			:cssText(data.id2OtherParams)
			:wikitext(data.id2)
	end

	local title = mw.title.getCurrentTitle()
	if (title.namespace == 2) and not title.text:match("/") then
		return tostring(root) -- regular user page
	elseif title.namespace == 14 then
		return tostring(root) -- category
	elseif title.isTalkPage then
		return tostring(root) -- talk page
	end

	local legible = true
	local contrast = require('Module:Color contrast')._ratio

	local function has_text(wikitext)
		wikitext = wikitext:gsub("]]", "|]]")
		wikitext = wikitext:gsub("%[%[%s*[Mm][Ee][Dd][Ii][Aa]%s*:[^|]-(|.-)]]", "")
		wikitext = wikitext:gsub("%[%[%s*[Ii][Mm][Aa][Gg][Ee]%s*:[^|]-(|.-)]]", "")
		wikitext = wikitext:gsub("%[%[%s*[Ff][Ii][Ll][Ee]%s*:[^|]-(|.-)]]", "")
		return mw.text.trim(wikitext) ~= ""
	end

	if contrast { data.infoColor, data.backgroundColor, error = 0 } < 4.5 then
		legible = false
	end

	-- For bold text >= 14pt, requirement is only 3.
	local idContrastThreshold = 4.5
	local id2ContrastThreshold = 4.5
	if (data.idFontSize or 0) >= 14 then
		idContrastThreshold = 3
	end
	if (data.id2FontSize or 0) >= 14 then
		id2ContrastThreshold = 3
	end
	
	if data.showId and contrast { data.idColor, data.idBackgroundColor, error = 0 } < idContrastThreshold then
		if has_text(data.id or "") then
			legible = false
		end
	end

	if data.showId2 and contrast { data.id2Color, data.id2BackgroundColor, error = 0 } < id2ContrastThreshold then
		if has_text(data.id2 or "") then
			legible = false
		end
	end

	if not legible then
		root:wikitext('[[تصنيف:صناديق مستخدم مع تباين ألوان ضعيف]]')
	end

	return tostring(root)
end

function p.categories(args, page)
	-- Gets categories from [[Module:Category handler]].
	-- The page parameter makes the function act as though the module was being called from that page.
	-- It is included for testing purposes.
	local cats = {}
	cats[#cats + 1] = args.usercategory  or args['تصنيف مستخدم']
	cats[#cats + 1] = args.usercategory2 or args['تصنيف مستخدم 2']
	cats[#cats + 1] = args.usercategory3 or args['تصنيف مستخدم 3']
	cats[#cats + 1] = args.usercategory4 or args['تصنيف مستخدم 4']
	cats[#cats + 1] = args.usercategory5 or args['تصنيف مستخدم 5']
	-- Get the title object
	local title
	if page then
		title = mw.title.new(page)
	else
		title = mw.title.getCurrentTitle()
	end
	-- Build category handler arguments.
	local chargs = {}
	chargs.page = page
	chargs.nocat = args.nocat or args['لا تصنيف']
	chargs.main = '[[تصنيف:صفحات بها قوالب في نطاق خاطئ]]'
	if args.notcatsubpages then
		chargs.subpage = 'no'
	end
	-- User namespace.
	local user = ''
	for i, cat in ipairs(cats) do
		user = user .. makeCat(cat)
	end
	chargs.user = user
	-- Template namespace.
	local basepage = title.baseText
	local template = ''
	for i, cat in ipairs(cats) do
		template = template .. makeCat(cat, ' ' .. basepage)
	end
	chargs.template = template
	return categoryHandler(chargs)
end

return p
{{bottomLinkPreText}} {{bottomLinkText}}
وحدة:صندوق مستخدم
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?