Mô đun:Load WikiProject Modules

local p = {}
function standardicon(modulename)
	index = {}
	-- Take modulename as input, returns corresponding icon filename
	-- Returns default icon if no icon is defined
	-- Grow the library! Add default icons as needed by adding this line below:
	-- index'MODULENAME' = 'FILE NAME.ext'
	index'About' = 'Information Noun 176431.svg'
	index'Về chúng tôi' = 'Information Noun 176431.svg'
	index'Cảnh báo' = 'Bell icon.svg'
	index'Article alerts' = 'Bell icon.svg'
	index'Article Alerts' = 'Bell icon.svg'
	index'Hợp tác' = 'Handshake noun.svg'
	index'Quan hệ hợp tác' = 'Handshake noun.svg'
	index'Thảo luận' = 'Speechbubbles icon.svg'
	index'Sự kiện' = 'Simpleicons Business calendar-with-a-clock-time-tools.svg' -- Is this PD-shapes?
	index'Liên kết ngoài' = 'Link icon.svg'
	index'Liên kết ngoài' = 'Link icon.svg'
	index'Liên kết' = 'Link icon.svg'
	index'Bản đồ' = 'MapPin.svg'
	index'Số liệu thống kê' = 'ArticleCheck.svg'
	index'Tin tức' = 'Calendar icon 2.svg'
	index'Offline App' = 'Offline logo.svg'
	index'Press' = 'Cite newspaper.svg'
	index'Thay đổi gần đây' = 'Clock icon.svg'
	index'Thay đổi gần đây' = 'Clock icon.svg'
	index'Nội dung được chấp nhận' = 'RibbonPrize.svg'
	index'Nội dung được chấp nhận' = 'RibbonPrize.svg'
	index'Các dự án liên quan' = 'Contributions icon.svg' -- Not for use for the update bot, special use case, that expands the page	
	index'Dự án Wiki liên quan' = 'Contributions icon.svg'
	index'Yêu cầu' = 'Quotes icon.svg'
	index'Nghiên cứu' = 'Microscope icon (black OCL).svg'
	index'Nguồn tài liệu' = 'Cite book.svg'
	index'Giới thiệu' = 'RibbonPrize.svg'
	index'Nhiệm vụ' = 'ListBullet.svg'
	index'Công cụ' = 'Octicons-tools-minor.svg'
	index'Translations' = 'Translation icon.svg'
	index'Danh sách theo dõi' = 'OpenEye icon.svg'
	index'Danh sách công việc' = 'ListBullet.svg'
	for t, fn in pairs(index) do
		if t == modulename then
			return fn
		end
	end
	return 'Beta icon.svg' -- default if nothing matches
end
function editlinktest(modulename)
	no_edit_links = {'Thảo luận', 'Cảnh báo', 'Giới thiệu', 'Dự án Wiki liên quan'} -- no edit link for these standard modules
	
	for _, l in pairs(no_edit_links) do
		if l == modulename then
			return 'no'
		end
	end
	return 'yes'
