Jump to content

Module:File

From Wikiversity

Documentation for this module may be created at Module:File/doc

local p = {}

function p.content(frame)
	local text = mw.text.trim(frame.args[1])
	local title = mw.title.new(text)
	local content = title:getContent()
	return content
end

function p.information(frame)
	local text = mw.text.trim(frame.args[1])
	local namespace = 'File'
	local title = mw.title.new(text, namespace)
	local content = title:getContent()
	if string.find(string.lower(content), '{{information', 1, false) ~= nil then
		return '[[:' .. title.fullText .. ']]'
	else
		return nil
	end
end

-- Does not work.  Can't read from Special namespace.
function p.links(frame)
	local text = mw.text.trim(frame.args[1])
	local result = ''
	
	for line in string.gmatch(text, "[^\n]+") do
		if string.sub(line, 1, 5) == 'File:' then
			local title = mw.title.new('BrokenRedirects', 'Special')
			local content = title:getContent()
        	result = result .. line .. '<br>'
        	if content ~= nil then
        		result = result .. content .. '<br>'
        	end
        	result = result .. '<br>'
        end
	end
	
	return result
end

function p.test()
	return mw.site.namespaces['User'].id
end

return p