User:MZMcBride/twinklespeedy.js

// If TwinkleConfig aint exist. if( typeof( TwinkleConfig ) == 'undefined' ) { TwinkleConfig = {}; }

/** TwinkleConfig.watchSpeedyPages (array) What types of actions that should result in forced addition to watchlist */ if( typeof( TwinkleConfig.watchSpeedyPages ) == 'undefined' ) { TwinkleConfig.watchSpeedyPages = [ ]; }

/** TwinkleConfig.markSpeedyPagesAsMinor (boolean) If, when applying speedy template to page, to mark the edit as minor, default true */ if( typeof( TwinkleConfig.markSpeedyPagesAsMinor ) == 'undefined' ) { TwinkleConfig.markSpeedyPagesAsMinor = false; }

/** TwinkleConfig.notifyUserOnSpeedyDeletionNomination (array) What types of actions that should result that the author of the page should be notified of nomination */ if( typeof( TwinkleConfig.notifyUserOnSpeedyDeletionNomination ) == 'undefined' ) { TwinkleConfig.notifyUserOnSpeedyDeletionNomination = [ 't1', 't2', 't3' ]; }

/** TwinkleConfig.userTalkPageMode may take arguments: 'window': open a new window, remember the opened window 'tab': opens in a new tab, if possible. 'blank': force open in a new window, even if a such window exist */ if( typeof( TwinkleConfig.userTalkPageMode ) == 'undefined' ) { TwinkleConfig.userTalkPageMode = 'window'; }

/** TwinkleConfig.toolboxButtons (string) If id defined in this array, the button of the action is located in the toolbox instead of in the actions bar. */ if( typeof( TwinkleConfig.toolboxButtons ) == 'undefined' ) { TwinkleConfig.toolboxButtons = []; }

/** TwinkleConfig.orphanNormalPagesOnSpeedyDelete (hash) Defines if all backlinks to a page should be removed. property 'exclude' defined actions not to orphan */ if( typeof( TwinkleConfig.orphanBacklinksOnSpeedyDelete ) == 'undefined' ) { TwinkleConfig.orphanBacklinksOnSpeedyDelete = { exclude: ['g6'], orphan:true }; }

function twinklespeedy { if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) { return; }	if (wgNamespaceNumber == 10) { mw.util.addPortletLink( 'p-cactions', "javascript:twinklespeedy.callback", "csd", "tw-csd", "Tag for speedy deletion", ""); } } $(twinklespeedy);

twinklespeedy.callback = function twinklespeedyCallback { var Window = new SimpleWindow( 270, 160 ); Window.setTitle( "Choose criteria for speedy deletion" );

var form = new QuickForm( userIsInGroup( 'sysop' ) ? twinklespeedy.callback.evaluateSysop : twinklespeedy.callback.evaluateUser, 'change' ); if( userIsInGroup( 'sysop' ) ) { form.append( {				type: 'checkbox',				list: [					{						label: 'Tag page only, don\'t delete',						value: 'tag_only',						name: 'tag_only',						checked: true,						tooltip: '',						event: function( event ) {							event.target.form.notify.disabled = ! event.target.checked;							event.stopPropagation;						}					},				]			} ); }

form.append( {			type: 'checkbox',			list: [				{					label: 'Notify if possible',					value: 'notify',					name: 'notify',					checked: true,					tooltip: '',					event: function( event ) {						event.stopPropagation;					}				}			]		}	);

if( wgNamespaceNumber == 10 || wgNamespaceNumber == 11 ) { form.append( { type:'header', label: 'Templates' } ); form.append( {			type: 'radio',			name: 'csd',			list: [

{ 					label: 'T3: Templates that are deprecated or orphaned', value: 'deporph', }			]		} ); }

var result = form.render; Window.setContent( result ); Window.display; }

twinklespeedy.normalizeHash = { 'deporph': 't3', };

twinklespeedy.reasonHash = { 'deporph': 'was a deprecated or orphaned template', };

