Zelda Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!

Come join the Zelda Wiki community Discord server!

READ MORE

Zelda Wiki
Advertisement
This module exports the following functions.

image

image(game, subject, type, options)

See also utilsMarkup.file.

Parameters

Returns

  • A string of wikitext that renders a thumbnail.

Examples

#InputOutputResultStatus
1
image(
  "TWW",
  "Great Fairy Figurine",
  "Model",
  {
    size = "100px",
    link = "Great Fairy",
  }
)
Expected
"[[File:TWW Great Fairy Figurine Model.png|100px|link=Great Fairy|TWW Great Fairy Figurine Model.png]]"
Actual
"[[File:TWW Great Fairy Figurine Model.png|100px|link=Great Fairy]]"
TWW Great Fairy Figurine Model
TFH Red Link desperate
If file does not exist, show 'click to upload' thumbnail which links to Special:Upload.
2
image(
  "TWWHD",
  "Great Fairy Figurine",
  "Model",
  {
    size = "100px",
    link = "Great Fairy",
  }
)
Expected
"[[File:No Image Upload.png|100px|link=https://zelda.gamepedia.com/Special:Upload?wpDestFile=TWWHD+Great+Fairy+Figurine+Model.png|File:No Image Upload.png]]"
Actual
"[[File:No Image Upload.png|100px|link=https://zelda.fandom.com/wiki/Special:Upload?wpDestFile=TWWHD+Great+Fairy+Figurine+Model.png]]"
No Image Upload
TFH Red Link desperate

icon

icon(game, subject, options)

Parameters

Returns

  • An icon thumbnail for the subject in the given game.

Examples

#InputOutputResultStatus
3
icon("LANS", "Pineapple", nil)
Expected
"[[File:LANS Pineapple Icon.png|LANS Pineapple Icon.png]]"
Actual
"[[File:LANS Pineapple Icon.png]]"
LANS Pineapple Icon
TFH Red Link desperate
4
icon("LADX", "Pineapple", nil)
Expected
"[[File:LADX Pineapple Sprite.png|LADX Pineapple Sprite.png]]"
Actual
"[[File:LADX Pineapple Sprite.png]]"
LADX Pineapple Sprite
TFH Red Link desperate

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)
		})
		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 = "[https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img Alt text] for the image.",
		},
	}
}

p.Schemas = {
	image = {
		game = {
			type = "string",
			required = true,
			desc = "A [[Data:Franchise|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 [[Data:Franchise|game code]]."
		},
		subject = {
			type = "string",
			required = true,
		},
		options = options,
	}
}

p.Documentation = {
	image = {
		desc = "See also [[Module:UtilsMarkup#file|utilsMarkup.file]].",
		params = {"game", "subject", "type", "options"},
		returns = "A <code>string</code> of wikitext that renders a thumbnail.",
		cases = {
			{
				args = {"TWW", "Great Fairy Figurine", "Model", { 
					link = "Great Fairy", 
					size = "100px"
				}},
				expect = "[[File:TWW Great Fairy Figurine Model.png|100px|link=Great Fairy|TWW Great Fairy Figurine Model.png]]",
			},
			{
				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 = "[[File:No Image Upload.png|100px|link=https://zelda.gamepedia.com/Special:Upload?wpDestFile=TWWHD+Great+Fairy+Figurine+Model.png|File:No Image Upload.png]]",
			},
		}
	},
	icon = {
		params = {"game", "subject", "options"},
		returns = "An icon thumbnail for the subject in the given game.",
		cases = {
			{
				args = {"LANS", "Pineapple"},
				expect = "[[File:LANS Pineapple Icon.png|LANS Pineapple Icon.png]]"
			},
			{
				args = {"LADX", "Pineapple"},
				expect = "[[File:LADX Pineapple Sprite.png|LADX Pineapple Sprite.png]]"
			},
		}
	}
}

return p
Advertisement