More actions
m forgot lua is index1 based lol, it fixed bug with specifying # of most recent changelogs in write_changelogs |
m swap mw.getCurrentFrame() with frame |
||
(13 intermediate revisions by 2 users not shown) | |||
Line 33: | Line 33: | ||
local function write_changelog_lines(id, config, tag_to_filter) | local function write_changelog_lines(id, config, tag_to_filter) | ||
-- Get the data for the respective line | -- Get the data for the respective line | ||
local | local changelog_data = mw.loadJsonData(id_to_changelog_data_page(id)) | ||
local lines = "" | local lines = "" | ||
Line 44: | Line 39: | ||
description = line["Description"] | description = line["Description"] | ||
if tag_to_filter == 'All' then | if tag_to_filter == 'All' then | ||
lines = lines .. description .. " | lines = lines .. description .. "\n" | ||
else | else | ||
for index2, tag in ipairs(line["Tags"]) do | for index2, tag in ipairs(line["Tags"]) do | ||
if tag == tag_to_filter then | if tag == tag_to_filter then | ||
lines = lines .. description .. " | lines = lines .. description .. "\n" | ||
end | end | ||
end | end | ||
Line 54: | Line 49: | ||
end | end | ||
return lines | return lines | ||
end | end | ||
-- Write changelogs table | -- Write changelogs table | ||
p. | p.write_changelog_by_tag = function(frame) | ||
tag = frame.args[1] | tag = frame.args[1] | ||
num_dates_str = frame.args[2] | num_dates_str = frame.args[2] | ||
Line 87: | Line 67: | ||
-- Write changelog for each date | -- Write changelog for each date | ||
for index, id in ipairs(ordered_ids) do | |||
config = changelog_configs[id] | |||
if (num_dates_str ~= nil and index > num_dates) then | if (num_dates_str ~= nil and index > num_dates) then | ||
break | break | ||
else | else | ||
local date = config["date"] | |||
local frontfacing_date_id = config["frontfacing_date_id"] | |||
local template_title_row = "Update history table/row" | |||
local template_args_row = {} | |||
local changes | |||
--05-03-2024 to May 3, 2024 | |||
template_args_row["update"] = frontfacing_date_id | |||
template_args_row["changes"] = write_changelog_lines(id, config, tag) | |||
if (template_args_row["changes"] ~= "") then | |||
changes = frame:expandTemplate{ title = template_title_row, args = template_args_row } | |||
else | |||
changes = "" | |||
end | |||
content = content .. frame:preprocess(changes) .. "\n" | |||
end | end | ||
index = index+1 | index = index+1 | ||
Line 99: | Line 93: | ||
template_args["contents"] = content | template_args["contents"] = content | ||
return | return frame:expandTemplate{ title = template_title, args = template_args } | ||
end | end | ||
Line 118: | Line 112: | ||
p.write_changelog_by_date_id = function(frame) | p.write_changelog_by_date_id = function(frame) | ||
local | local req_date_id = frame.args[1] | ||
--req = requested, as this is the requested changelog | |||
local config = changelog_configs[req_date_id] | |||
if config == nil then return "date id " .. req_date_id .. " not found" end | |||
local frontfacing_req_date_id = config["frontfacing_date_id"] | |||
local req_is_herolab = config["is_hero_lab"] | |||
-- Determine the previous and next update | -- Determine the previous and next update | ||
-- Find the index in dates list | -- Find the index in dates list | ||
--ordered_ids defined at global scope | --ordered_ids defined at global scope | ||
local | local previous_ff_id = '' | ||
local | local the_ff_id = '' | ||
local | local next_ff_id = '' | ||
local id_found = false | local id_found = false | ||
local frontfacing_date_id | |||
local is_herolab | |||
for i, id in ipairs(ordered_ids) do | for i, id in ipairs(ordered_ids) do | ||
if | frontfacing_date_id = changelog_configs[id]["frontfacing_date_id"] | ||
--id found | is_herolab = changelog_configs[id]["is_hero_lab"] | ||
if is_herolab == req_is_herolab then --only look at herolab or non-herolab patches, not mix and match | |||
if frontfacing_date_id == frontfacing_req_date_id then | |||
--id found | |||
the_ff_id = frontfacing_date_id | |||
the_id = id | |||
id_found = true | |||
elseif id_found and next_ff_id == '' then --on next iteration, save the next id | |||
next_ff_id = frontfacing_date_id | |||
break | |||
end | |||
if not id_found then | |||
previous_ff_id = frontfacing_date_id -- only update previous if the_id isnt found | |||
end | |||
end | end | ||
end | end | ||
if not id_found then | if not id_found then | ||
return "date_id " .. | return "date_id " .. req_date_id .. " not found" | ||
end | end | ||
local template_title = 'Update layout' | local template_title = 'Update layout' | ||
local template_args = { | local template_args = { | ||
['prev_update'] = | ['prev_update'] = prev_ff_id, | ||
['current_update'] = | ['current_update'] = the_ff_id, | ||
['next_update'] = | ['next_update'] = next_ff_id, | ||
['source'] = config[link], | ['source'] = config[link], | ||
['source_title'] = | ['source_title'] = the_ff_id .. ' Update', | ||
['notes'] = write_changelog_lines(the_id, config, 'All') | ['is_herolab'] = req_is_herolab, | ||
['notes'] = frame:preprocess(write_changelog_lines(the_id, config, 'All')) | |||
} | } | ||
return | return frame:expandTemplate{title = template_title, args = template_args} | ||
end | end | ||
p.get_last_updated = function(frame) | p.get_last_updated = function(frame) | ||
local tag_to_search = frame.args[1] | local tag_to_search = frame.args[1] | ||
local last_or_first = frame.args["last_or_first"] | |||
if last_or_first == nil or last_or_first == 'last' then | |||
last_or_first = 'last' | |||
else | |||
last_or_first = 'first' | |||
end | |||
local list = {} | |||
if last_or_first == 'last' then | |||
list = ordered_ids | |||
else | |||
-- Create the list in reverse | |||
for i = #ordered_ids, 1, -1 do | |||
table.insert(list, ordered_ids[i]) | |||
end | |||
end | |||
-- Iterate changelog dates | -- Iterate changelog dates | ||
for i, id in ipairs( | local frontfacing_date_id | ||
for i, id in ipairs(list) do | |||
-- Get frontfacing date from id | |||
frontfacing_date_id = changelog_configs[id]["frontfacing_date_id"] | |||
-- If next changelog data page doesn't yet exist, return latest page that exists | -- If next changelog data page doesn't yet exist, return latest page that exists | ||
local page_name = id_to_changelog_data_page(id) | local page_name = id_to_changelog_data_page(id) | ||
local title = mw.title.new(page_name) | local title = mw.title.new(page_name) | ||
if not (title and title.exists) then | if not (title and title.exists) then | ||
return '[[Update:' .. | return '[[Update:' .. frontfacing_date_id .. '|' .. frontfacing_date_id .. ']]' | ||
end | end | ||
Line 180: | Line 208: | ||
for _, tag in ipairs(tags) do | for _, tag in ipairs(tags) do | ||
if tag_to_search == tag then | if tag_to_search == tag then | ||
return '[[Update:' .. | return '[[Update:' .. frontfacing_date_id .. '|' .. frontfacing_date_id .. ']]' | ||
end | end | ||
end | end | ||
Line 198: | Line 226: | ||
for parent, children in pairs(branch) do | for parent, children in pairs(branch) do | ||
-- If parent starts with < or ends with >, its referencing individual page | |||
-- the link won't work, so instead we just display the parent raw | |||
local parent_str | |||
if string.sub(parent, 1, 1) == '<' or string.sub(parent, -1) == '>' then | |||
parent_str = parent | |||
else | |||
parent_str = string.format("[[%s#Update history|%s]]", parent, parent) | |||
end | |||
list_str = list_str .. string.rep("*", depth) .. parent_str .. "\n" | |||
if children ~= nil then | if children ~= nil then | ||
list_str = list_str .. p.write_branch(children, depth+1) | list_str = list_str .. p.write_branch(children, depth+1) |