twinklespeedy.callbacks = { user: { main: function( self ) { var xmlDoc = self.responseXML;

var exists = xmlDoc.evaluate( 'boolean(//pages/page[not(@missing)])', xmlDoc, null, XPathResult.BOOLEAN_TYPE, null ).booleanValue;

if( ! exists ) { self.statelem.error( "It seems that the page doesn't exists, perhaps it has already been deleted" ); return; }			var query = { 'title': wgPageName, 'action': 'submit' };

var wikipedia_wiki = new Wikipedia.wiki( 'Tagging page', query, twinklespeedy.callbacks.user.tagPage ); wikipedia_wiki.params = self.params; wikipedia_wiki.followRedirect = false; wikipedia_wiki.get; },		tagPage: function( self ) { form = this.responseXML.getElementById( 'editform' );

var text = form.wpTextbox1.value;

self.statelem.status( 'Checking for tags on the page...' );

var tag = /(\{\{(?:db-?|delete)\|?.*?\}\})/.exec( text );

if( tag ) { self.statelem.error( [ htmlNode( 'strong', tag[0] ), " is already placed on the page." ] ) return; }

var xfd = /(\{\{(?:[rsaitcm]fd|md1)[^{}]*?\}\})/i.exec( text );

if( xfd && !confirm( "The deletion related template " + xfd[0] + " is already present on the page, do you still want to apply CSD template?" ) ) {				return; }			var code; switch( self.params.normalized ) { default: code = "\{\{subst:db-deporph\}\}"; break; }

// Notification to first contributor var query = { 'action': 'query', 'prop': 'revisions', 'titles': wgPageName, 'rvlimit': 1, 'rvprop': 'user', 'rvdir': 'newer' }			var callback = function( self ) { var xmlDoc = self.responseXML; var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue; var query = { 'title': 'User talk:' + user, 'action': 'submit' };				var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, twinklespeedy.callbacks.user.userNotification ); wikipedia_wiki.params = self.params; wikipedia_wiki.get; }

if( self.params.usertalk ) { var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback ); wikipedia_api.params = self.params; wikipedia_api.post; }

var postData = { 'wpMinoredit': TwinkleConfig.markSpeedyPagesAsMinor ? '' : undefined, 'wpWatchthis': self.params.watch ? '' : undefined, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': "tagging for speedy deletion", 'wpTextbox1': code + "\n" + text };			self.post( postData ); },		userNotification: function( self ) { var form = self.responseXML.getElementById( 'editform' ); var text = form.wpTextbox1.value; text += "\n\{\{subst:Db-T3-notice|1=" + wgPageName + "\}\}"; var postData = { 'wpMinoredit': form.wpMinoredit.checked ? '' : undefined, 'wpWatchthis': form.wpWatchthis.checked ? '' : undefined, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': 'notification of speedy deletion nomination of \[\[' + wgPageName + '\]\]', 'wpTextbox1': text };			self.post( postData ); }	} }

twinklespeedy.callback.evaluateSysop = function twinklespeedyCallbackEvaluateSysop(e) {

wgPageName = wgPageName.replace( /_/g, ' ' ); // for queen/king/whatever and country!

var tag_only = e.target.form.tag_only; if( tag_only && tag_only.checked ) { return twinklespeedy.callback.evaluateUser(e); }

var value = e.target.value; var normalized = twinklespeedy.normalizeHash[ value ];

var params = { value: value, normalized: normalized, watch: TwinkleConfig.watchSpeedyPages.indexOf( normalized ) != -1, reason: twinklespeedy.reasonHash[ value ] };	Status.init( e.target.form );

var query = { 'action': 'query', 'titles': wgPageName }	var wikipedia_api = new Wikipedia.api( 'Checking if page exists', query, twinklespeedy.callbacks.sysop.main ); wikipedia_api.params = params; wikipedia_api.post; }

twinklespeedy.callback.evaluateUser = function twinklespeedyCallbackEvaluateUser(e) { wgPageName = wgPageName.replace( /_/g, ' ' ); // for queen/king/whatever and country! var value = e.target.value; var normalized = twinklespeedy.normalizeHash[ value ];

var params = { value: value, normalized: normalized, watch: TwinkleConfig.watchSpeedyPages.indexOf( normalized ) != -1, usertalk: TwinkleConfig.notifyUserOnSpeedyDeletionNomination.indexOf( normalized ) != -1 && e.target.form.notify.checked };

Status.init( e.target.form );

Wikipedia.actionCompleted.redirect = wgPageName; Wikipedia.actionCompleted.notice = "Tagging complete";

var query = { 'action': 'query', 'titles': wgPageName }

var wikipedia_api = new Wikipedia.api( 'Checking if page exists', query, twinklespeedy.callbacks.user.main ); wikipedia_api.params = params; wikipedia_api.post;

}