Jump to content

Module:Load WikiProject Modules: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
remove unnecessary vendor specifics
make variables local
Line 1: Line 1:
local p = {}
local p = {}


function standardicon(modulename)
local function standardicon(modulename)
index = {}
-- Take modulename as input, returns corresponding icon filename
-- Take modulename as input, returns corresponding icon filename
-- Returns default icon if no icon is defined
-- Returns default icon if no icon is defined
-- Grow the library! Add default icons as needed by adding this line below:
-- Grow the library! Add default icons as needed by adding this line below:
-- index['MODULENAME'] = 'FILE NAME.ext'
-- ['MODULENAME'] = 'FILE NAME.ext',
local index = {
index['About'] = 'Information Noun 176431.svg'
['default'] = 'Beta icon.svg', -- default if nothing matches
index['About us'] = 'Information Noun 176431.svg'
index['Alerts'] = 'Bell icon.svg'
['About'] = 'Information Noun 176431.svg',
index['Article alerts'] = 'Bell icon.svg'
['About us'] = 'Information Noun 176431.svg',
index['Article Alerts'] = 'Bell icon.svg'
['Alerts'] = 'Bell icon.svg',
index['Partners'] = 'Handshake noun.svg'
['Article alerts'] = 'Bell icon.svg',
index['Partnerships'] = 'Handshake noun.svg'
['Article Alerts'] = 'Bell icon.svg',
index['Discussions'] = 'Speechbubbles icon.svg'
['Partners'] = 'Handshake noun.svg',
['Partnerships'] = 'Handshake noun.svg',
index['Events'] = 'Simpleicons Business calendar-with-a-clock-time-tools.svg' -- Is this PD-shapes?
index['External Links'] = 'Link icon.svg'
['Discussions'] = 'Speechbubbles icon.svg',
['Events'] = 'Simpleicons Business calendar-with-a-clock-time-tools.svg', -- Is this PD-shapes?
index['External links'] = 'Link icon.svg'
index['Links'] = 'Link icon.svg'
['External Links'] = 'Link icon.svg',
index['Maps'] = 'MapPin.svg'
['External links'] = 'Link icon.svg',
index['Metrics'] = 'ArticleCheck.svg'
['Links'] = 'Link icon.svg',
index['News'] = 'Calendar icon 2.svg'
['Maps'] = 'MapPin.svg',
index['Offline App'] = 'Offline logo.svg'
['Metrics'] = 'ArticleCheck.svg',
index['Press'] = 'Cite newspaper.svg'
['News'] = 'Calendar icon 2.svg',
index['Recent changes'] = 'Clock icon.svg'
['Offline App'] = 'Offline logo.svg',
index['Recent Changes'] = 'Clock icon.svg'
['Press'] = 'Cite newspaper.svg',
index['Recognized content'] = 'RibbonPrize.svg'
['Recent changes'] = 'Clock icon.svg',
index['Recognized Content'] = 'RibbonPrize.svg'
['Recent Changes'] = 'Clock icon.svg',
['Recognized content'] = 'RibbonPrize.svg',
index['Related Projects'] = 'Contributions icon.svg' -- Not for use for the update bot, special use case, that expands the page
index['Related WikiProjects'] = 'Contributions icon.svg'
['Recognized Content'] = 'RibbonPrize.svg',
['Related Projects'] = 'Contributions icon.svg', -- Not for use for the update bot, special use case, that expands the page
index['Requests'] = 'Quotes icon.svg'
index['Research'] = 'Microscope icon (black OCL).svg'
['Related WikiProjects'] = 'Contributions icon.svg',
index['Resources'] = 'Cite book.svg'
['Requests'] = 'Quotes icon.svg',
index['Showcase'] = 'RibbonPrize.svg'
['Research'] = 'Microscope icon (black OCL).svg',
index['Tasks'] = 'ListBullet.svg'
['Resources'] = 'Cite book.svg',
index['Tools'] = 'Octicons-tools-minor.svg'
['Showcase'] = 'RibbonPrize.svg',
index['Translations'] = 'Translation icon.svg'
['Tasks'] = 'ListBullet.svg',
index['Watchlist'] = 'OpenEye icon.svg'
['Tools'] = 'Octicons-tools-minor.svg',
index['Worklists'] = 'ListBullet.svg'
['Translations'] = 'Translation icon.svg',
['Watchlist'] = 'OpenEye icon.svg',
['Worklists'] = 'ListBullet.svg',
}
for t, fn in pairs(index) do
for t, fn in pairs(index) do
if t == modulename then
if t == modulename then
Line 44: Line 47:
end
end
end
end
return 'Beta icon.svg' -- default if nothing matches
return index['default']
end
end


