MediaWiki:Common.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
spostato WikiMiniAtlas a MediaWiki:Gadget-WikiMiniAtlas.js
riordinate funzioni per tipologia, racchiuso codice in iffy
Riga 1:
/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */
/*global mwmediaWiki, $jQuery, importScript */
 
( function ( mw, $ ) {
/**
'use strict';
* Redirect bad mirrors to it.wikipedia.org
* [[m:User:Hoo man]]
*/**
* Redirect bad mirrors to it.wikipedia.org
( function () {
* @author [[m:User:Hoo man]]
var i, isBad,
*/
badMirrors = [
( function () {
'wikipedia.sapere.alice.it',
var i, isBad,
'212.48.3.33',
badMirrors = [
'wikipedia.virgilio.it',
'213wikipedia.92sapere.16alice.218it',
'212.48.3.33',
];
'wikipedia.virgilio.it',
for ( i = 0; i < badMirrors.length; i++ ) {
'213.92.16.218',
if ( document.___location.href.indexOf( badMirrors[ i ] ) !== -1 ) {
isBad = true];
for ( i = 0; i < badMirrors.length; i++ ) {
break;
if ( document.___location.href.indexOf( badMirrors[ i ] ) !== -1 ) {
isBad = true;
break;
}
}
if ( isBad ) {
}
// redirect users to the same page on itwiki
if ( isBad ) {
//document.___location.href = '//it.wikipedia.org/wiki/' + mw.config.get( 'wgPageName' );
// redirect users to the same page on itwiki
// redirect users to a landing page
//document.___location.href = '//it.wikipedia.org/wiki/' + mw.config.get( 'wgPageName' );
document.___location.href = '//it.wikipedia.org/wiki/Wikipedia:Live_mirror';
// redirect users to a landing page
document.___location.href = '//it.wikipedia.org/wiki/Wikipedia:Live_mirror';
}
} )();
 
 
/**
* Collegamento diretto alla pagina di upload di Commons nel portlet Strumenti
*/
$( function () {
mw.util.addPortletLink( 'p-tb', '//commons.wikimedia.org/wiki/Commons:Upload/it', 'Carica su Commons',
't-uploadcommons', 'Carica file multimediali su Wikimedia Commons', 'm', '#t-specialpages' );
} );
 
/**
* In "Pagina principale" aggiunge il link alla lista completa di tutte le pagine
*/
if ( mw.config.get( 'wgIsMainPage' ) || mw.config.get( 'wgPageName' ) === "Discussione:Pagina_principale" ) {
$( function () {
mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/Lista_di_Wikipedie',
'Lista completa', 'interwiki-completelist', 'Lista completa delle Wikipedie' );
} );
}
 
/**
* Utilizzata con [[template:Titolo errato]] per cambiare il titolo di una pagina,
* cerca un HTML (creato dal template) contenente:
* <div id="RealTitleBanner"><span id="RealTitle">titolo</span></div>
* Si può disattivare con un elemento con id="DisableRealTitle".
* Importata inizialmente da [[en:MediaWiki:Common.js]].
*/
 
function checkRealTitleBanner() {
var $realTitleBanner = $( '#RealTitleBanner' ), $realTitle, $firstH1;
if ( $realTitleBanner.length && !$( '#DisableRealTitle' ).length ) {
$realTitle = $realTitleBanner.find( '#RealTitle' );
$firstH1 = $( 'h1:first' );
if ( $realTitle.length && $firstH1.length ) {
$realTitleBanner.hide();
$firstH1.html( $realTitle.html() );
document.title = $realTitle.text() + ' - Wikipedia';
}
} )();
}
 
// ============================
$( checkRealTitleBanner );
// Caricamento script
// ============================
 
/**
* Ricerca in Wikidata
* Aggiunge un combobox a [[MediaWiki:Edittools]] per selezionare un gruppo di caratteri speciali.
*/
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||
 
( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
function comboboxEdittools() {
mw.loader.load( '//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript' );
var $specialChars = $( '#specialchars' ), $select;
}
if ( $specialChars.length ) {
$select = $( '<select>' ).change( function () {
/**
$specialChars.find( 'p' ).hide();
* Menu interprogetto nella sidebar, vedi anche [[Modulo:Interprogetto]]
$specialChars.find( 'option:selected' ).data().show();
} );*/
importScript( 'MediaWiki:InterProject.js' );
$specialChars.find( 'p' ).each( function () {
$( '<option>' ).html( $( this ).attr( 'id' ).replace( /_/g, ' ' ) )
/**
.data( $( this ) ).appendTo( $select );
* Esempio di diff in Aiuto:Diff
} );
*/
$specialChars.prepend( $select );
if ( mw.config.get( 'wgPageName' ) === 'Aiuto:Diff' ) {
$select.change();
mw.loader.load( 'mediawiki.action.history.diff' );
}
}
 
/**
$( comboboxEdittools );
* Caricamento script da parametro URL
 
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
/**
* @rev 5
* Layout pagina di modifica
*/
var extraJS = mw.util.getParamValue( 'withJS' );
$( function () {
if ( mw.config.get( 'wgAction' ) === 'edit'extraJS ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
/* Allarga l'edittools a tutta pagina */
importScript( extraJS );
$( '#Standard' ).css( 'width', '100%' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
} );
 
// ============================
/**
// Modifica HTML pagine
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
// ============================
* @rev 5
*/
/**
var extraJS = mw.util.getParamValue( 'withJS' );
* Portlets
if ( extraJS ) {
*/
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
function addPortlets() {
importScript( extraJS );
// Collegamento diretto alla pagina di upload di Commons nel portlet Strumenti
} else {
mw.util.addPortletLink( 'p-tb', '//commons.wikimedia.org/wiki/Commons:Upload/it', 'Carica su Commons',
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
't-uploadcommons', 'Carica file multimediali su Wikimedia Commons', 'm', '#t-specialpages' );
// In "Pagina principale" aggiunge il link alla lista completa di tutte le pagine
if ( mw.config.get( 'wgIsMainPage' ) || mw.config.get( 'wgPageName' ) === "Discussione:Pagina_principale" ) {
mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/Lista_di_Wikipedie',
'Lista completa', 'interwiki-completelist', 'Lista completa delle Wikipedie' );
}
}
}
 
$( addPortlets );
/**
* Utilizzata con [[template:Galleria]] per creare una galleria di immagini,
* cerca un HTML (creato dal template) contenente:
* <div class="ImageGroup"><div class="ImageGroupUnits">immagini</div></div>
* Idea originale da [[fr:MediaWiki:Common.js]] del 2007.
*
* @author [[it:User:Rotpunkt]]
*/
 
/**
function updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink ) {
* Aggiunge un combobox a [[MediaWiki:Edittools]] per selezionare un gruppo di caratteri speciali.
$images.hide().eq( currImg ).show();
*/
$countInfo.html( '(' + ( currImg + 1 ) + '/' + $images.length + ')' );
function comboboxEdittools() {
$prevLink.toggle( currImg !== 0 );
var $specialChars = $( '#specialchars' ), $select;
$nextLink.toggle( currImg !== $images.length - 1 );
if ( $specialChars.length ) {
}
$select = $( '<select>' ).change( function () {
 
$specialChars.find( 'p' ).hide();
function initImageGroup() {
$specialChars.find( 'option:selected' ).data().show();
$( 'div.ImageGroup > div.ImageGroupUnits' ).each( function ( i, imageGroupUnits ) {
var $images, $prevLink, $nextLink, $countInfo, currImg = 0;
$images = $( imageGroupUnits ).children( '.center' );
$countInfo = $( '<tt>' ).css( 'font-size', '110%' );
$prevLink = $( '<a>' )
.attr( 'href', '#' ).attr( 'title', 'Immagine precedente' )
.text( '◀' ).css( 'text-decoration', 'none' )
.click( function ( e ) {
e.preventDefault();
updateImageGroup( currImg -= 1, $images, $countInfo, $prevLink, $nextLink );
} );
$specialChars.find( 'p' ).each( function () {
$nextLink = $( '<a>' )
.attr $( 'href<option>', '#').html( $( this ).attr( 'titleid' ).replace( /_/g, 'Immagine successiva' ) )
.textdata( '▶'$( this ) ).cssappendTo( 'text-decoration', 'none'$select );
.click( function ( e ) {
e.preventDefault();
updateImageGroup( currImg += 1, $images, $countInfo, $prevLink, $nextLink );
} );
$specialChars.prepend( $select );
updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink );
$select.change();
$( imageGroupUnits ).prepend( $prevLink, $countInfo, $nextLink );
}
} );
}
 
$( initImageGroupcomboboxEdittools );
 
/**
* Layout pagina di modifica
* Toglie "Soggetto/Intestazione" nelle creazioni delle discussioni al Bar
*/
if ( mw.config.get( 'wgNamespaceNumber' ) === 4 &&
mw.config.get( 'wgPageName' ).indexOf( 'Wikipedia:Bar/' ) === 0 &&
mw.config.get( 'wgAction' ) === 'edit' &&
document.___URL.indexOf( '&section=new&preload=' ) !== -1) {
$( function () {
if ( mw.config.get( 'wgAction' ) === 'edit' ) {
document.getElementById( 'wpSummaryLabel' ).style.display = 'none';
/* Allarga l'edittools a tutta pagina */
document.getElementById( 'wpSummary' ).style.display = 'none';
$( '#Standard' ).css( 'width', '100%' );
}
} );
}
/**
* Toglie "Soggetto/Intestazione" nelle creazioni delle discussioni al Bar
*/
if ( mw.config.get( 'wgNamespaceNumber' ) === 4 &&
mw.config.get( 'wgPageName' ).indexOf( 'Wikipedia:Bar/' ) === 0 &&
mw.config.get( 'wgAction' ) === 'edit' &&
document.___URL.indexOf( '&section=new&preload=' ) !== -1) {
$( function () {
document.getElementById( 'wpSummaryLabel' ).style.display = 'none';
document.getElementById( 'wpSummary' ).style.display = 'none';
} );
}
/**
* Cambia posizione e link del link "modifica" delle sezioni
* Fatto in Common.css, questo è un fix per IE7
*/
if ( $.client.profile().name === 'msie' && $.client.profile().versionNumber < 8 ) {
$( function () {
$( '.editsection' ).each( function( i, e ) {
$( e ).parent().append( e );
} );
} );
}
 
// ============================
// Supporto ai template
// ============================
 
/**
* Utilizzata con [[template:Titolo errato]] per cambiare il titolo di una pagina,
* Cambia posizione e link del link "modifica" delle sezioni
* cerca un HTML (creato dal template) contenente:
* Fatto in Common.css, questo è un fix per IE7
* <div id="RealTitleBanner"><span id="RealTitle">titolo</span></div>
*/
* Si può disattivare con un elemento con id="DisableRealTitle".
if ( $.client.profile().name === 'msie' && $.client.profile().versionNumber < 8 ) {
* Importata inizialmente da [[en:MediaWiki:Common.js]].
$( function () {
*/
$( '.editsection' ).each( function( i, e ) {
function checkRealTitleBanner() {
$( e ).parent().append( e );
var $realTitleBanner = $( '#RealTitleBanner' ), $realTitle, $firstH1;
} );
if ( $realTitleBanner.length && !$( '#DisableRealTitle' ).length ) {
} );
$realTitle = $realTitleBanner.find( '#RealTitle' );
}
$firstH1 = $( 'h1:first' );
if ( $realTitle.length && $firstH1.length ) {
$realTitleBanner.hide();
$firstH1.html( $realTitle.html() );
document.title = $realTitle.text() + ' - Wikipedia';
}
}
}
$( checkRealTitleBanner );
/**
* Utilizzata con [[template:Galleria]] per creare una galleria di immagini,
* cerca un HTML (creato dal template) contenente:
* <div class="ImageGroup"><div class="ImageGroupUnits">immagini</div></div>
* Idea originale da [[fr:MediaWiki:Common.js]] del 2007.
* @author [[it:User:Rotpunkt]]
*/
function updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink ) {
$images.hide().eq( currImg ).show();
$countInfo.html( '(' + ( currImg + 1 ) + '/' + $images.length + ')' );
$prevLink.toggle( currImg !== 0 );
$nextLink.toggle( currImg !== $images.length - 1 );
}
 
function initImageGroup() {
/**
$( 'div.ImageGroup > div.ImageGroupUnits' ).each( function ( i, imageGroupUnits ) {
* Classe autocollapse con mw-collapsible: se presente più di una table con classe mw-collapsible,
var $images, $prevLink, $nextLink, $countInfo, currImg = 0;
* quelle con anche la classe autocollapse si chiudono da sole. Deve essere presente anche la classe navbox.
$images = $( imageGroupUnits ).children( '.center' );
*/
$countInfo = $( '<tt>' ).css( 'font-size', '110%' );
$( function () {
$prevLink = $( '<a>' )
if ( $( 'table.navbox.mw-collapsible' ).length > 1) {
.attr( 'href', '#' ).attr( 'title', 'Immagine precedente' )
$( 'table.navbox.mw-collapsible.autocollapse' ).each( function ( i, el ) {
if .text( !$( el'◀' ).hasClasscss( 'mwtext-collapseddecoration', )'none' ) {
.click( function ( e ) {
// makeCollapsible a volte è eseguita prima, a volte successivamente al Common.js,
e.preventDefault();
// se è già stata eseguita, non resta che simulare un click.
updateImageGroup( currImg -= 1, $images, $countInfo, $prevLink, $nextLink );
if ( $( el ).data( 'mw-made-collapsible' ) ) {
} );
// hide() chiude la tabella più velocemente di fadeOut
$nextLink = $( '<a>' )
$( el ).children( 'tr:not(:first)' ).hide();
.attr( 'href', '#' ).attr( 'title', 'Immagine successiva' )
$( el ).find( '.mw-collapsible-toggle > a' ).click();
.text( '▶' ).css( 'text-decoration', 'none' )
} else {
$.click( elfunction ).addClass( 'mw-collapsed'e ); {
e.preventDefault();
}
updateImageGroup( currImg += 1, $images, $countInfo, $prevLink, $nextLink );
}
} );
updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink );
$( imageGroupUnits ).prepend( $prevLink, $countInfo, $nextLink );
} );
}
} );
$( initImageGroup );
 
/**
/**
* Esempio di diff in Aiuto:Diff
* Utilizzata con [[Template:Navbox]]: se presente più di una table
*/
* con classi navbox e mw-collapsible, quelle con autocollapse si chiudono da sole.
if ( mw.config.get( 'wgPageName' ) === 'Aiuto:Diff' ) {
* @author [[it:User:Rotpunkt]]
mw.loader.load( 'mediawiki.action.history.diff' );
*/
}
function checkAutocollapse() {
 
if ( $( 'table.navbox.mw-collapsible' ).length > 1) {
/**
$( 'table.navbox.mw-collapsible.autocollapse' ).each( function ( i, el ) {
* Ricerca in Wikidata
if ( !$( el ).hasClass( 'mw-collapsed' ) ) {
*/
// makeCollapsible a volte è eseguita prima, a volte successivamente al Common.js,
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||
// se è già stata eseguita, non resta che simulare un click.
( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
if ( $( el ).data( 'mw-made-collapsible' ) ) {
mw.loader.load( '//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript' );
// hide() chiude la tabella più velocemente di fadeOut
}
$( el ).children( 'tr:not(:first)' ).hide();
$( el ).find( '.mw-collapsible-toggle > a' ).click();
} else {
$( el ).addClass( 'mw-collapsed' );
}
}
} );
}
}
 
$( checkAutocollapse );
/**
}( mediaWiki, jQuery ) );
* Menu interprogetto nella sidebar, vedi anche [[Modulo:Interprogetto]]
*/
importScript( 'MediaWiki:InterProject.js' );