Module:Link title
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Link title/doc
local getArgs = require('Module:Arguments').getArgs
local m_util = require('Module:Util')
local p = {}
local cargo = mw.ext.cargo
function p.Main( frame )
title_args = frame:getParent().args
local tag_timelimited = frame:expandTemplate{ title = "tag timelimited" }
if (title_args == nil or title_args == '') then
return "Error: No data was specified.[[Category:Pages with undefined inline title]]"
end
if (title_args[1] == nil or title_args[1] == '') then
return "Error: No title was specified.[[Category:Pages with undefined inline title]]"
end
local cargo_table = 'Titles'
local cargo_fields = 'Titles.title_name=name,Titles.title_image=image,Titles.title_text=text,Titles.description=description,Titles.company=company,Titles.company_full=companyfull,Titles.rank=rank,Titles.timelimited=timelimited'
local cargo_args = {
where = ('Titles.title_name="' .. title_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: Title: "' .. title_args[1] .. '" could not be found.[[Category:Pages with invalid inline title]]')
end
local title_name = nil -- The name of the title.
local title_link = nil -- A pre-formatted link which should link to the title's place on the Titles page.
local title_image = nil
if (cargo_result.name ~= nil and cargo_result.name ~= '') then
title_name = cargo_result.name
title_link = 'Titles#' .. cargo_result.name
title_image = cargo_result.image
end
title_customlink = nil
if (title_args['link'] ~= nil and title_args['link'] ~= '') then
title_customlink = title_args['link']
end
local title_text = nil
if (cargo_result.text ~= nil and cargo_result.text ~= '') then
title_text = cargo_result.text
end
local title_ranktext = nil
if (cargo_result.rank ~= nil and cargo_result.rank ~= '') then
title_ranktext = 'Obtained by purchasing the ' .. cargo_result.companyfull .. ' Rank ' .. cargo_result.rank .. ' Promotion.'
end
local title_timelimitedcheck = nil
if (cargo_result.timelimited ~= nil and cargo_result.timelimited ~= '') then
title_timelimitedcheck = cargo_result.timelimited -- This checks if the Title is timelimited
end
title_args.icon = m_util.cast.boolean(title_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 title_args.icon then
activator:wikitext(string.format(
'[[File:%s|50px|link=%s|%s]]',
title_image,
title_customlink or title_link,
title_name
)
)
else
activator:wikitext(string.format(
'[[%s|%s]]',
title_customlink or title_link,
title_name
)
)
end
end
local display = mw.html.create('span')
display:attr('class', 'c-item-hoverbox__display')
-- TITLE 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:' .. title_image .. '|74px]]')
:done()
:done()
:tag('span')
:addClass('details')
:tag('div')
:addClass('title pseudo-after')
:wikitext( title_name )
:done()
:tag('div')
:addClass('description')
:wikitext(string.format(
'%s',
title_text or title_ranktext
)
)
:done()
:done()
:done()
if title_timelimitedcheck ~= nil then
display:tag('div')
:wikitext( tag_timelimited )
:done()
end
container
:node(activator)
:node(display)
:done()
return tostring(container)
end
return p