Jump to content

User:CBM/ratemath.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by CBM (talk | contribs) at 23:44, 19 October 2007 (Version 0.1). 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.
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = {};
}

/**
 TwinkleConfig.summaryAd (string)
 If ad should be added or not to summary, default [[WP:TWINKLE|TWINKLE]]
 */
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
	TwinkleConfig.summaryAd = " using [[WP:TW|TW]]";
}

/**
 TwinkleConfig.watchRatedMathPages (boolean)
 If, when applying rating template to page, watch it, default true
 */
if( typeof( TwinkleConfig.watchRatedMathPages ) == 'undefined' ) {
	TwinkleConfig.watchRatedMathPages = true;
}

function twinklerate() {
	if( (wgNamespaceNumber != 0 && wgNamespaceNumber != 1) || wgCurRevisionId == false ) {
		return;
	}
	addPortletLink( 'p-cactions', "javascript:twinklerate.callback()", 
                        "Rate", "tw-rate", "Rate article for WikiProject Mathematics", "");
}
addOnloadHook(twinklerate);

twinklerate.callback = function twinklerateCallback() {
	var Window = new SimpleWindow( 400, 300 );
	Window.setTitle( "Rate article" );
	var form = new QuickForm( twinklerate.callback.evaluate );
	form.append( {
				type: 'select',
				name: 'quality',
				label: 'Quality: ',
				list: [
					{ label: 'Featured Article', value: 'FA' },
					{ label: 'A class', value: 'A' },
					{ label: 'Good Article', value: 'GA' },
					{ label: 'B+ class', value: 'Bplus' },
					{ label: 'B class', value: 'B' },
					{ label: 'Start class', value: 'Start' },
					{ label: 'Stub class', value: 'Stub' }
			              ]   
			} );
        form.append( {
				type: 'select',
				name: 'priority',
				label: 'priority: ',
				list: [
					{ label: 'Top', value: 'Top' },
					{ label: 'High', value: 'High' },
					{ label: 'Mid', value: 'Mid' },
					{ label: 'Low', value: 'Low' }
			              ]   
			} );
        form.append( {
				type: 'select',
				name: 'field',
				label: 'Field: ',
				list: [
		{ 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: 'Discrete mathematics', value: 'discrete' },
                { 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 = form.wpTextbox1.value;

		var tag_re = /\{\{math(s)? rating/;
		if( tag_re.test( text ) ) {
	               self.statelem.warn('Page already has a rating template, aborting procedure');
			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" + TwinkleConfig.summaryAd,
			'wpTextbox1': "\{\{maths rating|quality=" + 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();
}