local randomModule = require('Module:Random')
function cleanupArgs(argsTable) local cleanArgs = for key, val in pairs(argsTable) do if type(val)
function isAffirmed(val) if not(val) then return false end local affirmedWords = ' add added affirm affirmed include included on true yes y ' return string.find(affirmedWords, ' '..string.lower(val)..' ', 1, true) and true or falseend
function makeOutput(allItems, maxItems, more, notRandom) local output if notRandom then output = local itemIndex = 1 local maxCount = math.min(#allItems, maxItems) while itemIndex <= maxCount do output = output .. allItems[itemIndex] .. '\n' itemIndex = itemIndex + 1 end else local randomiseArgs = local randomisedItems = randomModule.main('array', randomiseArgs) output = table.concat(randomisedItems, '\n') end if more then output = output .. more end return mw.text.trim(output)end
function cleanForPatternMatching(wikitext) -- remove wikilink brackets local cleaned = mw.ustring.gsub(wikitext, "%[%[(.-)%]%]","%1") -- remove pipes that would have been in piped links cleaned = mw.ustring.gsub(cleaned, "%|"," ") -- remove external links cleaned = mw.ustring.gsub(cleaned, "%[.-%]"," ") return cleanedend
function makeCollapsed(outerText, innerText) return "" .. innerText .. ""end
-- Get current events for a "YYYY Month D" date. Returns a table of list items.function getRecentAdditions(subpage, keepPatterns, skipPatterns, showWikitext) local title = mw.title.new('Wikipedia:Recent additions' .. subpage) local raw = title:getContent local itemPattern = '%*%s?%.%.%.[%S ]*' local items = for item in mw.ustring.gmatch(raw, itemPattern) do local keep = false local skip = false local isListItem = (string.sub(item, 0, 1)
" .. mw.text.nowiki(cleanItem) .. "" cleanItem = makeCollapsed(cleanItem, itemWikitext) end table.insert(items, cleanItem) end end return itemsend
function getItems(maxMonths, patterns, skipPatterns, showWikitext) local allItems = local lang = mw.language.new('en') local currentYear = tonumber(lang:formatDate('Y', 'now')) local currentMonth = tonumber(lang:formatDate('n', 'now')) local monthsAgo = 0 while monthsAgo < maxMonths do local subpage if monthsAgo
function getPatterns(args, prefix) local patterns = local ii = 1 while args[prefix and prefix..ii or ii] do patterns[ii] = args[prefix and prefix..ii or ii] ii = ii + 1 end return patternsend
local p =
p.main = function(frame) local parent = frame.getParent(frame) local parentArgs = parent.args local args = cleanupArgs(parentArgs)
if args['not'] and not args['not1'] then args['not1'] = args['not'] end local patterns = getPatterns(args) if #patterns < 1 then return error("Search pattern not set") end
local skipPatterns = getPatterns(args, 'not')
local months = tonumber(args.months) or 30 local showWikitext = isAffirmed(args.wikitext)
local allItems = getItems(months, patterns, skipPatterns, showWikitext) if #allItems < 1 then return args.header and or args.none or 'No recent additions' end
local maxItems = tonumber(args.max) or 6
local more = args.more if isAffirmed(args.more) then more = "More recent additions..." end
local nonRandom = isAffirmed(args.latest)
local output = makeOutput(allItems, maxItems, more, nonRandom) if args.header then output = args.header .. '\n' .. output .. '\n' .. (args.footer or '') end local needsExpansion = mw.ustring.find(output, '