Module:Link comm
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Link comm/doc
local getArgs = require('Module:Arguments').getArgs
local m_util = require('Module:Util')
local p = {}
local cargo = mw.ext.cargo
function p.Main( frame )
comm_args = frame:getParent().args
if (comm_args == nil or comm_args == '') then
return "<small class=error>Error: No commendation was specified.</small>[[Category:Pages with undefined inline commendations]]"
end
if (comm_args[1] == nil or comm_args[1] == '') then
return "<small class=error>Error: No commendation was specified.</small>[[Category:Pages with undefined inline commendations]]"
end
local cargo_table = 'Commendations'
local cargo_fields = 'Commendations.comm_name=name,Commendations.image=image,Commendations.comm_text=text,Commendations.grade1=grade1,Commendations.grade2=grade2,Commendations.grade3=grade3,Commendations.grade4=grade4,Commendations.grade5=grade5, Commendations.grade6=grade6, Commendations.grade7=grade7, Commendations.grade8=grade8, Commendations.grade9=grade9, Commendations.grade10=grade10, Commendations.gradelist_html=gradelist_html, Commendations.goal_type=goal_type'
local cargo_args = {
where = ('Commendations.comm_name="' .. comm_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 ('<small class=error>Error: Commendation: "' .. comm_args[1] .. '" could not be found.</small>[[Category:Pages with invalid inline commendations]]')
end
local comm_name = nil -- The name of the commendation.
local comm_link = nil -- A pre-formatted link which should link to the commendation's place on the Commendations page.
if (cargo_result.name ~= nil and cargo_result.name ~= '') then
comm_name = cargo_result.name
comm_link = 'Commendations#' .. cargo_result.name
end
local comm_image = nil -- The image file in raw text.
if (cargo_result.image ~= nil and cargo_result.image ~= '') then
comm_image = cargo_result.image
end
local comm_customlink = nil
if (comm_args['link'] ~= nil and comm_args['link'] ~= '') then
comm_customlink = comm_args['link']
end
comm_gradecss = ''
if (comm_args['grade'] ~= nil and comm_args['grade'] ~= '') then
comm_gradecss = comm_args['grade'] -- This tracks the grade of the commendation.
end
local comm_gradelink = nil
if (comm_args['grade'] ~= nil and comm_args['grade'] ~= '') then
comm_gradelink = (comm_name .. ' (Grade ' .. comm_args['grade'] .. ')')
end
local comm_text = nil
if (cargo_result.text ~= nil and cargo_result.text ~= '') then
comm_text = cargo_result.text
end
local comm_gradecheck = nil
if (cargo_result.grade1 ~= nil and cargo_result.grade1 ~= '') then
comm_gradecheck = cargo_result.grade1 -- This checks if Grade data exists (requires data in Grade 1)
end
local comm_goaltype = ''
if (cargo_result.goal_type ~= nil and cargo_result.goal_type ~= '') then
comm_goaltype = cargo_result.goal_type
end
local comm_gradelisthtml = nil
if (cargo_result.gradelist_html ~= nil and cargo_result.gradelist_html ~= '') then
comm_gradelisthtml = cargo_result.gradelist_html
end
comm_args.icon = m_util.cast.boolean(comm_args.icon)
local container = mw.html.create('span')
container:addClass('c-item-hoverbox')
local activator = mw.html.create('span')
activator:addClass('c-item-hoverbox__activator')
if #cargo_result.name > 0 then
if comm_args.icon then
activator:wikitext(string.format(
'[[File:%s|50px|link=%s|%s]]',
comm_image,
comm_customlink or comm_link,
comm_name
)
)
else
activator:wikitext(string.format(
'[[%s|%s]]',
comm_customlink or comm_link,
comm_gradelink or comm_name
)
)
end
end
local display = mw.html.create('span')
display:attr('class', 'c-item-hoverbox__display')
-- COMMENDATION STATS BOX HTML GO HERE
:addClass('stats-box navigation-not-searchable -commendation pseudo-after')
:tag('span')
:addClass('top')
:tag('span')
:addClass('image-frame')
:tag('div')
:addClass('thumb-frame pseudo-before')
:wikitext('[[File:' .. comm_image .. '|74px]]')
:done()
:done()
:tag('span')
:addClass('details')
:tag('div')
:addClass('title pseudo-after')
:wikitext( comm_name )
:done()
:tag('div')
:addClass('description')
:wikitext( comm_text )
:done()
:done()
:done()
if comm_gradecheck ~= nil then
display:tag('div')
:addClass('gradelist grade' .. comm_gradecss)
:wikitext(comm_gradelisthtml)
:done()
end
container
:node(activator)
:node(display)
:done()
return tostring(container)
end
return p