Jump to content

User:Ale jrb/Scripts/csdcheck.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ale jrb (talk | contribs) at 15:53, 20 May 2009 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* ============================================== *\
** CSD Helper JavaScript
**   for Wikipedia
**
** Created by Alexander Barley [[User:Ale_jrb]]
**
\* ============================================== */

// the following settings are used in this script:
	

function csdHelper() {
	this.launch = function() {
		// launch helper. check whether there is a deletion tag on this page.
		if (document.getElementById('delete-criterion') != null) {
			// this page is tagged. check sysop.
			var iAmSysop = false;
			for (var i = 0; i < wgUserGroups.length; i ++) {
				if (wgUserGroups[i] == 'sysop') iAmSysop = true;
			}
			if ((iAmSysop == false) || (wgNamespaceNumber == 10)) { return false; // do nothing!
			} else {
				// all checks OK :).
				// launch controller.
				this.control	= new csdH_controller;
				this.control.attachLinks();
				return true;
			}
		} else { return false;  /* do nothing!*/}
		//this.control	= new csdH_controller;
		//		this.control.attachLinks();
		//		return true;
	}
}

function csdH_controller() {
	csdHController 		= this;
	var waApi			= wgScriptPath + '/api.php';
	
	this.declineReasons = new Array(
										['G1', 		'the page is not nonsense - there is meaningful content.'],
										['G2', 		'the page is not a test page.'],
										['G3', 		'the page is not blatantly vandalism or a hoax.'],
										['G4', 		'the page has not previously been deleted via a deletion discussion.'],
										['G5', 		'the page was not created by a banned user, or the page does not violate the user\'s ban.'],
										['G6', 		'the deletion of this page may be controvertial or is under discussion.'],
										['G7', 		'the author has not requested deletion, or other users have added substantial content.'],
										['G8', 		'this page does not rely on one that does not exist.'],
										['G9', 		'this criterion can only be used at the request of, or by, the Wikimedia Foundation.'],
										['G10', 	'the page is not blatantly an attack on a living person.'],
										['G11', 	'the page is not unambiguously promotional.'],
										['G12', 	'the page is not an unambiguous copyright infringement, or there is other content to save.'],
										
										['A1', 		'there is sufficient context to identify the subject of the article.'],
										['A2', 		'the article is in English, or does not exist at a foreign project.'],
										['A3', 		'the article contains sufficient content to be a stub.'],
										['A5', 		'the article has not been transwikied to another project.'],
										['A7', 		'the article makes an assertion of notability, sufficient to pass A7.'],
										['A9', 		'the article makes an assertion of notability, or is not a musical recording.'],
										
										['R2', 		'this page does not redirect to a different or incorrect namespace.'],
										['R3', 		'the page is a plausible, useful redirect or is not a redirect at all.'],
										
										['U1', 		'this criterion does not apply to user talk pages, or this is not a user page.'],
										['U2', 		'the user does exist, or this is not a user page.'],
										
										['NA', 		'the reason given is not a valid CSD criterion.'],
										['', 		'no reason given']
									);
	
	this.showcsdHWindow = function() {
		// grab position of button
		var offset = document.getElementById('ca-speedy').offsetLeft;
		
		// build window to show user
		if (this.interface == null) { 
			this.interface = new wa_window(document.getElementById('content')); this.visible = true; this.csdHelperLink.ele_obj.setAttribute('class', 'selected'); 
			this.interface.win_content = ''+
								'<div><div style="width: 596px; border-bottom: 1px solid #aaaaaa; padding: 2px; font-weight: bold;">Handle Speedy Deletion</div>'+
								'<div style="font-size: 11px; margin-left: 7px;">What do you want to do to this page?</div>'+
								'<div style="font-size: 11px; text-align: center; width: 100%;"><a href="#" onclick="csdHController.declinePage();">Decline Speedy</a> | <a href="#" onclick="csdHController.prodPage();">Change to PROD</a> | <a href="#" onclick="csdHController.deletePage();">Delete Page</a></div>'+
								'</div>'+
								'';
		} else {
			this.interface.win_content = ''+
								'<div><div style="width: 596px; border-bottom: 1px solid #aaaaaa; padding: 2px; font-weight: bold;">Handle Speedy Deletion</div>'+
								'<div style="font-size: 11px; margin-left: 7px;">What do you want to do to this page?</div>'+
								'<div style="font-size: 11px; text-align: center; width: 100%;"><a href="#" onclick="csdHController.declinePage();">Decline Speedy</a> | <a href="#" onclick="csdHController.prodPage();">Convert to PROD</a> | <a href="#" onclick="csdHController.deletePage();">Delete Page</a></div>'+
								'</div>'+
								'';
			
			if (this.visible == true) { 
				this.csdHelperLink.ele_obj.setAttribute('class', '');
				this.interface.win_disp = 'none'; 
				this.interface.applyAll(); 
				this.visible = false; 
				return true; 
			} else { 
				this.csdHelperLink.ele_obj.setAttribute('class', 'selected');
				this.interface.win_disp = 'block';
				this.interface.applyAll();
				this.visible = true; 
				return true;
			}
		}
		
		this.interface.win_left = offset - 17;
		this.interface.win_top = -1;
		this.interface.win_width = 600;
		this.interface.win_height = 100;
		this.interface.win_bg = '#fff';
		this.interface.win_bd = '#aaaaaa';
		this.interface.win_bd_wd = 1;
		this.interface.applyAll();
	}
	
	this.declinePage = function() {
		// build the selection options
		var declineOptions = '';
		for (var i = 0; i < this.declineReasons.length; i++) {
			var selected = '';
			if (document.getElementById('delete-criterion') != null) { 
				if (document.getElementById('delete-criterion').innerHTML == this.declineReasons[i][0]) selected = ' selected'; 
			}
			declineOptions += '<option value="'+i+'"'+selected+' >Criterion '+this.declineReasons[i][0]+' does not apply: '+this.declineReasons[i][1]+'</option>';
		}
		
		this.interface.win_content = ''+
								'<div><div style="width: 596px; border-bottom: 1px solid #aaaaaa; padding: 2px; font-weight: bold;">Decline Speedy Deletion</div>'+
								'<div style="font-size: 11px; margin-left: 7px;">Select the reason for declining the deletion from the list below. This text will be used as the edit summary.</div>'+
								'<select id="declineReason" style="font-size: 11px; margin-left: 9px;">'+declineOptions+'</select>'+
								'<div style="margin-top: 13px; float: right; margin-right: 300px; font-size: 11px; ">-- <a href="#" onclick="csdHController.declineDo();">decline speedy deletion</a> --</div>'+
								'<div style="margin-top: 10px; font-size: 11px; margin-left: 20px; vertical-align: middle;">notify tagger <input id="notifyTagger" style="position: relative; top: 3px; " type="checkbox" /></div>'+
								'</div>'+
								'';
		this.interface.applyAll();
	}
	this.declineDo = function(callback) {
		// get page content
		if (!callback) var callback = 0;
		switch (callback) {
			default:
				csdHController.pageReq = new wa_ajaxcall();
				csdHController.pageReq.requestUrl = waApi + '?action=query&prop=revisions&rvprop=content&format=xml&titles='+wgPageName+'';
				csdHController.pageReq.doRequest(function() { csdHController.declineDo('1'); });
				break;
				
			case '1':
				csdHController.pageContent = '';
				if (csdHController.pageReq.response.getElementsByTagName('rev')[0] == null) { csdHController.displayError(); return false; }
				for (var i = 0; i < csdHController.pageReq.response.getElementsByTagName('rev')[0].childNodes.length; i ++) {
					 csdHController.pageContent += csdHController.pageReq.response.getElementsByTagName('rev')[0].childNodes[i].nodeValue;
				}
				
				var regReplace = /[\s]*\{\{db(?:-?(?:.+?)?|\|(.+))\}\}[\s]*/gi;
				csdHController.pageContent = csdHController.pageContent.replace(regReplace, '');
				var regReplace = /[\s]*\{\{hangon\}\}[\s]*/gi;
				csdHController.pageContent = csdHController.pageContent.replace(regReplace, '');
				
				alert(csdHController.pageContent);
				break;
			
		}
		
	}
	
	this.prodPage = function() {
		csdHController.displayError();
	}
	
	this.deletePage = function() {
		csdHController.displayError();
	}
	
	this.displayError = function() {
		this.interface.win_content = ''+
								'<div><div style="width: 596px; border-bottom: 1px solid #aaaaaa; padding: 2px; font-weight: bold;">An error occured...</div>'+
								'</div>'+
								'';
		this.interface.applyAll();
	}
	
	this.attachLinks = function() {
		this.csdHelperLink 						= new wa_element('li');
		this.csdHelperLink.ele_obj.id			= 'ca-speedy';
		this.csdHelperLink.ele_obj.innerHTML	= '<a href="#" title="handle speedy deletion">speedy</a>';
		this.csdHelperLink.addScriptEvent('click', function() { csdHController.showcsdHWindow(); });
		
		this.csdHelperLink.attach(document.getElementById('ca-move'), 'before');
	};
}



// -- run program
function launchCsdHelper() {
	// lib proto
	wa_window.prototype = new wa_document;
	wa_element.prototype = new wa_document;
	
	// init object
	var obj_csdHelper = new csdHelper;
	obj_csdHelper.launch();
	
	return true;
}

importScript('User:Ale_jrb/Scripts/waLib.js');
hookEvent('load', launchCsdHelper);