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

Contenuto cancellato Contenuto aggiunto
m rimuovo trattini come da richiesta in talk
cerca un link diverso a seconda che il VE sia attivo
 
(11 versioni intermedie di 4 utenti non mostrate)
Riga 15:
// più le pagine qui di seguito configurate:
var extraPages = {
4: [ 'Officina', 'Oracolo', 'Richieste agli amministratori/Richieste correnti' ],
12: [ 'Sportello informazioni' ]
};
// Per verificare se i link "Cambusa" sono già stati aggiunti
Riga 24:
// La finestra di dialogo per configurare lo spostamento della discussione
var cambusaDialog;
// Nome dell'opzione nelle preferenze che controlla l'attivazione del VisualEditor
var veOptionName = 'visualeditor-betatempdisable';
// Chiavi dei messaggi che possono apparire come testo dei link di modifica sezione
var editLinkMsgKeys = {
0: 'visualeditor-ca-editsource-section', // VisualEditor attivo
1: 'editsection' // VisualEditor disattivo
};
 
/**
Riga 65 ⟶ 72:
___location.reload();
} ).fail ( function ( code, data ) {
OO.ui.getWindowManager().getCurrentWindow().close();
OO.ui.alert( 'Errore nel modificare la discussione: ' + code );
} );
Riga 83 ⟶ 91:
} )
.fail ( function ( code, data ) {
OO.ui.getWindowManager().getCurrentWindow().close();
OO.ui.alert( 'Errore nel creare la discussione: ' + code );
} );
Riga 102 ⟶ 111:
anchorHandler( data.parse.sections[ data.parse.sections.length - 1 ].anchor );
} ).fail ( function ( code, data ) {
OO.ui.getWindowManager().getCurrentWindow().close();
OO.ui.alert( 'Errore nel leggere l\'anchor della sezione: ' + code );
} );
Riga 123 ⟶ 133:
extraPages[ formData.destNamespaceNum ].join( ', ' );
}
 
cambusaDialog.close();
 
if ( error ) {
OO.ui.alert( error );
} else {
cambusaDialog.close();
formData.destTitle = formData.destNamespace + ':' + formData.destTitle;
from = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' );
text = '{{Cambusada|' + from + '|firma=~~\~~}}\n' + formData.sourceText;
// @todo L'utilizzo dell'alert qui rende necessaria una chiamata a OO.ui.getWindowManager().getCurrentWindow().close()
// prima di poter mostrare ulteriori alert
OO.ui.alert( 'Spostamento in corso...' );
addSection( formData.destTitle, formData.destSectionTitle, text, function ( newrevid ) {
getSectionAnchor( newrevid, function ( anchor ) {
text = '==' + formData.destSectionTitlesourceSectionTitle + '==\n\n' +
'{{Cambusa|' + formData.destIncipit + '|' + formData.destTitle + '#' + anchor + '|firma=~~\~~}}';
setSection( formData.sourceSection, text, 'cambusata discussione in [[' + formData.destTitle + ']]' );
Riga 149 ⟶ 162:
function buildCambusaDialog() {
var style = '.gc-container-button { width: 100%; text-align: center; margin-top: 10px }';
$( '<style>' )mw.textutil.addCSS( style ).appendTo( 'head' );
function CambusaDialog( config ) {
CambusaDialog.parent.call( this, config );
Riga 201 ⟶ 214:
} ),
new OO.ui.FieldLayout( this.sectionTitleInput, {
label: 'Titolo nuova discussione di destinazione:',
align: 'top'
} ),
Riga 223 ⟶ 236:
CambusaDialog.prototype.setSourceSection = function ( sourceSection, sourceSectionTitle, sourceText ) {
this.sourceSection = sourceSection;
this.sourceSectionTitle = sourceSectionTitle;
this.sectionTitleInput.setValue( sourceSectionTitle );
this.sourceText = sourceText;
Riga 236 ⟶ 250:
destNamespaceNum: this.namespaceDropdown.getMenu().findSelectedItem().getData(),
sourceSection: this.sourceSection,
sourceSectionTitle: this.sourceSectionTitle,
sourceText: this.sourceText
};
Riga 247 ⟶ 262:
* Aggiunge il link "Cambusa" a ogni sezione della pagina corrente.
*/
async function addCambusaLinks() {
await mw.loader.load( [ 'mediawiki.jqueryMsg', 'user.options' ] );
const editLinkMsgKey = editLinkMsgKeys[ mw.user.options.get( veOptionName ) ];
await api.loadMessagesIfMissing( [ editLinkMsgKey ] );
var windowManager;
$( '`span.mw-editsection > a:last-of-type'contains(${ mw.msg( editLinkMsgKey ) })` ).each( function ( i, el ) => {
var $link, sectiontitlehref = $( el ).attr( 'title' ).replace( /^(Modifica|Cancella) la sezione /g, 'href' );
$linkvar pageTitle = $mw.util.getParamValue( '<a>title', href );
if ( pageTitle !== mw.config.get( 'wgPageName' ) ) {
$( el ).after(
'<span> | </span>',
$( '<span>' )
.css( 'color', '#54595d' )
} );.attr(
'title',
'Sezione della pagina ' + pageTitle.replace( /_/g, ' ' )
} )
.text( 'sezione transclusa' )
} );
return;
}
var sectionTitle = $( el ).attr( 'title' ).replace( /^(Modifica|Cancella) la sezione /g, '' );
var $link = $( '<a>' )
.attr( 'href', '#' )
.attr( 'title', 'Cambusa la discussione ' + sectiontitlesectionTitle )
.text( 'cambusa' )
.click( functionasync ( event ) => {
event.preventDefault();
await mw.loader.usingload( [ 'mediawiki.api.edit', 'oojs-ui-core', 'oojs-ui-widgets',
'oojs-ui-windowscore', 'mediawiki.oojs-ui-widgets', ]'oojs-ui-windows', function () {'mediawiki.widgets'
api] = new mw.Api();
getSection( i +mw.util.getParamValue( 1'section', functionhref ), ( text ) => {
var match = text.match( /==\s*(.*?)\s*==\s*\n([\s\S]*)/ );
if ( !cambusaDialog ) {
cambusaDialog = buildCambusaDialog();
windowManager = new OO.ui.WindowManager();
$( 'body' ).append( windowManager.$element );
windowManager.addWindows( [ cambusaDialog ] );
}
cambusaDialog.setSourceSection( i + 1, match[ 1 ], match[ 2 ] );
windowManager.openWindow( cambusaDialog );
} );
} );
} );
Riga 289 ⟶ 321:
}
 
$( async function () {
if ( mw.config.get( 'wgAction' ) === 'view' && !cambusaLinksAllowed() ) {
return;
var portletLink = mw.util.addPortletLink( 'p-tb', '#', 'Cambusa', 't-cambusa', 'Aggiunge il link cambusa a ogni discussione' );
$( portletLink ).click( function ( event ) {
event.preventDefault();
if ( !inited ) {
addCambusaLinks();
inited = true;
}
} );
}
 
await mw.loader.load( 'mediawiki.util' );
 
var portletLink = mw.util.addPortletLink(
var portletLink = mw.util.addPortletLink( 'p-tb', '#', 'Cambusa', 't-cambusa', 'Aggiunge il link cambusa a ogni discussione' );
 
$( portletLink ).click( functionasync ( event ) => {
event.preventDefault();
 
if ( !inited ) {
await mw.loader.load( 'mediawiki.api' );
api = new mw.Api();
addCambusaLinks();
inited = true;
}
} );
} );
}( mediaWiki, jQuery ) );