MediaWiki:Rcpatrol.js

// //todo: warn users, check with current rev, only show rb if it's top, color diffs $(function { $('#rcp_settings').empty.append('      '); var $select = $(''); $select.append(' All (main) '); for(var i = 1; i < 200; i++) {    var ns = wgFormattedNamespaces[i];    if(ns != null){        $select.append('' + ns + ' ');    } } $('#namespace_s').append($select); $('#limit_s').empty.append(' Number of edits to fetch: '); $('#anon_s').empty.append(' Only show anonymous users: '); $('#minor_s').empty.append(' Only show non-minor edits: '); $('#since_s').empty.append(' Show edits since: '); $('#submit_s').empty.append('Submit '); $('#go').click(function { go; }); function undo(edit_token, base_stamp, start_stamp, page, revid, user) { $.ajax({		url: wgServer + '/api.php',		dataType: 'json',		type: 'POST',		data: {			'action': 'edit',			'title': page,			'undo': revid,			'summary': 'Undid revision ' + revid + ' by ' + user + ' (talk) using RC Patrol',			'basetimestamp': base_stamp,			'startimestamp': start_stamp,			'token': edit_token		},		success: function(response) {		}	}); } function go { var dropdown = $('#namespace').val || []; var ns = dropdown.join('|'); var limit = $('#limit').val.trim; var show = ""; if ($('#anon').attr('checked')) show = "|anon"; else if ($('#minor').attr('checked')) show = "|!minor"; var since = $('#rcsince').val.trim; var revIds = []; var pages = []; var users = [] var diffs = []; var comments = []; var tokens = []; var timestamps = []; function parse_diffs { for(var i = 0; i < revIds.length; i++) { diffs.push(""); users.push(""); comments.push(""); tokens.push(""); timestamps.push(""); }	for(var j = 0; j < revIds.length; j++) { $.ajax({			url: wgServer + '/api.php',			dataType: 'json',			data: {				'format': 'json',				'action': 'query',				'revids': revIds[j],				'prop': 'revisions',				'rvprop': 'timestamp|parsedcomment|user|ids',				'rvdiffto': 'prev',				'rvtoken': 'rollback',				'indexpageids': 'true'			},			success: function(response) {				var id = response.query.pages[response.query.pageids[0]].revisions[0].revid;				var k = 0;				while(revIds[k] != id) {					k++;				}				diffs[k] = response.query.pages[response.query.pageids[0]].revisions[0].diff['*'];				users[k] = response.query.pages[response.query.pageids[0]].revisions[0].user;				comments[k] = response.query.pages[response.query.pageids[0]].revisions[0].parsedcomment;				tokens[k] = response.query.pages[response.query.pageids[0]].revisions[0].rollbacktoken;				timestamps[k] = response.query.pages[response.query.pageids[0]].revisions[0].timestamp; if(k == 0) show_diff(0); }		});	} } function show_diff(i) {	$('#rcp_diff').empty.append('     ');	$('#article').empty.append(' ' + pages[i] + ' ');	var t = timestamps[i];	timestamps[i] = t.substring(11,19) + ' ' + t.substring(5,10) + '-' + t.substring(0,4);	$('#revision').empty.append('Revision on ' + timestamps[i] + ' by user: ' + users[i] + ' ');	$('#comment').empty.append('Comment: ');	if(comments[i] != "undefined")		$('#comment').append(comments[i]);	$('#comment').append(' ');	$('#rollback').empty.append('rollback</a> &bull; undo</a> ');	$('#rollback-link').click(function { $.ajax({			url: wgServer + '/api.php',			dataType: 'json',			type: 'POST',			data: {				'format': 'json',				'action': 'rollback',				'title': pages[i],				'user': users[i],				'token': tokens[i],				'summary': 'Reverted edits by ' + users[i] + ' (talk) using RC Patrol'			},			success: function(response) {				$('#rollback-link').empty.append(' Reverted ');			}		}); });	$('#undo-link').click(function { var edit_token, base_stamp, start_stamp; $.ajax({			url: wgServer + '/api.php',			dataType: 'json',			data: {				'format': 'json',				'action': 'query',				'prop': 'info|revisions',				'intoken': 'edit',				'titles': pages[i],				'indexpageids': true			},			success: function(response) {				edit_token = response.query.pages[response.query.pageids[0]].edittoken;				base_stamp = response.query.pages[response.query.pageids[0]].revisions[0].timestamp;				start_stamp = response.query.pages[response.query.pageids[0]].starttimestamp;				undo(edit_token, base_stamp, start_stamp, pages[i], revIds[i], users[i]);				$('#undo-link').empty.append(' undone ');			}		}); });	$('#diff').empty.append(diffs[i]);	$('#nav').empty.append('<button type="button" id="prev_b">Prev <button type="button" id="next_b">Next ');	if(i > 0)		$('#prev_b').click(function { show_diff(i-1); });	else		$('#prev_b').attr('disabled', );	if(i < revIds.length - 1)		$('#next_b').click(function { show_diff(i+1); });	else		$('#next_b').attr('disabled', );	$(document).keydown(function(e){ if (e.keyCode == 37 && i > 0) { show_diff(i-1); return false; }		else if (e.keyCode == 39 && i < revIds.length - 1) { show_diff(i+1); return false; }	}); } $.ajax({ url: wgServer + '/api.php', dataType: 'json', data: { 'format': 'json', 'action': 'query', 'list': 'recentchanges', 'rctype': 'edit|new', 'rcshow': '!bot' + show, 'rclimit': limit, 'rcprop': 'user|title|timestamp|ids', 'rcnamespace': ns, 'rcsince': since },	success: function(response) { response.query.recentchanges.reverse; for (var i in response.query.recentchanges) { var rc = response.query.recentchanges[i]; revIds.push(rc.revid); pages.push(rc.title); }		parse_diffs; } }); } }); //