We present a unified approach to the theory of multimodal laser cavities including a variable amount of structural disorder. A general mean-field theory is studied for waves in media with variable nonlinearity and randomness. Phase diagrams are reported in terms of optical power, degree of disorder, and degree of nonlinearity, tuning between closed and open cavity scenarios. In the thermodynamic limit of infinitely many modes, the theory predicts four distinct regimes: a continuous wave behavior for low power, a standard mode-locking laser regime for high power and weak disorder, a random laser for high pumped power and large disorder, and a novel intermediate regime of phase locking occurring in the presence of disorder but below the lasing threshold.