XWIKI-4689: Previewing a new form-based document does not set the right document syntax
* also done some related cleanup and bulletproofing