end
function p.build(frame)
	title = 
	intro = 
	image = 
	color = '#6af' -- default value
	displaymode = 'normal' -- default value
	modules = {}
	for key, value in pairs(frame:getParent().args) do  -- iterate through arguments, pick out values
		if key == 'title' then
			title = value
		elseif key == 'intro' then
			intro = value
		elseif key == 'image' then
			image = value
		elseif key == 'color' then
			color = value
		elseif key == 'displaymode' then
			displaymode = value
	elseif string.find(key, 'module') ~= nil then  -- matches module1, module2, etc.
		id = string.gsub(key, 'module', )
		id = tonumber(id)
		modulesid = value
		end
	end
	-- Rendering table of contents and body
	toc_args = {width = 80, height = 55} -- passed into Image Array module
	toc_args'font-size' = '100%'
	toc_args'margin' = 0
	body = ""
	
	-- Load a Table of Contents entry, transclude module, for each named module
	counter = 0
	for _, module in pairs(modules) do
		counter = counter + 1
		toc_args'image' .. counter = standardicon(module)
		toc_args'alt' .. counter = module
		if displaymode == "womeninred" then
			if module == "Metrics" or module == "Showcase" or module == "About us" or module == "Press" or module == "Research" or module == "External links" then
				toc_args'link' .. counter = "Wikipedia:WikiProject Women in Red/" .. module
			else
				toc_args'link' .. counter = "#" .. module
			end
		else
			toc_args'link' .. counter = "#" .. module
		end
		toc_args'caption' .. counter = "" .. toc_args'link' .. counter .. "|" .. module .. ""
		if module == "Dự án liên quan" then
			-- Load the appropriate subpage of Wikipedia:Dự án liên quan
			moduletitle = 'Related WikiProjects' .. '/' .. title
			moduletitle_encoded = string.gsub('Wikipedia:' .. moduletitle, ' ', '_')
			body = body .. "\n" .. frame:expandTemplate{ title = 'WPX header', args = { module, color = color, modulename = moduletitle_encoded, editlink = editlinktest(module) } }
			body = body .. "\n" .. frame:expandTemplate{ title = "Wikipedia:Dự án liên quan/" .. title, args = {color} }
		else
			if displaymode == "normal" or ( displaymode == "womeninred" and module ~= "Metrics" and module ~= "Showcase" and module ~= "About us" and module ~= "Press" and module ~= "Research" and module ~= "External links" ) then
				moduletitle = title .. '/' .. module
				moduletitle_encoded = string.gsub('Wikipedia:' .. moduletitle, ' ', '_')
				body = body .. "\n" .. frame:expandTemplate{ title = 'WPX header', args = { module, color = color, modulename = moduletitle_encoded, editlink = editlinktest(module) } }
				if mw.title.makeTitle('Wikipedia', moduletitle).exists == true then
					body = body .. "\n" .. frame:expandTemplate{ title = 'Wikipedia:' .. moduletitle, args = {color} } .. "\n"
				else
					-- Is module in question a Standard Module? If so, load the template with corresponding editintro
					if mw.title.makeTitle('Template', 'WPX module/' .. module).exists == true then
						preload = '&preload=Template:WPX_module/' .. string.gsub(module, ' ', '_')
						editintro = '&editintro=Template:WPX_editintro/' .. string.gsub(module, ' ', '_')
					else
						preload =  -- no preload
						editintro = '&editintro=Template:WPX_editintro/Generic' -- generic editintro
					end
					-- Create notice
					create_url = '//en.wikipedia.org/wiki/Wikipedia:' .. string.gsub(moduletitle, ' ', '_') .. '?action=edit' .. preload .. editintro
					create_button = frame:expandTemplate{ title = 'Template:Clickable button 2', args = {'Create Module', url = create_url, class = 'mw-ui-progressive' } }
					body = body .. 'Wikipedia:' .. moduletitle .. ' does not exist. ' .. create_button
				end
			end
		end
		
	end
	
	toc_args'perrow' = counter -- sets length of image array to the number of icons
	toc = "" .. frame:expandTemplate{ title='Image_array', args = toc_args } .. ""
	-- Adding header
	header = "__NOTOC__\n" -- top container
	if displaymode == "womeninred" then
		header = header .. "" -- intro
	else
		header = header .. "" -- intro
	end
	-- Adding project icon
	header = header .. ""
	header = header .. image .. ""
	-- Adding project title
	header = header .. "" -- header
header = header .. "" .. title .. ""
if displaymode == "womeninred" then
	header = header .. toc
end
	-- Adding intro blurb
	header = header .. ""
	header = header .. intro .. ""
	-- Adding announcement section
	if mw.title.makeTitle('Wikipedia', title .. "/" .. "Announcements").exists == true then
		header = header .. frame:expandTemplate{ title = 'Wikipedia:' .. title .. "/" .. "Announcements", args = { } }
	end
	header = header .. ""
	-- Adding member box
	header = header .. ""
	header = header .. frame:expandTemplate{ title = 'WPX member box', args = { } }
	header = header .. ""
	-- Closing off header
	header = header .. ""
	-- Assembling parts
	if displaymode == "womeninred" then
		contents = header .. body
	else
		contents = header .. toc .. body
	end
	return contents
end
return p