Jump to content

Module:Women in Red event/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MSGJ (talk | contribs) at 22:15, 24 January 2024 (Create sandbox version of Module:Women in Red event). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
require('strict')
local p = {}
local data = mw.loadJsonData('Wikipedia:WikiProject Women in Red/events')

local value = function(event, field)
	local data = data[tonumber(event)]
	if data and data[field] then
		return data[field]
	end
end

p.main = function(frame)
	local val = value(frame.args[1], frame.args[2])
	return val or frame.args[3]
end

local getDate = function(event)
	local months = {'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'}
	local start_month = value(event, 'month') or value(event, 'start month')
	local end_month = value(event, 'end month')
	local month = (start_month and months[start_month] or '')
		.. (end_month and ('–' .. months[end_month]) or '')
		.. ' '
	return month .. (value(event, 'year') or '')
end

p.date = function(frame)
	return getDate(frame.args[1])
end

p.text = function(frame)
	local months = {'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'}
	local month = value(frame.args[1], 'month')
	if type(tonumber(month))=='number' then
		month = months[tonumber(month)]
	end
	local date = (month and (month .. ' ') or '') .. (value(frame.args[1], 'year') or '')
	return '[[Wikipedia:WikiProject Women in Red/Meetup/' .. frame.args[1]
		.. '|' .. (value(frame.args[1], 'name') or '')
		.. ' ' .. (value(frame.args[1], 'type') or 'edit-a-thon')
		.. ']] in '
		.. getDate(frame.args[1])
		.. '.'
end

p.list = function()
	local table = mw.html.create('table')
		table:addClass('wikitable'):addClass('sortable'):tag('tr')
			:tag('th'):wikitext('Meetup'):done()
			:tag('th'):wikitext('Logo'):done()
			:tag('th'):wikitext('Name'):done()
			:tag('th'):wikitext('Date'):done()
			:tag('th'):wikitext('Wrapper'):done()
			:tag('th'):wikitext('Category'):done()
		:done()
	for n, event in pairs(data) do
		local logo = event.image and '[[File:' .. event.image .. '|50px]]'
		local link = '[[Wikipedia:WikiProject Women in Red/Meetup/' .. n .. (event.name and '|' .. event.name or '')  .. ']]'
		local cat = 'WikiProject Women in Red meetup ' .. n .. ' articles'
		local url = mw.uri.fullUrl(':Category:' .. cat, {
			action = 'edit',
			preload = 'Template:WIR category/preload',
			summary = 'Create meetup category for Women in Red',
			['preloadparams[1]'] = n,
			})
		local catText = '[[' .. ':Category:' .. cat .. '|' .. mw.site.stats.pagesInCategory(cat) .. ']]'
		if not mw.title.new(':Category:' .. cat).exists then
			catText = catText .. ' ([' .. tostring(url) .. ' create])'
		end
		table:tag('tr')
			:tag('td'):css('text-align', 'center'):wikitext(n):done()
			:tag('td'):wikitext(logo):done()
			:tag('td'):wikitext(link):done()
			:tag('td'):wikitext(getDate(n)):done()
			:tag('td'):css('text-align', 'center')
				:wikitext('{{[[:Template:WIR-' .. n .. '|WIR-' .. n .. ']]}}')
			:done()
			:tag('td'):css('text-align', 'center'):wikitext(catText)
		:done()
	end
	return table:allDone()
end

p.count_banners = function(frame)
	local title = mw.title.getCurrentTitle()
	if title.namespace==1 then
		local wikitext = title:getContent()
		local _, count = mw.ustring.gsub(wikitext,'%{%{%s*[Ww][Ii][Rr]','')
		if count>=2 then
			local out = '[[Category:Pages with ' .. tostring(count) .. ' WikiProject Women in Red banners]]'
			if frame.args[1]=='' then
				out = out .. '[[Category:Pages with duplicated and unconnected WikiProject Women in Red banners]]'
			end
			return out
		end
	end
end

return p