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

Contenuto cancellato Contenuto aggiunto
m mw.Api
 
(6 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';
 
var $dialog;
 
/**
* Cancella una sezione della pagina corrente.
*
* @param {string} section - La sezione da rimuovere
* @param {string} summary - L'oggetto della modifica
*/
function removeSection( section, summary ) {
Riga 30:
___location.reload();
} ).fail ( function ( code, data ) {
OO.ui.alert( 'Errore nel cancellare la sezione: ' + code );
$dialog.dialog( 'close' );
} );
}
 
/**
* RichiedeCrea illa testofinestra di dialogo per lla richiesta dell'oggetto della modifica.
*
* @return {Object} L'oggetto derivato da OO.ui.Dialog che rappresenta la finestra
*/
function showDialogbuildSummaryDialog( section, sectiontitle ) {
var style = '.gds-container { height: 30px }' +
var $descr, $label, $inputText;
'.gds-container-button { width: 100%; text-align: center }';
if ( !$dialog ) {
$dialog = $( '<divstyle>' ).attrtext( 'id', 'gds-dialog'style ).appendTo( 'bodyhead' );
function SummaryDialog( config ) {
SummaryDialog.parent.call( this, config );
}
OO.inheritClass( SummaryDialog, OO.ui.Dialog );
$descr = $( '<p>' ).text( 'Sezione: ' + sectiontitle );
SummaryDialog.static.name = 'summaryDialog';
$label = $( '<label>' ).css( { display: 'block', 'margin': '10px 0 2px 0' } )
SummaryDialog.prototype.initialize = function () {
.text( 'Oggetto per l\'edit di cancellazione:' );
var self = this;
$inputText = $( '<input/>' ).attr( 'type', 'text' )
SummaryDialog.parent.prototype.initialize.call( this );
.attr( 'size', 40 ).val( 'Sezione ' + sectiontitle + ' eliminata' );
var resultLabel = new OO.ui.LabelWidget( {
$dialog.empty().append( $descr, $label, $inputText );
classes: [ 'gds-container' ],
 
label: ' '
$dialog.dialog( {
} );
title: 'Accessorio cancella sezione',
var textInput = new OO.ui.TextInputWidget();
position: { my: 'center', at: 'center', of: window },
var textInputLayout = new OO.ui.FieldLayout( textInput, {
buttons: {
label: 'Oggetto per l\'edit di cancellazione:',
'Ok': function() {
align: 'top'
var summary = $.trim( $inputText.val() );
} );
if ( summary.length === 0 ) {
var okButton = new OO.ui.ButtonWidget( {
alert( 'L\'oggetto è obbligatorio.' );
}label: else {'Ok',
} ).on( 'click', function () {
$label.text( 'Cancellazione in corso...' );
var summary = $.trim( textInput.getValue() );
$inputText.replaceWith( $.createSpinner( { size: 'large', type: 'block' } ).css( 'margin', '10px' ) );
removeSectionif ( section, !summary ); {
resultLabel.setLabel( $( '<p>L\'oggetto &egrave; obbligatorio.</p>' ) );
}
}, else {
resultLabel.setLabel( $( '<p>Cancellazione sezione in corso...</p>' ) );
'Annulla': function () {
$removeSection( this )self.dialog(currSection, 'close'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'
} );
}
 
/**
$( function () {
* Aggiunge il link "cancella" a ogni sezione della pagina corrente.
if ( mw.config.get( 'wgAction' ) === 'view' && mw.config.get( 'wgNamespaceNumber' ) % 2 === 0 ) {
*/
$( 'span.mw-editsection > a:last-of-type' ).each( function ( i, el ) {
function addDeleteLinks() {
var $link, sectiontitle;
var summaryDialog, windowManager;
sectiontitle = $( el ).attr( 'title' ).split( 'Modifica la sezione ' )[1];
$( 'span.mw-editsection > a:first-of-type' ).each( function ( i, el ) {
$link = $( '<a>' )
var $link, sectiontitle;
.attr( 'href', '#' )
sectiontitle = $( el ).attr( 'title', ).split( 'CancellaModifica la sezione ' +)[ sectiontitle1 )];
.text$link = $( 'cancella<a>' )
.clickattr( function'href', ( event'#' ) {
.attr( 'title', 'Cancella la sezione ' + sectiontitle )
mw.loader.using( [ 'mediawiki.api', 'mediawiki.api.edit', 'jquery.ui.dialog', 'jquery.spinner' ], function () {
.attr( 'class', mw.config.get( 'skin' ) === 'minerva' ? 'mw-ui-icon mw-ui-icon-element mw-ui-icon-minerva-trash' : '')
showDialog( i + 1, sectiontitle );
.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();
}
} );