This sorta has a few other miscellaneous fixes in it, but it works!
There are maybe still funky behaviours left. Test it?
Also refactor some bits, so we aren't accessing mw.mediaViewer in the
interface code.
Change-Id: I69db8e7b4ff5f994ba706fd4965688f3c26859f4