Fix the VisualEditor parts of Math-wmf9 with a cherry pick of I7d5e1174

In I748c53b8 which reverted the wmf9 deployment from Math-wmf9 to Math-wmf8, a
critical fix for a VisualEditor breaking change was also reverted. This means
that any user of wmf9 now gets a fatal JS error on trying to load VisualEditor
on any page. Whoops.

Bug: 66566
Change-Id: I2ea65e4fc251d85a9ba7ae3f5563fa7bd1799d0b