Quasistatic fluid-fluid displacement in porous media: Invasion-percolation through a wetting transition