Right now if , a user inserts wikitext inside gallery inspector such as <gallery></gallery> or <ref> inside gallery inserter, it adds an empty gallery inside the page and if you switch to edit source you will see something like:
<gallery><gallery><ref></ref></gallery></gallery>
One possible solution to this issue could be let user know not to add any such wikitext/bad inputs inside gallery inspector
Test Environment: http://en.wikipedia.beta.wmflabs.org/
Browser: Chrome Version 26.0.1410.65 & FF 25
OS: MAC OS X 10. 8. 5
Version: unspecified
Severity: minor