Usuario:Mazbel/ScreenSuite.js

De Wikcionario, el diccionario libre

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.
/**
 * <nowiki>
 */
// Protege contra doble inclusión
if ( window.fastButtons === undefined ) {
 
    importScript( 'Special:Mypage/FB.js' );
 
    //Checker
    var fastButtons = {
        FBList: '',
        ufb: ', usando ScreenSuite',
        wikiURL: mw.util.wikiScript( 'index' ) + '?title=',
        isSysop: false
    };
 
    //Enlaza con window
    window.fastButtons = fastButtons;
 
    //Scope local para no contaminar espacio global
    (function ( $, mw ) {
        'use strict';
        //*********************************************************************
        //Funciones generales
        //*********************************************************************
        //readInputButton: ejecuta el código de un botón de acción que lee datos. Lee un dato del usuario.
        fastButtons.readInputButton = function ( mensaje, buttonType, wikiAction ) {
            wikiAction = wikiAction || 'edit';
            var input = window.prompt( decodeURI( mensaje ) );
            if ( input != null ) {
                location.href = fastButtons.wikiURL + wikiAction + '&' + buttonType + '=' + encodeURI( input );
            }
            return false;
        };
 
        //addTemplate: añade una plantilla al inicio de la página, y guarda.
        function addTemplate( plantilla, resumen ) {
            $( '#wpTextbox1' ).val( plantilla + '\n' + $( '#wpTextbox1' ).val() );
            $( '#wpSummary' ).val( resumen + fastButtons.ufb );
            $( '#editform' ).submit();
        }
 
        //addTemplateEnd: añade una plantilla al final de la página, y guarda.
        function addTemplateEnd( plantilla, resumen ) {
            $( '#wpTextbox1' ).val( $( '#wpTextbox1' ).val() + '\n' + plantilla );
            $( '#wpSummary' ).val( resumen + fastButtons.ufb );
            $( '#editform' ).submit();
        }
 
        //addFastButton: genera la cadena para añadir un botón, tomando ciertos parámetros.
        function addFastButton( buttonLabel, buttonType, typeParam, wikiAction ) {
            typeParam = typeParam || buttonLabel;
            wikiAction = wikiAction || 'edit';
            return '[<a href="' + fastButtons.wikiURL + wikiAction + '&' + buttonType + '=' +
                encodeURI( typeParam ) + '">' + buttonLabel + '<\/a>] ';
        }
 
        //addActionFastButton: genera la cadena para añadir un botón de acción.
        function addActionFastButton( buttonLabel, accion ) {
            return '[<a href="#" onclick="return ' + accion + ';">' + buttonLabel + '<\/a>] ';
        }
 
        //addBlockFastButton: genera la cadena para añadir un botón de bloqueo rápido. Es un botón con código más específico,
        //por lo que se hizo por aparte en vez de complicar las demás funciones generalizándolas tanto.
        function addBlockFastButton() {
            var targetName = '',
                urlHref = location.href;
            if ( urlHref.match( "Especial:Bloquear/" ) ) {
                targetName = decodeURI( urlHref.substring( urlHref.indexOf( "Especial:Bloquear/" ) + 18 ) );
            } else if ( urlHref.match( "Especial:Contribuciones/" ) ) {
                targetName = decodeURI( urlHref.substring( urlHref.indexOf( "Especial:Contribuciones/" ) + 24 ) );
            }
 
            if ( !targetName ) {
                return '';
            }
 
            return '[<a href="' + mw.util.wikiScript( 'index' ) + '?title=Especial:Bloquear/' +
                targetName + '&FBblock=31">31h, vandalismo<\/a>] ';
        }
 
        //*********************************************************************
        //Funciones de carga [por defecto] de los botones.
        //*********************************************************************
        //BOTONES PARA NO-SYSOP
        function loadNoSysop() {
            var tmp = '';
 
            tmp += addFastButton( 'Vandalismo', "FBdest" );
            tmp += addFastButton( 'Pruebas de edición', "FBdest" );
            tmp += addFastButton( 'Promocional', "FBdest" );
            if( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 0, 104 ] ) > -1 ) {
                tmp += addFastButton( 'A1', "FBdest" );
                tmp += addFastButton( 'Vacío', "FBdest" );
            }
            tmp += addActionFastButton( 'Plagio', "fastButtons.readInputButton( 'URL', 'FBplagio' );" );
            tmp += addActionFastButton( 'Otro', "fastButtons.readInputButton( 'Motivo', 'FBdest' );" );

            return tmp;
        }
 
        //BOTONES PARA SYSOP
        function loadSysop() {
            var tmp = '';
 
            tmp += addFastButton( 'Borrado rápido', 'FBdelete', 'default', 'delete' );
            tmp += addActionFastButton( 'Borrar', "fastButtons.readInputButton( 'Motivo', 'FBdelete', 'delete' );" );
 
            return tmp;
        }
 
        //PLANTILLAS (BOTONES GENERALES)
        function loadTemplates() {
            var tmp = '';
 
            if( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 0, 104 ] ) > -1 ) {
                // MANTENIMIENTO CRÍTICO
                tmp += addFastButton( 'SRA', 'FBplant', '{{sinrelevancia|{{subst:CURRENTDAY}}|{{subst:CURRENTMONTHNAME}}}}' );
                tmp += addFastButton( 'Promocional', 'FBplant', '{{promocional|{{subst:CURRENTDAY}}|{{subst:CURRENTMONTHNAME}}}}' );
                tmp += addFastButton( 'Fuente primaria', 'FBplant', '{{fuente primaria|{{subst:CURRENTDAY}}|{{subst:CURRENTMONTHNAME}}}}' );
                // CONTENIDO
                tmp += addActionFastButton( 'Problemas artículo', "fastButtons.readInputButton( 'Motivo(s):', 'FBpa' );" );
                tmp += addFastButton( 'Referencias', 'FBplant', '{{referencias|t={{subst:CURRENTTIMESTAMP}}}}' );                
                tmp += addFastButton( 'Desactualizado', 'FBplant', '{{desactualizado}}' ); // Artículo desactualizado
                tmp += addActionFastButton( 'Discutido', "fastButtons.readInputButton( 'Motivo por el que su veracidad es discutida (puede omitirse)', 'FBdiscutido' );" );
                tmp += addFastButton( 'Complejo', 'FBplant', '{{complejo}}' );
                // TRANSFERENCIA Y FUSIÓN
                tmp += addActionFastButton( 'Transferir a otro proyecto', 
                   "fastButtons.readInputButton( 'Proyecto de wikimedia: metawiki, receta, wikcionario, wikilibros, wikinoticias, wikiquote, wikisource, wikiversidad, wikiviajes', 'FBtransferir');");
            } else {
                // Botones de plantillas para espacios de nombres que no sean el Principal o Anexo
            }
 
            return tmp;
        }
 
        //BOTONES DE VARIAS FUNCIONALIDADES (BOTONES GENERALES)
        function loadMisc() {
            var tmp = '',
                warnMenu = encodeURI( "Aviso:\n(nada): Prueba\n0a: Etiqueta\n" +
                    "0b: Estilo\n0c: Spam\n2: Ediciones sin sentido\n2a: Blanqueo\n" +
                    "3: Detente\n4: Última advertencia\n5: Bloqueo" );
 
            if( mw.config.get( 'wgNamespaceNumber' ) != 3 ) {
                return tmp;
            }
 
            tmp += addActionFastButton( "Advertencia", "fastButtons.readInputButton(\'" + warnMenu + "\', 'FBwarn' );" );
            return tmp;
        }

        function loadTalk() {
            var tmp = '';

            if( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 1, 105 ] ) > -1 ) {
                tmp += addFastButton( 'No es un foro', 'FBplant', '{{no es un foro}}' );
                tmp += addFastButton( 'Discusión sosegada', 'FBplant', '{{discusión sosegada}}' );
                tmp += addFastButton( 'Tema polémico', 'FBplant', '{{polémico}}' );
                tmp += addFastButton( 'Contenido cuestionable', 'FBplant', '{{No está censurada}}' );
                tmp += addActionFastButton( 'Adjuntar a wikiproyecto', "fastButtons.readInputButton( 'Ingrese el nombre del wikiproyecto', 'FBwikiproyecto' );" );
            }
            return tmp;
        }

        function loadStyle() {
            var tmp = '';
            if( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 0, 104 ] ) > -1 ) {
                tmp += addFastButton( 'Wikificar', 'FBplant', '{{wikificar|t={{subst:CURRENTTIMESTAMP}}}}' );
                tmp += addFastButton( 'Ortografía', 'FBplant', '{{copyedit}}' );
                tmp += addFastButton( 'Largo', 'FBplant', '{{largo}}' );
                tmp += addFastButton( 'Mal traducido', 'FBplant', '{{mal traducido}}' );
                tmp += addFastButton( 'Publicidad', 'FBplant', '{{publicidad}}' );
                tmp += addFastButton( 'Formato de cita', 'FBplant', '{{formato de cita}}' );
            }
            return tmp;
        }

        function loadTpl() {
            var tmp = '';
            if( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 10 ] ) > -1 ) {
                tmp += addFastButton( 'Plantilla innecesaria', 'FBplant', '<noinclude>{{innecesaria}}</noinclude>' );
                tmp += addFastButton( 'En desarrollo', 'FBplant', '<noinclude>{{en desarrollo}}</noinclude>' );
                tmp += addFastButton( 'Plantilla con Lua', 'FBplant', '<noinclude>{{plantilla con Lua}}</noinclude>' );
                tmp += addActionFastButton( 'Plantilla en desuso', "fastButtons.readInputButton( 'Ingrese el nombre de la plantilla que la remplaza', 'FBplantendesuso' );" );
            }
            return tmp;
        }
   
        //*********************************************************************
        //Añadir los botones
        //*********************************************************************
        function cargar() {
            //Extraer datos de la página
            var tmp;
            if ( $.inArray( 'sysop', mw.config.get( 'wgUserGroups' ) ) > -1 ) {
                fastButtons.isSysop = true;
            }
 
            fastButtons.wikiURL = fastButtons.wikiURL + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) + "&action=";
 
            //Tiene que ser editable
            if ( mw.config.get( 'wgNamespaceNumber' ) >= 0 ) {
                //Botones para bibliotecarios
                if ( fastButtons.isSysop ) {
                    if ( typeof botonesSysop == 'function' ) {
                        tmp = botonesSysop();
                    } else {
                        tmp = loadSysop();
                    }
                    if ( tmp ) {
                        fastButtons.FBList = fastButtons.FBList + 'Sysop: ' + tmp + '<br>';
                    }
                } else { //Botones de destruir. Sólo aparecen a no-bibliotecarios.
                    if ( typeof botonesNoSysop == 'function' ) {
                        tmp = botonesNoSysop();
                    } else {
                        tmp = loadNoSysop();
                    }
                    if ( tmp ) {
                        fastButtons.FBList = fastButtons.FBList + 'Destruir: ' + tmp + '<br>';
                    }
                }
 
                //Mantenimiento. Aparecen para todos los usuarios.
                if ( typeof botonesPlantillas == 'function' ) {
                    tmp = botonesPlantillas();
                } else {
                    tmp = loadTemplates();
                }
                if ( tmp != '' ) {
                    fastButtons.FBList = fastButtons.FBList + 'Mantenimiento: ' + tmp + '<br>';
                }

                //Estilo. Mejora necesaria pero sin revisión de mantenimiento
                if ( typeof botonesEstilo == 'function' ) {
                    tmp = botonesEstilo();
                } else {
                    tmp = loadStyle();
                }
                if ( tmp ) {
                    fastButtons.FBList = fastButtons.FBList + 'Estilo: ' + tmp;
                }

                //Discusión. Botones para las páginas de discusión de los artículos
                if ( typeof botonesDiscusion == 'function' ) {
                    tmp = botonesDiscusion();
                } else {
                    tmp = loadTalk();
                }
                if ( tmp ) {
                    fastButtons.FBList = fastButtons.FBList + 'Discusión: ' + tmp;
                }

                // Plantilla:
                if ( typeof botonesTpl == 'function' ) {
                    tmp = botonesTpl();
                } else {
                    tmp = loadTpl();
                }
                if ( tmp ) {
                    fastButtons.FBList = fastButtons.FBList + 'Plantilla: ' + tmp;
                }
 
                //Otros. Aparecen a todos los usuarios.
                if ( typeof botonesOtros == 'function' ) {
                    tmp = botonesOtros();
                } else {
                    tmp = loadMisc();
                }
                if ( tmp ) {
                    fastButtons.FBList = fastButtons.FBList + 'Otros: ' + tmp;
                }
            } else {
                if ( fastButtons.isSysop ) {
                    if ( typeof botonesBloqueo == 'function' ) {
                        tmp = botonesBloqueo();
                    } else {
                        tmp = addBlockFastButton();
                    }
                    if ( tmp ) { //El <br> de más es porque el botón es peligroso y aparece muy pegado a las demás opciones
                        fastButtons.FBList = fastButtons.FBList + '<br>Bloqueo: ' + tmp;
                    }
                }
            }
        }
 
        /* Mostrar los botones en la página */
        function instalar() {
            var temp;
            cargar();
 
            if ( $( '#contentSub' ).html() ) {
                $( '#contentSub' ).html( $( '#contentSub' ).html() + '<br>' + fastButtons.FBList );
            } else {
                $( '#contentSub' ).html( fastButtons.FBList );
            }
 
            if ( mw.util.getParamValue( 'FBdest' ) != null ) {
                temp = mw.util.getParamValue( 'FBdest' );
                addTemplate( "{{destruir|1=" + temp + "}}", "Destruir: " + temp );
            } else if ( mw.util.getParamValue( 'FBwikiproyecto' ) != null ) {
                temp = mw.util.getParamValue( 'FBwikiproyecto' );
                addTemplate( "{{PR|1=" + temp + "|importancia=|calidad=}}", "Wikiproyecto: " + temp );
            } else if ( mw.util.getParamValue( 'FBplantendesuso' ) != null ) {
                temp = mw.util.getParamValue( 'FBplantendesuso' );
                addTemplate( "<noinclude>{{plantilla en desuso|1={{PAGENAME}}|2=" + temp + "}}</noinclude>", "Plantilla en desuso: " + temp );                
            } else if ( mw.util.getParamValue( 'FBdiscutido' ) != null ) {
                temp = mw.util.getParamValue( 'FBdiscutido' );
                addTemplate( "{{discutido|1=" + temp + "}}", "Discutido: " + temp );
            } else if ( mw.util.getParamValue( 'FBpa' ) != null ) {
                temp = mw.util.getParamValue( 'FBpa' );
                addTemplate( "{{PA|1=" + temp + "|t={{subst:CURRENTTIMESTAMP}}}}", "Problemas artículo: " + temp );
            } else if ( mw.util.getParamValue( 'FBtransferir' ) != null ) {
                temp = mw.util.getParamValue( 'FBtransferir' );
                addTemplate( "{{transferir a|1=" + temp + "}}", "Transferir a otro proyecto: " + temp );
            } else if ( mw.util.getParamValue( 'FBplant' ) != null ) {
                temp = mw.util.getParamValue( 'FBplant' );
                addTemplate( temp, "Plantilla: " + temp);
            } else if ( mw.util.getParamValue( 'FBplagio' ) != null ) {
                temp = mw.util.getParamValue( 'FBplagio' );
                addTemplate( '{{plagio|1=' + temp + '|2=--~~~~}}', "Plagio desde " + temp );
            } else if ( mw.util.getParamValue( 'FBdelete' ) != null ) {
                temp = mw.util.getParamValue( 'FBdelete' );
                if ( temp != 'default' ) {
                    $( '#wpReason' ).val( temp );
                }
                $( '#deleteconfirm' ).submit();
            } else if ( mw.util.getParamValue( 'FBwarn' ) != null ) {
                temp = mw.util.getParamValue( 'FBwarn' );
                addTemplateEnd( '{{subst:prueba' + decodeURI(temp) + '}} --~~~~', 'Aviso al usuario' );
            } else if ( mw.util.getParamValue( 'FBblock' ) != null ) {
                $( '#mw-input-wpExpiry' ).val( '31 hours' );
                $( '#mw-input-wpReason' ).val( '[[WP:VN|Vandalismo de páginas]]' );
                $( '#mw-input-wpDisableUTEdit' ).prop( 'checked', true );
                $( 'form.visualClear' ).submit();
            }
        }
 
        $( document ).ready( instalar );
 
    })( jQuery, mediaWiki ); // Fin de función anónima
} //fin de chequeo
//</nowiki>