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

Contenuto cancellato Contenuto aggiunto
m Rotpunkt ha spostato la pagina Utente:Rotpunkt/Gadget-cambusa.js a MediaWiki:Gadget-cambusa.js senza lasciare redirect: Nuovo accessorio
aggiunta configurazione per pagine non di discussione, fix vari
Riga 12:
'use strict';
 
var $dialog, $alert, $namespace, inited = false, api = new mw.Api();
api = new mw.Api(),
// Le pagine di partenza e destinazione per la cambusa
// possono appartenere solo ai namespace di discussione,
// più le pagine qui di seguito configurate:
extraPages = {
4: [ 'Malfunzionamenti', 'Oracolo' ],
12: [ 'Sportello informazioni' ]
},
$dialog, $alert, $namespace;
 
/**
Riga 92 ⟶ 101:
inputEl.autocomplete( {
source: function( request, response ) {
apnamespace:var ns = $namespace.find( 'option:selected' ).data( 'ns' ) - 1,;
$.ajax( {
if ( ns % 2 === 1 ) {
url: mw.util.wikiScript( 'api' ),
data:$.ajax( {
actionurl: mw.util.wikiScript( 'queryapi' ),
listdata: 'allpages',{
aplimit action: '10query',
apprefix list: request.term'allpages',
aplimit: '10',
apnamespace: $namespace.find( 'option:selected' ).data( 'ns' ) - 1,
format apprefix: 'json'request.term,
} apnamespace: ns - 1,
dataType format: 'json'
} ),
dataType: 'json'
.done( function ( data ) {
var} pages = [];)
$.eachdone( data.query.allpages,function function( i, pagedata ) {
response( var pages )= [];
pages.push( page.title.substring( page.title.indexOf( ':' ) + 1 ) );
$.each( data.query.allpages, function( i, page ) {
});
pages.push( page.title.substring( page.title.indexOf( ':' ) + 1 ) );
response( pages );
} );
response( pages );
} );
} else if ( extraPages[ns] ) {
response( extraPages[ns] );
} );
},
change: function ( e, ui ) {
Riga 134 ⟶ 148:
* Visualizza la finestra di dialogo per inserire i dati per la cambusa.
*/
function showDialogCambusa( section, sectiontitle, text ) {
var $fieldset, $dest, $desttitle, $incipit;
// crea il dialog
Riga 145 ⟶ 159:
$namespace = $( '<select>' ).attr( 'id', 'gc-ns' ).css( 'width', '150px' );
$.each( mw.config.get( 'wgFormattedNamespaces' ), function ( key, value ) {
if ( key > 0 && ( key % 2 === 1 || extraPages[key] ) ) {
$( '<option>' ).html( value ).data( 'ns', key ).appendTo( $namespace );
}
Riga 164 ⟶ 178:
buttons: {
'Ok': function () {
var from, error, incipit = $.trim( $incipit.val() ),
dest = $.trim( $dest.val() ),
desttitle = $.trim( $desttitle.val() );
Riga 180 ⟶ 194:
// cambusa
dest = $namespace.val() + ':' + dest;
var from = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' );
text = '{{Cambusada|' + from + '|--~~' + '~~}}\n' + text;
alert( 'Spostamento in corso...', true );
getSectionaddSection( sectiondest, function (desttitle, text, function () {
text = '== ' + sectiontitle + ' ==\n\n' + '{{Cambusa|' + incipit + '|' + dest + '|--~~' + '~~}}';
var from = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' );
textsetSection( =section, text.substring(, text.indexOf('cambusata discussione in [['==', 3+ )dest + 2']]' );
text = text.replace( /^\s+/g, '' );
text = '{{Cambusada|' + from + '|--~~' + '~~}}\n' + text;
addSection( dest, desttitle, text, function () {
text = '== ' + sectiontitle + ' ==\n' + '{{Cambusa|' + incipit + '|' + dest + '|--~~' + '~~}}';
setSection( section, text, 'cambusata discussione in [[' + dest + ']]' );
} );
} );
}
Riga 202 ⟶ 212:
function addLinks() {
$( 'span.mw-editsection > a:last-of-type' ).each( function ( i, el ) {
var $link, sectiontitle = $( el ).attr( 'title' ).splitreplace( '/^(Modifica|Cancella) la sezione /g, '' )[1];
$link = $( '<a>' )
.attr( 'href', '#' )
.attr( 'title', 'Cambusa la discussione ' + sectiontitle )
.text( 'cambusa' )
.click( function ( event ) {
Riga 211 ⟶ 221:
mw.loader.using( [ 'jquery.ui.dialog', 'mediawiki.api.edit',
'jquery.ui.autocomplete', 'jquery.spinner' ], function () {
showDialogCambusagetSection( i + 1, sectiontitlefunction ( text ); {
var match = text.match( /(.*?)\s*\n([\s\S]*)/ );
showDialogCambusa( i + 1, match[1], match[2] );
} );
} );
} );
Riga 217 ⟶ 230:
} );
inited = true;
}
/**
* Ritorna true se la pagina corrente può utilizzare il link "cambusa".
*/
function cambusaLinksAllowed() {
var ns = mw.config.get( 'wgNamespaceNumber' ),
title = mw.config.get( 'wgTitle' );
return ns % 2 === 1 ||
( extraPages[ns] && $.inArray( title, extraPages[ns] ) !== -1 );
}
 
$( function () {
if ( mw.config.get( 'wgAction' ) === 'view' && mw.config.getcambusaLinksAllowed( 'wgNamespaceNumber' ) % 2 === 1 ) {
var portletLink = mw.util.addPortletLink( 'p-tb', '#', 'Cambusa', 't-cambusa', 'Aggiunge il link cambusa a ogni discussione' );
$( portletLink ).click( function ( event ) {