MediaWiki:Gadget-DeleteSection.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiunti spazi parentesi, tab, jslint=>jshint per mw:Manual:Coding conventions/JavaScript
 
(10 versioni intermedie di 5 utenti non mostrate)
Riga 3:
* Aggiunge il link "cancella" a ogni sezione di una pagina,
* di fianco a "modifica" o "modifica sorgente", per cancellare l'intera sezione.
* RiscrittoQuesta daè zerouna a partireriscrittura da zero di:
* http://it.wikipedia.org/w/index.php?title=Wikipedia:Monobook.js/deledesection.js&oldid=58651956
*
* @author [[https://it.wikipedia.org/wiki/Utente:Rotpunkt]]
*/
/* global mediaWiki, jQuery, OO */
/*jshint unused: false */
/*global mediaWiki, jQuery */
 
( function ( mw, $ ) {
'use strict';
 
/**
// Messaggio di richiesta dell'oggetto della modifica
* Cancella una sezione della pagina corrente.
var msgEdit = 'Inserire l\'oggetto per l\'edit di cancellazione.\n' +
*
'Se non viene inserito verrà usato quello standard (Sezione "$1" eliminata)';
* @param {string} section - La sezione da rimuovere
* @param {string} summary - L'oggetto della modifica
*/
function removeSection( section, summary ) {
new mw.Api().postWithEditToken( {
action: 'edit',
format: 'json',
title: mw.config.get( 'wgPageName' ),
section: section,
text: '',
summary: summary
} ).done ( function ( data ) {
___location.reload();
} ).fail ( function ( code, data ) {
OO.ui.alert( 'Errore nel cancellare la sezione: ' + code );
} );
}
 
/**
$( document ).ready( function () {
* Crea la finestra di dialogo per la richiesta dell'oggetto della modifica.
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
*
// edit richiamato dallo script stesso per modificare la sezione
* @return {Object} L'oggetto derivato da OO.ui.Dialog che rappresenta la finestra
var gdsummary = mw.util.getParamValue( 'gdsummary' );
*/
if ( gdsummary && $( '#wpTextbox1' ).length && $( '#wpSummary' ).length && $( '#wpSave' ).length ) {
function buildSummaryDialog() {
$( '#wpTextbox1' ).val( '' );
var style = '.gds-container { height: 30px }' +
$( '#wpSummary' ).val( function ( i, text ) {
'.gds-container-button { width: 100%; text-align: center }';
var summary = text.replace( /\/\*\s(.+)\s\*\/.*/, 'Sezione "$1" eliminata' );
$( '<style>' ).text( style ).appendTo( 'head' );
return summary + ( gdsummary === 'true' ? '' : ': ' + gdsummary );
function SummaryDialog( config ) {
} );
SummaryDialog.parent.call( this, config );
$( '#wpSave' ).click();
}
OO.inheritClass( SummaryDialog, OO.ui.Dialog );
} else {
SummaryDialog.static.name = 'summaryDialog';
$( 'span.mw-editsection > a:not( .mw-editsection-visualeditor )' ).each( function () {
SummaryDialog.prototype.initialize = function () {
var url, section;
urlvar self = $( this ).attr( 'href' );
SummaryDialog.parent.prototype.initialize.call( this );
section = $( this ).attr( 'title' ).split( 'Modifica la sezione ' )[1];
var resultLabel = new OO.ui.LabelWidget( {
$( '<a>' )
.attr(classes: 'href',[ '#gds-container' )],
label: ' '
.attr( 'title', 'Cancella la sezione ' + section )
.text( "cancella" )
.click( function () {
var summary = prompt( msgEdit.replace( '$1', section ) );
if ( summary !== null ) {
document.___location = url + '&gdsummary=' +
( summary === '' ? 'true' : summary );
}
} )
.before( ' | ' ).insertAfter( this );
$( this ).after( '<span style="color: #555;"> | </span>' );
} );
var textInput = new OO.ui.TextInputWidget();
var textInputLayout = new OO.ui.FieldLayout( textInput, {
label: 'Oggetto per l\'edit di cancellazione:',
align: 'top'
} );
var okButton = new OO.ui.ButtonWidget( {
label: 'Ok',
} ).on( 'click', function () {
var summary = $.trim( textInput.getValue() );
if ( !summary ) {
resultLabel.setLabel( $( '<p>L\'oggetto &egrave; obbligatorio.</p>' ) );
} else {
resultLabel.setLabel( $( '<p>Cancellazione sezione in corso...</p>' ) );
removeSection( self.currSection, summary );
}
} );
var cancelButton = new OO.ui.ButtonWidget( {
label: 'Annulla'
} ).on( 'click', function () {
self.close();
} );
var buttons = new OO.ui.HorizontalLayout( {
items: [ okButton, cancelButton ],
classes: [ 'gds-container-button' ]
} );
this.textInput = textInput;
this.panelLayout = new OO.ui.PanelLayout( { padded: true, expanded: false } );
this.panelLayout.$element.append( textInputLayout.$element, resultLabel.$element, buttons.$element );
this.$body.append( this.panelLayout.$element );
};
SummaryDialog.prototype.getBodyHeight = function () {
return this.panelLayout.$element.outerHeight( true );
};
return new SummaryDialog( {
size: 'small'
} );
}
 
/**
* Aggiunge il link "cancella" a ogni sezione della pagina corrente.
*/
function addDeleteLinks() {
var summaryDialog, windowManager;
$( 'span.mw-editsection > a:first-of-type' ).each( function ( i, el ) {
var $link, sectiontitle;
sectiontitle = $( el ).attr( 'title' ).split( 'Modifica la sezione ' )[ 1 ];
$link = $( '<a>' )
.attr( 'href', '#' )
.attr( 'title', 'Cancella la sezione ' + sectiontitle )
.attr( 'class', mw.config.get( 'skin' ) === 'minerva' ? 'mw-ui-icon mw-ui-icon-element mw-ui-icon-minerva-trash' : '')
.text( 'cancella' )
.click( function ( event ) {
mw.loader.using( [ 'mediawiki.api', 'oojs-ui-core',
'oojs-ui-widgets', 'oojs-ui-windows' ] )
.done( function () {
if ( !summaryDialog ) {
summaryDialog = buildSummaryDialog();
windowManager = new OO.ui.WindowManager();
$( 'body' ).append( windowManager.$element );
windowManager.addWindows( [ summaryDialog ] );
}
summaryDialog.textInput.setValue ( 'Sezione ' + sectiontitle + ' eliminata' );
summaryDialog.currSection = i + 1;
windowManager.openWindow( summaryDialog );
} )
.fail( function () {
console.error( 'Impossibile avviare l\'accessorio DeleteSection.' );
} );
return false;
} );
$( el ).after( '<span> | </span>', $link );
} );
}
 
$( function () {
if ( mw.config.get( 'wgNamespaceNumber' ) % 2 === 0 ) {
addDeleteLinks();
}
} );