User:Kolega2357/reversion.js

From Meta, a Wikimedia project coordination wiki

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.
/*
 * Reversión
 * Fuente: //en.wikipedia.org/wiki/Usuario:Lorian/monobook.js y [[Usuario:Axxgreazz/Monobook-Suite]]
 * <nowiki>
 */
// Protects against double inclusion
if ( window.reversion === undefined ) {
 
    //Link with window
    var reversion = {
        lista: ["k", "prueba", "prueba", "prueba0a", "prueba0b", "prueba0c",
                "prueba2", "prueba2a", "prueba3", "prueba4", "prueba5"],
        listaMensajes: ["Test", "Wikietiqueta", "Style", "Spam", "Nonsense",
                "Blanked", "Stop", " Final Warning", "Block"]
    };
    window.reversion = reversion;
 
    //Scope local for non-pulluting global spac
    (function ( $, mw ) {
        'use strict';
 
        reversion.darMensaje = function ( where, user1, user2, oldid ) {
            var message = window.prompt( 'Message' + ':', '' );
            if ( message != null ) {
                window.location.href = mw.util.wikiScript( 'index' ) + '?title=' +
                    mw.util.getParamValue( 'title' ) + '&action=edit&oldid=' + oldid +
                    '&' + where + '=2&user1=' + user1 + '&user2=' + user2 +
                    '&message=' + message;
            }
            return false;
        };
 
        function install() {
            if ( mw.util.getParamValue( 'diff' ) ) {
                // Get username of submitter
                var user1 = document.getElementById( 'mw-diff-otitle2' );
                if ( user1 ) {
                    user1 = user1.getElementsByTagName( 'a' )[0].innerHTML;
 
                    var user2 = document.getElementById( 'mw-diff-ntitle2' )
                            .getElementsByTagName( 'a' )[0].innerHTML,
                        oldid = mw.util.getParamValue( 'oldid', document.getElementById( 'mw-diff-otitle1' )
                            .getElementsByTagName( 'a' )[0] ),
                        msAviTemp = '',
                        separador = ' / ',
                        largoListaMensajes = reversion.listaMensajes.length,
                        i;
 
                    for ( i = 0; i < largoListaMensajes; i++ ) {
                        if ( i == largoListaMensajes - 1 ) {
                            separador = '';
                        }
                        msAviTemp = msAviTemp + '<a href="' + mw.util.wikiScript( 'index' ) +
                            '?title=User_talk:' + user2 + '&action=edit&warnMS=' + i + '&titleP=' +
                            mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ) + '">' +
                            reversion.listaMensajes[i] + '</a>' + separador;
                    }
 
                    document.getElementById( 'contentSub' ).innerHTML = '(<a href="' +
                        mw.util.wikiScript( 'index' ) + '?title=' + mw.util.getParamValue( 'title' ) +
                        '&action=edit&oldid=' + oldid + '&revertMS=1&user1=' + user1 + '&user2=' + user2 +
                        '">' + 'Rollback' + '</a> / ' +
                        '<a href="#" onclick="return reversion.darMensaje(\'revertMS\', \'' + user1 +
                        '\', \'' + user2 + '\', \'' + oldid + '\');">' + 'Message' + '</a>) ' +
                        '(Aviso a usuarios: ' + msAviTemp + ')';
                }
            } else if ( mw.util.getParamValue( 'revertMS' ) == 1 ) {
                $( '#wpSummary' ).val( 'Reverted edits by [[Special:Contributions/' +
                    mw.util.getParamValue( 'user2' ) + '|' + mw.util.getParamValue( 'user2' ) +
                    ']] to last version by [[Special:Contributions/' + mw.util.getParamValue('user1') + '|' +
                    mw.util.getParamValue('user1') + ']]' );
                $( '#editform' ).submit();
            } else if ( mw.util.getParamValue( 'revertMS' ) == 2 ) {
                $( '#wpSummary' ).val( 'Reverted edits by [[Special:Contributions/' +
                    mw.util.getParamValue( 'user2' ) + '|' + mw.util.getParamValue( 'user2' ) +
                    ']] to last version by [[Special:Contributions/' + mw.util.getParamValue('user1') + '|' +
                    mw.util.getParamValue('user1') + ']] (' + mw.util.getParamValue( 'Message' ) + ')' );
                $( '#editform' ).submit();
            } else if ( mw.config.get( 'wgCanonicalNamespace' ) == 'User_talk' && mw.config.get( 'wgAction' ) == "edit" && mw.util.getParamValue( 'warnMS' ) !== null ) {
                var indice = parseInt( location.href.substring( location.href.indexOf( "&titleP=" ) - 1,
                         location.href.indexOf( "&titleP=" ) ), 10 ),
                    parametros = '';
                if ( indice == 0 ) {
                    parametros = '|' + mw.util.getParamValue( 'titleP' );
                }
 
                $( '#wpSummary' ).val( 'Warnings' );
                $( '#wpTextbox1' ).val( $( '#wpTextbox1' ).val() + '\n{{subst:' + reversion.lista[indice + 2] + parametros + '}} --~~~~' );
                $( '#editform' ).submit();
            }
        }
 
        $(document).ready( install );
 
    })( jQuery, mediaWiki ); // End of anonymous function
} //End of chec
//</nowiki>