function editlinktest(modulename)
local function editlinktest(modulename)
no_edit_links = {'Discussions', 'Alerts', 'Showcase', 'Related WikiProjects'} -- no edit link for these standard modules
local no_edit_links = {'Discussions', 'Alerts', 'Showcase', 'Related WikiProjects'} -- no edit link for these standard modules
for _, l in pairs(no_edit_links) do
for _, l in pairs(no_edit_links) do
Line 59: Line 62:


function p.build(frame)
function p.build(frame)
title = ''
local title = ''
intro = ''
local intro = ''
image = ''
local image = ''
color = '#6af' -- default value
local color = '#6af' -- default value
displaymode = 'normal' -- default value
local displaymode = 'normal' -- default value
modules = {}
local modules = {}
local id
for key, value in pairs(frame:getParent().args) do -- iterate through arguments, pick out values
for key, value in pairs(frame:getParent().args) do -- iterate through arguments, pick out values
if key == 'title' then
if key == 'title' then
Line 84: Line 88:


-- Rendering table of contents and body
-- Rendering table of contents and body
local toc_args = {
toc_args = {width = 80, height = 55} -- passed into Image Array module
width = 80,
toc_args['font-size'] = '100%'
height = 55,
toc_args['margin'] = 0
['font-size'] = '100%',
body = ""
['margin'] = 0
} -- passed into Image Array module
local body = ""
-- Load a Table of Contents entry, transclude module, for each named module
-- Load a Table of Contents entry, transclude module, for each named module
counter = 0
local counter = 0
local moduletitle
local moduletitle_encoded
for _, module in pairs(modules) do
for _, module in pairs(modules) do
counter = counter + 1
counter = counter + 1
Line 138: Line 147:
toc_args['perrow'] = counter -- sets length of image array to the number of icons
toc_args['perrow'] = counter -- sets length of image array to the number of icons
toc = "<div style='margin-bottom:4em;'>" .. frame:expandTemplate{ title='Image_array', args = toc_args } .. "</div><div style='clear:both;'></div>"
local toc = "<div style='margin-bottom:4em;'>" .. frame:expandTemplate{ title='Image_array', args = toc_args } .. "</div><div style='clear:both;'></div>"


-- Adding header
-- Adding header
header = "__NOTOC__\n<div style='display: flex; flex-flow: row wrap;'>" -- top container
local header = "__NOTOC__\n<div style='display: flex; flex-flow: row wrap;'>" -- top container
if displaymode == "womeninred" then
if displaymode == "womeninred" then
header = header .. "<div style='flex: 1 0; border-top: solid .7em " .. color .. ";'>" -- intro
header = header .. "<div style='flex: 1 0; border-top: solid .7em " .. color .. ";'>" -- intro
Line 172: Line 181:


-- Assembling parts
-- Assembling parts
local contents
if displaymode == "womeninred" then
if displaymode == "womeninred" then
contents = header .. body
contents = header .. body

Revision as of 00:07, 3 November 2022

local p = {}

