Ben Stokes put England on top against Bangladesh with a four-wicket haul in the first innings.