Module:FileExists

local checkType = require( 'libraryUtil' ).checkType

-- Check if a file exists on the wiki. Will fail if the expensive parser function -- limit is exceeded. -- -- @param string fileName -- @return boolean local function scribuntoCheck( fileName ) local file = mw.title.new( fileName ) return file.fileExists end

-- Use Cargo as a fallback to check if a file exists. -- -- @param string fileName -- @return boolean local function cargoCheck( fileName ) local cargoData = mw.ext.cargo.query( '_pageData', '_pageID', {   where = string.format( '_pageName="%s"', fileName )  } ) return ( #cargoData ~= 0 ) end

return function ( fileName ) checkType( 'fileExists', 1, fileName, 'string' )

local success, result = pcall( scribuntoCheck, fileName ) if not success then result = cargoCheck( fileName ) end

return result end