local function standardicon(modulename)
	-- 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:
	-- ['MODULENAME'] = 'FILE NAME.ext',
	local index = {
		['default'] = 'Beta icon.svg', -- default if nothing matches
		['About'] = 'Information Noun 176431.svg',
		['About us'] = 'Information Noun 176431.svg',
		['Alerts'] = 'Bell icon.svg',
		['Article alerts'] = 'Bell icon.svg',
		['Article Alerts'] = 'Bell icon.svg',
		['Partners'] = 'Handshake noun.svg',
		['Partnerships'] = 'Handshake noun.svg',
		['Discussions'] = 'Speechbubbles icon.svg',
		['Events'] = 'Simpleicons Business calendar-with-a-clock-time-tools.svg', -- Is this PD-shapes?
		['External Links'] = 'Link icon.svg',
		['External links'] = 'Link icon.svg',
		['Links'] = 'Link icon.svg',
		['Maps'] = 'MapPin.svg',
		['Metrics'] = 'ArticleCheck.svg',
		['News'] = 'Calendar icon 2.svg',
		['Offline App'] = 'Offline logo.svg',
		['Press'] = 'Cite newspaper.svg',
		['Recent changes'] = 'Clock icon.svg',
		['Recent Changes'] = 'Clock icon.svg',
		['Recognized content'] = 'RibbonPrize.svg',
		['Recognized Content'] = 'RibbonPrize.svg',
		['Related Projects'] = 'Contributions icon.svg', -- Not for use for the update bot, special use case, that expands the page	
		['Related WikiProjects'] = 'Contributions icon.svg',
		['Requests'] = 'Quotes icon.svg',
		['Research'] = 'Microscope icon (black OCL).svg',
		['Resources'] = 'Cite book.svg',
		['Showcase'] = 'RibbonPrize.svg',
		['Tasks'] = 'ListBullet.svg',
		['Tools'] = 'Octicons-tools-minor.svg',
		['Translations'] = 'Translation icon.svg',
		['Watchlist'] = 'OpenEye icon.svg',
		['Worklists'] = 'ListBullet.svg',
	}
	for t, fn in pairs(index) do
		if t == modulename then
			return fn
		end
	end
	return index['default']
end

local function editlinktest(modulename)
	local no_edit_links = {'Discussions', 'Alerts', 'Showcase', 'Related WikiProjects'} -- 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)
	local title = ''
	local intro = ''
	local image = ''
	local color = '#6af' -- default value
	local displaymode = 'normal' -- default value
	local modules = {}
	local id
	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)
    		modules[id] = value
		end
	end

	-- Rendering table of contents and body
	local toc_args = {
		width = 80,
		height = 55,
		['font-size'] = '100%',
		['margin'] = 0
	} -- passed into Image Array module
	local body = ""
	
	-- Load a Table of Contents entry, transclude module, for each named module
	local counter = 0
	local moduletitle
	local moduletitle_encoded
	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 == "Related WikiProjects" then
			-- Load the appropriate subpage of [[Wikipedia:Related WikiProjects]]
			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:Related WikiProjects/" .. 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<div style='clear:both;'></div>"
				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
	local toc = "<div style='margin-bottom:4em;'>" .. frame:expandTemplate{ title='Image_array', args = toc_args } .. "</div><div style='clear:both;'></div>"

	-- Adding header
	local header = "__NOTOC__\n<div style='display: flex; flex-flow: row wrap;'>" -- top container
	if displaymode == "womeninred" then
		header = header .. "<div style='flex: 1 0; border-top: solid .7em " .. color .. ";'>" -- intro
	else
		header = header .. "<div style='flex: 1 0; padding-bottom: 3em; border-top: solid .7em " .. color .. ";'>" -- intro
	end
	-- Adding project icon
	header = header .. "<div class='nomobile' style='float:left; margin-top: 1em; margin-right: 2em; margin-bottom: 1em; text-align: center;'>"
	header = header .. image .. "</div>"
	-- Adding project title
	header = header .. "<div style='font-size: 120%; padding: 0;'>" -- header
    header = header .. "<h1 style='font-weight: bold; border-bottom: none; margin:0; padding-top:0.5em;'>" .. title .. "</h1></div>"
    if displaymode == "womeninred" then
    	header = header .. toc
    end
	-- Adding intro blurb
	header = header .. "<div style='margin-top: 1em; font-size: 110%;'>"
	header = header .. intro .. "</div>"
	-- 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 .. "</div>"
	-- Adding member box
	header = header .. "<div style='flex: 0 1 20em;'>"
	header = header .. frame:expandTemplate{ title = 'WPX participants box', args = { } }
	header = header .. "</div>"
	-- Closing off header
	header = header .. "</div></div>"

	-- Assembling parts
	local contents
	if displaymode == "womeninred" then
		contents = header .. body
	else
		contents = header .. toc .. body
	end
	return contents
end

return p