Module:Keywords
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Keywords/doc
--Code for getting text for Keywords & Icons
local p = {}
local KeyData = mw.loadData( 'Module:Keywords/data')
local Shared = require( 'Module:Shared' )
function p.getIconValue(icon, valName, asString)
if(asString == nil) then asString = false end
if(valName == nil or valName == "") then
return "ERROR: No value chosen"
end
local result = nil
valName = string.upper(valName)
if(valName == "NAME") then
result = icon.Name
elseif(valName == "CODE") then
if(icon.Code ~= nil) then
result = icon.Code
else
result = icon.Name
end
elseif(valName == "IMAGE") then
result = icon.Image
elseif(valName == "ORACLE") then
result = icon.Oracle
elseif(valName == "LINK") then
result = icon.Link
elseif(valName == "TEXT") then
result = icon.Text
elseif(valName == "TEXT2") then
result = icon.Text2
elseif(valName == "TEXT3") then
result = icon.Text3
elseif(valName == "TEXT4") then
result = icon.Text4
elseif(valName == "TOOLTIP") then
local name = p.getIconValue(icon, "NAME")
local oracle = p.getIconValue(icon, "ORACLE")
local text = p.getIconValue(icon, "TEXT")
local text2 = p.getIconValue(icon, "TEXT2")
local text3 = p.getIconValue(icon, "TEXT3")
local text4 = p.getIconValue(icon, "TEXT4")
result = ''
if name ~= nil then
result = name
end
if oracle ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..oracle
end
if text ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..text
end
if text2 ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..text2
end
if text3 ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..text3
end
if text4 ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..text4
end
end
if(result == nil and asString) then
return ''
end
return result
end
function p.getKeyValue(keyword, valName, asString)
if(asString == nil) then asString = false end
if(keyword == nil) then return nil end
if(valName == nil or valName == "") then
return "ERROR: No value chosen"
end
local result = nil
valName = string.upper(valName)
if(valName == "NAME") then
return keyword.Name
elseif(valName == "CODE") then
if(keyword.Code ~= nil) then
return keyword.Code
else
return keyword.Name
end
elseif(valName == "LINK") then
if(keyword.Link ~= nil) then
return keyword.Link
else
return keyword.Name
end
elseif(valName == "TEXT") then
return keyword.Text
elseif(valName == "TEXT2") then
return keyword.Text2
elseif(valName == "TEXT3") then
return keyword.Text3
elseif(valName == "TEXT4") then
return keyword.Text4
elseif(valName == "ORACLE") then
return keyword.Oracle
elseif(valName == "IMAGE") then
if(keyword.Image ~= nil) then
return keyword.Image
end
elseif(valName == "TOOLTIP") then
local name = p.getKeyValue(keyword, "NAME")
local oracle = p.getKeyValue(keyword, "ORACLE")
local text = p.getKeyValue(keyword, "TEXT")
local text2 = p.getKeyValue(keyword, "TEXT2")
local text3 = p.getKeyValue(keyword, "TEXT3")
local text4 = p.getKeyValue(keyword, "TEXT4")
result = ''
if name ~= nil then
result = name
end
if oracle ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..oracle
end
if text ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..text
end
if text2 ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..text2
end
if text3 ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..text3
end
if text4 ~= nil then
if name ~= nil then result = result..':\\n' end
result = result..text4
end
end
if(result == nil and asString) then
return ''
end
return result
end
function p.Icon(frame)
local iName = frame.args ~= nil and frame.args[1] or nil
local addtext = frame.args ~= nil and frame.args[2] or nil
local imgsize = frame.args ~= nil and frame.args.imgsize or nil
local addtooltip = frame.args ~= nil and frame.args.tooltip or nil
local text = frame.args ~= nil and frame.args.text or nil
return p._Icon(iName, addtext, imgsize, addtooltip, text)
end
--Pulls an icon from the list of icons and displays it
--Adds a tooltip if available, and links to the appropriate page
function p._Icon(iconName, addtext, imgsize, addTooltip, overrideText)
if(addtext == nil) then addtext = '' end
addtext = string.upper(addtext)
if(addTooltip ~= nil or addTooltip ~= '') then addTooltip = 'YES'
else addTooltip = string.upper(addTooltip) end
if(imgsize == nil or imgsize == '') then
imgsize = '20'
end
local result = ''
for i, Icon in pairs(KeyData["Icons"]) do
local code = p.getIconValue(Icon, "Code")
local name = p.getIconValue(Icon, "Name")
if(code == iconName or name == iconName) then
local text = p.getIconValue(Icon, "Text")
local text2 = p.getIconValue(Icon, "Text2")
local text3 = p.getIconValue(Icon, "Text3")
local text4 = p.getIconValue(Icon, "Text4")
local image = p.getIconValue(Icon, "Image")
local oracle = p.getIconValue(Icon, "Oracle")
local link = p.getIconValue(Icon, "Link")
local tooltip = p.getIconValue(Icon, "Tooltip")
result = '[[File:'..image..'|'..imgsize..'px'
if(link ~= nil) then
result = result..'|link='..link
elseif(name ~= nil) then
result = result..'|'..text
end
result = result..']]'
if(addtext == 'YES' or addtext == 'TEXT') then
if(link ~= nil) then
if(overrideText == nil or overrideText == '') then
result = result..' [['..link..'|'..name..']]'
else
result = result..' [['..link..'|'..overrideText..']]'
end
elseif(name ~= nil) then
if(overrideText == nil or overrideText == '') then
result = result..' '..name
else
result = result..' '..overrideText
end
end
end
--Icon does not need tooltip IMO
--if(addTooltip == 'YES' or addTooltip == "TRUE") then
-- result = '<span class = "basic-tooltip" title="'..tooltip..'">'..result..'</span>'
--end
return result
end
end
return nil
end
function p.Keyword(frame)
local keyname = frame.args ~= nil and frame.args[1] or nil
local addtooltip = frame.args ~= nil and frame.args.tooltip or nil
local text = frame.args ~= nil and frame.args.text or nil
return p._Keyword(keyname, addtooltip, text)
end
function p.KeywordTooltip(frame)
local keyName = frame.args[1] or frame.args["keyword"] or nil
return p._KeywordTooltip(keyName)
end
function p._Keyword(keyname, addTooltip, overrideText)
if(keyname == nil or keyname == "") then return "ERROR: No keyword chosen" end
if(addTooltip == nil or addTooltip == '') then addTooltip = 'YES'
else addTooltip = string.upper(addTooltip) end
local result = ''
for i, Key in pairs(KeyData["Keywords"]) do
local code = p.getKeyValue(Key, 'Code')
local name = p.getKeyValue(Key, 'Name')
if(code == keyname or name == keyname) then
local link = p.getKeyValue(Key, 'Link')
local tooltip = p.getKeyValue(Key, 'Tooltip')
local image = p.getKeyValue(Key, 'Image')
local text2 = p.getKeyValue(Key, 'Text2')
local text3 = p.getKeyValue(Key, 'Text3')
local text4 = p.getKeyValue(Key, 'Text4')
local oracle = p.getKeyValue(Key, 'Oracle')
local imageSize = '20px'
if(link ~= nil) then
if (link == mw.title.getCurrentTitle().text) then
if(overrideText == nil or overrideText == '') then
result = '<span style="color:#20211f">'..name..'</span>'
else
result = '<span style="color:#20211f">'..overrideText..'</span>'
end
else
if(overrideText == nil or overrideText == '') then
result = '[['..link..'|'..name..']]'
else
result = '[['..link..'|'..overrideText..']]'
end
end
else
if(overrideText == nil or overrideText == '') then
result = name
else
result = overrideText
end
end
if(image ~= nil) then
result = '[[File:'..image..'|link='..link..'|'..imageSize..'|middle]] '..result..''
end
if(addTooltip == 'YES' or addTooltip == "TRUE") then
result = '<span class = "keyword-tooltip" data-name="'..name..'">'..result..'</span>'
end
return result
end
end
end
function p._KeywordTooltip(keyname)
if(keyname == nil or keyname == "") then return "ERROR: No keyword chosen" end
for i, Key in pairs(KeyData["Keywords"]) do
local code = p.getKeyValue(Key, 'Code')
local name = p.getKeyValue(Key, 'Name')
if(code == keyname or name == keyname) then
local text = p.getKeyValue(Key, 'Text')
local text2 = p.getKeyValue(Key, 'Text2')
if (text2 == nil) then
text2 = p.getKeyValue(keyword, "TEXT2")
end
local text3 = p.getKeyValue(Key, 'Text3')
if (text3 == nil) then
text3 = p.getKeyValue(keyword, "TEXT3")
end
local text4 = p.getKeyValue(Key, 'Text4')
if (text4 == nil) then
text4 = p.getKeyValue(keyword, "TEXT4")
end
local image = p.getKeyValue(Key, 'Image')
local oracle = p.getKeyValue(Key, 'Oracle')
local oracleText = ''
--Oracle Colors
oracleText = '<span style="font-weight:bold; font-size: 13px; '
--Moonie
if (oracle == "Moonie") then
oracleText = oracleText..'color:royalBlue">Moonie</span>'
--Cellarius
elseif (oracle == "Cellarius") then
oracleText = oracleText..'color:lightSkyBlue">Cellarius</span>'
--Hevelius
elseif (oracle == "Hevelius") then
oracleText = oracleText..'color:goldenRod">Hevelius</span>'
--Austra
elseif (oracle == "Austra") then
oracleText = oracleText..'color:brown">Austra</span>'
--Sothis
elseif (oracle == "Sothis") then
oracleText = oracleText..'color:sandyBrown">Sothis</span>'
--Orion
elseif (oracle == "Orion") then
oracleText = oracleText..'color:blueViolet">Orion</span>'
--Any
elseif (oracle == "Any") then
oracleText = oracleText..'color:grey">Any</span>'
else
oracleText = oracleText..'color:#89a2a3">'..oracle..'</span>'
end
local imageSize = '25x25px'
local windowSize = '320px'
local cellSize = '10%'
local padding = '10px 10px 10px 10px'
if(text2 == nil) then
result = '{| style="word-break:break-word; border: 2px solid burlyWood; background-color: #20211f; border-radius: 10px; width:'..windowSize..'; padding: 10px 5px 10px 5px"'
result = result..'\n|rowspan="2" style="width:'..cellSize..';"|[[File:'..image..'|'..imageSize..']]'
result = result..'\n|colspan="2" |<div style="font-size: 17px; font-weight:bold; font size: 17px; padding: 4px 0px 0px 0px; color:#FFFFFF">'..name
result = result..'\n|-'
result = result..'\n|colspan="2"|<div style="vertical-align: top; padding: 0px 0px 0px 0px;">'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 0px 5px 0px 0px; color:#FFFFFF">'..text..'</div>'
result = result..'\n|-'
result = result..'|}'
elseif(text2 ~= nil and text3 == nil) then
result = '{| style="word-break:break-word; border: 2px solid burlyWood; background-color: #20211f; border-radius: 10px; width:'..windowSize..'; padding: 10px 5px 10px 5px"'
result = result..'\n|rowspan="2" style="width:'..cellSize..';"|[[File:'..image..'|'..imageSize..']]'
result = result..'\n|colspan="2" |<div style="font-size: 17px; font-weight:bold; font size: 17px; padding: 4px 0px 0px 0px; color:#FFFFFF">'..name
result = result..'\n|-'
result = result..'\n|colspan="2"|<div style="vertical-align: top; padding: 0px 0px 0px 0px;">'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 0px 5px 0px 0px; color:#FFFFFF">'..text..'</div>'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 5px 5px 0px 0px; border-top: 2px solid burlyWood; color:#FFFFFF">'..text2..'</div>'
result = result..'\n|-'
result = result..'|}'
elseif(text3 ~= nil and text4 == nil) then
result = '{| style="word-break:break-word; border: 2px solid burlyWood; background-color: #20211f; border-radius: 10px; width:'..windowSize..'; padding: 10px 5px 10px 5px"'
result = result..'\n|rowspan="2" style="width:'..cellSize..';"|[[File:'..image..'|'..imageSize..']]'
result = result..'\n|colspan="2" |<div style="font-size: 17px; font-weight:bold; font size: 17px; padding: 4px 0px 0px 0px; color:#FFFFFF">'..name
result = result..'\n|-'
result = result..'\n|colspan="2"|<div style="vertical-align: top; padding: 0px 0px 0px 0px;">'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 0px 5px 0px 0px; color:#FFFFFF">'..text..'</div>'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 5px 5px 0px 0px; border-top: 2px solid burlyWood; color:#FFFFFF">'..text2..'</div>'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 5px 5px 0px 0px; border-top: 2px solid burlyWood; color:#FFFFFF">'..text3..'</div>'
result = result..'\n|-'
result = result..'|}'
elseif(text4 ~= nil) then
result = '{| style="word-break:break-word; border: 2px solid burlyWood; background-color: #20211f; border-radius: 10px; width:'..windowSize..'; padding: 10px 5px 10px 5px"'
result = result..'\n|rowspan="2" style="width:'..cellSize..';"|[[File:'..image..'|'..imageSize..']]'
result = result..'\n|colspan="2" |<div style="font-size: 17px; font-weight:bold; font size: 17px; padding: 4px 0px 0px 0px; color:#FFFFFF">'..name
result = result..'\n|-'
result = result..'\n|colspan="2"|<div style="vertical-align: top; padding: 0px 0px 0px 0px;">'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 0px 5px 0px 0px; color:#FFFFFF">'..text..'</div>'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 5px 5px 0px 0px; border-top: 2px solid burlyWood; color:#FFFFFF">'..text2..'</div>'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 5px 5px 0px 0px; border-top: 2px solid burlyWood; color:#FFFFFF">'..text3..'</div>'
result = result..'\n|-'
result = result..'\n|colspan="3"|<div style="word-wrap: break-word; padding: 5px 5px 0px 0px; border-top: 2px solid burlyWood; color:#FFFFFF">'..text4..'</div>'
result = result..'\n|-'
result = result..'|}'
end
return result
end
end
end
function p.FillIcons(text, addTooltip)
local result = text
for i, Icon in pairs(KeyData["Icons"]) do
local code = p.getIconValue(Icon, "Code")
if(Shared.contains(result, code)) then
local newText = p._Icon(code, nil, nil, addTooltip)
result = string.gsub(result, code, newText)
end
end
return result
end
function p.FillKeywords(text, addTooltip)
local result = text
for i, Key in pairs(KeyData["Keywords"]) do
local code = p.getKeyValue(Key, "Code")
if(Shared.contains(result, code)) then
local newText = p._Keyword(code, addTooltip)
result = string.gsub(result, code:gsub('%-','%%-'), newText)
end
end
return result
end
function p.ListKeywords(frame)
local data = {}
for i, Key in pairs(KeyData["Keywords"]) do
local code = p.getKeyValue(Key, "Code")
if(code ~= nil) then
local text = p._Keyword(code)
table.insert(data, code..' ('..text..')')
end
end
table.sort(data)
local result = 'All '..Shared.tableCount(data)..' keywords:\n'
for i, str in pairs(data) do
result = result..'\n* '..str
end
return result
end
function p.ListIcons(frame)
local data = {}
for i, Icon in pairs(KeyData["Icons"]) do
local code = p.getIconValue(Icon, "Code")
if(code ~= nil) then
local text = p._Icon(code)
table.insert(data, code..' ('..text..')')
end
end
table.sort(data)
local result = 'All '..Shared.tableCount(data)..' icons:\n'
for i, str in pairs(data) do
result = result..'\n* '..str
end
return result
end
return p