MediaWiki:Gadget-SpecialPages.js/DoubleRedirects.js

// Special:DoubleRedirects // ( function ( mw, $ ) { if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'DoubleRedirects' ) {    function fixDoublesRedirects( index, doubleRedirect, redirectTarget ) {      var writeRedirect = '#REDIRECT ' + redirectTarget + '';      new mw.Api.postWithToken( 'edit', { action: 'edit', title: doubleRedirect, minor: true, recreate: true, text: writeRedirect, summary: editSummary } ).done( function ( fixed ) { if ( fixed.edit.result === 'Success' ) { $( '#row-' + index ).html( $( '#row-' + index ).html.replace( 'Fix this redirect!', 'Fixed!' ) ); $( '#row-' + index ).attr( { href: '#reload', title: 'Reload the page!', onclick: 'setTimeout( function { location.reload; }, 500 );' } ); } else { $( '#row-' + index ).html( $( '#row-' + index ).html.replace( 'Fix this redirect!', 'Something failed! Try again?' ) ); }     } );    }    var nextLink = $( '.mw-nextlink' ).html;    if ( nextLink === undefined || nextLink === '' || nextLink === null ) {      $( 'div.mw-spcontent p:eq( 1 )' ).append( '' + 'Recent Changes' + 'Special Pages' + '' );   } else {      var limit = document.location.href.slice( document.location.href.search( 'limit=' ) + 6, document.location.href.search( '&' ) );      var editSummary = 'Fixing Special:DoubleRedirects using Double redirect fixer';      if ( nextLink !== null && ( !$.isNumeric( limit ) || limit === '' ) ) {        limit = document.location.href.slice( document.location.href.search( 'limit=' ) + 6 );      } else if ( nextLink !== null && limit !== 1000 ) {        setTimeout( function { location = '?limit=1000' }, 1 );      }      $( 'ol.special' ).find( 'li' ).each( function( i ) { var doubleRedirect = $( this ).find( 'a:first' ).attr( 'title' ).replace( /'/g, '\\\'' ); var redirectTarget = $( this ).find( 'a:last' ).attr( 'title' ).replace( /'/g, '\\\'' ); $( this ).append( ' (- Fix this redirect! -)' ); } );   }  } } )( mediaWiki, jQuery ); //