Module:File

local Franchise = require("Module:Franchise") local utilsMarkup = require("Module:UtilsMarkup") local utilsPage = require("Module:UtilsPage") local utilsString = require("Module:UtilsString") local utilsTable = require("Module:UtilsTable")

local p = {}

function p.Icon(frame) local args = frame.args return p.icon(args[1], args[2], {		size = args.size	}) end

function p.image(game, subject, type, options) local parts = utilsTable._filter(utilsString.notEmpty)({game, subject, type}) local filename = table.concat(parts, " ") .. ".png" if utilsPage.exists("File:" .. filename) then return utilsMarkup.file(filename, options) else local uploadUrl = mw.uri.fullUrl("Special:Upload") uploadUrl:extend({			wpDestFile = filename		}) local options = utilsTable.merge({}, options, {			link = tostring(uploadUrl)		}) -- Make sure thumbnail for 'no image' is no less than 100x100px local size for dimension in string.gmatch(options.size or "", "[0-9]+") do			if tonumber(dimension) < 100 then size = "100px" end end options.size = size or options.size or "100px" return utilsMarkup.file("File:No Image Upload.png", options) end end

function p.icon(game, subject, options) local type = "Icon" if Franchise.graphics(game) == "2D" then type = "Sprite" end return p.image(game, subject, type, options) end

local optionsSchema = { type = "record", properties = { {			name = "size", type = "string", desc = "Image size in pixels.", },		{			name = "link", type = "string", desc = "Name of a page on the wiki or an external URL for the image thumbnail to link to.", },		{			name = "caption", type = "string", desc = "Alt text for the image.", },	} }

p.Schemas = { image = { game = { type = "string", required = true, desc = "A game code." },		subject = { type = "string", required = true, },		type = { type = "string", required = true, enum = {"", "Artwork", "Icon", "Model", "Render", "Screenshot", "Sprite", "Texture"}, },		options = options },	icon = { game = { type = "string", required = true, desc = "A game code." },		subject = { type = "string", required = true, },		options = options, } }

p.Documentation = { image = { desc = "See also utilsMarkup.file.", params = {"game", "subject", "type", "options"}, returns = "A  of wikitext that renders a thumbnail.", cases = { {				args = {"TWW", "Great Fairy Figurine", "Model", { link = "Great Fairy", size = "100px" }},				expect = "", },			{				desc = "If file does not exist, show 'click to upload' thumbnail which links to Special:Upload.", args = {"TWWHD", "Great Fairy Figurine", "Model", { link = "Great Fairy", size = "150px" }},				expect = "", },			{				desc = "'No image' thumbnail has minimum 100px width, because it is illegible at smaller sizes.", args = {"TWWHD", "Great Fairy Figurine", "Model", { link = "Great Fairy", size = "64px", }},				expect = "", },		}	},	icon = { params = {"game", "subject", "options"}, returns = "An icon thumbnail for the subject in the given game.", cases = { {				args = {"LANS", "Pineapple"}, expect = "" },			{				args = {"LADX", "Pineapple"}, expect = "" },		}	} }

return p