define(["jquery"],function(a){var b=function(){var c=this;c.init=function(){var k=a("html");if(k.data("xwiki-reference")!==undefined){c.documentReference=XWiki.Model.resolve(k.data("xwiki-reference"),XWiki.EntityType.DOCUMENT);var e=documentReference.extractReference(XWiki.EntityType.WIKI);var f=documentReference.extractReference(XWiki.EntityType.SPACE);c.document=XWiki.Model.serialize(documentReference.relativeTo(e));c.wiki=e.getName();c.space=XWiki.Model.serialize(f.relativeTo(e));c.page=documentReference.getName();c.version=k.data("xwiki-version");c.restURL=k.data("xwiki-rest-url");c.form_token=k.data("xwiki-form-token");c.userReference=XWiki.Model.resolve(k.data("xwiki-user-reference"),XWiki.EntityType.DOCUMENT);c.isNew=k.data("xwiki-isnew")}else{var l=a("meta");var n=["document","wiki","space","page","version","restURL","form_token"];for(var h=0;h<l.length;++h){var m=a(l[h]);var d=m.attr("name");for(var g=0;g<n.length;++g){if(d==n[g]){c[d]=m.attr("content")}}}}};c.setVersion=function(d){c.version=d;document.fire("xwiki:document:changeVersion",{version:c.version,documentReference:documentReference})};c.refreshVersion=function(d){var e=c.restURL;e+="?media=json&timestamp="+new Date().getTime();a.getJSON(e).done(function(f){c.setVersion(f.version)}).fail(function(f){if(f.status===404&&typeof(d)==="function"){d(f)}else{console.error("Error while refreshing the version from URL "+e,f)}})};c.init()};return new b()});