Usuari:Andiport/prova.js

De la Viquipèdia, l'enciclopèdia lliure

Nota: Després de desar, heu de netejar la memòria cau del navegador per veure els canvis. En la majoria de navegadors amb Windows o Linux, premeu Ctrl+F5 o bé premeu Shift i cliqueu el botó "Actualitza" (Ctrl i "Actualitza" amb Internet Explorer). Vegeu més informació i instruccions per a cada navegador a Viquipèdia:Neteja de la memòria cau.

/**Especial:Contributions
 * FastButtons de Racso, adaptats a la Viquipèdia per Syum90.
 * <nowiki>
 */
// Protege contra doble inclusión
if ( window.fastButtons === undefined ) {
 
    importScript( 'Special:Mypage/FB.js' );
 
    //Checker
    var fastButtons = {
        FBList: '',
        ufb: ', usant [[:es:Wikipedia:FastButtons|FastButtons]]',
        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:Bloca/" ) ) {
                targetName = decodeURI( urlHref.substring( urlHref.indexOf( "Especial:Bloca/" ) + 18 ) );
            } else if ( urlHref.match( "Especial:Contribucions/" ) ) {
                targetName = decodeURI( urlHref.substring( urlHref.indexOf( "Especial:Contribucions/" ) + 24 ) );
            }
 
            if ( !targetName ) {
                return '';
            }
 
            return '[<a href="' + mw.util.wikiScript( 'index' ) + '?title=Especial:Bloca/' +
                targetName + '&FBblock=31">31h, vandalisme<\/a>] ';
        }
 
        //*********************************************************************
        //Funciones de carga [por defecto] de los botones.
        //*********************************************************************
        //BOTONES PARA NO-SYSOP
        function loadNoSysop() {
            var tmp = '';
 
            tmp += addFastButton( 'Vandalisme', "FBdest" );
            tmp += addFastButton( 'Proves', "FBdest" );
            tmp += addFastButton( 'Publicitat', "FBdest" );
            if( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 0, 104 ] ) > -1 ) {
                tmp += addFastButton( 'Sense sentit', "FBdest" );
                tmp += addFastButton( 'Sense contingut', "FBdest" );
                tmp += addFastButton( 'No significatiu', "FBdest" );
                tmp += addFastButton( 'No és en català', "FBdest" );
                tmp += addFastButton( 'Sense context', "FBdest" );
                tmp += addFastButton( 'Sense ús ni útil', "FBdest" );
                tmp += addFastButton( 'Sense contingut significatiu', "FBdest" );
                tmp += addFastButton( 'Contingut ja esborrat', "FBdest" );
            }
            tmp += addActionFastButton( 'Plagi', "fastButtons.readInputButton( 'URL', 'FBplagio' );" );
            tmp += addActionFastButton( 'Altre motiu', "fastButtons.readInputButton( 'Motiu', 'FBdest' );" );
 
            return tmp;
        }
 
        //BOTONES PARA SYSOP
        function loadSysop() {
            var tmp = '';
 
            tmp += addFastButton( 'Esborra ràpid', 'FBdelete', 'default', 'delete' );
            tmp += addActionFastButton( 'Esborra', "fastButtons.readInputButton( 'Motiu', 'FBdelete', 'delete' );" );
 
            return tmp;
        }
 
        //PLANTILLAS (BOTONES GENERALES)
        function loadTemplates() {
            var tmp = '';
 
            if( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 0, 104 ] ) > -1 ) {
                tmp += addFastButton( 'Desambiguació', 'FBplant', '{{Desambiguació}}' );
                tmp += addFastButton( 'Incomplet', 'FBplant', '{{Incomplet}}' );
                tmp += addFastButton( 'Referències', 'FBplant', '{{Falten referències}}' );
                tmp += addFastButton( 'Ortografia', 'FBplant', '{{Millorar ortografia}}' );
                tmp += addFastButton( 'Imprecís', 'FBplant', '{{Imprecís}}' );
                tmp += addFastButton( 'Neutralitzar', 'FBplant', '{{Neutralitat}}' );
                tmp += addFastButton( 'Traducció', 'FBplant', '{{Millorar traducció}}' );
                tmp += addFastButton( 'En construcció', 'FBplant', '{{Inacabat}}' );
                tmp += addActionFastButton( 'Proposar eliminació', "fastButtons.readInputButton( 'Motiu per a ser esborrat', 'FBproposta' );" );
                tmp += addFastButton( 'Format', 'FBplant', '{{Millorar format}}' );
                tmp += addFastButton( 'Admissibilitat', 'FBplant', '{{Falta verificar admissibilitat}}' );
            	tmp += addFastButton( 'No enciclopèdic', 'FBplant', '{{Text no enciclopèdic}}' );
            }
 
            return tmp;
        }
 
        //BOTONES DE VARIAS FUNCIONALIDADES (BOTONES GENERALES)
        function loadMisc() {
            var tmp = '',
                warnMenu = encodeURI( "Motiu:\n(res): Proves revertides\n0: Edicions polèmiques\n" +
                    "0a: Edicions ofensives\n0b: Edicions sense estil\n0c: Edicions propagandístiques\n2: Edicions arbitràries\n" +
                    "2a: Esborrament arbitrari\n3: Atureu-vos\n4: Darrer avís\n5: Compte blocat" );
 
            if( mw.config.get( 'wgNamespaceNumber' ) != 3 ) {
                return tmp;
            }
 
            tmp += addActionFastButton( "Advertència", "fastButtons.readInputButton(\'" + warnMenu + "\', 'FBwarn' );" );
            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 + 'Administradors: ' + 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 + 'Destrucció: ' + tmp + '<br>';
                    }
                }
 
                //Plantillas. Aparecen a todos los usuarios.
                if ( typeof botonesPlantillas == 'function' ) {
                    tmp = botonesPlantillas();
                } else {
                    tmp = loadTemplates();
                }
                if ( tmp != '' ) {
                    fastButtons.FBList = fastButtons.FBList + 'Plantilles: ' + tmp + '<br>';
                }
 
                //Otros. Aparecen a todos los usuarios.
                if ( typeof botonesOtros == 'function' ) {
                    tmp = botonesOtros();
                } else {
                    tmp = loadMisc();
                }
                if ( tmp ) {
                    fastButtons.FBList = fastButtons.FBList + 'Altres: ' + 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>Bloqueja: ' + 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( "{{Destrucció|1=" + temp + "}}", "Destrucció: " + 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( '{{Copyright|1=' + temp + '|2={{subst:CURRENTDAY}} {{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}', "Plagi des de " + temp );
            } else if ( mw.util.getParamValue( 'FBproposta' ) != null ) {
                temp = mw.util.getParamValue( 'FBproposta' );
                addTemplate( '{{Esborrar1|1=' + temp + '}}', "Proposta d'eliminació: " + 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:Proves' + decodeURI(temp) + '}} --~~~~', 'Avís a usuari' );
            } else if ( mw.util.getParamValue( 'FBblock' ) != null ) {
                $( '#mw-input-wpExpiry' ).val( '31 hours' );
                $( '#mw-input-wpReason' ).val( 'vandalisme' );
                $( '#mw-input-wpDisableUTEdit' ).prop( 'checked', true );
                $( 'form.visualClear' ).submit();
            }
        }
 
        $( document ).ready( instalar );
 
    })( jQuery, mediaWiki ); // Fin de función anónima
} //fin de chequeo
//</nowiki>