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

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
action controllata dal ResourceLoader
 
(6 versioni intermedie di 2 utenti non mostrate)
Riga 1:
/**
* View the next/ previous edit of a revision in MediaWiki multi diffs.
* Uses the localization provided by MediaWiki, requires mediawiki.util to work.
* and mediawiki.api to work.
*
*
* This program is free software; you can redistribute it and/or modify
* 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
* theit Freeunder Softwarethe Foundation;terms eitherof versionthe 2GNU ofGeneral thePublic License, oras published by
* (atthe yourFree option)Software anyFoundation; latereither version. 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License along
* 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.,
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
* http://www.gnu.org/copyleft/gpl.html
*
*
* @author Marius Hoch < hoo@online.de >
* @author Marius Hoch < hoo@online.de >
*/
*/
( function( mw, $ ) {
'use strict';
var oldRevision, newRevision, nextRevisionText, prevRevisionText;
 
function show() {
/**
'use strict';
* Get an interface message
*
* @param {string} msg Message key (without MediaWiki:)
*
* @return {jQuery.promise}
*/
function getMessage( msg ) {
return $.ajax( {
url: mw.util.wikiScript( 'index' ),
data: {
title: 'MediaWiki:' + msg,
action: 'raw',
usemsgcache: true
},
dataType: 'text',
cache: true
} );
}
 
var oldRevision, newRevision, nextRevisionText, prevRevisionText;
if ( mw.config.get( 'wgAction' ) !== 'view' ) {
// Diffs have action=view
return;
}
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 ) {
* Load missing messages needed by this script
nextRevisionText = $( '#differences-nextlink' ).text();
*
getPrevRevisionText();
* @return {jQuery.promise}
} else {
*/
getMessage( 'nextdiff' )
.done( function functionloadMessages( textmsg ) {
return new mw.Api().loadMessagesIfMissing( [
nextRevisionText = text;
'previousdiff',
} )
'nextdiff'
.done( getPrevRevisionText );
] );
}
}
 
if ( !$( '.diff-multi' ).length ) {
/**
// No multi diff
* This function gets the interface text for the next revision and
return;
* calls doLink after
}
*/
oldRevision = mw.util.getParamValue(
function getPrevRevisionText() {
'oldid',
if ( $( '#differences-prevlink' ).length ) {
$( '#mw-diff-otitle1' ).find( 'a' ).eq(0).attr( 'href' )
prevRevisionText = $( '#differences-prevlink' ).text();
doLink( );
newRevision = mw.util.getParamValue(
} else {
'oldid',
getMessage( 'previousdiff' )
$( '#mw-diff-ntitle1' ).find( 'a' ).eq(0).attr( 'href' )
.done( function( text ) {
);
prevRevisionText = text;
if ( !newRevision || !oldRevision ) {
} )
// Weird
.done( doLink );
return;
}
}
 
if ( $( '#differences-nextlink' ).length ) {
/**
nextRevisionText = $( '#differences-nextlink' ).text();
* Insert the diff links after the interface messages have been loaded
getPrevRevisionText();
*/
} else {
function doLink() {
loadMessages()
var nextLink = $( '<a>' )
.done( function nextDiff () {
.attr( 'href', mw.util.wikiScript( 'index' ) + '?oldid=' + oldRevision + '&diff=next' )
nextRevisionText = mw.msg( 'nextdiff' );
.text( nextRevisionText ),
prevLink = $( '<a>' } )
.done( getPrevRevisionText );
.attr( 'href', mw.util.wikiScript( 'index' ) + '?oldid=' + newRevision + '&diff=prev' )
}
.text( prevRevisionText ),
separator = $( '<span>' )
.text( ' | ' );
 
/**
if ( $( '#differences-prevlink' ).length ) {
* This function gets the interface text for the next revision and
// Only add a separator if we already have a visible link
* calls doLink after
$( '#mw-diff-otitle4' )
*/
.append(
function getPrevRevisionText() {
separator.clone(),
if ( $( '#differences-prevlink' ).length ) {
nextLink
prevRevisionText = $( '#differences-prevlink' ).text();
);
doLink();
} else {
} else {
$( '#mw-diff-otitle4' )
loadMessages()
.append(
.done( function previousDiff () {
nextLink
prevRevisionText = mw.msg( 'previousdiff' );
);
} )
}
.done( doLink );
}
}
 
/**
if ( $( '#differences-nextlink' ).length ) {
* Insert the diff links after the interface messages have been loaded
// Only add a separator if we already have a visible link
*/
$( '#mw-diff-ntitle4' )
function doLink() {
.find( 'a' )
var nextLink = $( '<a>' )
.before(
.attr( 'href', mw.util.wikiScript( 'index' ) + '?oldid=' + oldRevision + '&diff=next' )
prevLink,
.text( nextRevisionText ),
separator.clone()
prevLink = $( '<a>' )
);
.attr( 'href', mw.util.wikiScript( 'index' ) + '?oldid=' + newRevision + '&diff=prev' )
} else {
.text( prevRevisionText ),
$( '#mw-diff-ntitle4' )
separator = $( '<span>' )
.append(
.text( ' | ' );
prevLink
 
);
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 );
} )( mediaWiki, jQuery );