We explore a mean-field theory of fluid imbibition and drainage through permeable porous solids. In the limit of vanishing inertial and viscous forces, the theory predicts the hysteretic "retention curves" relating the capillary pressure applied across a connected domain to its degree of saturation in wetting fluid in terms of known surface energies and void space geometry. To avoid complicated calculations, we adopt the simplest statistical mechanics, in which a pore interacts with its neighbors through narrow openings called "necks," while being either full or empty of wetting fluid. We show how the main retention curves can be calculated from the statistical distribution of two dimensionless parameters λ and α measuring the specific areas of, respectively, neck cross section and wettable pore surface relative to pore volume. The theory attributes hysteresis of these curves to collective first-order phase transitions. We illustrate predictions with a porous domain consisting of a random packing of spheres, show that hysteresis strength grows with λ and weakens as the distribution of α broadens, and reproduce the behavior of Haines jumps observed in recent experiments on an ordered pore network.