You are putting everything into global scoper here. Please wrap the file's whole code in a scope and apply the <code>use strict</code> statement.
In addition, please stick to the Wikibase coding conventions in general: http://www.mediawiki.org/wiki/Wikibase/Coding_conventions.