User:Auto~enwiki/csd.js

/* ============================================== *\ \* ============================================== */
 * CSD Helper - JavaScript CSD Script
 * for Wikipedia
 * Created by Alex Barley User:Ale_jrb
 * Tracker: User:Ale_jrb/Scripts
 * You are advised to import this script to your
 * monobook.js page - AVOID CREATING YOUR OWN
 * VERSION WHERE POSSIBLE.
 * Instructions for this script can be found at
 * User:Ale_jrb/Scripts - refer to this for
 * setting details.
 * Instructions for this script can be found at
 * User:Ale_jrb/Scripts - refer to this for
 * setting details.

// NB. this script relies on User:Ale_jrb/Scripts/waLib.js. // the following settings are used in this script: if (notifyByDefaultDec == null) 	var notifyByDefaultDec	= true;			// whether to check the 'notify tagger' box by default when declining a speedy deletion request if (notifyByDefaultDel == null) 	var notifyByDefaultDel	= false;		// whether to check the 'notify tagger' box by default when changing a speedy deletion rationale if (notifyByDefaultPrd == null) 	var notifyByDefaultPrd	= true;			// whether to check the 'notify tagger' box by default when converting a speedy deletion to PROD if (notifyLimit == null) 			var notifyLimit			= 12;			// how many revisions should be retrieved when determining who tagged the page //if (notificationTemplate == null)	var notificationTemplate = 'User:Ale_jrb/Scripts/csdnotify'; // the template to subst with the notification message (does {subst:templatename|notification type|page title|criterion|reason} )

if (redirectAfterDel == null) 		var redirectAfterDel	= 'http://en.wikipedia.org/w/index.php?title=Category:Candidates_for_speedy_deletion&action=purge#Pages_in_category'; // where to redirect after deletion if (myDeleteReasons == null)		var myDeleteReasons		= new Array; 	// any addition speedy deletion reasons to add to the list

if (overwriteDeclineReasons == null)var overwriteDeclineReasons	= false; 		// whether to overwrite the in-build decline reasons with the user defined ones if (myDeclineReasons == null)		var myDeclineReasons		= new Array; 	// any addition speedy deletion decline reasons to add to the list if (myDeclineListing == null)		var myDeclineListing		= '%CRITERION%: %REASON%' // the appearance of the option in the drop-down box if (myDeclineSummary == null)		var myDeclineSummary		= 'Speedy deletion %ACTION%. Criterion %CRITERION% does not apply: %REASON%';	// the summary to use when removing a deletion tag from a page because it has been declined or contested if (myDeclineSummarySpecial == null)var myDeclineSummarySpecial	= 'Speedy deletion %ACTION%. %REASON%';	// the summary to use when removing a deletion tag from a page IN A SEPCIAL CASE. NOTE: %CRITERION% will be blank! var csdHLogApi = null; function csdHLogDecline(phase) { if (declineLogPath == null) // redundant return; csdHLogApi = new wa_mediawikiApi; // TODO: fix tabs in a real editor document.getElementById('workingStatus').innerHTML += "- Logging action to " + declineLogPath + " "; var raison = (csdHController.declineCategory == 'OTHER') ? csdHController.declineText : csdHController.declineReason; var crit = document.getElementById('delete-criterion').innerHTML; var pageName = wgPageName.replace(/_/g," "); var message = "|-\n| " + pageName + " || " + csdHController.tagger + " || CSD " + crit + " || " +raison + " || " + "" + "" + "~\n";

