<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pttlink.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AFile</id>
	<title>Module:File - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pttlink.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AFile"/>
	<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:File&amp;action=history"/>
	<updated>2026-05-05T00:49:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://wiki.pttlink.org/index.php?title=Module:File&amp;diff=11171&amp;oldid=prev</id>
		<title>Kg7qin: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:File&amp;diff=11171&amp;oldid=prev"/>
		<updated>2022-01-24T07:59:41Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 07:59, 24 January 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Kg7qin</name></author>
	</entry>
	<entry>
		<id>https://wiki.pttlink.org/index.php?title=Module:File&amp;diff=11170&amp;oldid=prev</id>
		<title>Mediawiki&gt;CptViraj: Changed protection settings for &quot;Module:File&quot;: High-risk Lua module ([Edit=Allow only template editors and administrators] (indefinite) [Move=Allow only template editors and administrators] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:File&amp;diff=11170&amp;oldid=prev"/>
		<updated>2021-07-05T08:21:42Z</updated>

		<summary type="html">&lt;p&gt;Changed protection settings for &amp;quot;&lt;a href=&quot;/wiki/Module:File&quot; title=&quot;Module:File&quot;&gt;Module:File&lt;/a&gt;&amp;quot;: &lt;a href=&quot;https://commons.wikimedia.org/wiki/Protection_policy&quot; class=&quot;extiw&quot; title=&quot;commons:Protection policy&quot;&gt;High-risk Lua module&lt;/a&gt; ([Edit=Allow only template editors and administrators] (indefinite) [Move=Allow only template editors and administrators] (indefinite))&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Module for handling Media files (Origin: Wikimedia Commons)&lt;br /&gt;
&lt;br /&gt;
require('Module:No globals')&lt;br /&gt;
&lt;br /&gt;
-- ==================================================&lt;br /&gt;
-- === helper Lookup table ==========================&lt;br /&gt;
-- ==================================================&lt;br /&gt;
&lt;br /&gt;
local extensionMap = {&lt;br /&gt;
	-- File types with full support in Commons (See [[c:Commons:File types]]).&lt;br /&gt;
	DJVU = 'image/vnd.djvu',&lt;br /&gt;
	FLAC = 'audio/x-flac',&lt;br /&gt;
	GIF  = 'image/gif',&lt;br /&gt;
	JPEG = 'image/jpeg',&lt;br /&gt;
	JPG  = 'image/jpeg',&lt;br /&gt;
	MID  = 'audio/midi',&lt;br /&gt;
	MP3  = 'audio/mpeg',&lt;br /&gt;
	OGA  = 'audio/ogg',&lt;br /&gt;
	OGG  = 'audio/ogg',&lt;br /&gt;
	OGV  = 'video/ogg',&lt;br /&gt;
	PDF  = 'application/pdf',&lt;br /&gt;
	PNG  = 'image/png',&lt;br /&gt;
	SVG  = 'image/svg+xml',&lt;br /&gt;
	TIF  = 'image/tiff',&lt;br /&gt;
	TIFF = 'image/tiff',&lt;br /&gt;
	WEBM = 'video/webm',&lt;br /&gt;
	WAV  = 'audio/x-wav',&lt;br /&gt;
	XCF  = 'image/xcf',&lt;br /&gt;
&lt;br /&gt;
	-- Other file types with restrictions (not accepted in standard uploads on Commons but in 'User:' namespace).&lt;br /&gt;
	-- They could be supported in Wiki pages by embedding their content in an &amp;lt;pre&amp;gt; or &amp;lt;source&amp;gt; elements.&lt;br /&gt;
	CSS  = 'text/css',&lt;br /&gt;
	CSV  = 'text/csv',&lt;br /&gt;
	JS   = 'application/javascript',&lt;br /&gt;
	JSON = 'application/json',&lt;br /&gt;
	TXT  = 'text/plain',&lt;br /&gt;
	XML  = 'application/xml',&lt;br /&gt;
&lt;br /&gt;
	-- Only generated by MediaWiki on output of some queries, restricted in all uploads.&lt;br /&gt;
	GZ   = 'application/gzip', -- delivered only only for some wiki results&lt;br /&gt;
	ZIP  = 'application/zip', -- delivered only for some wiki data exports&lt;br /&gt;
&lt;br /&gt;
	-- Other file types not supported and to convert (a few of them may be in special administration namespaces).&lt;br /&gt;
	DOC  = 'application/msword', -- please convert to PDF, DJVU, or Wiki&lt;br /&gt;
	F4V  = 'video/mpeg', -- (deprecated, replaced by MP4) please convert to OGV or WEBM&lt;br /&gt;
	FLV  = 'video/x-flv', -- (deprecated, replaced by MP4) please convert to OGV or WEBM&lt;br /&gt;
	ICO  = 'image/vnd.microsoft.icon', -- used in MediaWiki resources for 'website icons'&lt;br /&gt;
	MP4  = 'video/mp4', &lt;br /&gt;
	QT   = 'video/quicktime', -- (deprecated, replaced by MP4) please convert to OGV or WEBM&lt;br /&gt;
	RA   = 'audio/vnd.rn-realaudio', -- (deprecated, replaced by MP3) please convert to OGA&lt;br /&gt;
	SWF  = 'video/x-flv', -- (deprecated, replaced by MP4) please convert to OGV or WEBM&lt;br /&gt;
	WMA  = 'audio/x-ms-wma', -- please convert to OGA&lt;br /&gt;
	WMV  = 'video/x-ms-wmv', -- please convert to OGV or WEBM&lt;br /&gt;
	XLS  = 'application/vnd.ms-excel', -- please convert to PDF, DJVU, or Wiki&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- ==================================================&lt;br /&gt;
-- === Local functions ==============================&lt;br /&gt;
-- ==================================================&lt;br /&gt;
&lt;br /&gt;
local function filename(frame)&lt;br /&gt;
	return frame.args[1] or frame.args[&amp;quot;file&amp;quot;] or frame.args[&amp;quot;title&amp;quot;] &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getMetadata(frame)&lt;br /&gt;
	local fname = filename(frame)&lt;br /&gt;
	local title&lt;br /&gt;
	if fname then&lt;br /&gt;
        title = mw.title.new(fname, 6)&lt;br /&gt;
	else&lt;br /&gt;
        title = mw.title.getCurrentTitle()&lt;br /&gt;
	end&lt;br /&gt;
	if title then&lt;br /&gt;
		return title.file&lt;br /&gt;
	else&lt;br /&gt;
		return {exists=false}&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- ==================================================&lt;br /&gt;
-- === External functions ===========================&lt;br /&gt;
-- ==================================================&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- p.csExtension(&amp;quot;Foo.bar.svg&amp;quot;)&lt;br /&gt;
-- @return &amp;quot;svg&amp;quot;&lt;br /&gt;
function p.csExtension(frame)&lt;br /&gt;
	local fname = filename(frame) or mw.title.getCurrentTitle().text&lt;br /&gt;
	local parts = mw.text.split(fname, '.', true)&lt;br /&gt;
	if #parts&amp;gt;1 then&lt;br /&gt;
		return parts[#parts]&lt;br /&gt;
	else&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.extension(frame)&lt;br /&gt;
	return p.csExtension(frame):lower()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.extensionUpper(frame)&lt;br /&gt;
	return p.csExtension(frame):upper()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- p.woExtension(&amp;quot;Foo.bar.svg&amp;quot;)&lt;br /&gt;
-- @return &amp;quot;Foo.bar&amp;quot;&lt;br /&gt;
-- Original author: Bawolff at [[Module:FileName]]&lt;br /&gt;
function p.woExtension(frame)&lt;br /&gt;
	local fname = filename(frame) or mw.title.getCurrentTitle().text&lt;br /&gt;
	local parts = mw.text.split(fname , '.', true)&lt;br /&gt;
	local upTo = #parts - 1&lt;br /&gt;
	if upTo == 0 then upTo = 1 end&lt;br /&gt;
	return table.concat(parts, '.', 1, upTo)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.mime(frame)&lt;br /&gt;
	local meta  = getMetadata(frame)&lt;br /&gt;
	if meta.exists then&lt;br /&gt;
		return meta.mimeType&lt;br /&gt;
	else&lt;br /&gt;
		return extensionMap[p.extensionUpper(frame)] or 'unknown'&lt;br /&gt;
	end&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
function p.mimeType(frame)&lt;br /&gt;
	return getMetadata(frame).mimeType&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.fileExists(frame)&lt;br /&gt;
	return getMetadata(frame).exists or ''&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- This one won't throw errors at you&lt;br /&gt;
function p.fileExistsRelaxed(frame)&lt;br /&gt;
	local ok, metadata = pcall(getMetadata(frame))&lt;br /&gt;
	if ok then&lt;br /&gt;
		return metadata.exists or ''&lt;br /&gt;
	else&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.maxthumb(frame)&lt;br /&gt;
-- Limits in megapixels are currently stored in Commons templates, they could be in this module.&lt;br /&gt;
-- There may be more limits for other supported mime types (djvu, flac, ogv, pdf, svg, webm, xcf).&lt;br /&gt;
	local maxthumbMap = {&lt;br /&gt;
		['image/gif']  = 1000, &lt;br /&gt;
		['image/png' ] = 2500, -- see Template:LargePNG/limit&lt;br /&gt;
		['image/tiff'] = 1000, -- see Template:LargeTIFF/limit&lt;br /&gt;
	}&lt;br /&gt;
	local mime = p.mime(frame)&lt;br /&gt;
	return maxthumbMap[mime] or 'unknown @Module:File'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.dateWorkCreated(frame)&lt;br /&gt;
	return '' -- no longer supported&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.width(frame)&lt;br /&gt;
	return getMetadata(frame).width&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.height(frame)&lt;br /&gt;
	return getMetadata(frame).height&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.dimensions(frame)&lt;br /&gt;
	local d = getMetadata(frame)&lt;br /&gt;
	if d.exists then&lt;br /&gt;
		return d.width .. ' × ' .. d.height  &lt;br /&gt;
	else&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.size(frame)&lt;br /&gt;
	return getMetadata(frame).size&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.pageCount(frame)&lt;br /&gt;
	local pages = getMetadata(frame).pages or {1}&lt;br /&gt;
	return #pages&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Mediawiki&gt;CptViraj</name></author>
	</entry>
</feed>