define(["jquery"],function(a){var b=function(){var c=this;c.init=function(){var l=a("html");if(l.data("xwiki-reference")!==undefined){c.documentReference=XWiki.Model.resolve(l.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=l.data("xwiki-version");c.restURL=l.data("xwiki-rest-url");c.form_token=l.data("xwiki-form-token");var k=l.data("xwiki-user-reference");if(k){c.userReference=XWiki.Model.resolve(k,XWiki.EntityType.DOCUMENT)}else{c.userReference=null}c.isNew=l.data("xwiki-isnew")}else{var m=a("meta");var o=["document","wiki","space","page","version","restURL","form_token"];for(var h=0;h<m.length;++h){var n=a(m[h]);var d=n.attr("name");for(var g=0;g<o.length;++g){if(d==o[g]){c[d]=n.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()});