Usuário(a):OTAVIO1981/testes.js
Aspeto
Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5.
/**
* Ferramentas para diffs (Reversão e avisos)
*
* Em páginas de comparação de 2 edições, inclui atalhos de reverter e avisar o usuário.
* @source: [[:en:Wikipedia:WikiProject_User_scripts/Scripts/Revert_tools]]
* @see: [[WP:Software/Scripts/Reversão e avisos]]
* @author: [[:en:User:Lorian]]
* @author: Helder (https://github.com/he7d3r)
* @license: CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0/>
*/
/*jslint browser: true, white: true, devel: true, todo: true */
/*global mediaWiki, jQuery */
( function( mw, $ ) {
'use strict';
var DiffTools = function() {
/* Private Members */
var options,
that = this,
// user1 = $('#mw-diff-otitle2').find('a').first().html(),
user2 = $( '#mw-diff-ntitle2' ).find( 'a' ).first().html() || $( '#mw-revision-name' ).find( '.mw-userlink' ).html(),
pageName = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ),
api = new mw.Api();
options = {
'revert': {
'description': false,
'Opções': {
'Reverter': {
'desc': 'Reverte o artigo para a versão mostrada' +
' à esquerda',
'sum': 'Reversão de uma ou mais' +
' edições de [[Special:Contribs/$2|$2]] para a' +
' versão $3 de [[User:$1|$1]],'
},
'+comentário': {
'desc': 'Reverte o artigo para a versão mostrada' +
' à esquerda, mas permite incluir informações' +
' extras no sumário de edição',
'url': function () {
var sum = 'Reversão de uma ou mais edições de [[Special:Contribs/$2|$2]]'
+ ' para a versão $3 de [[User:$1|$1]]',
oldid = mw.util.getParamValue(
'oldid',
$( '#mw-diff-otitle1' ).find( 'a' ).first().attr( 'href' )
),
text = prompt( 'Comentário a acrescentar ao sumário da reversão:', '' );
if ( text ) {
sum += ' (' + text + '),';
that.revert(
pageName,
oldid,
sum
);
}
}
}
}
},
'warn': {
'description': '<li>[{{fullurl:Especial:Registro de abusos|wpSearchTitle={{FULLPAGENAMEE}}}} <span title="Ver os registros do filtro de edições para esta página">Registros do filtro de edições</span>]</li>',
'Boas-vindas': {
'bv': {
'desc': 'Envia uma mensagem de boas-vindas ao novo usuário',
'subst': 'Bem-vindo',
'sum': 'Mensagem de boas-vindas a novo usuário'
},
'bv-ip': {
'desc': 'Envia uma mensagem de boas-vindas ao usuário anônimo',
'subst': 'Bem-vindo IP',
'sum': 'Mensagem de boas-vindas a usuário anônimo'
}
},
}
};
/* Public Methods */
/**
* Reverts an edit
*/
this.revert = function( page, oldid, summary ) {
mw.notify(
$.parseHTML(
'Consultando o histórico da página "<a href="'
+ mw.util.getUrl( page ) + '">' + page.replace( /_/g, ' ' ) + '</a>"...'
)
);
$.getJSON(
mw.util.wikiScript( 'api' ), {
'format': 'json',
'action': 'query',
'titles': page,
'prop': 'revisions',
'rvprop': 'user|content|ids',
'rvstartid': oldid,
'rvlimit': 1,
'indexpageids': true
}
).done( function( data ) {
var rev;
if ( data.error !== undefined ) {
mw.notify( 'Erro da API: ' + data.error.code + '. ' + data.error.info );
} else if ( data.query && data.query.pages && data.query.pageids ) {
rev = data.query.pages[ data.query.pageids[ 0 ] ];
if ( rev.missing === '' ) {
mw.notify(
$.parseHTML(
'A página "<a href="' + mw.util.getUrl( page ) + '">' + page + '</a> não existe!'
)
);
} else {
rev = rev.revisions[ 0 ];
that.editPage(
page,
rev[ '*' ],
summary.replace( /\$1/g, rev.user )
.replace( /\$2/g, user2 )
.replace( /\$3/g, rev.revid )
);
$( '.patrollink a' ).first().click();
}
} else {
mw.notify( 'Houve um erro inesperado ao usar a API do MediaWiki.' );
}
} ).fail( function() {
mw.notify( 'Houve um erro ao usar AJAX para consultar o conteúdo da página.' );
} );
};
/**
* Edits a page
*/
this.editPage = function( page, text, summary, section ) {
mw.notify(
'Preparando a edição da página "' + page.replace( /_/g, ' ' ) + '"...'
);
var data = {
format: 'json',
action: 'edit',
minor: true,
watchlist: 'nochange',
title: page,
text: text,
summary: summary + ' (com [[WP:RA|Reversão e avisos]]).',
token: mw.user.tokens.get( 'editToken' ),
done: {
success: function() {
mw.notify(
$.parseHTML(
'A página "' + page.replace( /_/g, ' ' ) + '" <a href="'
+ mw.util.getUrl( page ) + '?diff=0">foi editada</a> (<a href="'
+ mw.util.getUrl( page ) + '">abrir</a>).'
)
);
},
apiError: function() {
mw.notify( 'Houve um erro ao requisitar a edição da página.' );
}
}
};
if ( section === 'new' ) {
data.appendtext = '\n\n' + text;
data.text = '';
}
api.editPage( data ).fail( function() {
mw.notify( 'Houve um erro ao usar AJAX para editar a página.' );
} );
};
/**
* Sets the links (buttons)
*/
this.setLink = function( text, data, action ) {
var $link = $( '<a href="#" title="' + data.desc + '">' + text + '</a>' );
if ( typeof data.url === 'string' ) {
$link.attr( 'href', data.url );
} else {
$link.click( function( event ) {
event.preventDefault(); // avoid jumping to the top (href=#)
if ( $.isFunction( data.url ) ) {
data.url();
} else if ( action === 'revert') {
that.revert(
mw.config.get( 'wgPageName' ),
mw.util.getParamValue(
'oldid',
$( '#mw-diff-otitle1' ).find( 'a' ).first().attr( 'href' )
),
data.sum
);
} else if ( action === 'warn' ) {
// edit user talk
that.editPage(
mw.config.get( 'wgFormattedNamespaces' )[ 3 ] + ':' + user2,
'{' + '{subst:' + data.subst + '}} ~~' + '~~',
data.sum, // = section title
'new'
);
}
} );
}
return $link;
};
/**
* Inserts additional tools on diff pages
*/
this.addOptions = function() {
var $ulSections = $( '<ul></ul>' );
$.each( options, function( section, list ) {
var $liSection = $( '<li class="diff-tools-section"></li>' ),
$ulSubSections = $( '<ul></ul>' );
$.each( list, function( subsection, sublist ) {
var $ulItems = $( '<ul></ul>' ),
$liSubSection = $( '<li class="diff-tools-subsection"></li>' );
if ( subsection === 'description' ) {
$liSection.prepend( sublist || '' );
} else {
$.each( sublist, function( text, data ) {
$ulItems.append(
$( '<li></li>' ).append( that.setLink( text, data, section ) )
);
} );
$liSubSection.append( $ulItems );
$ulSubSections.append( $liSubSection );
}
} );
$liSection.append( $ulSubSections );
$ulSections.append( $liSection );
} );
$( '#contentSub' ).prepend(
$( '<span id="diff-tools"></span>' ).append( $ulSections )
);
};
};
if ( mw.config.get( 'wgNamespaceNumber' ) !== -1
&& ( mw.util.getParamValue( 'diff' ) || mw.util.getParamValue( 'oldid' ) )
) {
// Executes the script when page is ready
$( new DiffTools().addOptions );
}
}( mediaWiki, jQuery ) );
// [[Categoria:!Código-fonte de scripts|Reversão e avisos]]
// [[en:Wikipedia:WikiProject User scripts/Scripts/Revert tools]]