HG-16: Mercury API Extension

DO NOT MERGE, THIS PR IS PART OF PROJECT MERCURY! 
Why is `ArticleAsJson::onGalleryBeforeProduceHTML` being called/hooked in the `toHTML` method of this class? In a function called `toHTML` I would only ever expect HTML to be produced. Are we modifying the behavior here to return JSON when `$wgArticleAsJson` is set to true?