On periodic solutions of nonlinear wave equations, including Einstein equations with a negative cosmological constant