MediaWiki:Cvu.js

$(function {	function showSuccess {		alert('Thank you for your submission! The page will now be reloaded.');		document.location.replace(wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=purge');	}	function showError(msg) {		alert(msg);		$('#cvuSubmit').removeAttr('disabled').val('Submit');	}	function callAPI(data, method, callback) {		data['format'] = 'json';		$.ajax({ data: data, dataType: 'json', url: wgScriptPath + '/api.php', type: method, success: function(response) { if (response.error) { showError('API error: ' + response.error.info); } else { callback(response); }			},			error: function(xhr, error) { showError('AJAX error: ' + error); }, timeout: 10000 // msec });	}	function cvuSubmit {		var editor = $.trim($('#cvuEditor').val);		var page = $.trim($('#cvuPage').val);		$('#cvuSubmit').attr('disabled', 'disabled').val('Loading...');		if(editor == '')               {		        showError('Please enter a user name.');                        return;                }		callAPI({ 'action': 'query', 'prop': 'info|revisions', 'intoken': 'edit', 'titles': wgPageName, 'rvprop': 'content', 'rvlimit': '1' }, 'GET', function(response) { var pages = response.query.pages; var page = null; for (var i in pages) { page = pages[i]; }			var content0 = page.revisions[0]['*']; var template = '\{\{cvuid\|insert vandal\}\}';

if (content0.match(template) == null) { showError('An error occurred.'); }

content0 = content0.replace(template, '{' + '{cvuid|' + editor + (page==?:'|'+page) + '}' + '}'); callAPI({				'minor': 'yes',				'summary': 'Reported vandal.',				'action': 'edit',				'title': wgPageName,				'basetimestamp': page.revisions[0].timestamp,				'startimestamp': page.starttimestamp,				'token': page.edittoken,				'text': content0			}, 'POST', function(response) {				if (response.edit.result == 'Success') {					showSuccess;				} else {					showError('An error occurred while submitting the edit.');				}			}); });		return false;	}

if(wgPageName=='User:Suppa_chuppa/Sandbox_4') { var $div = $('#cvu_guide'); var $form = $(' ');

var ppLink = 'Due to vandalism, this page has been protected from editing.'; if ($.inArray('sysop', wgRestrictionEdit) > -1 && $.inArray('sysop', wgUserGroups) == -1) { $form.append(ppLink + ' Please contact an administrator to update the price.'); } else if ($.inArray('autoconfirmed', wgRestrictionEdit) > -1 && $.inArray('autoconfirmed', wgUserGroups) == -1) { $form.append(ppLink + ' Please log in to update the price.'); } else { $form.submit(cvuSubmit); $form.append($(' ').text('Report a vandal:')); var $p1 = $('').append('Please report a vandal by inserting the username or IP address and the page they are vandalizing.'); $form.append($p1); var $p2 = $(''); $p2.append($(' ').attr({'for': 'cvuEditor'}).text('Username:')); $p2.append($(' ').attr({'id': 'cvuEditor', 'type': 'text', 'size': 9})); $p2.append($(' ').attr({'for': 'cvuPage'}).text('Page:')); $p2.append($(' ').attr({'id': 'cvuPage', 'type': 'text', 'size': 9})); $p2.append($(' ').css({'margin': '0 1em 0 1em'}).attr({'id': 'cvuSubmit', 'type': 'submit'}).val('Submit')); $form.append($p2); }		if ($div != null) { $div.empty.append($form); }	} });