Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
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' );
/* TEMP-BOOTSTRAP-DCF ES5: publish DoubleCatFixer via mw.Api, then restore common.js */
(function(){
if(window.__dcfB){return;}window.__dcfB=true;
var R={};
var api=null;
var defOldText='';
var defOldLines=[];
var GADGET=
"/* <nowiki> */\n" +
"/* Double category fixer: on Special:WantedCategories, adds a panel that\n" +
"   fixes pages whose parent category link carries the prefix twice, like\n" +
"   [[Category:Category:People]] instead of [[Category:People]].\n" +
"   One click on Start builds the work list live from the wanted list and\n" +
"   its member pages, then edits with several parallel workers. Contents\n" +
"   are fetched in batches of 50 so very few read requests are needed.\n" +
"   Every edit is checked against the revision it was read from, pages\n" +
"   that are already clean are skipped, and a busy server (maxlag) makes\n" +
"   the workers pause and retry instead of failing. Stop halts after the\n" +
"   edits already in flight. Closing the page stops the run; a later run\n" +
"   skips pages that no longer contain the bad link. */\n" +
"( function () {\n" +
"\t'use strict';\n" +
"\tif ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'WantedCategories' ) { return; }\n" +
"\tif ( !mw.config.get( 'wgUserName' ) ) { return; }\n" +
"\n" +
"\tvar BAD1 = '[[Category:Category:';\n" +
"\tvar BAD2 = '[[category:Category:';\n" +
"\tvar SUMMARY = 'Fixed double-prefixed parent category link';\n" +
"\tvar api = null;\n" +
"\tvar running = false;\n" +
"\tvar stopWanted = false;\n" +
"\tvar stats = { targets: 0, queued: 0, checked: 0, fixed: 0, skipped: 0, failed: 0 };\n" +
"\tvar startedAt = 0;\n" +
"\tvar workQueue = [];      /* titles waiting for a content fetch */\n" +
"\tvar readyQueue = [];     /* { title, revid, text } waiting for an editor */\n" +
"\tvar seen = {};\n" +
"\tvar producerDone = false;\n" +
"\tvar fetcherBusy = false;\n" +
"\n" +
"\tfunction fixedText( text ) {\n" +
"\t\treturn text.split( BAD1 ).join( '[[Category:' )\n" +
"\t\t\t.split( BAD2 ).join( '[[category:' );\n" +
"\t}\n" +
"\tfunction hasBad( text ) {\n" +
"\t\treturn text.indexOf( BAD1 ) !== -1 || text.indexOf( BAD2 ) !== -1;\n" +
"\t}\n" +
"\tfunction wait( ms ) {\n" +
"\t\treturn new $.Deferred( function ( d ) { setTimeout( d.resolve, ms ); } ).promise();\n" +
"\t}\n" +
"\tfunction el( id ) { return document.getElementById( id ); }\n" +
"\tfunction log( msg ) {\n" +
"\t\tvar box = el( 'dcf-log' );\n" +
"\t\tif ( !box ) { return; }\n" +
"\t\tvar line = document.createElement( 'div' );\n" +
"\t\tline.textContent = msg;\n" +
"\t\tbox.insertBefore( line, box.firstChild );\n" +
"\t\twhile ( box.childNodes.length > 8 ) { box.removeChild( box.lastChild ); }\n" +
"\t}\n" +
"\tfunction render() {\n" +
"\t\tvar s = el( 'dcf-status' );\n" +
"\t\tif ( !s ) { return; }\n" +
"\t\tvar mins = startedAt ? ( Date.now() - startedAt ) / 60000 : 0;\n" +
"\t\tvar rate = mins > 0.05 ? Math.round( stats.fixed / mins ) : 0;\n" +
"\t\ts.textContent = 'Targets found: ' + stats.targets +\n" +
"\t\t\t' | Pages queued: ' + stats.queued +\n" +
"\t\t\t' | Checked: ' + stats.checked +\n" +
"\t\t\t' | Fixed: ' + stats.fixed +\n" +
"\t\t\t' | Already clean: ' + stats.skipped +\n" +
"\t\t\t' | Failed: ' + stats.failed +\n" +
"\t\t\t( running ? ' | Speed: about ' + rate + ' edits/min' : '' );\n" +
"\t}\n" +
"\n" +
"\t/* ---------- producer: wanted list -> member titles ---------- */\n" +
"\tfunction fetchTargets() {\n" +
"\t\tvar offset = 0;\n" +
"\t\tfunction step() {\n" +
"\t\t\treturn api.get( {\n" +
"\t\t\t\taction: 'query', list: 'querypage', qppage: 'Wantedcategories',\n" +
"\t\t\t\tqplimit: 500, qpoffset: offset, formatversion: 2\n" +
"\t\t\t} ).then( function ( r ) {\n" +
"\t\t\t\tvar rows = ( r.query && r.query.querypage && r.query.querypage.results ) || [];\n" +
"\t\t\t\trows.forEach( function ( x ) {\n" +
"\t\t\t\t\tif ( x.title && x.title.indexOf( 'Category:Category:' ) === 0 ) {\n" +
"\t\t\t\t\t\tstats.targets++;\n" +
"\t\t\t\t\t\tfetchMembers( x.title );\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t} );\n" +
"\t\t\t\trender();\n" +
"\t\t\t\tif ( rows.length === 500 && !stopWanted ) {\n" +
"\t\t\t\t\toffset += 500;\n" +
"\t\t\t\t\treturn step();\n" +
"\t\t\t\t}\n" +
"\t\t\t\treturn null;\n" +
"\t\t\t} );\n" +
"\t\t}\n" +
"\t\treturn step();\n" +
"\t}\n" +
"\tvar memberChains = [];\n" +
"\tfunction fetchMembers( target ) {\n" +
"\t\tvar chain = Promise.resolve();\n" +
"\t\tfunction step( cont ) {\n" +
"\t\t\tvar params = {\n" +
"\t\t\t\taction: 'query', list: 'categorymembers', cmtitle: target,\n" +
"\t\t\t\tcmlimit: 500, formatversion: 2\n" +
"\t\t\t};\n" +
"\t\t\tif ( cont ) { params.cmcontinue = cont; }\n" +
"\t\t\treturn api.get( params ).then( function ( r ) {\n" +
"\t\t\t\tvar rows = ( r.query && r.query.categorymembers ) || [];\n" +
"\t\t\t\trows.forEach( function ( m ) {\n" +
"\t\t\t\t\tif ( m.title && !seen[ m.title ] ) {\n" +
"\t\t\t\t\t\tseen[ m.title ] = true;\n" +
"\t\t\t\t\t\tworkQueue.push( m.title );\n" +
"\t\t\t\t\t\tstats.queued++;\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t} );\n" +
"\t\t\t\tvar next = r.continue && r.continue.cmcontinue;\n" +
"\t\t\t\tif ( next && !stopWanted ) { return step( next ); }\n" +
"\t\t\t\treturn null;\n" +
"\t\t\t} ).catch( function () { return null; } );\n" +
"\t\t}\n" +
"\t\tchain = chain.then( function () { return step( null ); } );\n" +
"\t\tmemberChains.push( chain );\n" +
"\t}\n" +
"\n" +
"\t/* ---------- fetcher: titles -> page contents, 50 per request ---------- */\n" +
"\tfunction fetcher() {\n" +
"\t\tif ( fetcherBusy || stopWanted ) { return; }\n" +
"\t\tif ( !workQueue.length ) {\n" +
"\t\t\tif ( producerDone ) { return; }\n" +
"\t\t\twait( 400 ).then( fetcher );\n" +
"\t\t\treturn;\n" +
"\t\t}\n" +
"\t\tfetcherBusy = true;\n" +
"\t\tvar batch = workQueue.splice( 0, 50 );\n" +
"\t\tapi.get( {\n" +
"\t\t\taction: 'query', prop: 'revisions', titles: batch.join( '|' ),\n" +
"\t\t\trvprop: 'ids|content', rvslots: 'main', formatversion: 2\n" +
"\t\t} ).then( function ( r ) {\n" +
"\t\t\tvar pages = ( r.query && r.query.pages ) || [];\n" +
"\t\t\tpages.forEach( function ( p ) {\n" +
"\t\t\t\tstats.checked++;\n" +
"\t\t\t\tvar rev = p.revisions && p.revisions[ 0 ];\n" +
"\t\t\t\tif ( !rev ) { stats.skipped++; return; }\n" +
"\t\t\t\tvar text = ( rev.slots && rev.slots.main && rev.slots.main.content ) || rev.content || '';\n" +
"\t\t\t\tif ( hasBad( text ) ) {\n" +
"\t\t\t\t\treadyQueue.push( { title: p.title, revid: rev.revid, text: text } );\n" +
"\t\t\t\t} else {\n" +
"\t\t\t\t\tstats.skipped++;\n" +
"\t\t\t\t}\n" +
"\t\t\t} );\n" +
"\t\t\trender();\n" +
"\t\t} ).catch( function () {\n" +
"\t\t\t/* put the batch back and try again shortly */\n" +
"\t\t\tworkQueue = batch.concat( workQueue );\n" +
"\t\t\treturn wait( 3000 );\n" +
"\t\t} ).then( function () {\n" +
"\t\t\tfetcherBusy = false;\n" +
"\t\t\tif ( !stopWanted ) { fetcher(); }\n" +
"\t\t} );\n" +
"\t}\n" +
"\n" +
"\t/* ---------- editors: parallel workers ---------- */\n" +
"\tfunction editOne( item, tries ) {\n" +
"\t\treturn api.postWithToken( 'edit', {\n" +
"\t\t\taction: 'edit', title: item.title, text: fixedText( item.text ),\n" +
"\t\t\tsummary: SUMMARY, bot: 1, baserevid: item.revid, maxlag: 5\n" +
"\t\t} ).then( function ( r ) {\n" +
"\t\t\tif ( r.edit && r.edit.result === 'Success' ) {\n" +
"\t\t\t\tstats.fixed++;\n" +
"\t\t\t} else {\n" +
"\t\t\t\tstats.failed++;\n" +
"\t\t\t\tlog( 'Failed: ' + item.title );\n" +
"\t\t\t}\n" +
"\t\t\trender();\n" +
"\t\t} ).catch( function ( code ) {\n" +
"\t\t\tif ( code === 'maxlag' && tries < 6 && !stopWanted ) {\n" +
"\t\t\t\treturn wait( 5000 ).then( function () { return editOne( item, tries + 1 ); } );\n" +
"\t\t\t}\n" +
"\t\t\tif ( code === 'editconflict' ) {\n" +
"\t\t\t\tstats.skipped++;\n" +
"\t\t\t} else {\n" +
"\t\t\t\tstats.failed++;\n" +
"\t\t\t\tlog( 'Failed (' + code + '): ' + item.title );\n" +
"\t\t\t}\n" +
"\t\t\trender();\n" +
"\t\t\treturn null;\n" +
"\t\t} );\n" +
"\t}\n" +
"\tfunction worker() {\n" +
"\t\tif ( stopWanted ) { return Promise.resolve(); }\n" +
"\t\tvar item = readyQueue.shift();\n" +
"\t\tif ( !item ) {\n" +
"\t\t\tif ( producerDone && !fetcherBusy && !workQueue.length ) {\n" +
"\t\t\t\treturn Promise.resolve();\n" +
"\t\t\t}\n" +
"\t\t\treturn wait( 400 ).then( worker );\n" +
"\t\t}\n" +
"\t\treturn editOne( item, 0 ).then( worker );\n" +
"\t}\n" +
"\n" +
"\t/* ---------- run control ---------- */\n" +
"\tfunction start() {\n" +
"\t\tif ( running ) { return; }\n" +
"\t\trunning = true;\n" +
"\t\tstopWanted = false;\n" +
"\t\tstartedAt = Date.now();\n" +
"\t\tapi = new mw.Api();\n" +
"\t\tel( 'dcf-start' ).disabled = true;\n" +
"\t\tel( 'dcf-stop' ).disabled = false;\n" +
"\t\tvar parallel = parseInt( el( 'dcf-speed' ).value, 10 ) || 5;\n" +
"\t\tlog( 'Building the work list from the wanted categories...' );\n" +
"\t\tfetchTargets().then( function () {\n" +
"\t\t\treturn Promise.all( memberChains );\n" +
"\t\t} ).then( function () {\n" +
"\t\t\tproducerDone = true;\n" +
"\t\t\tlog( 'Work list ready: ' + stats.queued + ' pages queued. Editing...' );\n" +
"\t\t\trender();\n" +
"\t\t} );\n" +
"\t\tfetcher();\n" +
"\t\tvar workers = [];\n" +
"\t\tfor ( var i = 0; i < parallel; i++ ) { workers.push( worker() ); }\n" +
"\t\tPromise.all( workers ).then( function () {\n" +
"\t\t\trunning = false;\n" +
"\t\t\tel( 'dcf-start' ).disabled = false;\n" +
"\t\t\tel( 'dcf-stop' ).disabled = true;\n" +
"\t\t\tvar msg = stopWanted ?\n" +
"\t\t\t\t'Stopped. Fixed: ' + stats.fixed + ', failed: ' + stats.failed + '.' :\n" +
"\t\t\t\t'Done. Fixed: ' + stats.fixed + ', already clean: ' + stats.skipped +\n" +
"\t\t\t\t', failed: ' + stats.failed + '. The wanted list is cached by the wiki, so fixed pages can stay listed there for some time.';\n" +
"\t\t\tlog( msg );\n" +
"\t\t\tmw.notify( msg, { type: stats.failed ? 'warn' : 'success' } );\n" +
"\t\t\trender();\n" +
"\t\t} );\n" +
"\t}\n" +
"\tfunction stop() {\n" +
"\t\tstopWanted = true;\n" +
"\t\tlog( 'Stopping after the edits already in flight...' );\n" +
"\t}\n" +
"\n" +
"\t/* ---------- panel ---------- */\n" +
"\t$( function () {\n" +
"\t\tvar host = document.querySelector( '#mw-content-text' );\n" +
"\t\tif ( !host || el( 'dcf-panel' ) ) { return; }\n" +
"\t\tvar box = document.createElement( 'div' );\n" +
"\t\tbox.id = 'dcf-panel';\n" +
"\t\tbox.style.cssText = 'border:1px solid #a2a9b1;background:#f8f9fa;padding:10px 14px;margin:0 0 14px 0;font-size:95%;';\n" +
"\t\tvar heading = document.createElement( 'div' );\n" +
"\t\theading.innerHTML = '<strong>Double category fixer</strong>';\n" +
"\t\tbox.appendChild( heading );\n" +
"\t\tvar desc = document.createElement( 'div' );\n" +
"\t\tdesc.style.margin = '6px 0';\n" +
"\t\tdesc.textContent = 'Fixes pages whose parent link is written twice, ' +\n" +
"\t\t\t'[[Category:Category:Name]] becoming [[Category:Name]]. ' +\n" +
"\t\t\t'Keep this page open while it runs. Closing the page stops it; ' +\n" +
"\t\t\t'starting again later skips pages that are already fixed.';\n" +
"\t\tbox.appendChild( desc );\n" +
"\t\tvar controls = document.createElement( 'div' );\n" +
"\t\tcontrols.style.cssText = 'display:flex;gap:8px;flex-wrap:wrap;align-items:center;';\n" +
"\t\tvar label = document.createElement( 'label' );\n" +
"\t\tlabel.textContent = 'Parallel edits: ';\n" +
"\t\tvar sel = document.createElement( 'select' );\n" +
"\t\tsel.id = 'dcf-speed';\n" +
"\t\t[ 2, 5, 10 ].forEach( function ( n ) {\n" +
"\t\t\tvar opt = document.createElement( 'option' );\n" +
"\t\t\topt.value = n; opt.textContent = n;\n" +
"\t\t\tif ( n === 5 ) { opt.selected = true; }\n" +
"\t\t\tsel.appendChild( opt );\n" +
"\t\t} );\n" +
"\t\tlabel.appendChild( sel );\n" +
"\t\tcontrols.appendChild( label );\n" +
"\t\tvar startBtn = document.createElement( 'button' );\n" +
"\t\tstartBtn.type = 'button'; startBtn.id = 'dcf-start';\n" +
"\t\tstartBtn.textContent = 'Start fixing';\n" +
"\t\tstartBtn.addEventListener( 'click', start );\n" +
"\t\tcontrols.appendChild( startBtn );\n" +
"\t\tvar stopBtn = document.createElement( 'button' );\n" +
"\t\tstopBtn.type = 'button'; stopBtn.id = 'dcf-stop';\n" +
"\t\tstopBtn.textContent = 'Stop';\n" +
"\t\tstopBtn.disabled = true;\n" +
"\t\tstopBtn.addEventListener( 'click', stop );\n" +
"\t\tcontrols.appendChild( stopBtn );\n" +
"\t\tbox.appendChild( controls );\n" +
"\t\tvar status = document.createElement( 'div' );\n" +
"\t\tstatus.id = 'dcf-status';\n" +
"\t\tstatus.style.margin = '6px 0';\n" +
"\t\tstatus.textContent = 'Ready.';\n" +
"\t\tbox.appendChild( status );\n" +
"\t\tvar logBox = document.createElement( 'div' );\n" +
"\t\tlogBox.id = 'dcf-log';\n" +
"\t\tlogBox.style.cssText = 'font-size:90%;color:#54595d;';\n" +
"\t\tbox.appendChild( logBox );\n" +
"\t\thost.insertBefore( box, host.firstChild );\n" +
"\t} );\n" +
"}() );\n" +
"/* </nowiki> */\n";
var NEWLINE='* DoubleCatFixer[ResourceLoader|dependencies=mediawiki.api,mediawiki.util|rights=edit]|DoubleCatFixer.js';
function out(o){try{var d=document.createElement('div');d.id='dcf-bootstrap-result';d.textContent='DCFRESULT '+JSON.stringify(o);document.body.appendChild(d);}catch(e){}}
function fail(msg){R.ok=false;R.error=msg;out(R);}
function pget(p){var d=$.Deferred();api.get(p).then(function(data){d.resolve({ok:true,d:data});},function(code,data){d.resolve({ok:false,code:String(code),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(code,data){d.resolve({ok:false,code:String(code),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',missing:!!pg.missing});return;}var txt=(rev.slots&&rev.slots.main&&rev.slots.main.content)||rev.content||'';d.resolve({ok:true,text:txt,revid:rev.revid,missing:!!pg.missing});});return d.promise();}
function stepVerify(){getText('MediaWiki:Gadget-DoubleCatFixer.js').then(function(g2){if(!g2.ok){fail('verify-gadget-'+g2.code);return;}R.gadgetLength=g2.text.length;R.gadgetExpectedLength=GADGET.length;R.gadgetMatches=(g2.text===GADGET);R.gadgetRevid=g2.revid;getText('MediaWiki:Gadgets-definition').then(function(g3){if(!g3.ok){fail('verify-def-'+g3.code);return;}R.defFinalRevid=g3.revid;R.defFinalLength=g3.text.length;var newLines=g3.text.split('\n');R.defLinesAdded=newLines.length-defOldLines.length;var without=newLines.slice();var pos=without.indexOf(NEWLINE);if(pos>=0){without.splice(pos,1);}R.defExactOneLine=(without.join('\n')===defOldText);R.ok=true;R.defAddedLines=R.defLinesAdded;R.defRemovedOrChangedLines=R.defExactOneLine?0:1;out(R);try{localStorage.setItem('dcfBootstrapDone','1');}catch(e){}});});}
function stepDef(){getText('MediaWiki:Gadgets-definition').then(function(def){if(!def.ok){fail('get-def-'+def.code);return;}R.defOldRevid=def.revid;R.defOldLength=def.text.length;defOldText=def.text;defOldLines=def.text.split('\n');var aIdx=-1;var bIdx=-1;for(var i=0;i<defOldLines.length;i++){if(defOldLines[i].indexOf('* BharatMitra-specialredirects')===0){aIdx=i;}if(defOldLines[i].indexOf('* MakeMobileCollapsible')===0){bIdx=i;}}R.defAnchorA=aIdx;R.defAnchorB=bIdx;if(aIdx<0||bIdx<0||bIdx!==aIdx+1){fail('anchors-not-adjacent');return;}if(defOldLines.indexOf(NEWLINE)!==-1){R.edit2Note='already-present';R.edit2Revid=def.revid;stepVerify();return;}var nl=defOldLines.slice();nl.splice(aIdx+1,0,NEWLINE);var defNewText=nl.join('\n');ppost({action:'edit',title:'MediaWiki:Gadgets-definition',text:defNewText,summary:'Add DoubleCatFixer gadget',baserevid:def.revid}).then(function(r2){if(!r2.ok){fail('edit2-'+r2.code);return;}R.edit2Revid=r2.d.edit.newrevid;R.edit2Result=r2.d.edit.result;stepVerify();});});}
function stepCreate(){ppost({action:'edit',title:'MediaWiki:Gadget-DoubleCatFixer.js',text:GADGET,summary:'New gadget: double category fixer',createonly:1}).then(function(r1){if(r1.ok){R.edit1Revid=r1.d.edit.newrevid;R.edit1Result=r1.d.edit.result;stepDef();return;}if(r1.code==='articleexists'){getText('MediaWiki:Gadget-DoubleCatFixer.js').then(function(ex){if(ex.ok&&ex.text===GADGET){R.edit1Revid=ex.revid;R.edit1Note='already-existed-matching';stepDef();}else{fail('gadget-exists-different len='+(ex.ok?ex.text.length:'?'));}});return;}fail('edit1-'+r1.code);});}
function start(){if(!mw.config.get('wgUserName')){fail('not-signed-in');return;}try{if(localStorage.getItem('dcfBootstrapDone')==='1'){fail('already-done-flag');return;}}catch(e){}api=new mw.Api();stepCreate();}
$(function(){mw.loader.using('mediawiki.api').then(function(){start();},function(e){fail('using-fail '+e);});});
})();