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"]

- -- access point - 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 input_date:lower ~= "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 == "unknown" then display = string.wrapHtml("Unknown Date", ' ', { style='font-variant:small-caps;' }) 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 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[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.update(frame) local page = args[1]

end -- Finish Module return p