Dynamics of magmatic intrusions in the upper crust: Theory and applications to laccoliths on Earth and the Moon