Water in star-forming regions with Herschel (WISH). VI. Constraints on UV and X-ray irradiation from a survey of hydrides in low- to high-mass young stellar objects