Usuario:Mazbel/MediaWiki:Gadget-reversion.js

Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.

  • Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
  • Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
  • Internet Explorer/Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
  • Opera: Presiona Ctrl+F5.
/*
 * Reversión
 * Fuente: //en.wikipedia.org/wiki/Usuario:Lorian/monobook.js y [[Usuario:Axxgreazz/Monobook-Suite]]
 * <nowiki>
 */
// Protege contra doble inclusión
if ( window.reversion === undefined ) {

    //Enlaza con window
    var reversion = {
        lista: ["k", "prueba", "prueba", "prueba0a", "prueba0b", "prueba0c",
                "prueba2", "prueba2a", "prueba3", "prueba4", "prueba5"],
        listaMensajes: ["Prueba", "Wikietiqueta", "Estilo", "Spam", "Sin sentido",
                "Blanqueo", "Detente", "Ultima advertencia", "Bloqueo"]
    };
    window.reversion = reversion;

    //Scope local para no contaminar espacio global
    (function ( $, mw ) {
        'use strict';

        reversion.darMensaje = function ( where, user1, user2, oldid ) {
            var message = window.prompt( 'Mensaje' + ':', '' );
            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 +
                        '">' + 'Revertir' + '</a> / ' +
                        '<a href="#" onclick="return reversion.darMensaje(\'revertMS\', \'' + user1 +
                        '\', \'' + user2 + '\', \'' + oldid + '\');">' + 'Mensaje' + '</a>) ' +
                        '(Aviso a usuarios: ' + msAviTemp + ')';
                }
            } else if ( mw.util.getParamValue( 'revertMS' ) == 1 ) {
                $( '#wpSummary' ).val( 'Revertidos los cambios de [[Special:Contributions/' +
                    mw.util.getParamValue( 'user2' ) + '|' + mw.util.getParamValue( 'user2' ) +
                    ']] a la última edición de [[Special:Contributions/' + mw.util.getParamValue('user1') + '|' +
                    mw.util.getParamValue('user1') + ']]' );
                $( '#editform' ).submit();
            } else if ( mw.util.getParamValue( 'revertMS' ) == 2 ) {
                $( '#wpSummary' ).val( 'Revertidos los cambios de [[Special:Contributions/' +
                    mw.util.getParamValue( 'user2' ) + '|' + mw.util.getParamValue( 'user2' ) +
                    ']] a la última edición de [[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( 'Aviso al usuario' );
                $( '#wpTextbox1' ).val( $( '#wpTextbox1' ).val() + '\n{{subst:' + reversion.lista[indice + 2] + parametros + '}} --~~~~' );
                $( '#editform' ).submit();
            }
        }

        $(document).ready( install );

    })( jQuery, mediaWiki ); // Fin de función anónima
} //fin de chequeo
//</nowiki>