It's at the discretion of the external examiners. Although about 30% of people who start a PhD (or MPhil/PhD) still don't have one after 7 years, only a few people ever actually fail. Most of those who don't finish up with a PhD have dropped out, either at the MPhil stage or just when it all got too much. Others, whilst never dropping out, never got round to writing up.
For those who fall at the viva stage rather than being 'failed' they can be asked to resubmit their thesis - this can involve re-writing anything from a single chapter to virtually the whole thing. Another alternative open to the examiners if they feel the work carried out is not sufficiently novel or does not make enough of a contribution to knowledge is to award an MPhil.
HEFCE figures show that after 7 years 5% of full time students will have been awarded an MPhil & not a PhD - most of these will have stopped at the MPhil stage after only 1 or 2 years of study.