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

Contenuto cancellato Contenuto aggiunto
Nuovo gadget
 
 
(18 versioni intermedie di 7 utenti non mostrate)
Riga 1:
/**
* Gadget-DeleteSection.js
* PerAggiunge il link "cancella" a ogni sezione di una pagina, aggiunge di fianco al link "Modifica"
* undi nuovofianco linka "Cancellamodifica" 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 */
 
( 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;
var self = this;
url = $(this).attr('href');
SummaryDialog.parent.prototype.initialize.call( this );
section = $(this).attr('title').split('sezione ')[1];
var resultLabel = new OO.ui.LabelWidget( {
$('<a>')
classes: [ 'gds-container' ],
.attr('href', '#')
label: ' '
.attr('title', 'Cancella la sezione ' + section)
} );
.text("cancella")
var textInput = new OO.ui.TextInputWidget();
.click(function () {
var textInputLayout = new OO.ui.FieldLayout( textInput, {
var summary = prompt(msgEdit.replace('$1', section));
label: 'Oggetto per l\'edit di cancellazione:',
if (summary != null)
align: 'top'
document.___location = url + '&gdsummary=' +
} );
(summary == '' ? 'true' : summary);
var okButton = new OO.ui.ButtonWidget( {
})
label: 'Ok',
.before(' | ').insertAfter(this);
} ).on( 'click', function () {
});
var summary = $.trim( textInput.getValue() );
}
if ( !summary ) {
});
resultLabel.setLabel( $( '<p>L\'oggetto &egrave; obbligatorio.</p>' ) );
}(mediaWiki, jQuery));
} 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();
}
} );
}( mediaWiki, jQuery ) );