MediaWiki:Gadget-SpecialPages.js/DoubleRedirects.js

From Lotro-Wiki.com
Jump to navigation Jump to search

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// [[Special:DoubleRedirects]]
// <nowiki>
//( 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();
    var limit = document.location.href.slice( document.location.href.search( 'limit=' ) + 6, document.location.href.search( '&' ) );
    var editSummary = 'Fixing [[Special:DoubleRedirects]] using [[MediaWiki:Gadget-SpecialPages.js/DoubleRedirects.js|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( ' (- <a href="#' + redirectTarget + '" id="row-' + i + '" onClick="fixDoublesRedirects( ' + i + ', \'' + doubleRedirect + '\', \'' + redirectTarget + '\' )">Fix this redirect!</a> -)' );
    } );
  }
//} )( mediaWiki, jQuery );
// </nowiki> [[Category:Gadgets]]