Global analysis of linear and nonlinear wave equations on cosmological spacetimes