MediaWiki:Gadget-MultiDiffConsecutive.js
Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.
Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.
/**
* View the next/ previous edit of a revision in MediaWiki multi diffs.
* Uses the localization provided by MediaWiki, requires mediawiki.util
* and mediawiki.api to work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @author Marius Hoch < hoo@online.de >
*/
function show() {
'use strict';
var oldRevision, newRevision, nextRevisionText, prevRevisionText;
/**
* Load missing messages needed by this script
*
* @return {jQuery.promise}
*/
function loadMessages( msg ) {
return new mw.Api().loadMessagesIfMissing( [
'previousdiff',
'nextdiff'
] );
}
if ( !$( '.diff-multi' ).length ) {
// No multi diff
return;
}
oldRevision = mw.util.getParamValue(
'oldid',
$( '#mw-diff-otitle1' ).find( 'a' ).eq(0).attr( 'href' )
);
newRevision = mw.util.getParamValue(
'oldid',
$( '#mw-diff-ntitle1' ).find( 'a' ).eq(0).attr( 'href' )
);
if ( !newRevision || !oldRevision ) {
// Weird
return;
}
if ( $( '#differences-nextlink' ).length ) {
nextRevisionText = $( '#differences-nextlink' ).text();
getPrevRevisionText();
} else {
loadMessages()
.done( function nextDiff () {
nextRevisionText = mw.msg( 'nextdiff' );
} )
.done( getPrevRevisionText );
}
/**
* This function gets the interface text for the next revision and
* calls doLink after
*/
function getPrevRevisionText() {
if ( $( '#differences-prevlink' ).length ) {
prevRevisionText = $( '#differences-prevlink' ).text();
doLink();
} else {
loadMessages()
.done( function previousDiff () {
prevRevisionText = mw.msg( 'previousdiff' );
} )
.done( doLink );
}
}
/**
* Insert the diff links after the interface messages have been loaded
*/
function doLink() {
var nextLink = $( '<a>' )
.attr( 'href', mw.util.wikiScript( 'index' ) + '?oldid=' + oldRevision + '&diff=next' )
.text( nextRevisionText ),
prevLink = $( '<a>' )
.attr( 'href', mw.util.wikiScript( 'index' ) + '?oldid=' + newRevision + '&diff=prev' )
.text( prevRevisionText ),
separator = $( '<span>' )
.text( ' | ' );
if ( $( '#differences-prevlink' ).length ) {
// Only add a separator if we already have a visible link
$( '#mw-diff-otitle4' )
.append(
separator.clone(),
nextLink
);
} else {
$( '#mw-diff-otitle4' )
.append(
nextLink
);
}
if ( $( '#differences-nextlink' ).length ) {
// Only add a separator if we already have a visible link
$( '#mw-diff-ntitle4' )
.find( '#differences-nextlink' )
.before(
prevLink,
separator.clone()
);
} else {
$( '#mw-diff-ntitle4' )
.append(
prevLink
);
}
}
}
$( document ).ready( show );