Module:Changelog
Overview
Generates lines of changes for all data pages. See [[Category:Changelog Dates]] for the dates of all changelogs, and Changelogs for list of all the data pages that contain a Changelog.
Functions
All of these functions are callable by wikitext, i.e. {{#invoke|Changelog|invokable_name|param1|paramN}}
write_changelog_by_tag
The main invokable that will be used. Given a specific tag, it outputs all relevant changelogs from all dates in a Template:Update history table.
Parameters
- tag - Tag to search relevant changelogs for. Should be localized, i.e. Abrams for hero_atlas in english.
- num_dates - (OPTIONAL) Number of dates to add, recommend 3 for articles. If unprovided, defaults to all.
Examples
For use on Pocket/Update history:
{{#invoke:Changelog|write_changelog_by_tag|Pocket}}
Outputs Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates' is not a valid JSON page).
For use on Pocket#Update history:
{{#invoke:Changelog|write_changelog_by_tag|Pocket|3}}
Outputs
Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates' is not a valid JSON page).
write_changelog_by_date_id
Write's a specific date's changelog, as opposed to a specific tag's changelog.
Parameters
- date_id_to_write - Date-id to write, format yyyy-mm-dd, view all at [[Category:Changelog Dates]]
Examples
For a non-herolab patch page
{{#invoke:Changelog|write_changelog_by_date_id|2024-05-03}}
Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates' is not a valid JSON page).
For a herolab patch page
{{#invoke:Changelog|write_changelog_by_date_id|2024-12-06_HeroLab}}
Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates' is not a valid JSON page).
write_data_pages_list
Writes list of all changelog data pages using the list of patches at Data:ChangelogConfigs.json. Used on [[Category:Changelog Dates]].
Parameters
None
Examples
{{#invoke:Changelog|write_data_pages_list}}
Outputs
Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates' is not a valid JSON page).
get_last_updated
Retrieve the last (or first) date that a tag was updated on. Planned to be used on a given tag's page, i.e. Abrams's infobox could mention that it was last updated on 2024-05-03, or that Mirage was released on 2024-05-03, etc.
Parameters
- tag - Tag to search
- last_or_first - Named optional - Must be last or first - defaults to last - Retrieves last or first date
Examples
Example using last
{{#invoke:Changelog|get_last_updated|Basic Magazine}}
Outputs
Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates' is not a valid JSON page).
Example using first
{{#invoke:Changelog|get_last_updated|Basic Magazine|last_or_first=first}}
Outputs
Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates' is not a valid JSON page).
local p = {};
local date_module = require('Module:Date')
local changelog_dates = mw.loadJsonData("Data:Changelog Dates")
--Only Data:Changelog_05-03-2024.json is loaded right now, as it still needs work and for now it was uploaded manually, need an uploader script to handle it
--Returns all lines of a given date that has that tag
local function date_tag_to_lines(date, tag_to_filter)
-- Get the data for the respective line
local changelog_data = mw.loadJsonData("Data:Changelog_" .. date .. ".json")
local lines = ""
for index, line in ipairs(changelog_data) do
description = line["Description"]
for index2, tag in ipairs(line["Tags"]) do
if tag == tag_to_filter then
lines = lines .. description .. "<br>"
end
end
end
return lines
end
--Expand the Update history table/row template for 1 specific changelog
local function write_changelog(date, tag_to_filter)
local template_title = "Update history table/row"
local template_args = {}
--05-03-2024 to May 3, 2024
template_args["update"] = date_module.format_date(date)
template_args["changes"] = date_tag_to_lines(date, tag_to_filter)
if (template_args["changes"] ~= "") then
return mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
else
return ""
end
end
-- Write changelogs table
p.write_changelogs = function(frame)
tag = frame.args[1]
num_dates_str = frame.args[2]
local num_dates
if (tag == nil) then return "tag parameter must be provided" end
if (num_dates_str ~= nil) then
num_dates = tonumber(num_dates_str)
if (num_dates == nil) then return "num_dates parameter must be numerical" end
end
local template_title = "Update history table"
local template_args = {}
local content = ""
-- Write changelog for each date
for index, date in ipairs(changelog_dates) do
if (index > num_dates) then
break
else
content = content .. write_changelog(date, tag)
end
end
return content
end
p.invoke_write_changelog = function(frame)
date = frame.args[1]
tag = frame.args[2]
return write_changelog(date, tag)
end
--testing by invoke in sandbox, will be called properly by other funcs later
p.invoke_date_tag_to_lines = function(frame)
date = frame.args[1]
tag = frame.args[2]
return date_tag_to_lines(date, tag)
end
--Shows all changelog date data pages as a list of pages
p.write_data_pages_list = function(frame)
local str = ""
for index, date in ipairs(changelog_dates) do
str = str .. "[[Data:Changelog " .. date .. ".json]]<br>"
end
return str
end
return p