Module:Sandbox: Difference between revisions

From Fanon Wiki
m (I'll let it go this way for the moment)
m (Assuming it's ok to use this to test since it hasn't been touched in a while and is a sandbox, modifying Module:File to see if this fixes the error where calling an empty source parameter breaks the no source detection)
Line 7: Line 7:
local description = frame.args["description"] or "No description provided [[Category:Files lacking description]]"
local description = frame.args["description"] or "No description provided [[Category:Files lacking description]]"
local type = mw.ustring.lower(frame.args["type"] or "")
local type = mw.ustring.lower(frame.args["type"] or "")
local source = frame.args["source"] or "No source specified [[Category:Files lacking a source]]"
local source  
if frame.args["source"]=="" then source="No source specified [[Category:Files lacking a source]]" else source=frame.args["source"] end
local result = {}
local result = {}
local t = {}
local t = {}
t = {
t = {
    ['art'] = "Official artwork [[Category:Official artworks]]",
    ['art'] = "Official artwork [[Category:Official artwork]]",
    ['artwork'] = "Official artwork [[Category:Official artworks]]",
    --removing other types for testing purposes
    ['art work'] = "Official artwork [[Category:Official artworks]]",
   
    ['audio'] = "Audio [[Category:Audio files]]",
    ['sound'] = "Audio [[Category:Audio files]]",
    ['music'] = "Audio [[Category:Audio files]]",
    ['sound'] = "Audio [[Category:Audio files]]",
   
    ['fanart'] = "Fanart [[Category:Fanarts]]",
    ['fan art'] = "Fanart [[Category:Fanarts]]",
    ['fanartwork'] = "Fanart [[Category:Fanarts]]",
   
    ['flag'] = "Flag [[Category:Flags]]",
   
    ['logo'] = "Logotype [[Category:Logos]]",
    ['logotype'] = "Logotype [[Category:Logos]]",
    ['logomark'] = "Logotype [[Category:Logos]]",
    ['wordmark'] = "Logotype [[Category:Logos]]",
   
    ['map'] = "Map [[Category:Maps]]",
   
    ['photo'] = "Photograph [[Category:Photographs]]",
    ['photograph'] = "Photograph [[Category:Photographs]]",
    ['photography'] = "Photograph [[Category:Photographs]]",
   
    ['scan'] = "Scan [[Category:Scans]]",
    ['magazine'] = "Scan [[Category:Scans]]",
   
    ['screenshot'] = "Screenshot [[Category:Screenshots]]",
    ['screen shot'] = "Screenshot [[Category:Screenshots]]",
    ['printscreen'] = "Screenshot [[Category:Screenshots]]",
    ['print screen'] = "Screenshot [[Category:Screenshots]]",
    ['prtscr'] = "Screenshot [[Category:Screenshots]]",
   
    ['sprite'] = "Sprite [[Category:Sprites]]",
    ['spritesheet'] = "Sprite [[Category:Sprites]]",
    ['sprite sheet'] = "Sprite [[Category:Sprites]]",
   
    ['vector'] = "Vector graphic [[Category:Vector images]]",
    ['svg'] = "Vector graphic [[Category:Vector images]]",
   
    ['video'] = "Video [[Category:Video files]]",
    ['movie'] = "Video [[Category:Video files]]",
    ['film'] = "Video [[Category:Video files]]",
    ['short'] ="Video [[Category:Video files]]"
}
}
 
 
type = t[type] or "No type specified. [[Category:Unspecified files]]"
type = t[type] or "No type specified. [[Category:Files without a type specified]]"
table.insert(result, '<div class="panel" style="--panel-color: #c5c5c5"><div class="mb-2 panel-title">File information</div><table class="table-responsive"><tr><th class="p-2" style="background: #ff4242; color: #fff; border-radius: .5rem 0 0 0">Description</th><td class="p-2">'.. description ..'</td></tr><tr><th class="p-2" style="background: #4292ff; color: #fff">Type</th><td class="p-2" style="background: rgba(0,0,0,.12)">'.. type ..'</td></tr><tr><th class="p-2" style="background: #f5ff42; border-radius: 0 0 0 .5rem">Source/author</th><td class="p-2">'.. source ..'</td></tr></table></div>')
local license = mw.title.getCurrentTitle():getContent()
if license:find('%{%{License%-') then license = "" else license = "[[Category:Files without licenses]]" end
local panel = '<div class="panel" style="--panel-color: #c5c5c5"><div class="mb-2 panel-title">File information</div><table class="table-responsive"><tr><th class="p-2" style="background: #ff4242; color: #fff; border-radius: .5rem 0 0 0">Description</th><td class="p-2">'.. description ..'</td></tr><tr><th class="p-2" style="background: #4292ff; color: #fff">Type</th><td class="p-2" style="background: rgba(0,0,0,.12)">'.. type ..'</td></tr><tr><th class="p-2" style="background: #f5ff42; border-radius: 0 0 0 .5rem">Source/author</th><td class="p-2">'.. source ..'</td></tr></table></div>'.. license ..''
if mw.title.getCurrentTitle().namespace ~= 6 then panel = "Hey! The module does not spawn here because it's intended to be used on File pages only." end
table.insert(result, panel)
return table.concat(result, "")
return table.concat(result, "")
end
end


return f
return f

Revision as of 18:15, 11 November 2023

A sandbox for testing lua modules. Since this is a module, it uses actual programming code instead of wiki formatting.


--Hey, this is a sandbox for Lua!
--Be careful :O

local f = {}

function f.main(frame)
	local description = frame.args["description"] or "No description provided [[Category:Files lacking description]]"
	local type = mw.ustring.lower(frame.args["type"] or "")
	local source 
	if frame.args["source"]=="" then source="No source specified [[Category:Files lacking a source]]" else source=frame.args["source"] end
	local result = {}
	local t = {}
	t = {
	    ['art'] = "Official artwork [[Category:Official artwork]]",
	    --removing other types for testing purposes
	 }
	 
	type = t[type] or "No type specified. [[Category:Files without a type specified]]"
	
	local license = mw.title.getCurrentTitle():getContent()
	if license:find('%{%{License%-') then license = "" else license = "[[Category:Files without licenses]]" end
	
	local panel = '<div class="panel" style="--panel-color: #c5c5c5"><div class="mb-2 panel-title">File information</div><table class="table-responsive"><tr><th class="p-2" style="background: #ff4242; color: #fff; border-radius: .5rem 0 0 0">Description</th><td class="p-2">'.. description ..'</td></tr><tr><th class="p-2" style="background: #4292ff; color: #fff">Type</th><td class="p-2" style="background: rgba(0,0,0,.12)">'.. type ..'</td></tr><tr><th class="p-2" style="background: #f5ff42; border-radius: 0 0 0 .5rem">Source/author</th><td class="p-2">'.. source ..'</td></tr></table></div>'.. license ..''
	
	if mw.title.getCurrentTitle().namespace ~= 6 then panel = "Hey! The module does not spawn here because it's intended to be used on File pages only." end
	
	table.insert(result, panel)
	return table.concat(result, "")
end

return f