Fix the VisualEditor parts of Math-wmf9 with a working 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: I498053de4b0b878d091bda045bc0b7f7861b86b3