မာတိကာသို့ ခုန်သွားရန်

မဝ်ဂျူ:WOTD

နူ ဝိက်ရှေန်နရဳ

Contains a function used in T:WOTD to find which of several possible English audio files exists and create a file link to it.


local export = {}

local fun_xpcall_module = "Module:fun/xpcall"

local assert = assert
local ipairs = ipairs
local log = mw.log
local new_title = mw.title.new
local tostring = tostring

local function xpcall(...)
	xpcall = require(fun_xpcall_module)
	return xpcall(...)
end

local function do_format(frame)
	local args = frame.args
	local format_arg = assert(args.format, "Format parameter not supplied")
	for _, file in ipairs(args) do
		local page = new_title(file)
		if page then
			local page_file = page.file
			if page_file and page_file.exists then
				return format_arg:format(file)
			end
		else
			log(file .. " is not a valid file name")
		end
	end
end

function export.check_pages(frame)
	local success, res = xpcall(do_format, log, frame)
	if success then
		return res
	end
end

return export