csdHLogApi.onCompleteAction = function { // TODO: extract to separate function or use Alex' switch-based idiom var pageWiki = csdHLogApi.data['page']['revisions'][0]['content']; if(pageWiki == null || pageWiki.length == 0) // create new page with empty wikitable { // table may be unnecessarily elaborate pageWiki = "{| class=\"sortable wikitable\" style=\"font-size: 80%;\" border=\"2\" cellpadding=\"1\" background:#f9f9f9;\"|\n|-\n! style=\"text-align: left\" | Article\n! Tagger\n! Criterion\n! Decline reason\n! Date\n|}"; }

var newWiki = pageWiki.replace("|}", message + "|}"); csdHLogApi.onCompleteAction = function { if(!csdHController.declineNotify) {   window.location.reload(true); csdHController.showcsdHWindow; } }; // closure, callback after log adding csdHLogApi.editPage(declineLogPath, newWiki, "adding " + pageName + " (CSDH)", false, 'text'); }; // closure, callback after retrieving log wikicode csdHLogApi.getPage(declineLogPath, 1, 'user|content'); }

//main script function csdHelper { this.launch = function { // launch helper. check whether there is a deletion tag on this page. if ((document.getElementById('delete-criterion') != null) || (document.body.innerHTML.indexOf('speedy deletion of this page is contested.') > -1)) { if (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!*/ }	} }

function csdH_controller { csdHController 		= this; this.notifyExempt	= new Array('SDPatrolBot','Ale jrb 2'); // these editors are exempt from being notified (if they added the tag, notification will fail) csdHController.deleteRegex = /[\s]*\{\{(?:db|speedy ?delet(?:e|ion)|speedy|d|rm|del(?:ete)? ?(?:because)?|csd|nn)(?:-(?:.+?))?(?:\|(?:.+?))?\}\}[\s]*/gi; csdHController.hangonRegex = /[\s]*\{\{(?:hang|hold)(?: |-)?oo?n(?:\|.+?)?\}\}[\s]*/gi; csdHController.doNotifyDec = ; csdHController.doNotifyDel = ; csdHController.doNotifyPrd = ''; if (notifyByDefaultDec == true) csdHController.doNotifyDec = ' checked'; if (notifyByDefaultDel == true) csdHController.doNotifyDel = ' checked'; if (notifyByDefaultPrd == true) csdHController.doNotifyPrd = ' checked'; if (waUser.isSysop == true) { csdHController.decAction = 'declined'; } else { csdHController.decAction = 'contested'; } // default arrays - it's fine to edit these, but if you simply wish to add additional decline reasons, use the // setting for additional options described above. this.declineReasons = new Array(										['G1', 		'Not nonsense - there is meaningful content'],										['G2', 		'Not a test page'],										['G3', 		'Not blatantly vandalism or a hoax'],										['G4', 		'Not previously been deleted via a deletion discussion'],										['G5', 		'Not created by a banned user, or the page does not violate the user\'s ban'],										['G6', 		'Deletion of this page may be controvertial or is under discussion'],										['G7', 		'Author has not requested deletion, or other users have added substantial content'],										['G8', 		'Does not rely on a page that does not exist'],										['G9', 		'G9 can only be used at the request of, or by, the Wikimedia Foundation'],										['G10', 	'Not blatantly an attack page or negative BLP'],										['G11', 	'Not unambiguously promotional'],										['G12', 	'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', 		'Contains sufficient content to be a stub'], ['A5', 		'The article has not been transwikied to another project'], ['A7', 		'The article makes a credible assertion of importance or significance, sufficient to pass A7'], ['A7', 		'A7 does not apply to schools'], ['A7', 		'A7 does not apply to software'], ['A9', 		'The article makes a credible assertion of importance or significance, or is not a musical recording'], ['R2', 		'Does not redirect to a different or incorrect namespace'], ['R3', 		'Is a plausible, useful redirect or is not a redirect at all'], ['R3',		'Not a recently created redirect - consider WP:RfD'], ['U1', 		'Not a user page'], ['U1', 		'Does not apply to user talk pages'], ['U2', 		'User does exist, or this is not a user page'] );	this.deleteReasons = new Array( ['N/A', 	'You must select a rationale...'], ['G1', 		'Patent nonsense, meaningless, or incomprehensible'], ['G2', 		'Test page'], ['G3', 		'Vandalism'], ['G3', 		'Vandalism - blatant hoax or misinformation'], ['G4', 		'Recreation of a page that was deleted per a deletion discussion'], ['G5', 		'Creation by a banned user in violation of ban'], ['G6', 		'Housekeeping and routine (non-controversial) cleanup'], ['G7', 		'One author who has requested deletion or blanked the page'], ['G8', 		'Page dependent on a deleted or nonexistent page'], ['G8',		'Talk page of a deleted page'], ['G10', 	'Attack page or negative unsourced BLP that serves no purpose but to threaten or disparage its subject'], ['G11', 	'Unambiguous advertising or promotion'], ['G12', 	'Unambiguous copyright infringement'], ['A1', 		'Not enough context to identify article\'s subject'], ['A2', 		'Article in a foreign language that exists on another project'], ['A3', 		'Article that has no meaningful, substantive content'], ['A5', 		'Article that has been transwikied to another project'], ['A7', 		'No indication that the article may meet the guidelines for inclusion'], ['A7',		'Article about a real person, which does not indicate the importance or significance of the subject'], ['A7',		'Article about a band, singer, musician, or musical ensemble that does not indicate the importance or significance of the subject'], ['A7',		'Article about a web site, blog, web forum, webcomic, podcast, browser game, or similar web content, which does not indicate the importance or significance of the subject'], ['A7',		'Article about a company or other organization, which does not indicate the importance or significance of the subject'], ['A7',		'Article about a group or club, which does not indicate the importance or significance of the subject'], ['A9', 		'Non-notable music by artist with no Wikipedia article'], ['R2', 		'Cross-namespace redirect from mainspace'], ['R3', 		'Recently-created, implausible redirect'], ['U1', 		'User request to delete pages in own userspace'], ['U2', 		'Userpage or subpage of a nonexistent user'], ['U3', 		'Non-free gallery'] );	// Handle user defined content...	// declining	if (overwriteDeclineReasons == true) {		this.declineReasons.length = 0; this.declineReasons = myDeclineReasons;	} else {		this.declineReasons = this.declineReasons.concat(myDeclineReasons);	}	// deleting	this.deleteReasons = this.deleteReasons.concat(myDeleteReasons);	// append necessary options to decline reasons	var declineReasonsEnd = new Array( ['INVALID', 		'The reason given is not a valid speedy deletion criterion'],	// don't touch this ['DONTPROVIDE', 	'No reason given.'], 						// don't touch this ['OTHER', 			'Other - provide your own reason below']	// don't touch this );	this.declineReasons = this.declineReasons.concat(declineReasonsEnd);	// main GUI function	this.showcsdHWindow = function {		// grab position of button		var offset = document.getElementById('ca-speedy').offsetLeft;		// build window to show user		if (waUser.isSysop == true) { var showSys = 'Delete Page ' } else { var showSys = ; }		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 = +								' Handle Speedy Deletion '+								' What do you want to do to this page? '+								' '+									showSys+ 'Decline Speedy '+ 'Change to PROD '+ ' '+								'';		} else { this.interface.win_content = ''+ ' Handle Speedy Deletion '+ ' What do you want to do to this page? '+								' '+									showSys+ 'Decline Speedy '+ 'Change to PROD '+ ' '+								'';			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.win_height = 170; 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 = 170; 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 = ''; var optionSelected = false; for (var i = 0; i < this.declineReasons.length; i++) { var selected = ''; // determine whether this option should be selected if (optionSelected == false) { if (document.getElementById('delete-criterion') != null) { // if this matches the criterion provided, select it. if (document.getElementById('delete-criterion').innerHTML == this.declineReasons[i][0]) { selected = ' selected '; optionSelected = true; } if ( (this.declineReasons[i][0] == 'INVALID') && (optionSelected == false) ) { selected = ' selected '; optionSelected = true; } } else { // if no criterion was selected, wait until 'other' is selected. if (this.declineReasons[i][0] == 'OTHER') { selected = ' selected '; optionSelected = true; } }			}			// build the visible message for use in the drop-down. var tempVisible = myDeclineListing.replace(/%CRITERION%/gi, this.declineReasons[i][0]); tempVisible = tempVisible.replace(/%REASON%/gi, this.declineReasons[i][1]); declineOptions += ''+tempVisible+' '; }		this.interface.win_content = ''+ ' Decline Speedy Deletion '+ ' Select the reason for declining the deletion from the list. This text will be used as the edit summary. '+								''+declineOptions+' '+ ' Or provide your own reason and summary below. '+								''+ ' -- decline speedy deletion -- '+ ' notify tagger  '+ ' '+								'';		this.interface.applyAll; }	this.declineDo = function(callback) { // get page content if (!callback) var callback = 0; switch (callback) { default: // main vars csdHController.declineText = 	document.getElementById('declineText').value; csdHController.declineSel = 	document.getElementById('declineReason').selectedIndex; csdHController.declineNotify = 	document.getElementById('notifyTagger').checked; if ((csdHController.declineText == '') && (csdHController.declineSel == csdHController.declineReasons.length-1)) { // if no reason is typed, byt 'Other' is selected, use the 'No reason provided' option. csdHController.declineSel = csdHController.declineReasons.length - 2; }				csdHController.declineCategory 	= 	csdHController.declineReasons[csdHController.declineSel][0]; csdHController.declineReason 	=	csdHController.declineReasons[csdHController.declineSel][1]; // build all messages if ( (csdHController.declineCategory == 'INVALID') || (csdHController.declineCategory == 'DONTPROVIDE') ) { // if it's a 'special' case, use the 'special' summary var tempSummary = myDeclineSummarySpecial; tempSummary = tempSummary.replace(/%ACTION%/gi, csdHController.decAction); tempSummary = tempSummary.replace(/%REASON%/gi, csdHController.declineReason); csdHController.editSummary = tempSummary; } else if (csdHController.declineCategory == 'OTHER') { // if they've typed a reason, use that var tempSummary = myDeclineSummarySpecial; tempSummary = tempSummary.replace(/%ACTION%/gi, csdHController.decAction); tempSummary = tempSummary.replace(/%REASON%/gi, csdHController.declineText); csdHController.editSummary = tempSummary; } else { // otherwise, use the 'normal' summary var tempSummary = myDeclineSummary; tempSummary = tempSummary.replace(/%ACTION%/gi, csdHController.decAction); tempSummary = tempSummary.replace(/%CRITERION%/gi, csdHController.declineCategory); tempSummary = tempSummary.replace(/%REASON%/gi, csdHController.declineReason); csdHController.editSummary = tempSummary; }				csdHController.editSummary += ' (CSDH)'; // start this.interface.win_content = ''+ ' Working... '+								' Please wait while CSDHelper performs the requested operations. This can take several seconds. '+								' - Retrieving existing content... '+								' '+								'';				this.interface.applyAll; csdHController.pageReq = new wa_mediawikiApi; csdHController.pageReq.onCompleteAction = function { csdHController.declineDo('1'); }; csdHController.pageReq.getPage(wgPageName, notifyLimit, 'user|content'); break; case '1': document.getElementById('workingStatus').innerHTML += '- Removing tags... ';				csdHController.pageContent = csdHController.pageReq.data['page']['revisions'][0]['content']; var regReplace = csdHController.deleteRegex; csdHController.pageContent = csdHController.pageContent.replace(regReplace, ''); var regReplace = csdHController.hangonRegex; csdHController.pageContent = csdHController.pageContent.replace(regReplace, ''); csdHController.newContent = csdHController.pageContent; // grab a record of that document.getElementById('workingStatus').innerHTML += '- Updating page... ';				csdHController.editReq = new wa_mediawikiApi; csdHController.editReq.onCompleteAction = function { csdHController.declineDo('2'); }; csdHController.editReq.editPage(wgPageName, csdHController.newContent, csdHController.editSummary, false, 'text'); break; case '2': // check for notify if (csdHController.declineNotify || declineLogPath != null) { document.getElementById('workingStatus').innerHTML += '- Determining user who tagged page... ';					var tags = 0; csdHController.tagger = ''; for (var i = 0; i < notifyLimit; i ++) { var thisPage = csdHController.pageReq.data['page']['revisions'][i]['content']; // count tags var regTest = csdHController.deleteRegex; var k = 1; var count = 0; while (k != null) { k = regTest.exec(thisPage); if (k != null) count ++; }						regTest.lastIndex = 0; // check if we have fewer than last time (1 was added on that rev) if (count < tags) { csdHController.tagger = csdHController.pageReq.data['page']['revisions'][i - 1]['user']; break; } else { tags = count; }					}					if (csdHController.tagger == '') { document.getElementById('workingStatus').innerHTML += '- Could not determine tagger: will not notify. Finished. '; break; } for (var i = 0; i < csdHController.notifyExempt.length; i ++) { if (csdHController.tagger == csdHController.notifyExempt[i]) { document.getElementById('workingStatus').innerHTML += '- Tagger ('+csdHController.tagger+') is on the tagger exempt list, and will not be notified. Finished. ';							return true; }					}                               if(declineLogPath != null) {                                  csdHLogDecline; }                                       if(csdHController.declineNotify) {

document.getElementById('workingStatus').innerHTML += '- Tagged by \''+csdHController.tagger+'\' - notifying user... ';					    csdHController.declineDo('3'); } 					} else { window.location.reload(true); csdHController.showcsdHWindow; } break; case '3': // edit summary csdHController.editSummary = 'Notifying about '+csdHController.decAction+' speedy deletion (CSDH)'; // fix message - handle other special case if (csdHController.declineCategory == 'OTHER') csdHController.declineReason = csdHController.declineText; // fix message - handle punctuation at the end of the message (it must be added if absent). var p = csdHController.declineReason.substr(csdHController.declineReason.length - 1); if ( (p != '.') && (p != '!') && (p != '?') ) csdHController.declineReason += '.'; // message var message = '== Speedy deletion '+csdHController.decAction+': '+wgPageName.replace(/_/g, ' ')+' == \nHi '+csdHController.tagger+'! \n\nI '+csdHController.decAction+' the speedy deletion of '+wgPageName.replace(/_/g, ' ')+'. ' + csdHController.declineReason + ' Regards, '+''; csdHController.saveReq = new wa_mediawikiApi; csdHController.saveReq.onCompleteAction = function { window.location.reload(true); csdHController.showcsdHWindow; }; csdHController.saveReq.editPage('User_talk:'+csdHController.tagger, message, csdHController.editSummary, false, 'appendtext');

