Jump to content

User:PerfektesChaos/js/versionControl/r.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/// PerfektesChaos/js/versionControl/r.js
/// 2018-08-24 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#85E48FCE#
///<nowiki>
(function(mw,$){
"use strict";
var VC="versionControl";
if(typeof mw.libs[VC]!=="object"||!mw.libs[VC]){
mw.libs[VC]={};}
mw.libs[VC].vsn=4.0;
mw.libs[VC].type=VC;
VC=mw.libs[VC];
if(!VC.debugging){
VC.debugging={loud:false};}
if(VC.vsn<=0){
VC.debugging.loud=true;}
VC.debugging.say="vc";
if(!VC.proj){
VC.proj={};}
VC.selfID="user:PerfektesChaos/"+VC.type;
VC.g={projname:mw.config.get("wgDBname"),username:mw.config.get("wgUserName")};
VC.doc="[[w:en:User:PerfektesChaos/js/"+VC.type+"]]";
VC.feed=function(){
var i;
if(typeof(VC.config.signer)==="string"){
VC.exec.signer=VC.config.signer;
}else{
VC.exec.signer=VC.g.username;}
VC.exec.signer=mw.util.wikiUrlencode(VC.exec.signer);
if(typeof(VC.config.store)==="string"){
VC.exec.store=VC.config.store;
}else{
if(typeof(VC.g.userspace)!=="string"){
VC.g.userspace=mw.config.get("wgFormattedNamespaces");
VC.g.userspace=VC.g.userspace["2"];}
VC.exec.store=VC.g.userspace+":"+VC.exec.signer+"/versionControl.js";}
if(typeof(VC.config.symbol)==="string"){
VC.exec.symbol=VC.config.symbol;
}else{
VC.exec.symbol="vc_"+VC.g.projname+"_"+VC.exec.signer;}
if(VC.exec.symbol.indexOf("%")>=0){
VC.exec.symbol.replace("%","_");}
if(typeof(VC.proj[VC.g.projname])!=="object"){
VC.proj[VC.g.projname]={};}
if(typeof(VC.proj[VC.g.projname][VC.exec.signer])!=="object"){
VC.proj[VC.g.projname][VC.exec.signer]={};}
VC.exec.deep=VC.proj[VC.g.projname][VC.exec.signer];
if(typeof VC.exec.deep.rv!=="object"){
if(typeof window[VC.exec.symbol]==="object"){
VC.exec.deep.rv=window[VC.exec.symbol];}}
if(typeof(VC.exec.deep.rv)==="object"){
if($.isArray(VC.exec.deep.rv)){
if(!VC.exec.deep.rv.length){
VC.exec.deep.rv=false;}
}else{
VC.exec.deep.rv=false;}}
VC.exec.deep.store=VC.exec.store;
if(typeof(VC.exec.deep.start)!=="string"){
i=VC.exec.deep.store.indexOf("/");
if(i>0){
VC.exec.deep.start=VC.exec.deep.store.substr(0,i+1);
}else{
VC.exec.deep.start="";}}
if(typeof(VC.exec.deep.rv)==="object"||typeof(VC.exec.deep.source)==="string"){
VC.fit();
}else{
if(typeof(VC.api)!=="object"){
VC.api=new mw.Api();}
VC.api.get({action:"raw",title:VC.exec.deep.store,format:"",maxage:0
},{url:mw.config.get("wgScript"),dataType:"text"})
.done(VC.fetched);}
};
VC.fetch=function(){
VC.api.get(VC.exec.query).done(VC.found);
};
VC.fetched=function(arrived){
if(typeof(arrived)==="string"){
VC.exec.deep.source=arrived;
VC.fit();}
};
VC.finalize=function(){
};
VC.fire=function(){
var rls;
if(!mw.loader.getState(VC.selfID)){
rls={};
rls[VC.selfID]="loading";
mw.loader.state(rls);
if(typeof VC.exec!=="object"){
VC.exec={};}
if(typeof VC.opt==="object"&&VC.opt){
VC.config=VC.opt;
}else{
VC.config={};}
rls[VC.selfID]="ready";
mw.loader.state(rls);
VC.feed();}
};
VC.fit=function(){
var e,i,n,s,u;
if(typeof this.exec.deep.rv!=="object"){
if(typeof window[VC.exec.symbol]==="object"){
this.exec.deep.rv=window[VC.exec.symbol];}}
if(typeof this.exec.deep.rv==="object"){
if($.isArray(this.exec.deep.rv)){
if(!this.exec.deep.rv.length){
this.exec.deep.rv=false;}
}else{
this.exec.deep.rv=false;}}
if(typeof this.exec.deep.rv==="object"){
if(typeof this.exec.deep.source==="string"){
try{
eval(this.exec.deep.source);
}catch(exc){
window.alert("mw.libs.versionControl.fit\n"+exc+" in "+this.exec.deep.store);
return;}}}
if(typeof this.exec.deep.rv==="object"){
n=this.exec.deep.rv.length;
if(n>1){
s=this.exec.deep.store;
u="|"+this.exec.deep.start;
for(i=1;i<n;i++){
e=this.exec.deep.rv[i][0];
s=s+u+mw.util.wikiUrlencode(e);}
if(typeof this.api!=="object"){
this.api=new mw.Api();}
this.exec.query={prop:"info",titles:s,indexpageids:true};
window.setTimeout(VC.fetch,5000);
window.setTimeout(VC.fetch,30000);}}
};
VC.format=function(){
var d=new Date(),e="[\""+d.toUTCString()+"\"]",i,n=VC.exec.deep.updates.length,r="\\[\"[- 0-9:A-Z,a-z]+\"\\]",s=VC.exec.deep.source.replace(new RegExp(r,"g"),e),u;
r="^\\[\"[- 0-9:A-Z,a-z]+\"\\](,)?$";
for(i=0;i<n;i++){
u=VC.exec.deep.updates[i];
e=VC.exec.deep.rv[u[0]];
r="(\\[\""+mw.RegExp.escape(e[0])+"\", *)"+"([0-9]+),?"+"( *)"+"(\"[-0-9:A-Z]*\")?"+"( *)"+"\\]";
d="$1"+u[1]+",$3\""+u[2]+"\"$5]";
s=s.replace(new RegExp(r,"g"),d);
e[1]=u[1];
e[2]=u[2];}
VC.exec.deep.source=s;
VC.exec.edit={action:"edit",token:mw.user.tokens.get("csrfToken"),title:VC.exec.deep.store,text:VC.exec.deep.source,summary:"VersionControl "+VC.vsn,nocreate:true};
if(typeof(VC.api)!=="object"){
VC.api=new mw.Api();}
VC.api.post(VC.exec.edit).done(VC.finalize);
};
VC.found=function(arrived){
var i,j,k,m,n,p,query=(typeof(arrived)==="object"),s;
if(query){
query=arrived.query;}
if(query){
n=query.pageids.length;
if(n){
k=VC.exec.deep.start.length;
m=VC.exec.deep.rv.length;
VC.exec.deep.updates=[];
for(i=0;i<n;i++){
s=query.pageids[i];
if(s.charCodeAt(0)!==45){
p=query.pages[s];
for(j=0;j<m;j++){
if(p.title.substr(k)===VC.exec.deep.rv[j][0]){
if(VC.exec.deep.rv[j][1]!==p.lastrevid){
p=[j,p.lastrevid,p.touched];
VC.exec.deep.updates=VC.exec.deep.updates.concat([p]);}
break;}}}}
if(VC.exec.deep.updates.length){
if(typeof(VC.exec.deep.source)==="string"){
VC.format();
}else{
VC.exec.deep.rv=false;
VC.feed();}}}}
};
mw.loader.using(["user","mediawiki.api","mediawiki.RegExp","mediawiki.user","mediawiki.util"],VC.fire);
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>versionControl/r.js