Auto-close all unclosed block tags in image captions.

It turns out that image captions can have unclosed block tags
which then messes up the entire DOM and wraps the reset of the
page into the image caption which is wrong and also screws up
the RTing in turn.  So, we forcibly close all unclosed block
tags by treating the caption as a well-nested DOM context.

Fixes parse output and RTing of wikitext like this:
----------------------------
[[File:Tomb.jpg|thumb|<center>foo<center>]]
{|
|-
|bar
|}
----------------------------

Eliminates a lot of RT errors on some pages:
en:Krippin Virus
en:List of Theban Tombs
en:Polish Chess Championship

Change-Id: I81cb4f143575e6a3c8866a48590e743953e95612