break; }	}	this.prodPage = function { var prodOptions = ''; var content = document.getElementById('bodyContent'); var regTest = /criteria for speedy deletion<\/a><\/i> because (.*?)\.<\/b> For valid criteria,/i var rationale = regTest.exec(content); if (rationale != null) { rationale = rationale[1]; } else { rationale = ''; } this.interface.win_content = ''+ ' Convert to PROD '+ ' You are asserting that the page cannot be speedy deleted, but can be deleted by proposed deletion. '+								'Enter the reason for deletion below - if the tagger provided one, it will be filled automatically. '+								''+ 'notify tagger of convertion  '+ ' -- convert to PROD</a> -- '+ ' '+								'';		this.interface.applyAll; }	this.prodDo = function(callback) { if (!callback) var callback = 0; switch (callback) { default: csdHController.prodReason = document.getElementById('prodReason').value; csdHController.prodNotify = document.getElementById('notifyTagger').checked; this.interface.win_content = ''+ ' Working... '+								' Please wait while CSDHelper performs the requested operations. This can take several seconds. '+								' '+								' '+								'';				this.interface.applyAll; if (csdHController.prodNotify == true) { document.getElementById('workingStatus').innerHTML += '- Searching for tagger... ';					if (notifyLimit > 15) notifyLimit = 15; csdHController.pageReq = new wa_mediawikiApi; csdHController.pageReq.onCompleteAction = function { csdHController.prodDo('1'); }; csdHController.pageReq.getPage(wgPageName, notifyLimit + 1, 'content|user'); } else { csdHController.pageReq = new wa_mediawikiApi; csdHController.pageReq.onCompleteAction = function { csdHController.prodDo('3'); }; csdHController.pageReq.getPage(wgPageName, 1, 'content|user'); }				break; case '1': var tags = 0; csdHController.tagger = ''; for (var i = 0; i < notifyLimit; i ++) { var thisPage = csdHController.pageReq.data['page']['revisions'][i]['content']; // count tags var regTest = csdHController.deleteRegex; var k = 1; var count = 0; while (k != null) { k = regTest.exec(thisPage); if (k != null) count ++; }					regTest.lastIndex = 0; // check if we have fewer than last time (1 was added on that rev) if (count < tags) { csdHController.tagger = csdHController.pageReq.data['page']['revisions'][i - 1]['user']; break; } else { tags = count; }				}				if (csdHController.tagger == '') { document.getElementById('workingStatus').innerHTML += '- Could not determine tagger. Moving to tag page... '; csdHController.prodDo('3'); break; } for (var i = 0; i < csdHController.notifyExempt.length; i ++) { if (csdHController.tagger == csdHController.notifyExempt[i]) { document.getElementById('workingStatus').innerHTML += '- Tagger ('+csdHController.tagger+') is on the tagger exempt list, and will not be notified. Moving to tag page... ';						csdHController.prodDo('3'); return true; }				}				csdHController.prodDo('2'); break; case '2': // notify tagger document.getElementById('workingStatus').innerHTML += '- Tagged by \''+csdHController.tagger+'\' - notifying user... ';				// edit summary csdHController.editSummary = 'Notifying about speedy deletion converted to PROD (CSDH)'; // message var message = 	'== Speedy Deletion Converted to PROD: '+wgPageName.replace(/_/g, ' ')+' == \nHello '+csdHController.tagger+', and thanks for your work patrolling new changes. I am just informing you that '+ 'I have changed a page you tagged ('+wgPageName.replace(/_/g, ' ')+') from being tagged for speedy deletion to being tagged for proposed deletion. '+								'The speedy deletion criteria are very narrow to protect the encyclopedia, and do not fit the page in question. Please review the criteria for speedy deletion before tagging further pages. '+								'If you have any questions or problems, please let me know. Thanks again! '+'';				csdHController.notifyReq = new wa_mediawikiApi; csdHController.notifyReq.onCompleteAction = function { csdHController.prodDo('3'); }; csdHController.notifyReq.editPage('User_talk:'+csdHController.tagger, message, csdHController.editSummary, false, 'appendtext'); break; case '3': document.getElementById('workingStatus').innerHTML += '- Converting tags... ';				csdHController.pageContent = csdHController.pageReq.data['page']['revisions'][0]['content']; var regReplace = csdHController.deleteRegex; csdHController.pageContent = csdHController.pageContent.replace(regReplace, ''); var regReplace = csdHController.hangonRegex; csdHController.pageContent = csdHController.pageContent.replace(regReplace, ''); if (csdHController.prodReason != 'nn') { csdHController.pageContent = '{'+'{subst:prod|'+csdHController.prodReason+'}'+'}\n' + csdHController.pageContent; } else { csdHController.pageContent = '{'+'{subst:prod-nn}'+'}\n' + csdHController.pageContent; } csdHController.newContent = csdHController.pageContent; // grab a record of that csdHController.editSummary = 'Speedy deletion converted to PROD (CSDH)'; document.getElementById('workingStatus').innerHTML += '- Updating page... ';				csdHController.editReq = new wa_mediawikiApi; csdHController.editReq.onCompleteAction = function { window.location.reload(true); csdHController.showcsdHWindow; }; csdHController.editReq.editPage(wgPageName, csdHController.newContent, csdHController.editSummary, false, 'text'); break; }	}	this.deletePage = function { // build the selection options var deleteOptions = ''; var optionSelected = false; for (var i = 0; i < this.deleteReasons.length; i++) { var selected = ''; if ( (document.getElementById('delete-criterion') != null) && (optionSelected == false) ) { if (document.getElementById('delete-criterion').innerHTML == this.deleteReasons[i][0]) { csdHController.initialRationale = this.deleteReasons[i][0]; selected = ' selected'; optionSelected = true; } } else { if (this.deleteReasons[i][0] == 'N/A') { selected = ' selected '; optionSelected = true; } }			// general var visibleReasoning = this.deleteReasons[i][1].replace(/\[\[(?:.*?\|)(.+?)\]\]/g, '$1'); deleteOptions += '<option value="'+i+'"'+selected+'>'+this.deleteReasons[i][0]+': '+visibleReasoning+' '; }		if (document.getElementById('delete-criterion') == null) { var displayTagCommand = 'display: none;'; } else { var displayTagCommand = 'display: block;'; } this.interface.win_content = ''+ ' Perform Speedy Deletion '+ ' Select the reason for deletion from the list. The rationale specified by the tagger is automatically selected. If you select a reason that does not '+ 'match the tag, will be given the option of notifying the tagger. '+								'<select id="deleteReason" style="font-size: 11px; margin-left: 9px; width: 576px;" onchange="'+									'if (document.getElementById(\'delete-criterion\') != null) {'+										'if (csdHController.deleteReasons[document.getElementById(\'deleteReason\').selectedIndex][0] != document.getElementById(\'delete-criterion\').innerHTML) { '+											'if (csdHController.deleteReasons[document.getElementById(\'deleteReason\').selectedIndex][0] == \'N/A\') { document.getElementById(\'notifyTaggerDiv\').style.display = \'none\'; } else { document.getElementById(\'notifyTaggerDiv\').style.display = \'block\'; }'+										'} else {'+											'document.getElementById(\'notifyTaggerDiv\').style.display = \'none\'; '+										'}'+									'} else { document.getElementById(\'notifyTaggerDiv\').style.display = \'none\'; }'+									'if (csdHController.deleteReasons[document.getElementById(\'deleteReason\').selectedIndex][0] == \'N/A\') {'+ 'document.getElementById(\'performDeletionDiv\').style.display = \'none\'; '+ '} else {'+ 'document.getElementById(\'performDeletionDiv\').style.display = \'block\'; '+ '}'+								'">'+deleteOptions+' '+								'<div id="notifyTaggerDiv" style="display: none; margin-top: 10px; font-size: 11px; margin-left: 20px; float: left; vertical-align: middle;">notify tagger of rationale change <input id="notifyTagger"'+csdHController.doNotifyDel+' style="position: relative; top: 3px; " type="checkbox" /> '+								'<div id="performDeletionDiv" style="margin: auto; margin-top: 13px; font-size: 11px; width: 200px; text-align: center; '+displayTagCommand+'">-- <a href="#" onclick="csdHController.deleteDo;">perform speedy deletion</a> -- '+								' '+								'';		this.interface.applyAll;	}	this.deleteDo = function(callback) {		if (!callback) var callback = 0;		switch (callback) {			default:				csdHController.deleteSel 		= document.getElementById('deleteReason').selectedIndex;				csdHController.deleteNotify 	= document.getElementById('notifyTagger').checked; if (document.getElementById('delete-criterion') == null) { csdHController.allowDelNotify = false; } else { csdHController.allowDelNotify = (csdHController.deleteReasons[csdHController.deleteSel][0] != document.getElementById('delete-criterion').innerHTML); } this.interface.win_content = ''+ ' Working... '+								' Please wait while CSDHelper performs the requested operations. This can take several seconds. '+								' '+								' '+								'';				this.interface.applyAll; if ((csdHController.deleteNotify == true) && (csdHController.allowDelNotify == true)) { document.getElementById('workingStatus').innerHTML += '- Searching for tagger... ';					if (notifyLimit > 15) notifyLimit = 15; csdHController.pageReq = new wa_mediawikiApi; csdHController.pageReq.onCompleteAction = function { csdHController.deleteDo('1'); }; csdHController.pageReq.getPage(wgPageName, notifyLimit + 1, 'content|user'); } else { csdHController.deleteDo('3'); } break; case '1': var tags = 0; csdHController.tagger = ''; for (var i = 0; i < notifyLimit; i ++) { var thisPage = csdHController.pageReq.data['page']['revisions'][i]['content']; // count tags var regTest = csdHController.deleteRegex; var k = 1; var count = 0; while (k != null) { k = regTest.exec(thisPage); if (k != null) count ++; }					regTest.lastIndex = 0; // check if we have fewer than last time (1 was added on that rev) if (count < tags) { csdHController.tagger = csdHController.pageReq.data['page']['revisions'][i - 1]['user']; break; } else { tags = count; }				}				if (csdHController.tagger == '') { document.getElementById('workingStatus').innerHTML += '- Could not determine tagger. Moving to deletion... '; csdHController.deleteDo('3'); break; } for (var i = 0; i < csdHController.notifyExempt.length; i ++) { if (csdHController.tagger == csdHController.notifyExempt[i]) { document.getElementById('workingStatus').innerHTML += '- Tagger ('+csdHController.tagger+') is on the tagger exempt list, and will not be notified. Moving to deletion... ';						csdHController.deleteDo('3'); return true; }				}				csdHController.deleteDo('2'); break; case '2': // notify tagger document.getElementById('workingStatus').innerHTML += '- Tagged by \''+csdHController.tagger+'\' - notifying user... ';				// edit summary csdHController.editSummary = 'Notifying about altered speedy deletion rationale (CSDH)'; // message var message = 	'== Altered Speedy Deletion rationale: '+wgPageName.replace(/_/g, ' ')+' == \nHello '+csdHController.tagger+', and thanks for your work patrolling new changes. I am just informing you that '+ 'I have deleted a page you tagged ('+wgPageName.replace(/_/g, ' ')+') under a criterion different from the one your provided, which was inappropriate or incorrect. CSD criteria are narrow and specific '+ 'to protect the encyclopedia, and the process is more effective if the correct deletion rationale is supplied. Consider reviewing the criteria for speedy deletion. '+								'If you have any questions or problems, please let me know. Thanks again! '+'';				csdHController.notifyReq = new wa_mediawikiApi; csdHController.notifyReq.onCompleteAction = function { csdHController.deleteDo('3'); }; csdHController.notifyReq.editPage('User_talk:'+csdHController.tagger, message, csdHController.editSummary, false, 'appendtext'); break; case '3': // perform the edit document.getElementById('workingStatus').innerHTML += '- Deleting page... ';				var deleteReason = ''+csdHController.deleteReasons[csdHController.deleteSel][0]+': ' + csdHController.deleteReasons[csdHController.deleteSel][1] + ' (CSDH)'; csdHController.deleteReq = new wa_mediawikiApi; csdHController.deleteReq.onCompleteAction = function(callback) { if ( (callback == null) || (callback == false) || (wgNamespaceNumber != 0) ) { // no talk page window.location = redirectAfterDel; csdHController.showcsdHWindow; } else { // talk page exists csdHController.talkpageId = callback; document.getElementById('workingStatus').innerHTML = ''+ ' Warning: this page now has an orphaned talk page. Do you wish to delete it under G8?

'+																							' <a href="#" onclick="document.getElementById(\'workingStatus\').innerHTML = \'- Deleting talk page... \'; csdHController.deleteDo(\'4\');">Delete</a> | <a href="#" onclick="window.location = redirectAfterDel; csdHController.showcsdHWindow; ">Ignore</a> '+ '';																					}																				};				csdHController.deleteReq.performAction('delete', wgPageName, deleteReason); break; case '4': // delete the talk page - get the title var talkPage = 'Talk:' + wgPageName; csdHController.deleteReq = new wa_mediawikiApi; csdHController.deleteReq.onCompleteAction = function { window.location = redirectAfterDel; csdHController.showcsdHWindow; }; csdHController.deleteReq.performAction('delete', talkPage, 'G8: Talk page of deleted page. (CSDH)'); break; }	}	this.displayError = function { this.interface.win_content = ''+ ' An error occured... '+								' '+								'';		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);