Module:Women in Red event
This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
Usage
demeseThis module reads the list of WIR events stored at Wikipedia:WikiProject Women in Red/events for use in Template:WIR and elsewhere.
main function
demese{{#invoke:Women in Red event|main|event|field}}
- Given an event number, reads one of the fields (event, year, month, type, image)
For example:
{{#invoke:Women in Red event|main|294|name}}
gives "Lua tuure: bad argument #1 to 'mw.loadJsonData' ('Wikipedia:WikiProject Women in Red/events' is not a valid JSON page)."{{#invoke:Women in Red event|main|7|year}}
gives "Lua tuure: bad argument #1 to 'mw.loadJsonData' ('Wikipedia:WikiProject Women in Red/events' is not a valid JSON page)."
text function
demeseProduces a piped link to the event page followed by the date, for use in the project banner. For example:
{{#invoke:Women in Red event|text|291}}
gives "Lua tuure: bad argument #1 to 'mw.loadJsonData' ('Wikipedia:WikiProject Women in Red/events' is not a valid JSON page)."
date function
demeseProduces a formatted date (including month and year) of the event. For example:
{{#invoke:Women in Red event|date|210}}
gives "Lua tuure: bad argument #1 to 'mw.loadJsonData' ('Wikipedia:WikiProject Women in Red/events' is not a valid JSON page)."
require('strict')
local p = {}
local data = mw.loadJsonData('Wikipedia:WikiProject Women in Red/events')
local value = function(event, field, default)
local data = data[tonumber(event)]
if data and data[field] then
return data[field]
else
return default
end
end
p.main = function(frame)
return value(frame.args[1], frame.args[2], frame.args[3])
end
local _date = 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 _date(frame.args[1])
end
p.text = function(frame)
local meetup = frame.args[1]
return '[[Wikipedia:WikiProject Women in Red/Meetup/' .. meetup
.. '|' .. (value(meetup, 'name') or '')
.. ' ' .. (value(meetup, 'type') or 'edit-a-thon')
.. ']] in '
.. _date(meetup)
.. '.'
end
local _name = function(meetup)
local series = value(meetup, 'series')
return (series and (series..': ') or '') .. value(meetup, 'name', '')
end
p.name = function(frame)
return _name(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 .. '|' .. _name(n) .. ']]'
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 event.year==2022 and 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(_date(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.articleBySeries = function(frame)
local series = frame.args[1]
local table = mw.html.create('table')
table:addClass('wikitable'):addClass('sortable'):tag('tr')
:tag('th'):wikitext('Meetup'):done()
:tag('th'):wikitext('Name'):done()
:tag('th'):wikitext('Date'):done()
:tag('th'):wikitext('Articles'):done()
:done()
for n, event in pairs(data) do
if event.series==series then
local link = '[[Wikipedia:WikiProject Women in Red/Meetup/' .. n .. '|' .. (event.name or '') .. ']]'
local cat = 'WikiProject Women in Red meetup ' .. n .. ' articles'
local catText
if mw.title.new(':Category:' .. cat).exists then
catText = '[[' .. ':Category:' .. cat .. '|' .. mw.site.stats.pagesInCategory(cat) .. ']]'
else
catText = ''
end
table:tag('tr')
:tag('td'):css('text-align', 'center'):wikitext(n):done()
:tag('td'):wikitext(link):done()
:tag('td'):wikitext(_date(n)):done()
:tag('td'):css('text-align', 'center'):wikitext(catText)
:done()
end
end
return table:allDone()
end
p.articleByYear = function(frame)
local year = frame.args[1]
local table = mw.html.create('table')
table:addClass('wikitable'):addClass('sortable'):tag('tr')
:tag('th'):wikitext('Meetup'):done()
:tag('th'):wikitext('Name'):done()
:tag('th'):wikitext('Date'):done()
:tag('th'):wikitext('Articles'):done()
:done()
for n, event in pairs(data) do
if tostring(event.year)==year then
local link = '[[Wikipedia:WikiProject Women in Red/Meetup/' .. n .. '|' .. _name(n) .. ']]'
local cat = 'WikiProject Women in Red meetup ' .. n .. ' articles'
local catText
if mw.title.new(':Category:' .. cat).exists then
catText = '[[' .. ':Category:' .. cat .. '|' .. mw.site.stats.pagesInCategory(cat) .. ']]'
else
catText = ''
end
table:tag('tr')
:tag('td'):css('text-align', 'center'):wikitext(n):done()
:tag('td'):wikitext(link):done()
:tag('td'):wikitext(_date(n)):done()
:tag('td'):css('text-align', 'center'):wikitext(catText)
:done()
end
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]','')
local _, count2 = mw.ustring.gsub(wikitext,'%{%{%s*[Ww]ikiProject Women in Red','')
if count+count2>=2 then
local out = '[[Category:Pages with ' .. tostring(count+count2) .. ' 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