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.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)		}) 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 = "100px" }},				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