Module:Link milestone
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Link milestone/doc
local getArgs = require('Module:Arguments').getArgs
local m_util = require('Module:Util')
local p = {}
local cargo = mw.ext.cargo
function p.Main( frame )
milestone_args = frame:getParent().args
if (milestone_args == nil or milestone_args == '') then
return "Error: No data was specified.[[Category:Pages with undefined inline milestone]]"
end
if (milestone_args[1] == nil or milestone_args[1] == '') then
return "Error: No milestone was specified.[[Category:Pages with undefined inline milestone]]"
end
local class = nil
if (milestone_args['class'] == nil or milestone_args['class'] == '') then
return "Error: Milestone class must be defined with \"class=\"[[Category:Pages with missing milestone classes]]"
else
class = tonumber(milestone_args['class'])
if (class == nil) then
return "Error: Milestone class must be a number.[[Category:Pages with non-numeric milestone classes]]"
end
end
local cargo_table = 'Milestones'
local cargo_fields = 'Milestones.milestone_name=name,Milestones.milestone_type=m_type,Milestones.to_class=toclass,Milestones.goal_type=goaltype,Milestones.reward=reward,Milestones.alignment=alignment'
local cargo_args = {
where = ('Milestones.milestone_name="' .. milestone_args[1] .. '"'),
limit = 1,
}
local cargo_results = cargo.query( cargo_table, cargo_fields, cargo_args )
local cargo_result = cargo_results[1]
if (cargo_result == nil or cargo_result == '') then
return ('Error: Milestone: "' .. milestone_args[1] .. '" could not be found.[[Category:Pages with invalid inline milestone]]')
end
local milestone_name = nil -- The name of the milestone.
if (cargo_result.name ~= nil and cargo_result.name ~= '') then
milestone_name = cargo_result.name
end
local milestone_alignment = nil -- The alignment of the milestone
if (cargo_result.alignment ~= nil and cargo_result.alignment ~= '') then
milestone_alignment = cargo_result.alignment
end
local milestone_type = nil -- The type of the milestone.
local milestone_type_link = '' -- Format for inserting milestone type into links.
local milestone_link = nil -- A pre-formatted link which should link to the milestone's place on the Milestones page.
if (cargo_result.m_type ~= nil and cargo_result.m_type ~= '') then
milestone_type = cargo_result.m_type
milestone_type_link = '_' .. cargo_result.m_type .. '_Milestone'
milestone_link = 'Milestones#' .. cargo_result.name .. milestone_type_link
else
milestone_link = 'Milestones#' .. cargo_result.name
end
local milestone_subtitle = ''
if (cargo_result.m_type ~= nil and cargo_result.m_type ~= '') then
milestone_subtitle = cargo_result.m_type .. ' Milestone' .. ' '
end
local toclass = nil
if (cargo_result.toclass ~= nil and cargo_result.toclass ~= '') then
toclass = cargo_result.toclass
end
local goaltype = nil
if (cargo_result.goaltype ~= nil and cargo_result.goaltype ~= '') then
goaltype = cargo_result.goaltype
end
if (cargo_result.alignment ~= nil and cargo_result.alignment ~= '') then
alignment = cargo_result.alignment
end
local container = mw.html.create('span')
container:addClass('c-item-hoverbox')
local activator = mw.html.create('span')
activator:addClass('c-item-hoverbox__activator')
activator:wikitext(string.format(
'[[%s|%s]]',
milestone_link,
milestone_name
))
local display = mw.html.create('span')
display:attr('class', 'c-item-hoverbox__display')
-- MILESTONE STATS BOX HTML GO HERE
:addClass('stats-box -commendation pseudo-after rep-voyager')
:tag('span')
:addClass('top')
:tag('span')
:addClass('image-frame')
:tag('div')
:wikitext('[[File:Milestones.png|74px]]')
:done()
:done()
:tag('span')
:addClass('details')
:tag('div')
:addClass('title pseudo-after')
:wikitext(milestone_name)
:tag('div')
:addClass('description')
:wikitext(milestone_subtitle .. ' - ' .. milestone_alignment )
:done()
:done()
:tag('div')
:addClass('description')
:wikitext('Class to unlock: ' .. class)
:tag('br')
:done()
:wikitext('Total to unlock: ' .. tostring(math.floor(toclass * class)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse() .. ' ' .. goaltype)
:done()
:done()
:done()
container
:node(activator)
:node(display)
:done()
return tostring(container)
end
return p