Module:History

-- local p = {}

--Import commonly used modules (See Module:LoadLib/Autoloads for the list) local string = require('Module:String') local table = require('Module:Table') local getArgs = require('Module:Arguments').getArgs

-- import all string data local aliases = require('Module:History/Aliases') local update_aliases = aliases["update"] local months = aliases["month"] local short_months = aliases["short_month"] local versions = aliases["version"]

- -- Template:History -- -- Displays a row of history description with changelog link - function p.history(frame) args = getArgs(frame) local input_date = args[1] local version = args["version"] or args["ver"] local link = args["link"] or args["l"]

-- get technically infinite amount of arguments for text local rows = 2 local text = {} while args[rows] do		text[rows-1] = args[rows] rows = rows + 1 end rows = rows - 2 return string.pcall(p._history, input_date, text, rows, version, link) end

-- Module access point function p._history(input_date, text, rows, version, link) -- remove whitespace from the beginning and the back of input_date input_date = string.trim(input_date) if not update_aliases[input_date:lower] and not input_date:lower:find('%d%d%d%d/%a%a%a+%s%d%d?') and not input_date:lower:match('unknown') then return string.error('Invalid date or version %q', input_date) elseif update_aliases[input_date:lower] then --convert aliases into proper date input_date = update_aliases[input_date:lower] or input_date end local unknown -- if input_date is set to unknown, then display it	local display if input_date:lower:match('unknown') then local alt = input_date:match('[Uu]nknown%s*;%s*(.*)') display = string.wrapHtml(alt or "Unknown Date", ' ', (not alt and { style='font-variant:small-caps;' } or nil) ) unknown = true end -- if display was NOT previously set to "Unknown Date" if not display then -- split the date into parts local year = input_date:match("^(%d*)/.* %d%d?") local month = input_date:match("^%d*/(.*) %d%d?") local day = input_date:match("^%d*/.* (%d%d?)") local subpage = input_date:match("^%d*/.* %d%d?/(.*)") if #day == 2 and day:sub(1,1) == "0" then day = day:sub(2,2) end -- check for errors in date if not (tonumber(year) >= 2019 and tonumber(year) <= 2099) then error('Invalid year "'..year..'"', 2) end if not (tonumber(day) > 0 and tonumber(day) <= 31) then error('Invalid day "'..day..'"', 2) end -- convert short month names top full ones, and check for errors month = months[month:lower] or error('Invalid month "'..month..'"', 2) -- assemble both normal and display date local date = table.concat{ year, "/",			month, " ",			day, subpage and ('/%s'):format(subpage) or '', }		local display_date = table.concat{ short_months[month:lower], " ",			day, ", ",			year, }		-- convert date to version number if not version then version = versions[date] or nil end -- check if link is set to none. if true, don't display any link, just text if link and link:lower == "none" then display = display_date -- if link is not set to none, display the link alongside the date elseif link and (link:find('%[%[') and link:find('%]%]')) then display = table.concat{, link:gsub('[%[%', ), '|', display_date, ']]'} elseif link then display = table.concat{'[', link, ' ', display_date, ']'} -- if link is not specified, display standard text else display = string.makeLink({ "Changelog/", date}, display_date) end -- if display WAS previously set to "Unknown Date" else -- dont display version at all version = nil -- add link, if applicable if link then display = table.concat{'[',link, ' ', display, ']'} end end ---	-- construct the history table local table_str = {} -- if version is not set to "none" if version and version:lower ~= "none" then table.push(table_str, ' '..string.wrapHtml(display, ' ', { rowspan=rows })) table.push(table_str, string.wrapHtml(version, 'th', { rowspan=rows })) -- if version is either not present or set to "none" else table.push(table_str, ' '..string.wrapHtml(display, ' ', { rowspan=rows, colspan=2 })) end -- display error if no text is specified if not text or not text[1] then error("No text specified") end -- always display the first text table.push(table_str, string.wrapTag(text[1], "td").." ") -- display the following texts, if applicable for i=2,rows,1 do		table.push(table_str, string.wrapTag(text[i], { "td", 'tr' })) end if unknown then table.push(table_str, string.makeLink('Category:Pages with unknown history dates')) end -- concatenate the string return table.concat(table_str, '') end

function p.changelog(frame) local args = getArgs(frame) local ver = args.version or args[1] local alt = args.alt or args[2] local allowedReplacements = { { '^[Vv](.+)', '%1' }, { '^[Vv]ersion (.+)', '%1' } }	local page = update_aliases[(ver or ''):lower] for _, v in ipairs(allowedReplacements) do		if page then break end page = update_aliases[(ver or ''):gsub(v[1], v[2])] end if not (page or ver) then return ('%s'):format(alt or 'Changelog') end return ('%s'):format(page or ver or 'Changelog', alt or ver or 'Changelog') end -- Finish Module return p