MediaWiki:Gadget-diffTools.js e Ajuda:Página de testes: diferenças entre as páginas
m Ajuste |
Versão atualizada de Wikipédia:Software/Scripts/Reversão e avisos.js |
||
Linha 1: | Linha 1: | ||
/** |
|||
/** Reversão e avisos *********************************************************************** |
|||
* Ferramentas para diffs (Reversão e avisos) |
|||
* |
|||
* Ajuda: [[Wikipedia:Software/Scripts/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]] |
|||
* Autor: [[:en:User:Lorian]] <noinclude>[[Categoria:!Código-fonte de scripts|Reversão e avisos]] [[en:Wikipedia:WikiProject User scripts/Scripts/Revert tools]]</noinclude> |
|||
* @see: [[Wikipedia:Software/Scripts/Reversão e avisos]] |
|||
********************************************************************************************/ |
|||
* @author: [[:en:User:Lorian]] |
|||
function getElementsByClass(searchClass,node,tag) { |
|||
*/ |
|||
var classElements = new Array(); |
|||
if ( node == null ) |
|||
window.diffTools = new(function () { |
|||
node = document; |
|||
if ( tag == null ) |
|||
/* Private Members */ |
|||
tag = '*'; |
|||
var that = this, |
|||
var els = node.getElementsByTagName(tag); |
|||
defaultSep = ' . ', |
|||
var elsLen = els.length; |
|||
message = mw.util.getParamValue('message'), |
|||
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); |
|||
diff = mw.util.getParamValue('diff'), |
|||
for (i = 0, j = 0; i < elsLen; i++) { |
|||
user1 = $('#mw-diff-otitle2 a').first().html() || mw.util.getParamValue('user1'), |
|||
if ( pattern.test(els[i].className) ) { |
|||
user2 = $('#mw-diff-ntitle2 a').first().html() || mw.util.getParamValue('user2'), |
|||
classElements[j] = els[i]; |
|||
urlPrefix = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=', |
|||
j++; |
|||
revUrl = urlPrefix + '&action=edit&oldid=' + mw.util.getParamValue('oldid'); |
|||
} |
|||
var options = [{ |
|||
} |
|||
'desc': 'Reverter', |
|||
return classElements; |
|||
'sep': ' / ', |
|||
} |
|||
'sum': 'Revertidas edições para a última versão por [[User:$1|$1]] usando [[WP:RA|Reversão e avisos]]', |
|||
var _GET = new Array(); |
|||
'url': revUrl + '&user1=' + encodeURIComponent(user1) + '&user2=' + encodeURIComponent(user2) + '&difftool=0' |
|||
var _uri = location.href; |
|||
}, { |
|||
var _temp_get_arr = _uri.substring(_uri.indexOf('?')+1, _uri.length).split("&"); |
|||
'desc': '+comentário', |
|||
var _temp_get_arr_1 = new Array(); |
|||
'sep': ') (Usuário: ', |
|||
for(_get_arr_i=0; _get_arr_i<_temp_get_arr.length; _get_arr_i++){ |
|||
'sum': 'Revertidas edições de [[User:$2|$2]] para a última versão por [[User:$1|$1]] usando [[WP:RA|Reversão e avisos]] ($3)', |
|||
_temp_get_arr_1 = _temp_get_arr[_get_arr_i].split("="); |
|||
'url': function () { |
|||
_GET[decodeURI(_temp_get_arr_1[0])] = decodeURI(_temp_get_arr_1[1]); |
|||
window.location = revUrl + '&user1=' + encodeURIComponent(user1) + '&user2=' + encodeURIComponent(user2) + '&difftool=1&message=' + encodeURIComponent(that.getSummary()); |
|||
} |
|||
} |
|||
delete _uri; delete _temp_get_arr; delete _temp_get_arr_1; |
|||
}, { |
|||
function getMessage (where, user1, user2) { |
|||
'desc': 'bv', |
|||
var message = prompt ('Comentário a acrescentar ao sumário da reversão:', ''); |
|||
'subst': 'Bem-vindo', |
|||
window.location = 'http://pt.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&'+where+'=2&user1='+user1+'&user2='+user2+'&message='+message; |
|||
'sum': 'Mensagem de boas-vindas a novo usuário' |
|||
} |
|||
}, { |
|||
addOnloadHook(function (){ |
|||
'desc': 'bv-ip', |
|||
if (location.href.match(/diff=/)) { |
|||
'sep': ' / ', |
|||
var user1 = getElementsByClass('diff-otitle',null,'td'); user1 = user1[0].getElementsByTagName('a')[2].innerHTML; |
|||
'subst': 'Bem-vindo IP', |
|||
var user2 = getElementsByClass('diff-ntitle',null,'td'); user2 = user2[0].getElementsByTagName('a')[3].innerHTML; |
|||
'sum': 'Mensagem de boas-vindas a usuário anônimo' |
|||
document.getElementById('contentSub').innerHTML = '(<a href="http://pt.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&revert=1&user1='+user1+'&user2='+user2+'">Reverter</a> / <a href="javascript:var message = getMessage(\'revert\', \''+user1+'\', \''+user2+'\');">+comentário</a>) (Usuário: <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=1">bv</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=2">bv-ip</a> / <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=3">av</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=4">bv-av-reg</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=5">bv-av</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=6">av-t1</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=7">av-t2</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=8">av-t3</a> / <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=9">propaganda</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=10">mudança de grafia</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=11">assinatura em artigo</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=12">cópia</a> . <a href="http://pt.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=13">data</a>)'; |
|||
}, { |
|||
} else if (location.href.match(/revert=1/)) { |
|||
'desc': 'av', |
|||
document.getElementById('wpSummary').value = 'Revertidas edições para a última versão por [[User:'+_GET['user1']+'|'+_GET['user1']+']] usando [[WP:RA|Reversão e avisos]]'; |
|||
'subst': 'Aviso' |
|||
document.getElementById('editform').submit(); |
|||
}, { |
|||
} else if (location.href.match(/revert=2/)) { |
|||
'desc': 'bv-av-reg', |
|||
document.getElementById('wpSummary').value = 'Revertidas edições de [[User:'+_GET['user2']+'|'+_GET['user2']+']] para a última versão por [[User:'+_GET['user1']+'|'+_GET['user1']+']] usando [[WP:RA|Reversão e avisos]] ('+_GET['message']+')'; |
|||
'subst': 'Bv-av-registrado', |
|||
document.getElementById('editform').submit(); |
|||
'sum': 'Mensagem de boas-vindas e aviso a usuário registrado' |
|||
} else if (location.href.match(/warn=1/)) { |
|||
}, { |
|||
document.getElementById('wpSummary').value = 'Mensagem de boas-vindas a novo usuário'; |
|||
'desc': 'bv-av', |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Bem-vindo}} ~~'+'~~'; |
|||
'subst': 'Bv-av', |
|||
document.getElementById('editform').submit(); |
|||
'sum': 'Mensagem de boas-vindas e aviso a iniciante' |
|||
} else if (location.href.match(/warn=2/)) { |
|||
}, { |
|||
document.getElementById('wpSummary').value = 'Mensagem de boas-vindas a usuário anônimo'; |
|||
'desc': 'av-t1', |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Bem-vindo IP}} ~~'+'~~'; |
|||
'subst': 'Av-teste|1', |
|||
document.getElementById('editform').submit(); |
|||
'sum': 'Aviso 1' |
|||
} else if (location.href.match(/warn=3/)) { |
|||
}, { |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Aviso}} ~~'+'~~'; |
|||
'desc': 'av-t2', |
|||
document.getElementById('editform').submit(); |
|||
'subst': 'Av-teste|2', |
|||
} else if (location.href.match(/warn=4/)) { |
|||
'sum': 'Aviso 2' |
|||
document.getElementById('wpSummary').value = 'Mensagem de boas-vindas e aviso a usuário registrado'; |
|||
}, { |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Bv-av-registrado}} ~~'+'~~'; |
|||
'desc': 'av-t3', |
|||
document.getElementById('editform').submit(); |
|||
'sep': ' / ', |
|||
} else if (location.href.match(/warn=5/)) { |
|||
'subst': 'Av-teste|3', |
|||
document.getElementById('wpSummary').value = 'Mensagem de boas-vindas e aviso a iniciante'; |
|||
'sum': 'Aviso 3' |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Bv-av}} ~~'+'~~'; |
|||
}, { |
|||
document.getElementById('editform').submit(); |
|||
'desc': 'propaganda', |
|||
} else if (location.href.match(/warn=6/)) { |
|||
'subst': 'Propaganda', |
|||
document.getElementById('wpSummary').value = 'Aviso 1'; |
|||
'sum': 'Aviso sobre propaganda' |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Av-teste'+'|1'+'}}~~'+'~~'; |
|||
}, { |
|||
document.getElementById('editform').submit(); |
|||
'desc': 'mudança de grafia', |
|||
} else if (location.href.match(/warn=7/)) { |
|||
'subst': 'Ortografia', |
|||
document.getElementById('wpSummary').value = 'Aviso 2'; |
|||
'sum': 'Aviso sobre ortografia' |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Av-teste'+'|2'+'}}~~'+'~~'; |
|||
}, { |
|||
document.getElementById('editform').submit(); |
|||
'desc': 'assinatura em artigo', |
|||
} else if (location.href.match(/warn=8/)) { |
|||
'subst': 'Aviso-assinatura', |
|||
document.getElementById('wpSummary').value = 'Aviso 3'; |
|||
'sum': 'Aviso sobre assinatura em artigo' |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Av-teste'+'|3'+'}}~~'+'~~'; |
|||
}, { |
|||
document.getElementById('editform').submit(); |
|||
'desc': 'cópia', |
|||
} else if (location.href.match(/warn=9/)) { |
|||
'subst': 'Não copie', |
|||
document.getElementById('wpSummary').value = 'Aviso sobre propaganda'; |
|||
'sum': 'Aviso sobre direitos de autor' |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Propaganda}}~~'+'~~'; |
|||
}, { |
|||
document.getElementById('editform').submit(); |
|||
'desc': 'data', |
|||
} else if (location.href.match(/warn=10/)) { |
|||
'sep': ')', |
|||
document.getElementById('wpSummary').value = 'Aviso sobre ortografia'; |
|||
'subst': 'Av-data', |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Ortografia}} ~~'+'~~'; |
|||
'sum': 'Aviso sobre datas' |
|||
document.getElementById('editform').submit(); |
|||
}]; |
|||
} else if (location.href.match(/warn=11/)) { |
|||
document.getElementById('wpSummary').value = 'Aviso sobre assinatura em artigo'; |
|||
/* Public Methods */ |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Aviso-assinatura}} ~~'+'~~'; |
|||
document.getElementById('editform').submit(); |
|||
/** |
|||
} else if (location.href.match(/warn=12/)) { |
|||
* Returns the summary text provided by user |
|||
document.getElementById('wpSummary').value = 'Aviso sobre direitos de autor'; |
|||
* |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Não copie}} ~~'+'~~'; |
|||
* @return {String} Summary text |
|||
document.getElementById('editform').submit(); |
|||
*/ |
|||
} else if (location.href.match(/warn=13/)) { |
|||
this.getSummary = function () { |
|||
document.getElementById('wpSummary').value = 'Aviso sobre datas'; |
|||
return prompt('Comentário a acrescentar ao sumário da reversão:', ''); |
|||
document.getElementById('wpTextbox1').value = '{{sub'+'st:Av-data}} ~~'+'~~'; |
|||
}; |
|||
document.getElementById('editform').submit(); |
|||
} |
|||
/** |
|||
* Inserts additional tools on diff pages |
|||
*/ |
|||
this.addOptions = function () { |
|||
var html = '<span id="diff-tools">('; |
|||
for (var i = 0; i < options.length; i++) { |
|||
html += '<a id="diff-tools-link-' + i; |
|||
if (typeof options[i].url === 'function') { |
|||
html += '" class="diff-tools-f-link" href="#'; |
|||
} else if (typeof options[i].url === 'string') { |
|||
html += '" href="' + options[i].url; |
|||
} else { |
|||
html += '" href="' + urlPrefix + 'User_talk:' + encodeURIComponent(user2) + '&action=edit§ion=new&difftool=' + i; |
|||
} |
|||
html += '">' + options[i].desc + '</a>'; |
|||
html += options[i].sep || defaultSep; |
|||
} |
|||
html += '</span><br>'; |
|||
$('#contentSub').prepend(html); |
|||
$('#diff-tools a.diff-tools-f-link').click(function (e) { |
|||
e.preventDefault(); // avoid jumping to the top (href=#) |
|||
var opt = parseInt($(this).attr('id').replace('diff-tools-link-', ''), 10); |
|||
options[opt].url(); |
|||
}); |
|||
}; |
|||
/** |
|||
* Adds warnings to user pages |
|||
* @param {number} tool The number of tool (it's position in options array) |
|||
*/ |
|||
this.editUsingTool = function (tool) { |
|||
if (!(0 <= tool && tool < options.length)) { |
|||
return; |
|||
} |
|||
var sum = options[tool].sum; |
|||
if (sum) { |
|||
sum = sum.replace(/\$1/g, user1).replace(/\$2/g, user2).replace(/\$3/g, message); |
|||
$('#wpSummary').val(sum); |
|||
} |
|||
if (options[tool].subst) { |
|||
$('#wpTextbox1').text('{{sub' + 'st:' + options[tool].subst + '}} ~~' + '~~'); |
|||
} |
|||
$('#editform').submit(); |
|||
}; |
|||
/** |
|||
* Prepare and execute the tools |
|||
*/ |
|||
this.run = function () { |
|||
var num = parseInt(mw.util.getParamValue('difftool'), 10); |
|||
if (mw.config.get('wgCanonicalSpecialPageName')) { |
|||
return; |
|||
} |
|||
if (diff) { |
|||
that.addOptions(); |
|||
} else { |
|||
that.editUsingTool(num); |
|||
} |
|||
}; |
|||
// Executes the script when page is ready |
|||
$(this.run); |
|||
})(); |
|||
// [[Categoria:!Código-fonte de scripts|Reversão e avisos]] |
|||
// [[en:Wikipedia:WikiProject User scripts/Scripts/Revert tools]] |
Revisão das 18h16min de 26 de fevereiro de 2011
/**
* 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: Wikipedia:Software/Scripts/Reversão e avisos * @author: en:User:Lorian */
window.diffTools = new(function () {
/* Private Members */ var that = this, defaultSep = ' . ', message = mw.util.getParamValue('message'), diff = mw.util.getParamValue('diff'), user1 = $('#mw-diff-otitle2 a').first().html() || mw.util.getParamValue('user1'), user2 = $('#mw-diff-ntitle2 a').first().html() || mw.util.getParamValue('user2'), urlPrefix = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=', revUrl = urlPrefix + '&action=edit&oldid=' + mw.util.getParamValue('oldid'); var options = [{ 'desc': 'Reverter', 'sep': ' / ', 'sum': 'Revertidas edições para a última versão por $1 usando Reversão e avisos', 'url': revUrl + '&user1=' + encodeURIComponent(user1) + '&user2=' + encodeURIComponent(user2) + '&difftool=0' }, { 'desc': '+comentário', 'sep': ') (Usuário: ', 'sum': 'Revertidas edições de $2 para a última versão por $1 usando Reversão e avisos ($3)', 'url': function () { window.location = revUrl + '&user1=' + encodeURIComponent(user1) + '&user2=' + encodeURIComponent(user2) + '&difftool=1&message=' + encodeURIComponent(that.getSummary()); } }, { 'desc': 'bv', 'subst': 'Bem-vindo', 'sum': 'Mensagem de boas-vindas a novo usuário' }, { 'desc': 'bv-ip', 'sep': ' / ', 'subst': 'Bem-vindo IP', 'sum': 'Mensagem de boas-vindas a usuário anônimo' }, { 'desc': 'av', 'subst': 'Aviso' }, { 'desc': 'bv-av-reg', 'subst': 'Bv-av-registrado', 'sum': 'Mensagem de boas-vindas e aviso a usuário registrado' }, { 'desc': 'bv-av', 'subst': 'Bv-av', 'sum': 'Mensagem de boas-vindas e aviso a iniciante' }, { 'desc': 'av-t1', 'subst': 'Av-teste|1', 'sum': 'Aviso 1' }, { 'desc': 'av-t2', 'subst': 'Av-teste|2', 'sum': 'Aviso 2' }, { 'desc': 'av-t3', 'sep': ' / ', 'subst': 'Av-teste|3', 'sum': 'Aviso 3' }, { 'desc': 'propaganda', 'subst': 'Propaganda', 'sum': 'Aviso sobre propaganda' }, { 'desc': 'mudança de grafia', 'subst': 'Ortografia', 'sum': 'Aviso sobre ortografia' }, { 'desc': 'assinatura em artigo', 'subst': 'Aviso-assinatura', 'sum': 'Aviso sobre assinatura em artigo' }, { 'desc': 'cópia', 'subst': 'Não copie', 'sum': 'Aviso sobre direitos de autor' }, { 'desc': 'data', 'sep': ')', 'subst': 'Av-data', 'sum': 'Aviso sobre datas' }];
/* Public Methods */
/** * Returns the summary text provided by user * * @return {String} Summary text */ this.getSummary = function () { return prompt('Comentário a acrescentar ao sumário da reversão:', ); };
/**
* Inserts additional tools on diff pages
*/
this.addOptions = function () {
var html = '(';
for (var i = 0; i < options.length; i++) {
html += '<a id="diff-tools-link-' + i;
if (typeof options[i].url === 'function') {
html += '" class="diff-tools-f-link" href="#';
} else if (typeof options[i].url === 'string') {
html += '" href="' + options[i].url;
} else {
html += '" href="' + urlPrefix + 'User_talk:' + encodeURIComponent(user2) + '&action=edit§ion=new&difftool=' + i;
}
html += '">' + options[i].desc + '</a>';
html += options[i].sep || defaultSep;
}
html += '
';
$('#contentSub').prepend(html);
$('#diff-tools a.diff-tools-f-link').click(function (e) {
e.preventDefault(); // avoid jumping to the top (href=#)
var opt = parseInt($(this).attr('id').replace('diff-tools-link-', ), 10);
options[opt].url();
});
};
/** * Adds warnings to user pages * @param {number} tool The number of tool (it's position in options array) */ this.editUsingTool = function (tool) { if (!(0 <= tool && tool < options.length)) { return; } var sum = options[tool].sum; if (sum) { sum = sum.replace(/\$1/g, user1).replace(/\$2/g, user2).replace(/\$3/g, message); $('#wpSummary').val(sum); } if (options[tool].subst) { $('#wpTextbox1').text('{{sub' + 'st:' + options[tool].subst + '}} ~~' + '~~'); } $('#editform').submit(); };
/** * Prepare and execute the tools */ this.run = function () { var num = parseInt(mw.util.getParamValue('difftool'), 10); if (mw.config.get('wgCanonicalSpecialPageName')) { return; } if (diff) { that.addOptions(); } else { that.editUsingTool(num); } };
// Executes the script when page is ready $(this.run); })();
// //