User:RobinK/ratemath.js

//Script taken from User:CBM/ratemath.js. //Edited to change the following: //1. Order of fields displayed //2. Don't add page to watchlist by default //3. Custom edit summary //4. Added FL and List classes //5. Added C class

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

/** TwinkleConfig.summaryAd (string) If ad should be added or not to summary, default TWINKLE */ if( typeof( TwinkleConfig.summaryRatedAd ) == 'undefined' ) { TwinkleConfig.summaryRatedAd = " (script assisted). Please report any errors on my talk page."; }

/** TwinkleConfig.watchRatedMathPages (boolean) If, when applying rating template to page, watch it, default true */ if( typeof( TwinkleConfig.watchRatedMathPages ) == 'undefined' ) { TwinkleConfig.watchRatedMathPages = false; } function twinklerate { if( (wgNamespaceNumber != 0 && wgNamespaceNumber != 1) || wgCurRevisionId == false ) { return; }	mw.util.addPortletLink( 'p-cactions', "javascript:twinklerate.callback",                        "Rate math", "tw-rate", "Rate article for WikiProject Mathematics", ""); } $(twinklerate); twinklerate.callback = function twinklerateCallback { var Window = new SimpleWindow( 600, 250 ); Window.setTitle( "Rate article" ); var form = new QuickForm( twinklerate.callback.evaluate ); form.append( {				type: 'select',				name: 'quality',				label: 'Quality: ',				list: [					{ label: 'Stub class', value: 'Stub' },					{ label: 'Start class', value: 'Start' },					{ label: 'C class', value: 'C' },					{ label: 'B class', value: 'B' },					{ label: 'B+ class', value: 'Bplus' },					{ label: 'Good Article', value: 'GA' },					{ label: 'A class', value: 'A' },					{ label: 'Featured Article', value: 'FA' },					{ label: 'Featured List', value: 'FL' },					{ label: 'List', value: 'List' }			             ]   			} ); form.append( {				type: 'select',				name: 'priority',				label: 'Priority: ',				list: [					{ label: 'Low', value: 'Low' },					{ label: 'Mid', value: 'Mid' },					{ label: 'High', value: 'High' },					{ label: 'Top', value: 'Top' },			             ]   			} ); form.append( {				type: 'select',				name: 'field',				label: 'Field: ',				list: [               { label: 'Discrete mathematics', value: 'discrete' },		{ label: 'General', value: 'general' },		{ label: 'Analysis', value: 'analysis' },		{ label: 'Algebra', value: 'algebra' },		{ label: 'Applied mathematics', value: 'applied' },		{ label: 'Basic topics (elementary material and common facts)', value: 'basics' },                { label: 'Foundations (logic and set theory)', value: 'foundations' },        	{ label: 'Geometry', value: 'geometry' },                { label: 'History', value: 'history' },                { label: 'Mathematical Physics', value: 'mathematical physics' },                { label: 'Mathematicians', value: 'mathematicians' },                { label: 'Number theory', value: 'number theory' },                { label: 'Probability and statistics', value: 'probability and statistics' }, { label: 'Topology', value: 'topology' } ]  		} );	form.append( { type:'submit' } );	var result = form.render;	Window.setContent( result );	Window.display; } twinklerate.callbacks = {	main: function( self ) {		var form = self.responseXML.getElementById('editform');                var text = ;                if ( form == null ) { alert ("null"); }                if ( form != null ) { text = form.wpTextbox1.value; }		if(  text.search(/\{\{[mM]ath(s)?[ _]?rating/) != -1 ) {                   self.statelem.warn('Removing previous rating templates');		                   text =  text.replace(/\{\{[mM]aths?[ _]?rating([a-zA-Z |= \n])*\}\}/g,  );                     if(  text.search(/\{\{[mM]ath(s)?[ _]?rating/) != -1 ) {                      self.statelem.warn('Failed to remove previous templates, aborting');		 alert(text);                      return;                   }		}		var postData = {			'wpMinoredit': undefined, // Per memo 'wpWatchthis': TwinkleConfig.watchRatedMathPages ? 'true' : undefined, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': "Rating article for WikiProject Mathematics. Quality: " + self.params.quality + " / Priority: " + self.params.priority + " / Field: " +self.params.field + " " + TwinkleConfig.summaryRatedAd, 'wpTextbox1': "\{\{maths rating|class=" + self.params.quality + "|priority=" + self.params.priority + "|field=" +self.params.field + "}}\n" + text };		self.post( postData ); }, } twinklerate.callback.evaluate = function twinklerateCallbackEvaluate(e) { var form = e.target; var quality = form.quality.value; var priority = form.priority.value; var field = form.field.value; wgPageName = wgPageName.replace(/_/g, ' '); if ( wgNamespaceNumber == 0){ wgPageName = 'Talk:' + wgPageName; }	Status.init( form ); var query = { 'title': wgPageName, 'action': 'submit' };       Wikipedia.actionCompleted.redirect = wgPageName; Wikipedia.actionCompleted.notice = "Tagging complete, reloading talk page in some seconds"; var wikipedia_wiki = new Wikipedia.wiki('Tagging page', query, twinklerate.callbacks.main); wikipedia_wiki.params = { quality: quality, priority: priority, field: field}; wikipedia_wiki.followRedirect = false; wikipedia_wiki.get; }