To be honest, I copied the logic from here: https://github.com/Wikia/app/blob/dev/extensions/VisualEditor/VisualEditor.hooks.php#L126

I only renamed the variable to $pageExists to better represent how it was used.