Temporary bootstrap to throttle fetcher queue via mw.Api
Tag: Reverted
Restore personal script after diagnostic
Tags: Manual revert Mobile edit Mobile web edit Advanced mobile edit
 
(43 intermediate revisions by the same user not shown)
Line 2: Line 2:
mw.loader.load( 'ext.gadget.BharatMitra' );
mw.loader.load( 'ext.gadget.BharatMitra' );
mw.loader.load( 'ext.gadget.UserStats' );
mw.loader.load( 'ext.gadget.UserStats' );
mw.loader.load( 'https://en.bharatpedia.org/w/index.php?title=MediaWiki:Gadget-DoubleCatFixer.js&action=raw&ctype=text/javascript&maxage=0&smaxage=0&t=' + Date.now() );
/* TEMP-THROTTLE-DCF ES5: insert fetcher throttle via mw.Api, then restore common.js */
(function(){
if(window.__dcfThrottle){return;}window.__dcfThrottle=true;
var R={};
var api=null;
var ANCHOR="\t\tif ( fetcherBusy || stopWanted ) { return; }";
var BLOCK="\t\tif ( readyQueue.length > 200 ) {\n" + "\t\t\t/* editors are the bottleneck; do not pile up page texts in memory */\n" + "\t\t\twait( 1000 ).then( fetcher );\n" + "\t\t\treturn;\n" + "\t\t}\n";
var LINE1="\t\tif ( readyQueue.length > 200 ) {";
var LINE2="\t\t\t/* editors are the bottleneck; do not pile up page texts in memory */";
var LINE3="\t\t\twait( 1000 ).then( fetcher );";
var LINE4="\t\t\treturn;";
var LINE5="\t\t}";
function out(o){try{var d=document.createElement('div');d.id='dcf-throttle-result';d.textContent='DCFTHROTTLE '+JSON.stringify(o);document.body.appendChild(d);}catch(e){}}
function fail(m){R.ok=false;R.error=m;out(R);}
function countLines(t,n){var L=t.split('\n');var c=0;for(var i=0;i<L.length;i++){if(L[i]===n){c++;}}return c;}
function leadingTabs(s){var n=0;while(n<s.length&&s.charAt(n)==='\t'){n++;}return n;}
function pget(p){var d=$.Deferred();api.get(p).then(function(data){d.resolve({ok:true,d:data});},function(c,data){d.resolve({ok:false,code:String(c),d:data});});return d.promise();}
function ppost(p){var d=$.Deferred();api.postWithToken('csrf',p).then(function(data){d.resolve({ok:true,d:data});},function(c,data){d.resolve({ok:false,code:String(c),d:data});});return d.promise();}
function getText(t){var d=$.Deferred();pget({action:'query',prop:'revisions',titles:t,rvprop:'ids|content',rvslots:'main',formatversion:2}).then(function(r){if(!r.ok){d.resolve({ok:false,code:r.code});return;}var pages=(r.d.query&&r.d.query.pages)||[];var pg=pages[0]||{};var rev=pg.revisions&&pg.revisions[0];if(!rev){d.resolve({ok:false,code:'norev'});return;}var txt=(rev.slots&&rev.slots.main&&rev.slots.main.content)||rev.content||'';d.resolve({ok:true,text:txt,revid:rev.revid});});return d.promise();}
function doThrottle(){
if(!mw.config.get('wgUserName')){fail('not-signed-in');return;}
try{if(localStorage.getItem('dcfThrottleDone')==='1'){fail('already-done-flag');return;}}catch(e){}
api=new mw.Api();
getText('MediaWiki:Gadget-DoubleCatFixer.js').then(function(g){
if(!g.ok){fail('read-before-'+g.code);return;}
R.beforeLen=g.text.length;R.beforeRevid=g.revid;
R.anchorCountBefore=countLines(g.text,ANCHOR);
R.line1CountBefore=countLines(g.text,LINE1);
if(R.anchorCountBefore!==1){fail('anchor-count-not-1');return;}
if(R.line1CountBefore!==0){fail('block-already-present');return;}
R.blockLen=BLOCK.length;
var newText=g.text.replace(ANCHOR+'\n',ANCHOR+'\n'+BLOCK);
R.expectedNewLen=newText.length;
if(newText.length!==10446){fail('new-length-not-10446');return;}
if(countLines(newText,ANCHOR)!==1||countLines(newText,LINE1)!==1){fail('insert-check');return;}
ppost({action:'edit',title:'MediaWiki:Gadget-DoubleCatFixer.js',text:newText,summary:'Throttle fetcher queue',baserevid:g.revid}).then(function(r2){
if(!r2.ok){fail('edit-'+r2.code);return;}
R.newRevid=r2.d.edit.newrevid;
getText('MediaWiki:Gadget-DoubleCatFixer.js').then(function(g2){
if(!g2.ok){fail('read-after-'+g2.code);return;}
R.afterLen=g2.text.length;R.afterRevid=g2.revid;
var lines=g2.text.split('\n');
var ai=-1;for(var i=0;i<lines.length;i++){if(lines[i]===ANCHOR){ai=i;}}
R.anchorLine1Based=ai+1;
R.insertedLine1Tabs=ai>=0?leadingTabs(lines[ai+1]):-1;
R.insertedLine2Tabs=ai>=0?leadingTabs(lines[ai+2]):-1;
R.insertedLine3Tabs=ai>=0?leadingTabs(lines[ai+3]):-1;
R.insertedLine4Tabs=ai>=0?leadingTabs(lines[ai+4]):-1;
R.insertedLine5Tabs=ai>=0?leadingTabs(lines[ai+5]):-1;
R.insertedLinesExact=(ai>=0&&lines[ai+1]===LINE1&&lines[ai+2]===LINE2&&lines[ai+3]===LINE3&&lines[ai+4]===LINE4&&lines[ai+5]===LINE5);
R.removingBlockReproducesPrevious=(g2.text.replace(BLOCK,'')===g.text);
R.matchesNewText=(g2.text===newText);
R.ok=true;
out(R);
try{localStorage.setItem('dcfThrottleDone','1');}catch(e){}
});
});
});
}
$(function(){mw.loader.using('mediawiki.api').then(function(){doThrottle();},function(e){fail('using-fail '+e);});});
})();

Latest revision as of 02:34, 21 November 2026

mw.loader.load('https://en.bharatpedia.org/w/index.php?title=MediaWiki:Gadget-OneClickArchiver.js&action=raw&ctype=text/javascript&maxage=0&smaxage=0&t=' + Date.now());
mw.loader.load( 'ext.gadget.BharatMitra' );
mw.loader.load( 'ext.gadget.UserStats' );