FANDOM


 
local p = {}
 
local type_img_data = mw.loadData( 'Module:Inlinegfx/img_link_data.json' ) -- load json
local getArgs = require('Module:Arguments').getArgs
local strlower = string.lower -- Convert to lower case
 
-- Get data from json page given main type name and piece name
function getInlineInfo(inline_type, inline_piece)
    inline_type = strlower(inline_type)
 
    local inline_DB = mw.loadData("Module:Inlinegfx/img_link_data.json")
    local inline_chunk = inline_DB[inline_type]
 
    if inline_chunk and inline_DB[inline_type][inline_piece] then
       return inline_DB[inline_type][inline_piece]
    end
end
 
function p.Inlinegfx(frame) -- Implements {{Inlinegfx}}
	local args = getArgs(frame, {
		trim = false,
		removeBlanks = false
		})
	local nolink = false
	local nosort = false
 
	if args["nolink"] then
		nolink = true
	end
 
	if args["nosort"] then
        nosort = true
    end
 
	return p._Inlinegfx(args, nosort, nolink)
end
 
function p._Inlinegfx( args, hidesort, donotlink )
	local sort_tpl = ' '
	local img_type = args['type'] -- use type param for type
	if args['type'] == nil then -- use param 1, if no type=
	    img_type = args[1]
	elseif args[1] == nil then -- blank type if no param 1
	    img_type = ''
	end
	if img_type ~= nil then -- if not nil, make lowercase
		img_type = string.lower(img_type)
    end
	local img_filename = 'Inv_misc_questionmark.png'
	local img_wikitext = '[[File:' .. img_filename .. '|18px|link=]]'
	local img_size = nil
	local img_link = 'Warcraft universe'
	local img_tip = nil
 
	-- Use new img_type, if alias found
	if img_type ~= nil and getInlineInfo(img_type, "alias") ~= nil then
		img_type = getInlineInfo(img_type, "alias")
	end
 
	-- Get image size change if it exists
	if img_type ~= nil and getInlineInfo(img_type, "size") ~= nil then
	    img_size = getInlineInfo(img_type, "size")
	end
 
	-- Get link for image
	if img_type ~= nil and getInlineInfo(img_type, "link") ~= nil then
	    img_link = getInlineInfo(img_type, "link")
	end
 
	-- Get tooltip for image
	if img_type ~= nil and getInlineInfo(img_type, "tip") ~= nil then
	    img_tip = getInlineInfo(img_type, "tip")
	end
 
	if args['size'] ~= nil then -- use size= for img_size, if passed
		img_size = args['size']
	end
 
    -- Get image filename and build image wikitext
	if img_type ~= nil and getInlineInfo(img_type, "img") ~= nil then
	    	img_filename = getInlineInfo(img_type, "img") -- Get image filename
	    	-- Build image wikitext without link and close
	        if img_size ~= nil then -- add size, if it exists
	            -- Still use img_link for tooltip
	            img_wikitext = '[[File:' .. img_filename .. '|' .. img_size .. '|' .. img_link
	        else
	            -- Get tooltip for image
	            if img_tip ~= nil then
	                img_wikitext = '[[File:' .. img_filename .. '|' .. img_tip
	            -- Otherwise use img_link for tooltip
	            else
	                img_wikitext = '[[File:' .. img_filename .. '|' .. img_link
	            end
	        end
	        -- Add empty link if donotlink is true and close
			if donotlink then
			    img_wikitext = img_wikitext .. '|link=]]'
			-- Add img_link as link and close
			else
			    img_wikitext = img_wikitext .. '|link=' .. img_link .. ']]'
			end
    elseif img_type == nil then
        img_type = 'none'
    end
 
	-- Get sort order (if hidesort is true, then don't set sort_tpl)
	if img_type ~= nil and getInlineInfo(img_type, "sortorder") ~= nil and not hidesort then
	    sort_tpl = getInlineInfo(img_type, "sortorder")
	end
 
	-- Build sort span with image wikitext
	local img_span_link = mw.html.create('span')
	    :wikitext('<span style="display:none;">' .. sort_tpl .. '</span>' .. img_wikitext)
 
	-- Return sort span and image wikitext
	return img_span_link
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.