Modul:Banner shell

Ji Wîkîpediya, ensîklopediya azad.

Usage[çavkaniyê biguhêre]

This module implements Template:WikiProject banner shell. Please refer to that template's documentation.

local p = {}

local DuplicateBanners = function(text)
	local capture = '<span class="wpb%-project">([%w%s]*)</span>'
	local banners = {}
	for project in text:gmatch(capture) do
		if banners[project] == true then
			return project
		end
		banners[project] = true
	end
end

p.main = function(frame)
	local args = require('Modul:Arguments').getArgs(frame, {
		wrappers = {'Şablon:Kalika wîkîprojeyê'}
	})
	local title = args.demo_page and mw.title.new(args.demo_page) or mw.title.getCurrentTitle()
	local pagetype = require('Modul:Pagetype')._main{
		page = title.prefixedText,
		[1] = args.sinif,
		dab = 'cudakirin',
		defaultns = 'extended'
	}
	local classmask = require('Modul:Class mask')
	local class = pagetype=='gotar' and (args.sinif) or ''
	class = classmask._main({class}, title.talkPageTitle)
	local yesno = require('Modul:Yesno')
	local demo = not yesno(args.category or true, true) or args.demo_page
	local out = {}
	local addCategory
	addCategory = function(category, sort_key)
		if not demo and title.isTalkPage then
			local category_title = mw.title.new('Category:' .. category)
				table.insert(out, '[[' .. category_title.prefixedText .. 
					(sort_key and ('|' .. sort_key) or '') ..
					']]')

		end
	end
	if demo and not args.demo_page then
		pagetype = 'gotar'
	end
	if yesno(args.blp) or yesno(args.living) then
		table.insert(out,frame:expandTemplate{title = 'BLP'})
	elseif yesno(args.blpo) then
		table.insert(out,frame:expandTemplate{title = 'BLP others'})
	end
	if yesno(args.activepol) then
		table.insert(out, frame:expandTemplate{title = 'Active politician'})
	end
	local banner_args = {
		templatestyles = 'WikiProject banner shell/styles.css',
		collapsed = args.collapsed,
		class = 'wpbs',
	}
	if class=='' then -- check if class parameters are defined by any project banner
		local articleclass = require('Modul:WikiProject banner').readarticleclass(
			{ignore_blank = true, only_subtemplates = true},
			title.talkPageTitle.prefixedText
		)
		if articleclass~='' then -- class parameters is defined by one or more project banners
			class = nil -- no global assessment
			local raw_args = require('Modul:Arguments').getArgs(frame, {
				wrappers = {'Şablon:WikiProject banner shell'},
				removeBlanks = false
			})
			if raw_args.sinif and pagetype=='gotar' then
				addCategory('Articles using WikiProject banner shell with empty class parameter')
			end
		end
	end
	local class2 = class and class~='' and ('sinifa ' ..class) or 'Nesinifandî'
	local text, vital
	local icon_class = 'council'
	if yesno(args["bingehîn"]) then
						
		local page = mw.ustring.upper(mw.ustring.sub(title.subjectPageTitle.text, 1, 1)) -- get first letter of article name
		
		-- Define the Kurdish alphabet including special characters
		local kurdish_alphabet = "ABCÇDEÊFGHIÎJKLMNOPQRSŞTUÛVWXYZÇÊÎÛ"
		
		-- Check if the first letter is within the Kurdish alphabet
		if not string.find(kurdish_alphabet, page, 1, true) then
		    page = 'yên din' -- Use "Yên din" for letters not in the Kurdish alphabet
		end


		local data_page = mw.title.new('Wîkîpediya:Gotarên bingehîn/dane/' .. page .. '.json')
		if data_page.exists then
			local index = title.subjectPageTitle.text
			index = tostring(tonumber(index))==index and tonumber(index) or index --convert to number if page is numerical, otherwise loadJsonData does not work
			local data = mw.loadJsonData(data_page.fullText)[index]
			if data then
				local level = tostring(data.level)
				if level then
					local link = 'Wîkîpediya:Gotarên bingehîn'
					if level~='3' then
						link = link .. '/Level/' .. level
					end
					if (level=='4' or level=='5') and data.topic then
						link = link .. '/' .. data.topic
					end
					if data.sublist then
						link = link .. '/' .. data.sublist
					end
					
					if data.section then
					    -- Replace space characters with underscores
					    local section = string.gsub(data.section, " ", "_")
					    link = link .. '#' .. section
					end
					
					if not mw.title.new(link).exists then -- add tracking category if link does not exist
						addCategory('Gotarên bingehîn ên Wîkîpediyayê bi xeletiyê', 'L')
					end
					vital = 'Ev [[File:Círculos Concéntricos.svg|16px|link=|alt=]]&nbsp;<b>[[' .. link .. '|level-' .. level .. ' gotara bingehîn]]</b> '
				end
				local vitalCat = function(cat, valid_class, valid_level, valid_topic)
					if (not valid_class or (class~='NA' and class and class~=''))
						and (not valid_level or level~=nil)
						and (not valid_topic or data.topic) then
						local category = cat:gsub('_CLASS', class2)
							:gsub('_LEVEL', level or 'unknown')
							:gsub('_TOPIC', data.topic or 'an unknown topic')
						addCategory(category)
					else
						addCategory('Gotarên bingehîn ên Wîkîpediyayê bi xeletiyê', 'P')
					end
				end
				if (class == "") then
					addCategory('Gotarên bingehîn ên nehatine sinifandin', 'N')
					vitalCat('Gotarên bingehîn ên nehatine sinifandin bi level _LEVEL')
					vitalCat('Gotarên bingehîn ên Wîkîpediyayê bi level _LEVEL')
				else
					vitalCat('Gotarên bingehîn ên Wîkîpediyayê bi _CLASS')
					vitalCat('Gotarên bi _CLASS')
					vitalCat('Hemû Gotarên Wîkîprojeyan')
					vitalCat('Gotarên bingehîn ên Wîkîpediyayê bi level _LEVEL')
					vitalCat('Gotarên bingehîn ên Wîkîpediyayê bi level _LEVEL û _CLASS', true, true)
	--[[belkî dûre niha ev qas kategorî nikarin çêkin
					vitalCat('Gotarên bingehîn bi mijara _TOPIC')
					vitalCat('Level-_LEVEL gotarên bingehîn bi mijara _TOPIC', false, true, true)
					vitalCat('gotarên bingehîn bi _CLASS û mijara _TOPIC', true, false, true)
	--]]
				end
			else
				addCategory('Gotarên ku di lîsteya gotarên bingehîn de tine ne')
			end
		end
	end
	text = vital or 'Ev ' .. (pagetype=='gotar' and 'gotar' or ('<b>'..pagetype..'</b>')) .. ' '-- use bold if page type is not article
	if class or not args[1] then
		local icons = { -- map output of pagetype function to input of class icon function
			['rûpela projeyê'] = 'proje',
			['rûpela bikarhêneriyê'] = 'bikarhêner',
			['rûpela alîkariyê'] = 'navrû',
			['rûpela alîkariyê'] = 'alîkarî',
			['modul'] = 'modul',
			['disambiguation page'] = 'disambig',
			['rûpel'] = 'na'
		}
		icon_class = class=='NA' and (icons[pagetype] or pagetype) or class
		text = text .. ' li gorî mîzana Wîkîpediyayê ya [[Wîkîpediya:Nirxandina naverokê|nirxandina naverokan]]'
		if class=='' then
			text = text .. ' hîn nehatiye sinifandin.'
		else
			if args.sinif and class~='NA' then
				text = text .. ' wekî <span style="font-weight:bold;">sinifa ' .. class .. '</span> hatiye sinifandin.'
			else
				text = text .. ' ne hewce ye ku xwedî sinifekê be.'
			end
		end

		if args[1] then
			text = text .. '<br>Ev'
		elseif not yesno(args["bingehîn"]) then
			text = text .. '[[Kategorî:Gotarên bi ' .. class2 .. ']]' .. '[[Kategorî:Hemû Gotarên Wîkîprojeyan]]'
		end
	    if not args[1] or args[1] == '' then
	        text = text ..'[[Kategorî:Gotarên bi muhîmiya Nayê zanîn]]' 
	        if class2 == "Nesinifandî" then 
	        	text = text .. '[[Kategorî:Gotarên nehatine sinifandin û muhîmiya Nayê zanîn]]'
        	else
	        	text = text .. '[[Kategorî:Gotarên bi ' .. class2 .. ' û muhîmiya Nayê zanîn]]'
        	end
	    end
	end
	if args[1] then
		text = text .. ' têkildarî ' ..
			(yesno(args.collapsed) and 'çend [[Wîkîpediya:Wîkîproje|Wîkîprojeyan]] e.'
			or ('van [[Wîkîpediya:Wîkîproje|Wîkîprojeyan]] e:'))
	end
	local icon = require('Modul:Class')._icon{icon_class, size='35px'}
	local header = mw.html.create('td')
		:addClass('assess'):wikitext(icon):done()
		:tag('td'):addClass('banner-shell-header'):css('text-align', 'left'):css('font-weight', 'normal'):wikitext(text):done()
	banner_args.header = tostring(header)
	banner_args[1] = args[1] or ''
	table.insert(out, frame:expandTemplate{
		title='Banner holder',
		args=banner_args
	})
	if args[1] then
		local duplicate_cat = DuplicateBanners(args[1])
		if duplicate_cat and title.isTalkPage then
			addCategory('Pages using WikiProject banner shell with duplicate banner templates', duplicate_cat)
		end
	end

	if args.listas then
		table.insert(out,frame:preprocess('{{DEFAULTSORT:' .. args.listas .. '}}'))
	end
	if not demo then
		local tracking = require('Modul:Check for unknown parameters')._check({
			['unknown']='[[Category:Pages using WikiProject banner shell with unknown parameters|_VALUE_ ]]',
			['preview']='Page using [[Şablon:WikiProject banner shell]] with unknown parameter "_VALUE_"',
			'1', 'activepol', 'blp', 'blpo', 'category', 'sinif', 'collapsed', 'demo_page', 'listas', 'living', 'bingehîn'
		}, frame:getParent().args)
		table.insert(out, tracking)
	end
	return table.concat(out)
end
return p