Jump to content

User:Greg Tyler/categorise.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Greg Tyler (talk | contribs) at 17:11, 30 June 2009 (Right, let's see if this works *gulp*). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
function twinklecategorise() {
	addPortletLink( 'p-cactions', "javascript:twinklecategorise.callback()", "cat", "tw-cat", "Categorise deletion discussion", "");
}
addOnloadHook(twinklecategorise);

twinklecategorise.callback = function twinklecategoriseCallback() {
	var Window = new SimpleWindow( 800, 500 );
	Window.setTitle( "Choose category" );

	var form = new QuickForm( userIsInGroup( 'sysop' ) ? twinklespeedy.callback.evaluateSysop : twinklespeedy.callback.evaluateUser, 'change' );

		form.append( { type:'header', label:'Select a category' } );
		form.append ( {
				type: 'radio',
				name: 'csd',
				list: [
					{ 
						label: 'Media and music',
						value: 'M'
					},
					{ 
						label: 'Organisation, corporation, or product',
						value: 'O'
					},
					{ 
						label: 'Biographical',
						value: 'B'
					},
					{
						label: 'Society topics', 
						value: 'S'
					},
					{
						label: 'Web or internet',
						value: 'W'
					},
					{
						label: 'Games or sports',
						value: 'G'
					},
					{ 
						label: 'Science and technology',
						value: 'T'
					},
					{
						label: 'Fiction and the arts',
						value: 'F'
					},
					{
						label: 'Places and transportation',
						value: 'P'
					}
				]
			} );

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

twinklecategorise.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;
 
			var tag = /(\{\{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD\|(.*?)\}\})/.exec( text );
			if( !tag ) {
				self.statelem.error( [ htmlNode( 'strong', tag[0] ) , "Template not found!" ] );
				return;
			}


			text = str_replace(/(\{\{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD\|(.*?)\}\})/,"\{\{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD|" + self.params.value + "\}\}");
			var summaryText = "Categorising deletion discussion to [[:Category:AfD debates (" + categoryName + ")]].";
			

		var postData = {
			'wpMinoredit': undefined,
			'wpWatchthis': undefined,
			'wpStarttime': form.wpStarttime.value,
			'wpEdittime': form.wpEdittime.value,
			'wpAutoSummary': form.wpAutoSummary.value,
			'wpEditToken': form.wpEditToken.value,
			'wpSection': '',
			'wpSummary': summaryText + TwinkleConfig.summaryAd,
			'wpTextbox1': text
		};
 
		self.post( postData );
		}
	}
};