Modül:Dolaşım - Vikipedi

Modül belgelemesi[gör] [değiştir] [geçmiş] [temizle]
local p = {}  local navbar = require('Modül:Dolçub')._navbar local cfg = mw.loadData('Modül:Dolaşım/yapılandırma') local getArgs -- lazily initialized  local args local border local listnums local ODD_EVEN_MARKER = '\127_ODDEVEN_\127' local RESTART_MARKER = '\127_ODDEVEN0_\127' local REGEX_MARKER = '\127_ODDEVEN(%d?)_\127'  local function striped(wikitext) 	-- Return wikitext with markers replaced for odd/even striping. 	-- Child (subgroup) navboxes are flagged with a category that is removed 	-- by parent navboxes. The result is that the category shows all pages 	-- where a child navbox is not contained in a parent navbox. 	local orphanCat = '[[Kategori:Navbox orphans]]' 	if border == 'subgroup' and args.sahipsiz ~= 'yes' then 		-- No change; striping occurs in outermost navbox. 		return wikitext .. orphanCat 	end 	local first, second = 'odd', 'even' 	if args['çifttek'] then 		if args['çifttek'] == 'swap' then 			first, second = second, first 		else 			first = args['çifttek'] 			second = first 		end 	end 	local changer 	if first == second then 		changer = first 	else 		local index = 0 		changer = function (code) 			if code == '0' then 				-- Current occurrence is for a group before a nested table. 				-- Set it to first as a valid although pointless class. 				-- The next occurrence will be the first row after a title 				-- in a subgroup and will also be first. 				index = 0 				return first 			end 			index = index + 1 			return index % 2 == 1 and first or second 		end 	end 	local regex = orphanCat:gsub('([%[%]])', '%%%1') 	return (wikitext:gsub(regex, ''):gsub(REGEX_MARKER, changer))  -- () omits gsub count end  local function processItem(item, nowrapitems) 	if item:sub(1, 2) == '{|' then 		-- Applying nowrap to lines in a table does not make sense. 		-- Add newlines to compensate for trim of x in |parm=x in a template. 		return '\n' .. item ..'\n' 	end 	if nowrapitems == 'yes' or nowrapitems == 'evet' then 		local lines = {} 		for line in (item .. '\n'):gmatch('([^\n]*)\n') do 			local prefix, content = line:match('^([*:;#]+)%s*(.*)') 			if prefix and not content:match('^<span class="nowrap">') then 				line = prefix .. '<span class="nowrap">' .. content .. '</span>' 			end 			table.insert(lines, line) 		end 		item = table.concat(lines, '\n') 	end 	if item:match('^[*:;#]') then 		return '\n' .. item ..'\n' 	end 	return item end  local function renderNavBar(titleCell)  	if args['dolçub'] ~= 'kapalı' and args['dolçub'] ~= 'sade' and not (not args.ad and mw.getCurrentFrame():getParent():getTitle():gsub('/test$', '') == 'Şablon:Dolaşım') then 		titleCell:wikitext(navbar{ 			args.ad, 			mini = 1, 			fontstyle = (args['temelbiçim'] or '') .. ';' .. (args['başlıkbiçimi'] or '') .. ';background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none; padding:0;' 		}) 	end  end  -- --   Title row -- local function renderTitleRow(tbl) 	if not args['başlık'] then return end  	local titleRow = tbl:tag('tr')  	if args['başlıkgrubu'] then 		titleRow 			:tag('th') 				:attr('scope', 'row') 				:addClass('navbox-group')                 :addClass(args['başlıkgrubusınıfı'])                 :cssText(args['temelbiçim'])                 :cssText(args['grupbiçimi'])                 :cssText(args['başlıkgrububiçimi'])                 :wikitext(args['başlıkgrubu']) 	end  	local titleCell = titleRow:tag('th'):attr('scope', 'col')  	if args['başlıkgrubu'] then 		titleCell 			:css('border-left', '2px solid #fdfdfd') 			:css('width', '100%') 	end  	local titleColspan = 2     if args.resimsol then titleColspan = titleColspan + 1 end     if args.resim then titleColspan = titleColspan + 1 end     if args['başlıkgrubu'] then titleColspan = titleColspan - 1 end  	titleCell         :cssText(args['temelbiçim'])         :cssText(args['başlıkbiçimi']) 		:addClass('navbox-title') 		:attr('colspan', titleColspan)  	renderNavBar(titleCell)  	titleCell 		:tag('div') 			-- id for aria-labelledby attribute 			:attr('id', mw.uri.anchorEncode(args['başlık'])) 			:addClass(args['başlıksınıfı']) 			:css('font-size', '114%') 			:css('margin', '0 4em') 			:wikitext(processItem(args['başlık'])) end  -- --   Above/Below rows --  local function getAboveBelowColspan() 	local ret = 2     if args.resimsol then ret = ret + 1 end     if args.resim then ret = ret + 1 end 	return ret end  local function renderAboveRow(tbl) 	if not args['üst'] then return end  	tbl:tag('tr') 		:tag('td') 			:addClass('navbox-abovebelow')             :addClass(args['üstsınıf'])             :cssText(args['temelbiçim'])             :cssText(args['üstbiçim']) 			:attr('colspan', getAboveBelowColspan()) 			:tag('div') 				-- id for aria-labelledby attribute, if no title 				:attr('id', args['başlık'] and nil or mw.uri.anchorEncode(args['üst'])) 				:wikitext(processItem(args['üst'], args.nesnelerikesme)) end  local function renderBelowRow(tbl) 	if not args.alt then return end  	tbl:tag('tr') 		:tag('td') 			:addClass('navbox-abovebelow')             :addClass(args['altsınıf'])             :cssText(args['temelbiçim'])             :cssText(args['altbiçim']) 			:attr('colspan', getAboveBelowColspan()) 			:tag('div') 				:wikitext(processItem(args['alt'], args.nesnelerikesme)) end  -- --   List rows -- local function renderListRow(tbl, index, listnum) 	local row = tbl:tag('tr')  	if index == 1 and args.resimsol then 		row 			:tag('td') 				:addClass('navbox-image')                 :addClass(args['resimsınıfı']) 				:css('width', '1px')               -- Minimize width 				:css('padding', '0px 2px 0px 0px')                 :cssText(args['resimsolbiçimi']) 				:attr('rowspan', #listnums) 				:tag('div') 					:wikitext(processItem(args.resimsol)) 	end  	if args['grup' .. listnum] then 		local groupCell = row:tag('th')  		-- id for aria-labelledby attribute, if lone group with no title or above 		if listnum == 1 and not (args['başlık'] or args['üst'] or args.grup2) then 			groupCell 				:attr('id', mw.uri.anchorEncode(args.grup1)) 		end  		groupCell 			:attr('scope', 'row') 			:addClass('navbox-group')             :addClass(args['grupsınıfı'])             :cssText(args['temelbiçim']) 			:css('width', args['grupgenişliği'] or '1%') -- If groupwidth not specified, minimize width  		groupCell             :cssText(args['grupbiçimi']) 			:cssText(args['grup' .. listnum .. 'biçimi']) 			:wikitext(args['grup' .. listnum]) 	end  	local listCell = row:tag('td')  	if args['grup' .. listnum] then 		listCell 			:css('text-align', 'left') 			:css('border-left-width', '2px') 			:css('border-left-style', 'solid') 	else 		listCell:attr('colspan', 2) 	end  	if not args['grupgenişliği'] then 		listCell:css('width', '100%') 	end  	local rowstyle  -- usually nil so cssText(rowstyle) usually adds nothing 	if index % 2 == 1 then 		rowstyle = args['tekbiçim'] 	else 		rowstyle = args['çiftbiçim'] 	end  	local listText = args['liste' .. listnum] 	local oddEven = ODD_EVEN_MARKER 	if listText:sub(1, 12) == '</div><table' then 		-- Assume list text is for a subgroup navbox so no automatic striping for this row. 		oddEven = listText:find('<th[^>]*"navbox%-title"') and RESTART_MARKER or 'odd' 	end 	listCell 		:css('padding', '0px')         :cssText(args['listebiçimi']) 		:cssText(rowstyle)         :cssText(args['liste' .. listnum .. 'biçimi']) 		:addClass('navbox-list') 		:addClass('navbox-' .. oddEven)         :addClass(args['listesınıfı']) 		:addClass(args['liste' .. listnum .. 'sınıfı']) 		:tag('div') 			:css('padding', (index == 1 and args.liste1dolgusu) or args.listedolgusu or '0em 0.25em') 			:wikitext(processItem(listText, args.nesnelerikesme))  	if index == 1 and args.resim then 		row 			:tag('td') 				:addClass('navbox-image')                 :addClass(args['resimsınıfı']) 				:css('width', '1px')               -- Minimize width 				:css('padding', '0px 0px 0px 2px')                 :cssText(args['resimbiçimi']) 				:attr('rowspan', #listnums) 				:tag('div') 					:wikitext(processItem(args.resim)) 	end end   -- --   Tracking categories --  local function needsHorizontalLists() 	if border == 'subgroup' or args.izleme == 'no' then 		return false 	end 	local listClasses = { 		['plainlist'] = true, ['hlist'] = true, ['hlist hnum'] = true, 		['hlist hwrap'] = true, ['hlist vcard'] = true, ['vcard hlist'] = true, 		['hlist vevent'] = true, 	} 	return not (listClasses[args['listesınıfı']] or listClasses[args['gövdesınıfı']]) end  local function hasBackgroundColors() 	for _, key in ipairs({'başlıkbiçimi', 'grupbiçimi', 'temelbiçim', 'üstbiçim', 'altbiçim'}) do 		if tostring(args[key]):find('background', 1, true) then 			return true 		end 	end end  local function hasBorders() 	for _, key in ipairs({'grupbiçimi', 'temelbiçim', 'üstbiçim', 'altbiçim'}) do 		if tostring(args[key]):find('border', 1, true) then 			return true 		end 	end end  local function isIllegible() 	local styleratio = require('Modül:Color contrast')._styleratio  	for key, style in pairs(args) do 		if tostring(key):match("biçim$") or tostring(key):match("biçimi$") then 			if styleratio{mw.text.unstripNoWiki(style)} < 4.5 then 				return true 			end 		end 	end 	return false end  local function getTrackingCategories() 	local cats = {} 	if needsHorizontalLists() then table.insert(cats, 'Yatay listesi olmayan dolaşım şablonları') end 	if hasBackgroundColors() then table.insert(cats, 'Arkaplan rengi kullanan dolaşım şablonları') end 	--if isIllegible() then table.insert(cats, 'Muhtemel okunaksız dolaşım şablonları') end 	if hasBorders() then table.insert(cats, 'Kenar kalınlığı kullanan dolaşım şablonları') end 	return cats end  local function renderTrackingCategories(builder) 	local title = mw.title.getCurrentTitle() 	if title.namespace ~= 10 then return end -- not in template space 	local subpage = title.subpageText 	if subpage == 'belge' or subpage == 'deneme' or subpage == 'test' then return end  	for _, cat in ipairs(getTrackingCategories()) do 		builder:wikitext('[[Kategori:' .. cat .. ']]') 	end end  -- --   Main navbox tables -- local function renderMainTable() 	local tbl = mw.html.create('table') 		:addClass('nowraplinks') 		:addClass(args['gövdesınıfı'])  	local durum = args.durum or 'autocollapse' 	if durum == 'daraltılmış' then durum = 'collapsed' 	elseif durum == 'daraltılmamış' then durum = 'uncollapsed' 	elseif durum == 'genişletilmiş' then durum = 'expanded' 	elseif durum == 'otodaralt' then durum = 'autocollapse' 	end  	if args['başlık'] and (durum ~= 'plain' and durum ~= 'off') then 		tbl 			:addClass('collapsible') 			:addClass(durum or 'autocollapse') 	end  	tbl:css('border-spacing', 0) 	if border == 'subgroup' or border == 'none' then 		tbl 			:addClass('navbox-subgroup') 			:cssText(args['gövdebiçimi']) 			:cssText(args['biçim']) 	else  -- regular navbox - bodystyle and style will be applied to the wrapper table 		tbl 			:addClass('navbox-inner') 			:css('background', 'transparent') 			:css('color', 'inherit') 	end 	tbl:cssText(args['içbiçim'])  	renderTitleRow(tbl) 	renderAboveRow(tbl) 	for i, listnum in ipairs(listnums) do 		renderListRow(tbl, i, listnum) 	end 	renderBelowRow(tbl)  	return tbl end  function p._navbox(navboxArgs) 	args = navboxArgs 	listnums = {}  	for k, _ in pairs(args) do 		if type(k) == 'string' then 			local listnum = k:match('^liste(%d+)$') 			if listnum then table.insert(listnums, tonumber(listnum)) end 		end 	end 	table.sort(listnums)  	border = mw.text.trim(args.kenar or args[1] or '') 	if border == 'child' then 		border = 'subgroup' 	end  	-- render the main body of the navbox 	local tbl = renderMainTable()  	-- render the appropriate wrapper around the navbox, depending on the border param 	local res = mw.html.create() 	if border == 'none' then 		local nav = res:tag('div') 			:attr('role', 'navigation') 			:node(tbl) 		-- aria-labelledby title, otherwise above, otherwise lone group 		if args['başlık'] or args['üst'] or (args.grup1 and not args.grup2) then 			nav:attr('aria-labelledby', mw.uri.anchorEncode(args['başlık'] or args['üst'] or args.grup1)) 		else 			nav:attr('aria-label', 'Navbox') 		end 	elseif border == 'subgroup' then 		-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is 		-- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the 		-- padding being applied, and at the end add a <div> to balance out the parent's </div> 		res 			:wikitext('</div>') 			:node(tbl) 			:wikitext('<div>') 	else 		local nav = res:tag('div') 			:attr('role', 'navigation') 			:addClass('navbox') 			:addClass(args['dolaşımsınıfı']) 			:cssText(args['gövdebiçimi']) 			:cssText(args['biçim']) 			:css('padding', '3px') 			:node(tbl) 		-- aria-labelledby title, otherwise above, otherwise lone group 		if args['başlık'] or args['üst'] or (args.grup1 and not args.grup2) then 			nav:attr('aria-labelledby', mw.uri.anchorEncode(args['başlık'] or args['üst'] or args.grup1)) 		else 			nav:attr('aria-label', 'Navbox') 		end 	end  	if (args.katyok or 'false'):lower() == 'false' then 		renderTrackingCategories(res) 	end 	return striped(tostring(res)) end  function p.navbox(frame) 	if not getArgs then 		getArgs = require('Modül:Arguments').getArgs 	end 	args = getArgs(frame, {wrappers = {'Şablon:Dolaşım'}}) 	if frame.args.kenar then 		-- This allows Template:Navbox_subgroup to use {{#invoke:Navbox|navbox|border=...}}. 		args.kenar = frame.args.kenar 	end  	-- Read the arguments in the order they'll be output in, to make references number in the right order. 	local _ 	_ = args['başlık'] 	_ = args['üst'] 	for i = 1, 20 do 		_ = args["grup" .. tostring(i)] 		_ = args["liste" .. tostring(i)] 	end 	_ = args.alt  	return p._navbox(args) end  return p