FANDOM


-- Mostly done. This module has been taken from the WoW wikia site (http://wowwiki.wikia.com) 
-- and adapted for this Wikia.
 
local p = {}
-- load json 
local type_img_data = mw.loadData( 'Module:Iconlink/link_icon_data.json' ) 
local type_img_data_monsters = mw.loadData( 'Module:Iconlink/monsters_link_icon_data.json' )
-- include Arguments module at dev.wikia.com
local getArgs = require('Dev:Arguments').getArgs
local strlower = string.lower -- Convert to lower case
local strupper = string.upper -- Convert to upper case
 
function strucfirst(str)
	local ucfirst_string = mw.ustring.upper(mw.ustring.sub(str, 1, 1)) .. mw.ustring.sub(str, 2)
	return ucfirst_string
end
 
-- Get data from json page given main type name and piece name
function getIconInfo(icon_type, icon_piece)
    icon_type = strlower(icon_type)
 
    local icon_DB = mw.loadData("Module:Iconlink/link_icon_data.json")
    local icon_DB_monsters = mw.loadData("Module:Iconlink/monsters_link_icon_data.json")
    local icon_chunk = icon_DB[icon_type]
    local icon_chunk_monsters = icon_DB_monsters[icon_type]
 
    if icon_chunk and icon_DB[icon_type][icon_piece] then
       return icon_DB[icon_type][icon_piece]
    elseif icon_chunk_monsters and icon_DB_monsters[icon_type][icon_piece] then
	 	 return icon_DB_monsters[icon_type][icon_piece]
    end
end
 
function p.Iconlink(frame) -- Implements {{Iconlink}}
	local args = getArgs(frame, {
    trim = false,
    removeBlanks = false
    })
    local icononly = nil
    local useicon = nil
    local medium = false
    local large = false
    local xlarge = false
    local xxlarge = false --For Monster Icons only
    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
	 if args["xxlarge"] then
        xxlarge = true
    end
 
	return p._Iconlink(args, icononly, useicon, medium, large, xlarge, xxlarge, float)
end
 
function p._Iconlink( args, showonlyicon, showicon, showmedium, showlarge, showxlarge, showxxlarge, floating )
	local icon_index = args['class'] -- use class param for class
	if args['class'] == nil then -- use param 1, if no class=
	    icon_index = args[1]
	elseif args[1] == nil then -- blank type if no param 1
	    icon_index = ''
	end
	if icon_index ~= nil then -- if not nil, make lowercase
		icon_index = string.lower(icon_index)
    end
	local img_filename = 'ImagePlaceholder.png‎'
	local img_size = '20px'
    if showmedium then
        img_size = '32px'
    elseif showlarge then
        img_size = '48px'
    elseif showxlarge then
        img_size = '64px'
    elseif showxxlarge then
        img_size = '90px'
    end
	local icon_link = 'Monsters'
	local link_override = nil
	if args['link'] ~= nil then
		link_override = args['link'] -- use link param for final link override
	end
	local label = 'Monsters'
	local ttip = 'Stat'
	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 .. '|link=' .. icon_link .. ']]'
 
    if icon_index ~= nil then
        -- strip spaces for indexing
        icon_index = mw.ustring.gsub(icon_index, "%s", "")
 
        -- strip apostrophes for indexing
        icon_index = mw.ustring.gsub(icon_index, "\'", "")
 
        -- strip dashes for indexing
        icon_index = mw.ustring.gsub(icon_index, "\-", "")
    end
	-- Check if alias used.	If so reset to standard name.
	if icon_index ~= nil and getIconInfo(icon_index, "alias") ~= nil then
		icon_index = getIconInfo(icon_index, "alias")
	end
 
	-- Get image size change if it exists
	if icon_index ~= nil and getIconInfo(icon_index, "size") ~= nil then
	    img_size = getIconInfo(icon_index, "size")
	end
 
	-- Get link (also for the image)
	if icon_index ~= nil and getIconInfo(icon_index, "link") ~= nil then
	    icon_link = getIconInfo(icon_index, "link")
	end
 
	-- Get label
	if icon_index ~= nil and getIconInfo(icon_index, "label") ~= nil then
	    label = getIconInfo(icon_index, "label")
	end
 
-- Get tooltip
	if icon_index ~= nil and getIconInfo(icon_index, "tip") ~= nil then
		ttip = getIconInfo(icon_index, "tip")
	elseif icon_index ~= nil and getIconInfo(icon_index, "tip") == nil and getIconInfo(icon_index, "label") ~= nil then
		ttip = label
	end
 
    -- Get image filename and build image wikitext
	if icon_index ~= nil and getIconInfo(icon_index, "img") ~= nil then
	    img_filename = getIconInfo(icon_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'
        -- Or to 90px if xxlarge= was specified (Only for Monster Icons)
        elseif showxxlarge then
            img_size = '90px'
        end
 
        -- Build beginning image wikitext starting with filename and size if specified in JSON
        if getIconInfo(icon_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 .. '|<span class="abilitylink ajaxttlink">' .. ttip .. '</span>|link=' .. icon_link .. ']]'
    end
 
    -- If label= passed then use it for what link shows
    if link_label ~= nil then
        label = link_label
    end
 
	local final_link = nil
 
	-- Build variants
	local img_only_link = img_wikitext
 
	local img_with_link = img_wikitext .. '&nbsp;[['
	-- Add link or override, if set
	if link_override ~= nil then
		img_with_link = img_with_link .. link_override .. '|<span class="abilitylink ajaxttlink">' .. label .. '</span>]]'
	else
		img_with_link = img_with_link .. icon_link .. '|<span class="abilitylink ajaxttlink">' .. label .. '</span>]]'
	end
 
	local link_only = '[['
	-- Add link or override, if set
	if link_override ~= nil then
		link_only = link_only .. link_override .. '|<span class="abilitylink ajaxttlink">' .. label .. '</span>]]'
	else
		link_only = link_only .. icon_link .. '|<span class="abilitylink ajaxttlink">' .. label .. '</span>]]'
	end
 
	-- 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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.