Invariant conservation law-preserving discretizations of linear and nonlinear wave equations