FANDOM


local p = {}
 
local type_img_data = mw.loadData( 'Module:Proflink/link_icon_data.json' ) -- load json
local getArgs = require('Dev:Arguments').getArgs
local strlower = string.lower -- Convert to lower case
 
-- Get data from json page given main type name and piece name
function getprofInfo(prof_type, prof_piece)
    prof_type = strlower(prof_type)
 
    local prof_DB = mw.loadData("Module:Proflink/link_icon_data.json")
    local prof_chunk = prof_DB[prof_type]
 
    if prof_chunk and prof_DB[prof_type][prof_piece] then
       return prof_DB[prof_type][prof_piece]
    end
end
 
function p.Proflink(frame) -- Implements {{Proflink}}
	local args = getArgs(frame, {
    trim = false,
    removeBlanks = false
    })
    local icononly = nil
    local useicon = nil
    local medium = false
    local large = false
    local xlarge = false
    local float_check = args["float"]
    local float = nil
 
    if args["icononly"] then
        icononly = true
    else
        useicon = false
 
        if args["icon"] then
            useicon = true
        else
            useicon = false
        end
    end
 
    if float_check ~= nil then
        float_check = strlower(float_check)
 
        if float_check == "left" then
            float="left"
        end
        if float_check == "right" then
            float="right"
        end
        if float_check == "thumb" then
            float="thumb"
        end
    end
 
    if args["medium"] then
        medium = true
    end
    if args["large"] then
        large = true
    end
    if args["xlarge"] then
        xlarge = true
    end
 
	return p._Proflink(args, icononly, useicon, medium, large, xlarge, float)
end
 
function p._Proflink( args, showonlyicon, showicon, showmedium, showlarge, showxlarge, floating )
	local prof_index = args['type'] -- use type param for type
	if args['type'] == nil then -- use param 1, if no type=
	    prof_index = args[1]
	elseif args[1] == nil then -- blank type if no param 1
	    prof_index = ''
	end
	if prof_index ~= nil then -- if not nil, make lowercase
		prof_index = string.lower(prof_index)
    end
	local img_filename = 'Inv_misc_questionmark.png'
	local img_size = '21px'
    if showmedium then
        img_size = '32px'
    elseif showlarge then
        img_size = '48px'
    elseif showxlarge then
        img_size = '64px'
    end
	local prof_link = 'Profession'
	local label_tooltip = 'Profession'
	local link_label = nil
	if args['label'] ~= nil then
	    link_label = args['label'] -- use label param for type
	elseif args['label'] == nil and args[2] ~= nil then -- use param 2, if no label=
	    link_label = args[2]
	end
 
	-- Build beginning default image wikitext
	local img_wikitext = '[[File:' .. img_filename .. '|' .. img_size
	-- Add floating, if icon only
	if floating ~=nil and showonlyicon then
	            img_wikitext = img_wikitext .. '|' .. floating
    end
    -- Add default tooltip and link
	img_wikitext = img_wikitext .. '|' .. label_tooltip ..'|link=' .. prof_link .. ']]'
 
    if prof_index ~= nil then
        -- strip spaces for indexing
        prof_index = mw.ustring.gsub(prof_index, "%s", "")
 
        -- strip apostrophes for indexing
        prof_index = mw.ustring.gsub(prof_index, "\'", "")
 
        -- strip dashes for indexing
        prof_index = mw.ustring.gsub(prof_index, "\-", "")
    end
 
	-- Get image size change if it exists
	if prof_index ~= nil and getprofInfo(prof_index, "size") ~= nil then
	    img_size = getprofInfo(prof_index, "size")
	end
 
	-- Get link (also for for image)
	if prof_index ~= nil and getprofInfo(prof_index, "link") ~= nil then
	    prof_link = getprofInfo(prof_index, "link")
	end
 
	-- Get label/tooltip
	if prof_index ~= nil and getprofInfo(prof_index, "label") ~= nil then
	    label_tooltip = getprofInfo(prof_index, "label")
	end
 
    -- Get image filename and build image wikitext
	if prof_index ~= nil and getprofInfo(prof_index, "img") ~= nil then
	    	img_filename = getprofInfo(prof_index, "img") -- Get image filename
 
            -- Change size to 32px if medium= was specified
            if showmedium then
                img_size = '32px'
            -- Or to 48px if large= was specified
            elseif showlarge then
                img_size = '48px'
            -- Or to 64px if xlarge= was specified
            elseif showxlarge then
                img_size = '64px'
        	end
 
	    	-- Build beginning image wikitext starting with filename and size if specified in JSON
	        if getprofInfo(prof_index, "size") ~= nil or showmedium or showlarge then -- add size, if it exists
	            img_wikitext = '[[File:' .. img_filename .. '|' .. img_size
	        else
	            img_wikitext = '[[File:' .. img_filename
	        end
 
	        -- Add float, if icon only
	        if floating ~=nil and showonlyicon then
	            img_wikitext = img_wikitext .. '|' .. floating
            end
 
	        -- Add tooltip and link
	        img_wikitext = img_wikitext .. '|' .. label_tooltip .. '|link=' .. prof_link .. ']]'
    end
 
    -- If label= passed then use it for what link shows
    if link_label ~= nil then
        label_tooltip = link_label
    end
 
    -- If label= passed then use it for what link shows
    if link_label ~= nil then
        label_tooltip = link_label
    end
 
	local final_link = nil
	-- Build variants
	local img_only_link = img_wikitext
	local img_with_link = img_wikitext .. '&nbsp;[[' .. prof_link .. '|<span class="abilitylink ajaxttlink">' .. label_tooltip .. '</span>]]'
	local link_only = '[[' .. prof_link .. '|<span class="abilitylink ajaxttlink">' .. label_tooltip .. '</span>]]'
 
	-- Determine which variant to return
	if showonlyicon then
	    final_link = img_only_link
	else
	    if showicon then
	        final_link = img_with_link
	    else
	        final_link = link_only
	    end
	end
 
	-- Return variation wikitext
	return final_link
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.